@font-face {
  font-family: Vazir;
  src: url("../fonts/Vazir-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: Vazir;
  src: url("../fonts/Vazir-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: Vazir;
  src: url("../fonts/Vazir-Bold.woff2") format("woff2");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #1c1915;
  --muted: #6d665e;
  --line: #e3dcd0;
  --paper: #f4f1ea;
  --card: #fffdf8;
  --green: #0c6b4d;
  --green-dark: #084d38;
  --cream: #f6f3ea;
  --amber: #8a5a00;
  --amber-bg: #fff6e8;
  --red: #9d2c2c;
  --red-bg: #fff4f2;
  --shadow: 0 10px 30px rgba(48, 36, 18, 0.08);
  font-family: Vazir, Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: #e5dfd3;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(480px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
}

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 16px;
  background: var(--green);
  color: var(--cream);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  display: grid;
  flex: 0 0 auto;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0;
}

.top p {
  color: rgba(246, 243, 234, 0.82);
  font-size: 0.86rem;
}

.ghost,
.text-btn,
.secondary,
.save,
.choice,
.tabbar button,
.sorts button,
.hint-close {
  border: 0;
  cursor: pointer;
}

.ghost {
  flex: 0 0 auto;
  border: 1px solid rgba(246, 243, 234, 0.45);
  border-radius: 999px;
  padding: 8px 14px;
  background: transparent;
  color: var(--cream);
  font-size: 0.92rem;
  font-weight: 700;
}

main {
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}

.hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px 12px 12px 8px;
  border-radius: 14px;
  background: #e7f3ed;
  color: var(--green-dark);
  font-size: 0.92rem;
}

.hint p {
  flex: 1;
}

.hint-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: transparent;
  color: var(--green-dark);
  font-size: 1.3rem;
  line-height: 1;
}

.fix {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.fix[data-state="ready"] {
  border-color: #b7dfc9;
  background: #f3faf6;
}

.fix[data-state="weak"],
.fix[data-state="stale"] {
  border-color: #efd3a1;
  background: var(--amber-bg);
}

.fix[data-state="updating"] {
  border-color: #b7d4ea;
  background: #f4f9fc;
}

.fix[data-state="denied"],
.fix[data-state="timeout"],
.fix[data-state="unsupported"],
.fix[data-state="insecure"] {
  border-color: #f0c2bc;
  background: var(--red-bg);
}

.fix[data-state="updating"] .fix-acc {
  animation: fix-pulse 0.9s ease-in-out infinite;
}

.fix-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.fix-kicker {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.fix-title {
  margin-top: 2px;
  font-size: 1.05rem;
  font-weight: 700;
}

.fix-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.fix-acc {
  margin: 0;
  min-width: 72px;
  padding-top: 2px;
  color: var(--green-dark);
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.1;
  text-align: left;
}

.fix[data-state="weak"] .fix-acc,
.fix[data-state="stale"] .fix-acc {
  color: var(--amber);
}

.fix[data-state="denied"] .fix-acc,
.fix[data-state="timeout"] .fix-acc,
.fix[data-state="unsupported"] .fix-acc,
.fix[data-state="insecure"] .fix-acc {
  color: var(--red);
}

.fix-coord {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: left;
}

.text-btn {
  margin-top: 8px;
  padding: 0;
  background: none;
  color: var(--green-dark);
  font-size: 0.92rem;
  font-weight: 700;
}

form {
  display: grid;
  gap: 12px;
}

.edit-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #efe7d4;
}

.edit-banner p {
  font-size: 0.92rem;
  font-weight: 700;
}

.edit-banner .text-btn {
  margin: 0;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 0.92rem;
  font-weight: 700;
}

.field em {
  color: var(--muted);
  font-style: normal;
  font-weight: 500;
}

.field small {
  color: var(--red);
  font-size: 0.85rem;
}

input {
  width: 100%;
  height: 52px;
  padding: 0 14px;
  border: 1px solid #d9d1c4;
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  font-size: 17px;
}

input:focus {
  outline: 3px solid rgba(12, 107, 77, 0.22);
  border-color: var(--green);
}

input[aria-invalid="true"] {
  border-color: var(--red);
}

#phoneInput {
  text-align: left;
}

.secondary,
.save,
.choice {
  min-height: 52px;
  border-radius: 14px;
  font-weight: 700;
}

.secondary {
  background: #efe7d4;
  color: var(--ink);
}

.secondary[aria-pressed="true"] {
  background: var(--green);
  color: white;
}

.save {
  background: var(--green);
  color: white;
  font-size: 1.05rem;
}

.save:active:not(:disabled) {
  background: var(--green-dark);
}

.save:disabled {
  opacity: 0.5;
  cursor: default;
}

.list-tools {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.search input {
  background: var(--card);
}

.sorts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sorts button {
  min-height: 42px;
  border-radius: 999px;
  background: #ebe4d8;
  color: var(--ink);
  font-weight: 700;
}

.sorts button[aria-pressed="true"] {
  background: var(--green);
  color: white;
}

.cards {
  display: grid;
  gap: 12px;
}

.card {
  padding: 14px;
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--green);
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card h2 {
  font-size: 1.08rem;
  line-height: 1.4;
}

.distance {
  flex: 0 0 auto;
  color: var(--green-dark);
  font-size: 0.85rem;
  font-weight: 800;
}

.phone {
  display: inline-block;
  margin-top: 6px;
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 800;
  text-decoration: none;
  direction: ltr;
}

.note {
  margin-top: 6px;
  color: #3f3a34;
}

.meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.meta.warn {
  color: var(--amber);
  font-weight: 700;
}

.actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.8fr;
  gap: 8px;
  margin-top: 12px;
}

.actions button {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: #efeae1;
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
}

.actions button[data-action="route"] {
  background: var(--green);
  color: white;
}

.actions button[data-action="delete"] {
  color: var(--red);
}

.empty {
  padding: 28px 8px;
  color: var(--muted);
  text-align: center;
}

.empty strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 1.05rem;
}

.tabbar {
  position: fixed;
  z-index: 6;
  bottom: 0;
  left: 50%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(480px, 100%);
  transform: translateX(-50%);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.96);
  backdrop-filter: blur(10px);
}

.tabbar button {
  position: relative;
  min-height: 48px;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tabbar button[aria-selected="true"] {
  background: #e7f3ed;
  color: var(--green-dark);
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.4rem;
  height: 1.4rem;
  margin-inline-start: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--green);
  color: white;
  font-size: 0.75rem;
  line-height: 1;
}

.toast {
  position: fixed;
  z-index: 20;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  width: min(440px, calc(100% - 24px));
  padding: 12px 14px;
  border-radius: 14px;
  background: #1c1915;
  color: white;
  font-weight: 700;
  text-align: center;
  transform: translateX(-50%) translateY(-16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

dialog {
  width: min(420px, calc(100% - 24px));
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(28, 25, 21, 0.48);
}

.sheet {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.sheet h2 {
  font-size: 1.15rem;
}

.sheet-copy {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.95rem;
}

.coord {
  direction: ltr;
  text-align: left;
}

.choice {
  display: grid;
  place-items: center;
  width: 100%;
  background: #efeae1;
  color: var(--ink);
  text-decoration: none;
}

.choice.danger {
  background: var(--red);
  color: white;
}

.choice.quiet {
  background: transparent;
  color: var(--muted);
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.photos-field {
  display: grid;
  gap: 8px;
}

.photos-field > span {
  font-size: 0.92rem;
  font-weight: 700;
}

.photos-field em {
  color: var(--muted);
  font-style: normal;
  font-weight: 500;
}

.photo-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.photo-row,
.card-photos {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.photo-tile {
  position: relative;
  flex: 0 0 auto;
  width: 84px;
  height: 84px;
}

.photo-tile img,
.card-photos img,
#viewerImg {
  display: block;
  width: 100%;
  height: 84px;
  object-fit: cover;
  border-radius: 12px;
  background: #efeae1;
}

.card-photos {
  margin-top: 10px;
}

.card-photos img {
  width: 72px;
  height: 72px;
}

.photo-remove {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: rgba(28, 25, 21, 0.72);
  color: white;
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

#viewerImg {
  width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
  background: #1c1915;
}

@keyframes fix-pulse {
  50% {
    opacity: 0.35;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }

  .fix[data-state="updating"] .fix-acc {
    animation: none;
  }
}
