/* Booth Leads — capture PWA.
   Designed for one-handed use at a noisy booth: the primary action never
   scrolls away, state is legible at arm's length, and nothing here needs a
   build step or a network round-trip. */

@font-face { font-family: Vazirmatn; src: url(/fonts/Vazirmatn-Regular.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: Vazirmatn; src: url(/fonts/Vazirmatn-Medium.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: Vazirmatn; src: url(/fonts/Vazirmatn-Bold.woff2) format('woff2'); font-weight: 700; font-display: swap; }

:root {
  /* surfaces */
  --bg: #f4f6fb;
  --card: #ffffff;
  --sunken: #eef1f7;
  --line: #dde3ed;
  --line-strong: #c3ccdb;

  /* ink */
  --ink: #0f1a2e;
  --ink-2: #47536b;
  --ink-3: #77839a;

  /* brand + status */
  --primary: #2249e6;
  --primary-ink: #ffffff;
  --primary-soft: #e7ecff;
  --ok: #0e7a45;
  --ok-soft: #dcf5e7;
  --warn: #9a5b00;
  --warn-soft: #fdf0d5;
  --danger: #c62525;
  --danger-soft: #fde7e7;

  /* geometry */
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --tap: 48px;

  --shadow-1: 0 1px 2px rgba(15, 26, 46, .06), 0 1px 3px rgba(15, 26, 46, .04);
  --shadow-2: 0 4px 14px rgba(15, 26, 46, .10);
  --shadow-up: 0 -6px 20px rgba(15, 26, 46, .10);

  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1020;
    --card: #131c30;
    --sunken: #0f172a;
    --line: #26324a;
    --line-strong: #3a4863;

    --ink: #e8edf7;
    --ink-2: #a8b4c9;
    --ink-3: #7d8aa2;

    --primary: #5b7cff;
    --primary-ink: #06102a;
    --primary-soft: #1b2748;
    --ok: #4ade9b;
    --ok-soft: #10301f;
    --warn: #f0b661;
    --warn-soft: #3a2a0c;
    --danger: #ff8a8a;
    --danger-soft: #3a1616;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 4px 14px rgba(0, 0, 0, .45);
    --shadow-up: 0 -6px 20px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.65 Vazirmatn, system-ui, sans-serif;
  overscroll-behavior-y: contain;
}

/* Persian numerals and Latin digits both need to read left-to-right. */
[dir='ltr'] { direction: ltr; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ---------- typography ------------------------------------------------- */

h1 { font-size: 26px; line-height: 1.35; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 19px; line-height: 1.4; margin: 0 0 6px; }
.brand { color: var(--ink-3); margin: 0 0 28px; font-size: 15px; }
.hint { color: var(--ink-3); font-size: 13.5px; line-height: 1.7; }
.opt { color: var(--ink-3); font-weight: 400; font-size: 12.5px; }
.muted { color: var(--ink-2); font-size: 13.5px; }

/* ---------- shell ------------------------------------------------------ */

.screen { padding: 16px; flex: 1; }
.screen.login { padding: 32px 20px; display: flex; flex-direction: column; justify-content: center; }

.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}

/* Segmented control — two screens, so a segmented switch beats a nav bar. */
.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--sunken);
  border-radius: 999px;
}

.tab {
  appearance: none;
  border: 0;
  background: none;
  font: 500 14.5px/1 Vazirmatn, system-ui, sans-serif;
  color: var(--ink-2);
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .16s, color .16s;
}
.tab.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow-1); font-weight: 700; }

/* ---------- sync status ------------------------------------------------ */

.status {
  margin-inline-start: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid transparent;
  background: var(--sunken);
  color: var(--ink-2);
  font: 500 13px/1 Vazirmatn, system-ui, sans-serif;
  padding: 9px 13px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 38px;
}
.status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
  flex: none;
}
.status.is-synced { color: var(--ok); background: var(--ok-soft); }
.status.is-pending { color: var(--warn); background: var(--warn-soft); }
.status.is-failed { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.status.is-syncing .dot { animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }

.offline-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 10px 16px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13.5px;
  font-weight: 500;
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 25%, transparent);
}

/* ---------- forms ------------------------------------------------------ */

label { display: block; font-weight: 500; font-size: 14px; margin: 0 0 14px; color: var(--ink-2); }

input, select, textarea {
  width: 100%;
  margin-top: 7px;
  padding: 13px 14px;
  min-height: var(--tap);
  font: 400 16px/1.5 Vazirmatn, system-ui, sans-serif;  /* 16px: iOS zooms below it */
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  transition: border-color .14s, box-shadow .14s;
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent);
}

textarea { resize: vertical; min-height: 76px; }

/* The mobile number is the field that matters most — give it presence. */
label.lead-mobile { margin-bottom: 8px; }
label.lead-mobile input {
  font-size: 23px;
  font-weight: 500;
  letter-spacing: .04em;
  padding: 15px 16px;
  min-height: 60px;
}

fieldset { border: 0; padding: 0; margin: 0 0 16px; }
legend { font-weight: 500; font-size: 14px; color: var(--ink-2); padding: 0; margin-bottom: 9px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  appearance: none;
  min-height: 44px;
  padding: 11px 17px;
  background: var(--card);
  color: var(--ink-2);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  font: 500 14.5px/1 Vazirmatn, system-ui, sans-serif;
  cursor: pointer;
  transition: transform .12s, border-color .14s, background .14s, color .14s;
}
.chip:active { transform: scale(.96); }
.chip.on {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
  font-weight: 700;
}
/* Lead temperature carries its own colour — set inline, ringed here. */
.chip.on.tinted { color: #fff; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 18%, transparent); }

/* Optional fields fold away: the fast path is mobile → name → chips → save. */
details.more {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  margin-bottom: 16px;
  overflow: hidden;
}
details.more > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: 14.5px;
  color: var(--ink-2);
}
details.more > summary::-webkit-details-marker { display: none; }
/* Chevron points down when closed, up when open — unambiguous in RTL. */
details.more > summary::after {
  content: '';
  margin-inline-start: auto;
  width: 9px; height: 9px;
  border-left: 2px solid var(--ink-3);
  border-bottom: 2px solid var(--ink-3);
  transform: rotate(-45deg);
  transition: transform .18s;
}
details.more[open] > summary::after { transform: rotate(135deg) translate(-2px, -2px); }
details.more[open] > summary { border-bottom: 1px solid var(--line); }
.more-body { padding: 16px 16px 2px; }
.more-body label:last-of-type { margin-bottom: 14px; }
.badge-count {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
}

/* ---------- alerts ----------------------------------------------------- */

.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--r);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 14px;
}
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert svg { flex: none; margin-top: 2px; }
.error { color: var(--danger); font-size: 14px; margin: 0 0 10px; }

/* ---------- buttons ---------------------------------------------------- */

button, .btn { font-family: inherit; cursor: pointer; }

.primary, a.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 54px;
  padding: 15px;
  background: var(--primary);
  color: var(--primary-ink);
  text-align: center;
  text-decoration: none;
  border: 0;
  border-radius: var(--r);
  font: 700 16.5px/1 Vazirmatn, system-ui, sans-serif;
  box-shadow: var(--shadow-1);
  transition: transform .12s, opacity .14s;
}
.primary:active { transform: scale(.985); }
.primary:disabled { opacity: .55; }

.secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 14px;
  background: var(--card);
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  font: 500 15.5px/1 Vazirmatn, system-ui, sans-serif;
  text-decoration: none;
}
.secondary:active { transform: scale(.985); }

/* Sticky action bar: at a booth you must be able to save without scrolling. */
.actionbar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow-up);
}
.actionbar .primary { flex: 1; }

.iconbtn {
  flex: none;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  color: var(--ink-2);
  position: relative;
}
.iconbtn.has-photo { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.iconbtn input { display: none; }

.photo-strip { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.photo-strip img { width: 56px; height: 56px; object-fit: cover; border-radius: var(--r-sm); border: 1px solid var(--line); }
.linkbtn { border: 0; background: none; color: var(--danger); font: 500 13.5px/1 Vazirmatn, system-ui, sans-serif; padding: 8px; }

/* ---------- my leads --------------------------------------------------- */

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.filters input { grid-column: 1 / -1; margin-top: 0; }
.filters select { margin-top: 0; min-height: 44px; padding: 10px 12px; font-size: 14.5px; }

.leads { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }

.lead {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
  box-shadow: var(--shadow-1);
}
.lead.unsent { border-inline-start: 3px solid var(--warn); }
.lead-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.lead-name { font-weight: 700; font-size: 16px; }
.lead-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; color: var(--ink-2); font-size: 13.5px; }
.lead-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.badge { color: #fff; font-size: 12px; font-weight: 700; padding: 4px 11px; border-radius: 999px; white-space: nowrap; }
.pill { font-size: 12px; font-weight: 500; padding: 4px 11px; border-radius: 999px; background: var(--sunken); color: var(--ink-2); }
.pill.dup { background: var(--warn-soft); color: var(--warn); }
.pill.wait { background: var(--warn-soft); color: var(--warn); }

.actions { display: flex; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.actions a, .actions button {
  flex: 1;
  min-height: 40px;
  display: grid;
  place-items: center;
  font: 500 13.5px/1 Vazirmatn, system-ui, sans-serif;
  color: var(--ink-2);
  background: var(--sunken);
  border: 0;
  border-radius: var(--r-sm);
  text-decoration: none;
}
.actions a:active, .actions button:active { transform: scale(.97); }
.followup { margin-top: 12px; display: grid; gap: 8px; }

.empty { text-align: center; padding: 48px 24px; color: var(--ink-3); }
.empty svg { margin-bottom: 12px; }
.empty p { margin: 0; font-size: 14.5px; }

/* ---------- success sheet ---------------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 28, .55);
  display: flex;
  align-items: flex-end;
  z-index: 40;
  animation: fade .16s ease-out;
}
.sheetbody {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 16px calc(18px + var(--safe-b));
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  animation: rise .22s cubic-bezier(.2, .9, .3, 1);
}
.grabber { width: 40px; height: 4px; border-radius: 999px; background: var(--line-strong); margin: 0 auto 14px; }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.tick {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--ok-soft); color: var(--ok);
  display: grid; place-items: center; flex: none;
}
.sheet-head h2 { margin: 0; }
.sheet-head p { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; }
.share { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.share a {
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 14px 6px;
  background: var(--sunken);
  border-radius: var(--r);
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}
.share a:active { transform: scale(.97); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(18px); opacity: .5; } }

/* ---------- footer ----------------------------------------------------- */

.foot {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 16px calc(12px + var(--safe-b));
  font-size: 13px;
  color: var(--ink-3);
  border-top: 1px solid var(--line);
  background: var(--card);
}
.foot select {
  width: auto;
  margin: 0;
  padding: 7px 10px;
  min-height: 36px;
  font-size: 13px;
  border-radius: var(--r-sm);
  background: var(--sunken);
  border-color: transparent;
}
.foot .who { font-weight: 500; color: var(--ink-2); }
.link { border: 0; background: none; color: var(--danger); margin-inline-start: auto; font: 500 13px/1 Vazirmatn, system-ui, sans-serif; padding: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
