:root {
  --bg: #f3f1ec;
  --panel: #ffffff;
  --ink: #16181b;
  --ink-2: #4a4f57;
  --muted: #868b93;
  --line: #e2ded5;
  --accent: #f2541b;
  --accent-ink: #ffffff;
  --side: #16181b;
  --side-ink: #c9ccd1;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --bad: #c0392b;
  --radius: 10px;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: Manrope, system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
.hidden { display: none !important; }
a { color: inherit; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 0.92em; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--side); }
.login-card { background: var(--panel); padding: 28px; border-radius: 14px; width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login-card .brand { color: var(--ink); }

/* Shell */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-ink); padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; color: #fff; }
.brand-mark { background: var(--accent); color: #fff; font-family: var(--mono); font-size: 12px; width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; flex: none; }
#nav { display: grid; gap: 2px; }
#nav a { text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; }
#nav a:hover { background: #24272c; color: #fff; }
#nav a.active { background: #2b2f35; color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.btn.logout { margin-top: auto; color: var(--side-ink); border-color: #33373d; }
.view { padding: 24px 28px 90px; max-width: 1180px; width: 100%; min-width: 0; }
.bottom-nav { display: none; }

/* Header row */
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Buttons & inputs */
.btn { font: inherit; font-weight: 700; font-size: 14px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 9px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(0.95); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.55; cursor: wait; }
input, select, textarea { font: inherit; width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 76px; resize: vertical; }
label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }

/* Panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stack { display: grid; gap: 16px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); }

/* Status pipeline */
.pipeline { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.pipe { flex: 1 1 110px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; text-decoration: none; }
.pipe b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.pipe span { font-size: 12px; font-weight: 700; color: var(--muted); }
.pipe:hover { border-color: var(--ink-2); }

/* Chips */
.chip { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: #ecebe7; color: var(--ink-2); white-space: nowrap; }
.chip.Received { background: #e8eefc; color: #2949a8; }
.chip.Diagnosing { background: #f1e9fb; color: #6b35a8; }
.chip.Awaiting { background: #fdf1dc; color: #94600f; }
.chip.Repairing { background: #fde6dc; color: #b23d0c; }
.chip.Ready { background: #dcf3e5; color: #1a7a43; }
.chip.Collected { background: #e9ebee; color: #4a4f57; }
.chip.Cancelled { background: #f8e1df; color: #a32d22; }
.chip.sent { background: #dcf3e5; color: #1a7a43; }
.chip.failed { background: #f8e1df; color: #a32d22; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filters .btn.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Tables / lists */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: #faf9f6; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.cards { display: none; }
.empty { text-align: center; padding: 32px 12px; color: var(--muted); }
.row-list { display: grid; }
.row-item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.row-item:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
.money-box { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.money-box div { background: var(--bg); border-radius: 8px; padding: 10px; }
.money-box small { display: block; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.money-box b { font-size: 17px; font-variant-numeric: tabular-nums; }
.status-bar { display: flex; flex-wrap: wrap; gap: 6px; }
.status-bar .btn.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.sms-item { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sms-item:last-child { border-bottom: 0; }
.inline { display: flex; gap: 8px; align-items: end; }
.inline > * { flex: 1; }
.inline > .btn { flex: none; }
.search-results { border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; max-height: 220px; overflow-y: auto; }
.search-results button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 9px 11px; font: inherit; cursor: pointer; }
.search-results button:hover { background: #faf9f6; }
.picked { display: flex; justify-content: space-between; align-items: center; background: var(--bg); border-radius: 8px; padding: 10px 12px; }
.hint { font-size: 12px; color: var(--muted); }
.low { color: var(--bad); font-weight: 700; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 9px; font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); }

.print-area { display: none; }

@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .view { padding: 16px 16px 96px; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--side); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20; justify-content: space-around; }
  .bottom-nav a { color: var(--side-ink); text-decoration: none; font-size: 11px; font-weight: 700; padding: 6px 8px; border-radius: 8px; text-align: center; flex: 1; }
  .bottom-nav a.active { color: #fff; background: #2b2f35; }
  .bottom-nav a.new { background: var(--accent); color: #fff; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .table-wrap.has-cards { display: none; }
  .cards { display: grid; gap: 8px; }
  .card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; display: grid; gap: 4px; }
  .card .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
  .kv { grid-template-columns: 100px 1fr; }
  h1 { font-size: 20px; }
}

@media print {
  body { background: #fff; }
  #shell, #login, .toast { display: none !important; }
  .print-area { display: block; font-family: Manrope, sans-serif; color: #000; font-size: 12px; width: 76mm; }
  .print-area h3 { margin: 0 0 2px; font-size: 16px; }
  .print-area hr { border: 0; border-top: 1px dashed #000; margin: 8px 0; }
  .print-area .r { display: flex; justify-content: space-between; gap: 8px; }
}
