:root {
  --bg: #f5f5f4; --card: #ffffff; --text: #1c1917; --muted: #78716c; --border: #e7e5e4;
  --brand: #1e3a8a; --accent: #2563eb; --accent-h: #1d4ed8; --danger: #dc2626; --ok: #16a34a;
  --s-reg: #6b7280; --s-rec: #2563eb; --s-wh: #7c3aed; --s-way: #d97706; --s-out: #ea580c; --s-city: #0891b2;
  --s-done: #16a34a; --s-ret: #b91c1c; --s-can: #9ca3af;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917; --card: #292524; --text: #f5f5f4; --muted: #a8a29e; --border: #44403c;
    --brand: #1e3a8a; --accent: #3b82f6; --accent-h: #60a5fa; --danger: #f87171; --ok: #4ade80;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
header.top { background: var(--brand); color: #fff; padding: 12px 16px;
             display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
header.top .logo { font-weight: 700; font-size: 18px; }
header.top a, header.top button.link { color: #dbeafe; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
h2 { font-size: 17px; margin: 20px 0 10px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; min-width: 0; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label.f { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 3px; }
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-h); }
button.danger { color: var(--danger); }
button.link { background: none; border: 0; padding: 0; text-decoration: underline; }
button:disabled { opacity: .5; cursor: default; }

.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
tbody tr.sel { background: color-mix(in srgb, var(--accent) 16%, transparent); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
         color: #fff; background: var(--s-reg); }
/* Индекс нь db.STATUSES-ийн дараалалтай таарна */
.st-0 { background: var(--s-reg); } .st-1 { background: var(--s-rec); } .st-2 { background: var(--s-wh); }
.st-3 { background: var(--s-way); } .st-4 { background: var(--s-city); } .st-5 { background: var(--s-out); }
.st-6 { background: var(--s-done); } .st-7 { background: var(--s-ret); } .st-8 { background: var(--s-can); }
/* Рейсийн төлөв */
.tr-Төлөвлөсөн { background: var(--s-rec); } .tr-Хөдөлсөн { background: var(--s-way); }
.tr-Хүрсэн { background: var(--s-done); } .tr-Цуцлагдсан { background: var(--s-can); }
.route { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 600;
         background: color-mix(in srgb, var(--s-city) 15%, transparent); color: var(--s-city); }

.err { color: var(--danger); margin: 8px 0; min-height: 1em; }

/* Явцын шугам */
.steps { display: flex; justify-content: space-between; position: relative; margin: 18px 4px 6px; }
.steps::before { content: ""; position: absolute; left: 10px; right: 10px; top: 9px; height: 4px; background: var(--border); }
.steps .bar { position: absolute; left: 10px; top: 9px; height: 4px; background: var(--ok); }
.steps.bad .bar { background: var(--danger); }
.step { position: relative; text-align: center; flex: 1; font-size: 12px; color: var(--muted); }
.step .dot { width: 22px; height: 22px; border-radius: 50%; margin: 0 auto 4px; background: var(--card);
             border: 3px solid var(--border); }
.step.on .dot { background: var(--ok); border-color: var(--ok); }
.steps.bad .step.on .dot { background: var(--danger); border-color: var(--danger); }
.step.on { color: var(--text); }
.step.cur { font-weight: 700; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 14px; width: 10px; height: 10px;
                       border-radius: 50%; background: var(--accent); }

/* Нийтийн хуудсуудын дээд цэс */
header.top a.logo { color: #fff; text-decoration: none; }
nav.menu { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav.menu a { color: #dbeafe; text-decoration: none; padding: 6px 12px; border-radius: 8px; white-space: nowrap; }
nav.menu a:hover { background: rgb(255 255 255 / .1); }
nav.menu a.on { background: rgb(255 255 255 / .18); color: #fff; font-weight: 600; }
nav.menu a.cta { background: #f59e0b; color: #1f2937; font-weight: 600; }
nav.menu a.cta:hover { background: #fbbf24; }
header.top select.lang { width: auto; padding: 4px 6px; font-size: 13px; border-radius: 8px;
  background: rgb(255 255 255 / .12); color: #fff; border: 1px solid rgb(255 255 255 / .3); }
header.top select.lang option { color: #111; }
.hero { text-align: center; padding: 24px 0 8px; }
.hero h1 { margin: 0 0 6px; font-size: 24px; }

@media (max-width: 600px) {
  nav.menu { order: 3; flex-basis: 100%; }
  .step { font-size: 10px; }
  th, td { padding: 7px 8px; }
}

/* ====================================================================
   Загварын шинэчлэл (2026-11): зөөлөн сүүдэр, бөөрөнхий булан, хуруунд эвтэйхэн товч
   ==================================================================== */
:root { --radius: 14px; --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 6px 18px rgb(15 23 42 / .06); --tabbar-h: 64px; }
@media (prefers-color-scheme: dark) { :root { --shadow: 0 1px 2px rgb(0 0 0 / .4); } }
html { -webkit-text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
header.top { background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%); position: sticky; top: 0; z-index: 1000;
             box-shadow: 0 2px 12px rgb(15 23 42 / .18); padding-top: max(12px, env(safe-area-inset-top)); }
.card, .tablewrap { border-radius: var(--radius); box-shadow: var(--shadow); }
button:not(.link), .btn, select, input:not([type=checkbox]):not([type=radio]) { min-height: 42px; }
button.primary { box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 30%, transparent); font-weight: 600; }
.hero h1 { letter-spacing: -.01em; }
.tabbar, .fab, .tabsel, .sitefoot { display: none; }

/* --------------------------- Утас (≤720px) --------------------------- */
@media (max-width: 720px) {
  body { font-size: 16px; }   /* iPhone дээр input-д дарахад томруулахгүй */
  main { padding: 12px 12px 20px; }
  header.top { padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); flex-wrap: nowrap; gap: 8px; }
  header.top .logo { font-size: 17px; }
  header.top nav.menu, header.top > a.small { display: none; }
  .hero { padding: 14px 0 4px; }
  .hero h1 { font-size: 21px; }
  h2 { font-size: 16px; }

  /* Доод таб-самбар (нийтийн хуудсууд) */
  body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
            height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
            background: var(--card); border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgb(15 23 42 / .08); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
              color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500; }
  .tabbar a.on { color: var(--accent); font-weight: 700; }
  .tabbar a.on svg { stroke-width: 2.4; }
  .fab { display: flex; align-items: center; gap: 6px; position: fixed; right: 14px; z-index: 1001;
         bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom)); padding: 12px 18px 12px 14px;
         border-radius: 999px; background: #f59e0b; color: #1f2937; font-weight: 700; text-decoration: none;
         box-shadow: 0 6px 18px rgb(245 158 11 / .45); }
  body.has-fab .sitefoot { padding-bottom: 76px; }   /* "+ Зар" товчны доор контент нуугдахгүй */
  .sitefoot { display: block; text-align: center; padding: 8px 0 18px; font-size: 13px; }
  .sitefoot a { color: var(--muted); }

  /* Хүснэгт → карт (app.js нь нүд бүрт data-label тавина) */
  .tablewrap { overflow: visible; background: transparent; border: 0; box-shadow: none; }
  table.tcards thead { display: none; }
  table.tcards, table.tcards tbody, table.tcards tr, table.tcards td { display: block; width: 100%; }
  table.tcards tr { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
                   box-shadow: var(--shadow); padding: 10px 14px; margin-bottom: 10px; }
  table.tcards td { display: flex; justify-content: space-between; align-items: center; gap: 12px;
                   border: 0; padding: 4px 0; white-space: normal; text-align: right; min-height: 0; }
  table.tcards td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: none; }
  table.tcards td[data-label=""]::before { content: none; }
  table.tcards td[data-label=""] { justify-content: flex-end; }
  table.tcards td[colspan] { justify-content: center; text-align: center; }
  table.tcards td:empty { display: none; }
  table.tcards td button { width: 100%; }
  tbody tr:hover { background: var(--card); }

  /* Ачааны явц: босоо шат */
  .steps { flex-direction: column; align-items: stretch; gap: 12px; margin: 16px 0 6px; }
  .steps::before { left: 9px; right: auto; top: 11px; bottom: 11px; width: 4px; height: auto; }
  .steps .bar { display: none; }
  .step { display: flex; align-items: center; gap: 12px; text-align: left; font-size: 15px; }
  .step .dot { margin: 0; flex: none; }

  /* Admin: табын оронд сонгох цэс, бүтэн дэлгэцийн цонх */
  nav#tabs.tabs { display: none; }   /* admin.html-ийн өөрийн <style>-ээс давуу */
  .tabsel { display: block; width: 100%; margin: 0 0 12px; font-weight: 600; }
  dialog:has(.dh) { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  dialog:has(.dh) form { display: flex; flex-direction: column; height: 100%; }
  dialog:has(.dh) .db { flex: 1; overflow-y: auto; }
  .kv { grid-template-columns: 110px 1fr; }
}
