/* ============================================================
   MedRoute SaaS — Design System
   MedRoute brand (deep blue → green) · mobile-first · native-app feel · light/dark mode
   ============================================================ */

:root {
  --blue: #0a56b3; --blue-d: #00408a; --blue-l: #d6e6fa; --blue-xl: #eef5fd; --blue-t: #00408a;
  --teal: #0b8a6a; --brand-green: #1fa463;
  --brand-grad: linear-gradient(135deg, #00408a 0%, #0a56b3 48%, #0b8a6a 100%);
  --brand-top: #00408a;
  --ink: #0f172a; --ink-2: #334155; --mut: #64748b; --line: #e2e8f0; --line-2: #cbd5e1;
  --bg: #f1f5f9; --card: #ffffff; --card-2: #f8fafc;
  --green: #0e8a58; --green-bg: #dcf5e8; --amber: #d97706; --amber-bg: #fef3c7;
  --red: #dc2626; --red-bg: #fee2e2; --purple: #7c3aed; --purple-bg: #ede9fe;
  --radius: 14px; --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(2,6,23,.06), 0 8px 24px rgba(2,6,23,.06);
  --shadow-lg: 0 10px 40px rgba(2,6,23,.14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --side-w: 248px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e2e8f0; --ink-2: #cbd5e1; --mut: #94a3b8; --line: #1e293b; --line-2: #334155;
    --bg: #0b1220; --card: #111a2e; --card-2: #0e1628;
    --blue: #2f7fdc; --blue-d: #1d65b8; --blue-t: #9cc8f5; --blue-l: #1b3558; --blue-xl: #15233c;
    --green: #34c585;
    --green-bg: #052e1a; --amber-bg: #3a2707; --red-bg: #3b0d0d; --purple-bg: #241543;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.3; font-weight: 700; }
small { color: var(--mut); }
img { max-width: 100%; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.muted { color: var(--mut); }

/* ---------------- Buttons ---------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1.5px solid transparent;
  background: var(--card); color: var(--ink); font: 600 14px var(--font); padding: 10px 18px; border-radius: var(--radius-sm);
  cursor: pointer; transition: .15s; text-decoration: none !important; line-height: 1.2; }
.btn:hover { filter: brightness(.97); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-d); }
.btn-danger { background: var(--red); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line-2); color: var(--ink-2); }
.btn-ghost:hover { background: var(--card-2); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn-lg { padding: 15px 26px; font-size: 16px; border-radius: 13px; }
.btn-block { width: 100%; }
.btn[disabled], .btn.loading { opacity: .55; pointer-events: none; }
.link-btn { background: none; border: 0; color: var(--blue); font: inherit; cursor: pointer; padding: 0; }
.icon-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
  border-radius: 11px; color: var(--ink-2); background: transparent; border: 0; cursor: pointer; text-decoration: none !important; }
.icon-btn:hover { background: var(--card-2); }
.notif-dot { position: absolute; top: 3px; right: 2px; background: var(--red); color: #fff; font-size: 10px; font-weight: 800;
  min-width: 16px; height: 16px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 3px; }

/* ---------------- Cards / stats ---------------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card h2, .card h3 { font-size: 16px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-card .s-label { font-size: 12.5px; font-weight: 600; color: var(--mut); text-transform: uppercase; letter-spacing: .4px; display: flex; align-items: center; gap: 6px; }
.stat-card .s-label svg { opacity: .7; }
.stat-card .s-value { font-size: 26px; font-weight: 800; margin-top: 4px; letter-spacing: -.5px; }
.stat-card .s-sub { font-size: 12.5px; color: var(--mut); margin-top: 2px; }
.stat-card.accent { background: var(--brand-grad); border: 0; color: #fff; }
.stat-card.accent .s-label, .stat-card.accent .s-sub { color: rgba(255,255,255,.75); }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--mut);
  padding: 11px 14px; border-bottom: 1.5px solid var(--line); background: var(--card-2); white-space: nowrap; }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--blue-xl); }
.tbl .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------- Badges ---------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 10px;
  border-radius: 20px; white-space: nowrap; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-blue { background: var(--blue-l); color: var(--blue-t); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-gray { background: var(--card-2); color: var(--mut); border: 1px solid var(--line); }

/* ---------------- Forms ---------------- */
.form { max-width: 100%; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
.field input, .field select, .field textarea, .input {
  width: 100%; padding: 11px 13px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  font: 400 14.5px var(--font); background: var(--card); color: var(--ink); transition: border .15s; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(10,86,179,.16); }
.field textarea { min-height: 90px; resize: vertical; }
.field small { display: block; margin-top: 4px; }
.field .req::after { content: " *"; color: var(--red); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 18px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.form-row .field { flex: 1; min-width: 150px; }
.checkline { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.checkline input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--blue); }

/* ---------------- Alerts / flash ---------------- */
.alert { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 14px; border: 1px solid transparent; }
.alert.success { background: var(--green-bg); color: #14532d; border-color: rgba(22,163,74,.25); }
.alert.danger { background: var(--red-bg); color: #7f1d1d; border-color: rgba(220,38,38,.25); }
.alert.warning { background: var(--amber-bg); color: #78350f; border-color: rgba(217,119,6,.25); }
.alert.info { background: var(--blue-xl); color: var(--blue-t); border-color: rgba(10,86,179,.2); }
.alert-x { background: none; border: 0; font-size: 18px; cursor: pointer; color: inherit; opacity: .6; }

/* ---------------- App shell (admin/dist) ---------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--side-w); background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 60; transition: transform .22s; }
.sidebar-brand { display: flex; gap: 12px; align-items: center; padding: 18px 18px 14px; border-bottom: 1px solid var(--line); }
.brand-logo { width: 40px; height: 40px; border-radius: 12px; background: linear-gradient(135deg, var(--blue), var(--blue-d));
  color: #fff; font-weight: 800; font-size: 18px; display: flex; align-items: center; justify-content: center; }
.brand-name { font-weight: 800; font-size: 15.5px; }
.brand-sub { font-size: 11.5px; color: var(--mut); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 12px 20px; }
.sidebar-nav a { display: flex; align-items: center; gap: 11px; color: var(--ink-2); font-size: 13.8px; font-weight: 500;
  padding: 9.5px 12px; border-radius: 10px; margin-bottom: 2px; text-decoration: none !important; }
.sidebar-nav a:hover { background: var(--card-2); color: var(--ink); }
.sidebar-nav a.active { background: var(--blue-xl); color: var(--blue-t); font-weight: 700; }
.sidebar-nav a.active svg { color: var(--blue); }
.nav-group { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; color: var(--mut); padding: 16px 12px 6px; }
.sidebar-foot { border-top: 1px solid var(--line); padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--mut); }
.inline { display: inline; }
.ver { font-weight: 700; }

.main { flex: 1; margin-left: var(--side-w); display: flex; flex-direction: column; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 40; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 10px 22px; min-height: 60px; }
.topbar-title { font-size: 16.5px; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.content { padding: 22px; max-width: 1280px; width: 100%; }
.scrim { display: none; }
.only-mobile { display: none; }

/* dropdown */
.dropdown { position: relative; }
.dropdown-menu { display: none; position: absolute; right: 0; top: calc(100% + 8px); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-lg); min-width: 220px; overflow: hidden; z-index: 70; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a { display: block; padding: 11px 16px; color: var(--ink-2); font-size: 14px; text-decoration: none !important; }
.dropdown-menu a:hover { background: var(--card-2); }
.dropdown-head { padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 13.5px; }
.dropdown-head small { display: block; font-weight: 400; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--blue-l); color: var(--blue-t); font-weight: 800;
  border: 0; cursor: pointer; font-size: 15px; display: flex; align-items: center; justify-content: center; }

/* ---------------- Filters ---------------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.filters .field { margin: 0; min-width: 140px; flex: 1; max-width: 220px; }
.filters .btn { margin-bottom: 1px; }

/* ---------------- Pagination ---------------- */
.pagination { display: flex; gap: 6px; margin: 16px 0 4px; flex-wrap: wrap; align-items: center; }
.pagination a { padding: 7px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); font-size: 13.5px; color: var(--ink-2); text-decoration: none !important; }
.pagination a.on { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 700; }
.pagination a:hover { border-color: var(--blue); }
.pg-info { font-size: 12.5px; color: var(--mut); margin-left: 6px; }

/* ---------------- Empty / states ---------------- */
.empty-state { text-align: center; padding: 46px 20px; color: var(--mut); background: var(--card); border: 1.5px dashed var(--line-2); border-radius: var(--radius); }
.empty-state svg { color: var(--line-2); margin-bottom: 10px; }
.empty-state p { font-weight: 600; color: var(--ink-2); }
.empty-state small { display: block; margin: 4px 0 14px; }
.skeleton { background: linear-gradient(90deg, var(--card-2) 25%, var(--line) 50%, var(--card-2) 75%); background-size: 200% 100%;
  animation: shimmer 1.3s infinite; border-radius: 8px; min-height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------------- Detail pages ---------------- */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.kv .kv-item { background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 14px; }
.kv .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--mut); font-weight: 700; }
.kv .v { font-weight: 600; margin-top: 2px; font-size: 14.5px; word-break: break-word; }
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--line-2); }
.tl-item { position: relative; padding: 8px 0 14px; }
.tl-item::before { content: ""; position: absolute; left: -23px; top: 13px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--blue); }
.tl-item.warn::before { border-color: var(--amber); }
.tl-item .tl-time { font-size: 12px; color: var(--mut); font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 16px; font-size: 14px; font-weight: 600; color: var(--mut); border-bottom: 2.5px solid transparent; margin-bottom: -2px; text-decoration: none !important; white-space: nowrap; }
.tabs a.on { color: var(--blue); border-color: var(--blue); }

/* ---------------- Toast ---------------- */
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--ink); color: #fff; padding: 13px 18px; border-radius: 12px; box-shadow: var(--shadow-lg);
  font-size: 14px; display: flex; align-items: center; gap: 10px; max-width: 340px; animation: toastIn .25s; }
.toast.ok { background: var(--green); } .toast.err { background: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } }

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background: linear-gradient(160deg, var(--blue-xl) 0%, var(--bg) 45%, var(--bg) 100%); }
.auth-wrap { width: 100%; max-width: 400px; }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo { width: 62px; height: 62px; border-radius: 19px; background: linear-gradient(135deg, var(--blue), var(--blue-d)); color: #fff;
  font-size: 27px; font-weight: 800; display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; box-shadow: 0 10px 30px rgba(10,86,179,.35); }
.auth-brand h1 { font-size: 22px; }
.auth-brand p { color: var(--mut); font-size: 13px; margin-top: 3px; }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 30px 28px; box-shadow: var(--shadow-lg); }
.auth-card h2 { font-size: 19px; margin-bottom: 4px; }
.auth-card .muted { font-size: 13.5px; margin-bottom: 18px; }
.form-links { display: flex; justify-content: space-between; margin-top: 16px; font-size: 13.5px; }
.auth-foot { text-align: center; color: var(--mut); font-size: 12px; margin-top: 18px; }

/* ============================================================
   MR MOBILE PWA
   ============================================================ */
.mr-body { background: var(--bg); min-height: 100vh; -webkit-tap-highlight-color: transparent; }
.mr-shell { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column;
  padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
.mr-top { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; padding-top: calc(12px + env(safe-area-inset-top)); background: linear-gradient(135deg, var(--blue), var(--blue-d));
  color: #fff; border-radius: 0 0 20px 20px; }
.mr-top .icon-btn { color: #fff; }
.mr-top .icon-btn:hover { background: rgba(255,255,255,.14); }
.mr-top-left { display: flex; gap: 12px; align-items: center; }
.mr-avatar { width: 42px; height: 42px; border-radius: 14px; background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 17px; }
.mr-hello { font-weight: 800; font-size: 16px; }
.mr-date { font-size: 12px; opacity: .85; }
.mr-main { flex: 1; padding: 18px 16px 28px; }

.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; max-width: 560px; margin: 0 auto; z-index: 50;
  display: grid; grid-template-columns: repeat(5, 1fr); background: var(--card); border-top: 1px solid var(--line);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom)); }
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 600;
  color: var(--mut); padding: 5px 2px; border-radius: 12px; text-decoration: none !important; transition: .12s; }
.bottom-nav a.on { color: var(--blue); background: var(--blue-xl); }
.bottom-nav a.on svg { transform: scale(1.06); }

.net-banner { position: sticky; top: 0; z-index: 80; background: var(--amber); color: #fff; text-align: center;
  padding: 8px 14px; font-size: 13px; font-weight: 600; display: flex; gap: 8px; align-items: center; justify-content: center; }

.app-splash { position: fixed; inset: 0; z-index: 500; background: linear-gradient(160deg, var(--blue), var(--blue-d));
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; transition: opacity .4s; }
.app-splash.hide { opacity: 0; pointer-events: none; }
.app-splash-logo { width: 84px; height: 84px; border-radius: 26px; background: rgba(255,255,255,.16); color: #fff; font-size: 36px;
  font-weight: 800; display: flex; align-items: center; justify-content: center; animation: pulse 1.6s infinite; }
.app-splash-name { color: #fff; font-weight: 700; letter-spacing: .5px; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* GPS screen */
.gps-hero { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 22px 18px; text-align: center; box-shadow: var(--shadow); }
.gps-ring { width: 108px; height: 108px; margin: 6px auto 12px; border-radius: 50%; border: 5px solid var(--line);
  display: flex; align-items: center; justify-content: center; position: relative; transition: .3s; color: var(--mut); }
.gps-ring.active { border-color: var(--green); color: var(--green); animation: gpsPulse 2s infinite; }
.gps-ring.warn { border-color: var(--amber); color: var(--amber); }
.gps-ring.err { border-color: var(--red); color: var(--red); }
@keyframes gpsPulse { 0% { box-shadow: 0 0 0 0 rgba(22,163,74,.35); } 70% { box-shadow: 0 0 0 16px rgba(22,163,74,0); } 100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); } }
.gps-accuracy { font-size: 13px; color: var(--mut); }
.gps-btn { width: 100%; padding: 16px; font-size: 16px; font-weight: 800; border-radius: 15px; margin-top: 14px;
  background: var(--blue); color: #fff; border: 0; display: flex; gap: 10px; align-items: center; justify-content: center; cursor: pointer; }
.gps-btn:active { transform: scale(.98); }
.gps-btn[disabled] { opacity: .6; }
.gps-meta { display: flex; justify-content: center; gap: 18px; font-size: 12px; color: var(--mut); margin-top: 10px; flex-wrap: wrap; }
.mr-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.mr-card h3 { font-size: 15px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.mr-quick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.mr-quick a { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px 14px; text-decoration: none !important;
  color: var(--ink); display: flex; flex-direction: column; gap: 8px; font-weight: 700; font-size: 13.5px; box-shadow: var(--shadow); }
.mr-quick a svg { color: var(--blue); }
.mr-list { display: flex; flex-direction: column; gap: 10px; }
.mr-item { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 13px 15px; text-decoration: none !important;
  color: var(--ink); display: block; }
.mr-item:active { background: var(--card-2); }
.mr-item .t { font-weight: 700; font-size: 14.5px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.mr-item .s { font-size: 12.5px; color: var(--mut); margin-top: 3px; }
.big-num { font-size: 30px; font-weight: 800; letter-spacing: -1px; }
.sync-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 20px; }

/* Install prompt */
.install-banner { position: fixed; bottom: calc(80px + env(safe-area-inset-bottom)); left: 12px; right: 12px; max-width: 536px;
  margin: 0 auto; z-index: 90; background: var(--ink); color: #fff; border-radius: 16px; padding: 14px 16px;
  display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow-lg); }
.install-banner button { border: 0; background: var(--blue); color: #fff; font-weight: 700; padding: 9px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap; }
.install-banner .dismiss { background: transparent; opacity: .7; }

/* ---------------- Error pages ---------------- */
.error-page { text-align: center; padding: 20px 4px; }
.error-code { font-size: 72px; font-weight: 800; color: var(--blue); letter-spacing: -3px; line-height: 1; }
.error-page h1 { margin: 10px 0 6px; }
.error-page p { color: var(--mut); margin-bottom: 22px; }

/* ---------------- Charts ---------------- */
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 200px; }

/* ---------------- Progress steps (updates) ---------------- */
.stage-list { list-style: none; }
.stage-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.stage-list li:last-child { border: 0; }
.stage-dot { width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  background: var(--line); color: var(--mut); font-size: 12px; font-weight: 800; }
.stage-dot.ok { background: var(--green); color: #fff; }
.stage-dot.fail { background: var(--red); color: #fff; }
.stage-dot.run { background: var(--blue); color: #fff; animation: pulse 1s infinite; }

/* ---------------- Responsive ---------------- */
@media (max-width: 960px) {
  .sidebar { transform: translateX(-105%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(2,6,23,.5); z-index: 55; }
  .only-mobile { display: inline-flex; }
  .content { padding: 16px 14px 40px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card .s-value { font-size: 21px; }
  .topbar { padding: 8px 14px; }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 15px 14px; }
  .mr-quick { grid-template-columns: repeat(2, 1fr); }
  .auth-card { padding: 24px 20px; }
}

/* ============================================================
   v1.1 — MedRoute brand + mobile-first / native-app feel
   (appended last so it wins over the base rules above)
   ============================================================ */
html { background: var(--bg); -webkit-tap-highlight-color: transparent; text-size-adjust: 100%; }
a, button, .btn, .icon-btn, label, select, summary { touch-action: manipulation; }
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
img { height: auto; }

/* Status-bar cap: in an installed iPhone/Android app the page draws under the status bar
   (black-translucent). This brand-coloured strip keeps the clock/battery readable. It is
   0px tall in a normal browser tab. */
body::before { content: ""; position: fixed; top: 0; left: 0; right: 0; height: env(safe-area-inset-top, 0px);
  background: var(--brand-top); z-index: 1000; pointer-events: none; }
body.app, body.auth-body { padding-top: env(safe-area-inset-top, 0px); }
.mr-body::before { display: none; }
.topbar { top: env(safe-area-inset-top, 0px); }
.sidebar { padding-top: env(safe-area-inset-top, 0px); }

/* ---- brand marks ---- */
.brand-logo { width: 42px; height: 42px; border-radius: 13px; background: #fff; border: 1px solid var(--line); padding: 5px; box-shadow: none; }
.brand-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.auth-logo-img { display: block; width: min(230px, 60vw); height: auto; margin: 0 auto 10px; }
.auth-brand p { max-width: 300px; margin-left: auto; margin-right: auto; }
@media (prefers-color-scheme: dark) {
  .auth-logo-img { background: #fff; border-radius: 22px; padding: 14px 18px; box-shadow: var(--shadow); }
}
.auth-body { min-height: 100vh; min-height: 100dvh; background:
  radial-gradient(900px 420px at 85% -10%, rgba(31,164,99,.14), transparent 60%),
  radial-gradient(900px 420px at 0% -10%, rgba(10,86,179,.14), transparent 60%), var(--bg); }
.auth-card { border-radius: 22px; }
.btn-primary { background: var(--brand-grad); border-color: transparent; }
.btn-primary:hover { background: var(--brand-grad); filter: brightness(1.08); }
.gps-btn { background: var(--brand-grad); }
.link-btn, a { color: var(--blue); }

/* ---- MR header ---- */
.mr-mark { width: 46px; height: 46px; border-radius: 15px; background: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.2); flex-shrink: 0; }
.mr-mark img { width: 31px; height: auto; display: block; }
.mr-hello { font-size: 16px; line-height: 1.2; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mr-top { padding-bottom: 16px; }
.mr-main { animation: pageIn .22s ease-out; }
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .mr-main { animation: none; } * { scroll-behavior: auto !important; } }
@view-transition { navigation: auto; }

/* ---- splash (cold start only) ---- */
.app-splash { background: #fff; gap: 0; }
.app-splash-img { width: min(260px, 62vw); height: auto; animation: splashIn .6s ease-out both; }
@keyframes splashIn { from { opacity: 0; transform: scale(.94); } }
.app-splash-logo, .app-splash-name { display: none; }

/* ---- MR bottom navigation (native tab bar) ---- */
.bottom-nav { background: var(--card); background: color-mix(in srgb, var(--card) 90%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
  padding-top: 6px; box-shadow: 0 -6px 24px rgba(2,6,23,.06); }
.bottom-nav a { min-height: 52px; justify-content: center; font-size: 10.5px; letter-spacing: .1px; }
.bottom-nav a.on { background: transparent; color: var(--blue); }
.bottom-nav a.on svg { transform: none; }
.bottom-nav a:active { transform: scale(.94); }
.bottom-nav a.fab { position: relative; background: transparent !important; color: var(--mut); }
.bottom-nav a.fab.on { color: var(--blue); }
.bottom-nav .fab-circle { width: 54px; height: 54px; border-radius: 50%; margin-top: -30px; display: flex; align-items: center; justify-content: center;
  background: var(--brand-grad); color: #fff; border: 4px solid var(--bg); box-shadow: 0 8px 20px rgba(0,64,138,.38); }
.bottom-nav a.fab:active .fab-circle { transform: scale(.94); }
.bottom-nav a.fab > span:last-child { margin-top: -2px; }

/* ---- install banners ---- */
.install-banner .ib-logo { width: 38px; height: auto; background: #fff; border-radius: 10px; padding: 4px; flex-shrink: 0; }
.install-banner button { background: var(--brand-grad); }

/* ---- console bottom tab bar (distributor + admin, phones/tablets) ---- */
.tabbar { display: none; }
body.nav-open { overflow: hidden; }

@media (max-width: 960px) {
  .sidebar { width: min(86vw, 320px); }
  .sidebar-nav a { padding: 12px 14px; font-size: 15px; }
  .nav-group { padding-top: 18px; }
  .content { padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }
  .tabbar { display: grid; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--card);
    background: color-mix(in srgb, var(--card) 92%, transparent); -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
    border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -6px 24px rgba(2,6,23,.06); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px;
    font: 600 10.5px var(--font); color: var(--mut); background: none; border: 0; border-radius: 12px; text-decoration: none !important; cursor: pointer; }
  .tabbar a.on { color: var(--blue); background: var(--blue-xl); }
  .tabbar a:active, .tabbar button:active { transform: scale(.94); }
  #toasts { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); left: 12px; right: 12px; align-items: stretch; }
  .toast { max-width: none; }

  /* touch-friendly controls; 16px inputs stop iOS Safari zooming on focus */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }
  .icon-btn { width: 44px; height: 44px; }
  .field input, .field select, .field textarea, .input { font-size: 16px; min-height: 46px; }
  .field textarea { min-height: 96px; }
  .filters .field { max-width: none; flex: 1 1 44%; min-width: 120px; }
  .form-row .field { min-width: 130px; }
  .topbar-title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-actions .badge { display: none; }
  .dropdown-menu { position: fixed; right: 10px; top: calc(58px + env(safe-area-inset-top, 0px)); }
  .pagination a { padding: 10px 14px; }
}
.mr-shell input, .mr-shell select, .mr-shell textarea { font-size: 16px; }
.mr-shell .field input, .mr-shell .field select, .mr-shell .field textarea { min-height: 48px; }
.mr-shell .btn { min-height: 48px; }

/* ---- tables become cards on phones (class added by app.js) ---- */
@media (max-width: 720px) {
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  table.tbl.stack { min-width: 0; display: block; }
  .tbl.stack thead { display: none; }
  .tbl.stack tbody { display: block; }
  .tbl.stack tr { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px 14px;
    margin-bottom: 10px; box-shadow: var(--shadow); }
  .tbl.stack tbody tr:hover { background: var(--card); }
  .tbl.stack td { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; text-align: right;
    padding: 9px 0; border-bottom: 1px dashed var(--line); word-break: break-word; }
  .tbl.stack td:last-child { border-bottom: 0; }
  .tbl.stack td::before { content: attr(data-label); flex: 0 0 38%; text-align: left; font-size: 11.5px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .4px; color: var(--mut); padding-top: 2px; }
  .tbl.stack td[data-label=""]::before, .tbl.stack td[colspan]::before { display: none; }
  .tbl.stack td[colspan] { justify-content: center; text-align: center; }
  .tbl.stack .row-actions { justify-content: flex-end; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .kv { grid-template-columns: 1fr 1fr; }
  .card { border-radius: 16px; }
}
@media (max-width: 380px) { .stat-grid, .kv { grid-template-columns: 1fr; } }

/* ---- installed-app behaviour ---- */
@media (display-mode: standalone) {
  html, body { overscroll-behavior-y: contain; }
  .btn, .icon-btn, .bottom-nav, .tabbar, .mr-top, .sidebar-nav, .topbar { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  .install-banner { display: none !important; }
}

/* Footer (copyright + developer credit) */
.app-footer { margin-top: auto; padding: 16px 22px 20px; text-align: center; color: var(--mut); font-size: 12.5px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 10px; border-top: 1px solid var(--line); }
.app-footer a { color: var(--blue); text-decoration: none; font-weight: 600; }
.app-footer a:hover { text-decoration: underline; }
.auth-foot a:hover { color: var(--blue); }
@media (max-width: 960px) { .app-footer { padding: 14px 14px 90px; flex-direction: column; gap: 2px; } .app-footer-sep { display: none; } }
