/* ---------- Theme — SOLID, constant colors (ignores Telegram dark/light mode) ---------- */
:root {
  --bg:       #ffffff;   /* page background */
  --bg-2:     #f3f4f6;   /* secondary surface (filter row, toggle-card hover) */
  --fg:       #111827;   /* primary text */
  --muted:    #6b7280;   /* secondary text */
  --link:     #2563eb;   /* link blue */
  --btn:      #2563eb;   /* primary button */
  --btn-fg:   #ffffff;   /* primary button text */
  --border:   rgba(0,0,0,.08);
  --danger:   #dc2626;
  --success:  #16a34a;
  --warn:     #d97706;
  --pending:  #6b7280;
  --radius:   14px;
  --radius-sm: 10px;
  --pad:      14px;
  font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Tahoma, sans-serif;
  font-feature-settings: 'ss01', 'ss02';  /* Vazirmatn — nicer Persian variants */

  /* Override Telegram's own theme variables too, just in case any descendant
     element queries them directly. */
  color-scheme: light;
}

/* Form controls inherit the body font instead of the browser default. */
input, select, textarea, button {
  font-family: inherit;
}

/* min-width: 0 on every element prevents flex/grid children from forcing
   horizontal overflow when their min-content is wider than the cell. */
* { box-sizing: border-box; min-width: 0; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;       /* hard guard against any rogue overflow */
  background: var(--bg);
  color: var(--fg);
  -webkit-text-size-adjust: 100%;
}
body { font-size: 14px; line-height: 1.55; }

/* Anywhere we render free-form user text, wrap long unbroken strings
   (long URLs, brand IDs, etc.) instead of overflowing. */
.row-kv .v, .row-title, .row-sub, .section, .detail, .toast {
  overflow-wrap: anywhere;
  word-break: break-word;
}
img { max-width: 100%; height: auto; }

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- App bar ---------- */
.app-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.app-bar h1 {
  font-size: 16px; font-weight: 600; margin: 0; flex: 1;
  text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.icon-btn {
  background: transparent; border: 0; color: var(--fg);
  font-size: 22px; cursor: pointer; width: 32px; height: 32px;
  border-radius: 8px;
}
.icon-btn:hover { background: var(--bg-2); }
.user-chip { font-size: 12px; color: var(--muted); }

/* ---------- Main ---------- */
main {
  flex: 1;
  padding: 14px;
  /* Just enough space so content + form-nav clear the bottom tab bar. */
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  max-width: min(720px, 100%);
  width: 100%;
  margin: 0 auto;
  min-width: 0;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 8px; font-size: 18px; }
.card h3 { margin: 0 0 12px; font-size: 16px; }

.hero { text-align: center; padding: 28px 18px; }
.hero-emoji { font-size: 40px; margin-bottom: 6px; }
.hero p { margin: 8px 0 18px; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--bg-2);
  color: var(--fg);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 15px; font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  min-height: 42px;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--btn); color: var(--btn-fg); }
.btn-lg { padding: 14px 22px; font-size: 16px; width: 100%; }
.btn-mini { padding: 6px 10px; font-size: 13px; min-height: 34px; }
.btn-link { background: transparent; color: var(--link); padding: 8px; }
.btn[disabled] { opacity: .55; pointer-events: none; }

/* ---------- Form ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  /* Must stay >= 16px — anything smaller triggers iOS Safari's auto-zoom on focus. */
  font-size: 16px;
  font-family: inherit;
}
/* Also keep the combobox / filter / autocomplete inputs at >= 16px. */
.combobox input,
.filter-row select,
.suggestions li {
  font-size: 16px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--btn);
  outline-offset: -1px;
  border-color: transparent;
}
.field textarea { resize: vertical; }
.row { display: flex; gap: 8px; align-items: stretch; }
.row > select { flex: 1; }

/* ---------- Track picker ---------- */
.track-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
@media (max-width: 480px) {
  .track-grid { grid-template-columns: 1fr; }
}
.track-card {
  display: flex; flex-direction: column; gap: 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  background: var(--bg);
}
.track-card .t-emoji { font-size: 32px; }
.track-card .t-name  { font-weight: 700; font-size: 16px; }
.track-card .t-desc  { font-size: 12px; color: var(--muted); }
.track-card.selected {
  border-color: var(--btn);
  background: color-mix(in srgb, var(--btn) 8%, transparent);
}

/* ---------- Step indicator ---------- */
.steps {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
  padding: 0 0 12px;
}
.step {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 11px; color: var(--muted);
}
.step span {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg-2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
}
.step--active span { background: var(--btn); color: var(--btn-fg); }
.step--done span { background: var(--success); color: #fff; }

.step-panel { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.step-panel.hidden { display: none; }

/* ---------- Mobile tuning ---------- */
@media (max-width: 480px) {
  main { padding: 10px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .form-nav { padding: 10px 0; margin-top: 12px; }
  .form-nav .btn { padding: 8px 14px; font-size: 13px; min-height: 36px; min-width: 76px; }
  .form-nav .btn-primary { min-width: 96px; }
  .card { padding: 14px; border-radius: 12px; }
  .hero { padding: 22px 14px; }
  .app-bar { padding: 10px 12px; }
  .app-bar h1 { font-size: 15px; }
  .steps { gap: 2px; }
  .step { font-size: 10px; }
  .step span { width: 24px; height: 24px; font-size: 12px; }
  .toggle-card { padding: 12px; }
  .toggle-card .t-title { font-size: 14px; }
  .toggle-card .t-sub { font-size: 11px; }
  .channel-box { padding: 12px; }
  /* font-size stays at 16px on phones — anything less triggers iOS auto-zoom. */
  .field input, .field select, .field textarea { padding: 11px 12px; font-size: 16px; }
  .filter-row { flex-wrap: wrap; }
  .filter-row select { min-width: 0; flex: 1 1 140px; }
  .row { flex-wrap: wrap; }
  .row > select { min-width: 0; }
}
/* Extra-narrow phones: hide the step-label text, keep only the numbered chips. */
@media (max-width: 360px) {
  .step { font-size: 0; }     /* hides the label */
  .step span { font-size: 12px; }   /* re-enables font on the chip */
}

/* ---------- Combobox (autocomplete) ---------- */
.combobox { position: relative; }
.combobox input { width: 100%; }
.suggestions {
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  max-height: 240px;
  overflow-y: auto;
  position: absolute;
  inset-inline-start: 0;
  inset-inline-end: 0;
  z-index: 5;
}
.suggestions li {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-wrap: anywhere;
}
.suggestions li:hover, .suggestions li.active {
  background: var(--bg-2);
}
.suggestions li mark {
  background: color-mix(in srgb, var(--btn) 18%, transparent);
  color: inherit;
  padding: 0 1px;
  border-radius: 3px;
}
.suggestions li.add-new {
  border-top: 1px dashed var(--border);
  color: var(--link);
  font-weight: 500;
}
.suggestions li.add-new::before { content: '➕'; }

/* ---------- Toggle cards (channel selection) ---------- */
.toggle-card {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
}
.toggle-card:has(input:checked) {
  border-color: var(--btn);
  background: color-mix(in srgb, var(--btn) 8%, transparent);
}
.toggle-card input { width: 20px; height: 20px; accent-color: var(--btn); }
.t-title { display: block; font-weight: 600; }
.t-sub   { display: block; font-size: 12px; color: var(--muted); }

.channel-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.channel-box.hidden { display: none; }
.channel-box h4 { margin: 0 0 4px; }

/* ---------- Bottom nav ---------- */
.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  background: transparent; border: 0; color: var(--muted);
  padding: 12px 0;
  font-size: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  cursor: pointer;
}
.tab-icon { font-size: 18px; }
.tab--active { color: var(--btn); font-weight: 600; }

/* ---------- Form nav — sits at the natural end of the form, NOT fixed ---------- */
.form-nav {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  margin-top: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
/* Buttons size to their content — no full-width stretch. */
.form-nav .btn {
  flex: 0 0 auto;
  padding: 9px 18px;
  font-size: 14px;
  min-height: 38px;
  min-width: 84px;
}
.form-nav .btn-primary { min-width: 110px; }
/* Push the primary action (next or submit) to the inline end (left in RTL),
   while "previous" stays at the inline start (right in RTL). */
.form-nav #next-step,
.form-nav #submit-btn {
  margin-inline-start: auto;
}

/* ---------- List rows ---------- */
.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.list-row {
  display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  background: var(--bg);
}
.list-row:hover { background: var(--bg-2); }
.list-row .row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.list-row .row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .row-sub { font-size: 12px; color: var(--muted); }
.list-empty {
  padding: 24px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
}

/* ---------- Status badge ---------- */
.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  font-weight: 600;
}
.badge--pending  { background: rgba(107,114,128,.15); color: var(--pending); }
.badge--approved { background: rgba(22,163,74,.15);  color: var(--success); }
.badge--rejected { background: rgba(220,38,38,.15);  color: var(--danger);  }
.badge--assigned { background: rgba(217,119,6,.15);  color: var(--warn);    }
.badge--done     { background: rgba(37,99,235,.15);  color: var(--link);    }

/* ---------- Filter row ---------- */
.filter-row { display: flex; gap: 8px; margin-bottom: 12px; }
.filter-row select {
  flex: 1; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--fg);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: rgba(17,24,39,.92); color: #fff;
  padding: 10px 16px; border-radius: 12px;
  font-size: 13px;
  max-width: calc(100vw - 32px);
  text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, -6px);
}

/* ---------- Detail view ---------- */
.detail { display: flex; flex-direction: column; gap: 8px; }
.detail .row-kv {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}
.detail .row-kv .k { color: var(--muted); font-size: 13px; }
.detail .row-kv .v { font-weight: 500; text-align: end; }
.detail .section {
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-top: 8px;
}
.detail .section h4 { margin: 0 0 6px; font-size: 14px; }

/* ---------- Review summary ---------- */
.review { background: var(--bg-2); border-radius: var(--radius-sm); padding: 14px; font-size: 13px; }
.review .kv { display: flex; justify-content: space-between; padding: 4px 0; }
.review .kv .k { color: var(--muted); }
