/* Орлоо хүргэлт — нийтлэг загвар (нүүр, хянах хуудас, түншийн портал) */
:root {
  --brand: #1e3a8a;
  --brand-strong: #172554;
  --brand-dark: #0a192f;
  --brand-soft: #dbeafe;
  /* Туслах шар — гол үйлдэл, анхаарал (хаалгаар орж буй гэрэл) */
  --accent: #fbbf24;
  --accent-strong: #f59e0b;
  --on-accent: #0a192f;
  --success: #15803d;
  --success-soft: #dcfce7;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --text: #0f172a;
  --muted: #5b6478;
  --border: #e2e8f0;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #3b82f6;
    --brand-strong: #2563eb;
    --brand-dark: #06101f;
    --brand-soft: #172554;
    --success: #4ade80;
    --success-soft: #14532d;
    --bg: #0b1120;
    --surface: #111a2e;
    --surface-2: #18233a;
    --text: #e6ebf5;
    --muted: #94a3b8;
    --border: #27324a;
    --danger: #f87171;
    --danger-soft: #450a0a;
    --warning: #fbbf24;
    --warning-soft: #422006;
    --info: #93c5fd;
    --info-soft: #172554;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--brand-strong); }
@media (prefers-color-scheme: dark) { a { color: var(--brand); } }
h1, h2, h3 { line-height: 1.25; margin: 0 0 12px; }
h1 { font-size: clamp(24px, 4vw, 32px); }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0 0 12px; }
code, pre { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Top bar */
.topbar { background: var(--brand-dark); color: #fff; }
.topbar .inner { max-width: 1120px; margin: 0 auto; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; display: block; flex: none; }
.topbar a { color: #dbeafe; }

.container { max-width: 1120px; margin: 0 auto; padding: 24px 16px; }
.narrow { max-width: 640px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-header h2, .card-header h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.stat { padding: 16px; }
.stat .value { font-size: 28px; font-weight: 700; }
.stat .label { color: var(--muted); font-size: 13px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; background: var(--brand); color: #fff; }
.btn:hover { background: var(--brand-strong); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
form.inline { display: inline; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge-green, .status-delivered, .status-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-blue, .status-assigned, .status-picked_up, .status-in_transit { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-yellow, .status-pending, .env-test { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-red, .status-failed, .status-cancelled, .status-returned { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
@media (prefers-color-scheme: dark) {
  .badge-green, .status-delivered, .status-success { color: #86efac; }
}

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }

/* Forms */
.form-row { margin-bottom: 14px; }
label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 14px; }
input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.checkbox-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.checkbox-list label { font-weight: 400; display: flex; gap: 8px; align-items: center; }
.helptext { color: var(--muted); font-size: 13px; margin-top: 4px; }
.errorlist { color: var(--danger); margin: 4px 0 0; padding-left: 18px; font-size: 13px; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 160px; flex: 1; }

/* Alerts */
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface); }
.alert-success { background: var(--brand-soft); border-color: transparent; }
.alert-error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.alert-warning { background: var(--warning-soft); border-color: transparent; }
.secret-box { display: flex; gap: 8px; align-items: stretch; margin: 8px 0 16px; }
.secret-box code { flex: 1; background: var(--surface-2); border: 1px dashed var(--brand); border-radius: 8px; padding: 10px 12px; word-break: break-all; font-size: 14px; }

/* Timeline (хянах хуудас) */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 18px 30px; color: var(--muted); }
.timeline li::before { content: ""; position: absolute; left: 6px; top: 6px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface); }
.timeline li::after { content: ""; position: absolute; left: 12px; top: 20px; bottom: 0; width: 2px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline li.done { color: var(--text); }
.timeline li.done::before { background: var(--brand); border-color: var(--brand); }
.timeline li.done::after { background: var(--brand); }
.timeline .when { display: block; font-size: 13px; color: var(--muted); }

/* Portal layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 60px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 10px; }
.sidebar a { display: block; padding: 9px 12px; border-radius: 9px; color: var(--text); text-decoration: none; font-weight: 500; }
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; }
@media (prefers-color-scheme: dark) { .sidebar a.active { color: #bfdbfe; } }
.sidebar .section { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 14px 12px 4px; }
.main { padding: 24px; min-width: 0; }
.env-switch { display: inline-flex; border: 1px solid rgba(255,255,255,.3); border-radius: 999px; overflow: hidden; }
.env-switch button { background: transparent; border: 0; color: #dbeafe; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.env-switch button.on { background: #fff; color: #0a192f; font-weight: 700; }
.sandbox-banner { background: var(--warning-soft); color: var(--warning); text-align: center; font-size: 13px; padding: 6px 16px; font-weight: 600; }
.user-menu { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.user-menu button { background: transparent; border: 0; color: #dbeafe; cursor: pointer; font: inherit; text-decoration: underline; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; }
  .sidebar .section { display: none; }
  .main { padding: 16px; }
  .topbar .inner { flex-wrap: wrap; }
}

/* Хүргэлтийн мэдэгдэл (хянах хуудас) */
.flight { display: grid; gap: 4px; padding: 14px 16px; border-radius: var(--radius); margin-bottom: 16px;
  background: var(--brand-soft); color: var(--text); }
.flight strong { font-size: 17px; }
.flight-landed { background: var(--success-soft); }
.flight-hold, .flight-aborted { background: var(--danger-soft); }
.flight-countdown { background: var(--warning-soft); }
/* Од (баруунаас зүүн тийш — CSS-ээр өмнөх однуудыг тодруулна) */
.stars-input { border: 0; padding: 0; margin: 0 0 12px; display: inline-flex; flex-direction: row-reverse; gap: 4px; }
.stars-input legend { width: 100%; margin-bottom: 6px; }
.stars-input input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.stars-input label { font-size: 34px; line-height: 1; color: var(--border); cursor: pointer; margin: 0; }
.stars-input input:checked ~ label, .stars-input label:hover, .stars-input label:hover ~ label { color: #f59e0b; }
.stars-input input:focus-visible + label { outline: 2px solid var(--brand); border-radius: 4px; }
.stars-static { font-size: 28px; color: #f59e0b; margin: 0; letter-spacing: 2px; }
