:root {
  --bg: #f7f8fb; --surface: #fff; --line: #e6e8ee; --line2: #eef0f4;
  --ink: #1b1f2a; --ink2: #4b5363; --muted: #7b8394;
  --primary: #2f7cf6; --primary-d: #1f63d6; --primary-soft: #a9cffb; --primary-tint: #eaf3ff;
  --green: #18a058; --green-soft: #e6f6ec; --amber: #d48806; --amber-soft: #fff6dd; --red: #e5484d; --red-soft: #fde8e8;
  --radius: 6px; --side: 212px;
  font-family: Roboto, "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  font-size: 13px; color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.boot { padding: 40px; color: var(--muted); }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: var(--side); background: #f9fafd; border-right: 1px solid var(--line2); position: fixed; top: 0; bottom: 0; left: 0; overflow-y: auto; z-index: 20; transition: transform .2s; }
.side .brand { display: flex; align-items: center; gap: 9px; padding: 10px 16px; border-bottom: 1px solid var(--line2); height: 54px; }
.side .brand img { width: 28px; height: 28px; }
.side .brand b { font-size: 13px; letter-spacing: .3px; line-height: 1.1; }
.side .brand small { display: block; font-size: 8.5px; color: var(--muted); font-weight: 500; letter-spacing: 1px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 9px 18px; color: var(--ink); text-decoration: none; border-right: 3px solid transparent; font-size: 13px; }
.nav a:hover { background: var(--primary-tint); }
.nav a.active { background: var(--primary-soft); border-right-color: var(--primary); }
.nav a .ico { width: 18px; text-align: center; font-size: 14px; }
.nav a .count { margin-left: auto; background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.nav .group { padding: 14px 26px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.main { margin-left: var(--side); flex: 1; min-width: 0; transition: margin .2s; }
.shell.collapsed .side { transform: translateX(-100%); }
.shell.collapsed .main { margin-left: 0; }
.top { height: 54px; background: var(--surface); border-bottom: 1px solid var(--line2); display: flex; align-items: center; gap: 18px; padding: 0 22px; position: sticky; top: 0; z-index: 10; }
.burger { background: none; border: 0; font-size: 22px; cursor: pointer; padding: 4px 8px; }
.imei-search { display: flex; }
.imei-search input { width: 230px; border: 1px solid #9aa3b5; border-right: 0; border-radius: 6px 0 0 6px; padding: 6px 12px; }
.imei-search button { background: var(--primary); border: 0; color: #fff; border-radius: 0 6px 6px 0; width: 42px; cursor: pointer; font-size: 16px; }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; cursor: pointer; position: relative; }
.who .avatar { width: 30px; height: 30px; border: 2px solid var(--ink); border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.who b { display: block; font-size: 13px; }
.who span { color: var(--muted); font-size: 12px; }
.menu { position: absolute; right: 0; top: 48px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.08); min-width: 200px; overflow: hidden; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 12px 16px; cursor: pointer; }
.menu button:hover { background: var(--primary-tint); }
.page { padding: 16px 18px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 18px; }
.page-head p { margin: 3px 0 0; color: var(--ink2); font-size: 12px; }
.page-head .right { margin-left: auto; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.chip-info { font-size: 12px; color: var(--ink2); background: #eef1f6; padding: 4px 10px; border-radius: 4px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card > h3 { margin: 0; padding: 12px 14px 6px; font-size: 14px; }
.card .pad { padding: 10px 14px; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 12px; }
.kpi { padding: 12px 14px; }
.kpi .label { color: var(--ink2); font-size: 12px; }
.kpi .value { font-size: 17px; font-weight: 700; margin: 6px 0; }
.kpi .delta { font-size: 11px; color: var(--ink2); display: flex; align-items: center; gap: 8px; }
.pill { display: inline-block; padding: 2px 6px; border-radius: 3px; font-size: 11px; font-weight: 500; }
.pill.up { background: var(--green-soft); color: var(--green); }
.pill.down { background: var(--red-soft); color: var(--red); }
.pill.flat { background: #eef1f6; color: var(--ink2); }
.cols-3 { grid-template-columns: 1.1fr 1fr 1fr; }
.cols-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 1200px) { .cols-3, .cols-2 { grid-template-columns: 1fr; } }

/* ---------- tabs ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 0; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 8px 18px; cursor: pointer; font-weight: 600; color: var(--ink2); font-size: 13px; }
.tabs button.on { background: var(--primary-soft); color: var(--ink); }
.tabs button .n { background: var(--red); color: #fff; font-size: 11px; border-radius: 9px; padding: 1px 6px; margin-left: 6px; }

/* ---------- toolbar / forms ---------- */
.toolbar { display: flex; gap: 10px; align-items: flex-end; padding: 10px 14px; flex-wrap: wrap; border-bottom: 1px solid var(--line2); }
.toolbar .grow { flex: 1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 500; color: var(--ink2); }
.field .help { font-size: 12px; color: var(--muted); }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=password], input[type=month], input[type=search], select, textarea {
  border: 1px solid #c4cad6; border-radius: 6px; padding: 6px 10px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- buttons ---------- */
.btn { border: 1px solid transparent; border-radius: 6px; padding: 7px 14px; cursor: pointer; font-weight: 600; background: var(--primary); color: #fff; white-space: nowrap; }
.btn:hover { background: var(--primary-d); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--ink); border-color: #c4cad6; }
.btn.ghost:hover { background: #f2f4f8; }
.btn.danger { background: var(--red); }
.btn.green { background: var(--green); }
.btn.sm { padding: 5px 12px; font-size: 13px; font-weight: 500; }
.act { border-radius: 7px; padding: 2px 9px; background: #fff; border: 1px solid; cursor: pointer; font-size: 12px; margin-right: 4px; white-space: nowrap; }
.act.g { color: var(--green); border-color: var(--green); }
.act.o { color: #b06a00; border-color: #f0b100; }
.act.r { color: var(--red); border-color: var(--red); }
.act.b { color: var(--primary); border-color: var(--primary); }
.act:hover { filter: brightness(.96); background: #fafafa; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 18px; color: var(--ink2); padding: 6px; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; max-height: calc(100vh - 240px); }
.table-wrap.tall { max-height: none; }
table.t { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.t th { background: #f3f4f7; text-align: left; padding: 8px 9px; font-size: 12px; font-weight: 600; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
table.t td { padding: 6px 9px; border-top: 1px solid var(--line2); color: var(--ink2); vertical-align: middle; }
table.t tr:hover td { background: #fafbfd; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t td.strong { color: var(--ink); font-weight: 500; }
table.t tr.flag td:first-child { box-shadow: inset 4px 0 0 var(--red); }
table.t tfoot td { font-weight: 700; color: var(--ink); background: #fafbfd; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.foot { display: flex; gap: 22px; padding: 10px 16px; font-size: 12px; color: var(--ink2); border-top: 1px solid var(--line2); flex-wrap: wrap; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; white-space: nowrap; font-weight: 500; }
.b-green { background: var(--green-soft); color: var(--green); }
.b-red { background: var(--red-soft); color: var(--red); }
.b-amber { background: var(--amber-soft); color: var(--amber); }
.b-blue { background: var(--primary-tint); color: var(--primary-d); }
.b-gray { background: #eef1f6; color: var(--ink2); }
.dot-num { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 10px; font-size: 11px; padding: 0 6px; }

/* ---------- region / supplier cards ---------- */
.tiles { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.tile { padding: 14px; }
.tile .head { display: flex; justify-content: space-between; align-items: center; }
.tile h4 { margin: 10px 0; font-size: 14px; }
.tile .stat { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.tile .stat + .stat { border-top: 1px solid var(--line2); }
.tile .stat b { display: block; }
.tile .stat small { color: var(--ink2); }

/* ---------- manager bars ---------- */
.bars { padding: 4px 14px 14px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; padding: 6px 0; }
.bar-row .name { font-weight: 500; font-size: 13px; }
.bar-row .val { font-size: 12px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.bar-track { grid-column: 1 / -1; height: 6px; background: #eef1f6; border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 3px; }
.chart { padding: 8px 16px 16px; position: relative; }
.chart svg { width: 100%; height: 190px; display: block; }
.chart .tip { position: absolute; pointer-events: none; background: #1b1f2a; color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); }
.legend-line { display: flex; gap: 16px; flex-wrap: wrap; padding: 0 20px 16px; font-size: 13px; color: var(--ink2); }

/* ---------- modal & toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20, 24, 33, .45); display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 920px; }
.modal header { display: flex; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line2); }
.modal header h2 { margin: 0; font-size: 15px; }
.modal header .x { margin-left: auto; }
.modal .body { padding: 14px 18px; max-height: calc(100vh - 230px); overflow-y: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 18px; border-top: 1px solid var(--line2); }
.err { background: var(--red-soft); color: #a8151a; padding: 10px 12px; border-radius: 6px; margin-bottom: 14px; white-space: pre-wrap; }
.note { background: var(--primary-tint); color: #183f7a; padding: 10px 12px; border-radius: 6px; margin-bottom: 14px; font-size: 13px; }
.warn { background: var(--amber-soft); color: #7a4c00; padding: 10px 12px; border-radius: 6px; margin-bottom: 14px; font-size: 13px; }
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1b1f2a; color: #fff; padding: 12px 16px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 380px; }
.toast.error { background: #a8151a; }
.toast.ok { background: #136c3c; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 5px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.timeline li { padding: 6px 0 10px 16px; position: relative; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline small { color: var(--muted); }
.section-title { font-weight: 700; margin: 18px 0 8px; }
.err-list { max-height: 220px; overflow: auto; font-size: 13px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #eaf3ff, #f7f8fb); padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 26px; }
.login h1 { margin: 12px 0 4px; font-size: 22px; }
.login p { color: var(--ink2); margin: 0 0 22px; }
.login form { display: flex; flex-direction: column; gap: 14px; }

@media (max-width: 900px) {
  .side { transform: translateX(-100%); }
  .shell.open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .main { margin-left: 0; }
  .imei-search input { width: 150px; }
  .who div { display: none; }
}
@media print {
  .side, .top, .no-print, .toolbar { display: none !important; }
  .main { margin: 0; }
  .table-wrap { max-height: none; overflow: visible; }
}
table.t td.strong { white-space: nowrap; }

/* ---------- phone checkout ---------- */
.checkout { max-width: 520px; margin: 0 auto; }
.stepper { display: flex; align-items: flex-start; margin: 0 10px 16px; }
.stepper .st { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 130px; color: var(--ink2); }
.stepper .st span { width: 24px; height: 24px; border-radius: 50%; background: #9aa1ad; color: #fff; display: grid; place-items: center; font-size: 12px; }
.stepper .st.on span { background: #1976d2; }
.stepper .st.on small { color: var(--ink); font-weight: 600; }
.stepper .st small { font-size: 13px; }
.stepper .st-line { flex: 1; height: 1px; background: #bbb; margin-top: 12px; }
.co-form { display: flex; flex-direction: column; gap: 13px; }
label.float { position: relative; display: block; }
label.float input, label.float select { width: 100%; padding: 11px 12px; background: #f5f5f5; border: 1px solid #c8c8c8; border-radius: 4px; font-size: 14px; }
label.float span { position: absolute; left: 10px; top: 11px; color: #666; font-size: 14px; pointer-events: none; background: transparent; padding: 0 4px; transition: all .12s; }
label.float input:focus + span, label.float input:not(:placeholder-shown) + span, label.float.has span {
  top: -8px; font-size: 11.5px; background: linear-gradient(#fff 50%, #f5f5f5 50%); color: #555; }
label.float input:focus + span { color: #1976d2; }
.co-phone { background: var(--primary-tint); border-radius: 6px; padding: 10px 14px; font-size: 14px; }
.co-btn { width: 100%; padding: 11px; font-size: 14px; font-weight: 500; background: #3b82f6; color: #111; }
.co-btn:hover { background: #2f74e6; }
.co-confirm { margin-bottom: 16px; }
.co-actions { display: flex; gap: 12px; }
.co-actions .btn.ghost { width: 40%; }

/* phones: tables scroll sideways, toolbar stacks */
@media (max-width: 700px) {
  .page { padding: 12px 10px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .toolbar .field, .toolbar input[type=search] { width: 100%; min-width: 0 !important; }
  .page-head .right { margin-left: 0; width: 100%; }
  .overlay { padding: 16px 8px; }
  .modal .body { max-height: calc(100vh - 140px); }
  .kv { grid-template-columns: 120px 1fr; }
}

table.t td { white-space: nowrap; }
table.t td.wrap { white-space: normal; min-width: 180px; max-width: 320px; }

/* blank logo space – fills in when public/logo.png is added */
.logo-slot { display: grid; place-items: center; flex: none; }
.logo-slot img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-slot.sm { width: 30px; height: 30px; }
.logo-slot.lg { width: 120px; height: 64px; margin: 0 auto 4px; }
.login h1 { text-align: center; margin-bottom: 20px; }
