/* Pharmalive admin panel */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e3e8ec;
  --border-strong: #cfd7de;
  --text: #16212b;
  --text-2: #51606d;
  --text-3: #8795a1;
  --primary: #0f766e;
  --primary-2: #115e59;
  --primary-soft: #e6f4f2;
  --danger: #c2372d;
  --danger-soft: #fdecea;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --violet: #6d28d9;
  --violet-soft: #f1ebff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 1px 3px rgba(16, 24, 32, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 32, .18);
  --sidebar: 232px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 16px; }
.hidden-sm { }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex-shrink: 0; background: #0d2b2e; color: #cfe3e1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 22px; font-weight: 700; font-size: 16px; color: #fff; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: #8fb3b0; letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6d9591; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #cfe3e1; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav a.active { background: rgba(94, 234, 212, .12); color: #fff; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.sidebar-foot { margin-top: auto; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot .role { color: #8fb3b0; font-size: 12px; margin-bottom: 8px; }
.linkbtn { background: none; border: 0; padding: 0; color: #8fd9cf; cursor: pointer; font-size: 13px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.page { padding: 24px 28px 48px; max-width: 1480px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.crumb { font-size: 13px; color: var(--text-3); margin-bottom: 4px; }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; word-break: break-word; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { font-size: 12px; color: var(--text-3); }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.ok .value { color: var(--ok); } .stat.warn .value { color: var(--warn); } .stat.bad .value { color: var(--danger); }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 600;
  white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a42e25; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field .err { color: var(--danger); font-size: 12px; }
.field .hint { color: var(--text-3); font-size: 12px; }
.input, .select, .textarea {
  height: 36px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; width: 100%; min-width: 0;
}
.textarea { height: auto; min-height: 70px; padding: 8px 10px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid rgba(15, 118, 110, .25); border-color: var(--primary); }
.input.invalid, .select.invalid { border-color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); align-items: flex-end; }
.filters .field { min-width: 140px; }
.filters .field.search { flex: 1; min-width: 220px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 600; font-size: 12px; color: var(--text-3); padding: 9px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover td { background: #f3f8f7; }
.tbl .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.tbl tr.row-error td { background: #fff7f6; }
.tbl tr.row-dup td { background: #fffaf0; }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border); }
.empty { padding: 40px; text-align: center; color: var(--text-3); }

.pager { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-2); gap: 10px; flex-wrap: wrap; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #eef1f3; color: var(--text-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.s-new { background: #eef1f3; color: #4b5b68; }
.badge.s-received { background: var(--info-soft); color: var(--info); }
.badge.s-ready { background: var(--primary-soft); color: var(--primary); }
.badge.s-assigned { background: var(--violet-soft); color: var(--violet); }
.badge.s-on_the_way { background: var(--warn-soft); color: var(--warn); }
.badge.s-delivered { background: var(--ok-soft); color: var(--ok); }
.badge.s-failed, .badge.s-error { background: var(--danger-soft); color: var(--danger); }
.badge.s-returned { background: #fdf0e6; color: #9a4a0b; }
.badge.s-cancelled { background: #f1f1f1; color: #7a7a7a; text-decoration: line-through; }
.badge.s-duplicate { background: var(--warn-soft); color: var(--warn); }
.badge.s-ok, .badge.s-active { background: var(--ok-soft); color: var(--ok); }
.badge.s-off { background: #f1f1f1; color: #7a7a7a; }
.pill-warn { color: var(--warn); font-size: 12px; font-weight: 600; }

/* ---------- Alerts ---------- */
.alert { border-radius: var(--radius); padding: 12px 14px; border: 1px solid; margin-bottom: 14px; display: flex; gap: 10px; align-items: flex-start; }
.alert.warn { background: var(--warn-soft); border-color: #f5d7a8; color: #7a3f05; }
.alert.bad { background: var(--danger-soft); border-color: #f4c3be; color: #8a241c; }
.alert.ok { background: var(--ok-soft); border-color: #bfe5cb; color: #0f5b2c; }
.alert.info { background: var(--info-soft); border-color: #c8d7ff; color: #1b3a8f; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; padding: 10px 14px 0; border-bottom: 1px solid var(--border); }
.tab { border: 0; background: none; padding: 8px 12px; cursor: pointer; font-weight: 600; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--primary); border-color: var(--primary); }
.tab .count { font-weight: 500; color: var(--text-3); margin-left: 4px; }

/* ---------- Drop zone ---------- */
.drop { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 28px; text-align: center; background: var(--surface); cursor: pointer; transition: border-color .12s, background .12s; }
.drop:hover, .drop.over { border-color: var(--primary); background: var(--primary-soft); }
.drop strong { display: block; font-size: 15px; margin-bottom: 4px; }
.drop input { display: none; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 16px; bottom: 0; width: 2px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .t-title { font-weight: 600; }
.timeline .t-meta { font-size: 12px; color: var(--text-3); }
.timeline .t-data { font-size: 12.5px; color: var(--text-2); margin-top: 3px; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 25, 30, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 620px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.x { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-3); padding: 0 4px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #16212b; color: #fff; padding: 11px 14px; border-radius: 8px; box-shadow: var(--shadow-lg); max-width: 380px; font-size: 13.5px; }
.toast.bad { background: var(--danger); }
.toast.ok { background: #14532d; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #0d2b2e 0%, #134e4a 100%); }
.login { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 28px; box-shadow: var(--shadow-lg); }
.login .brand { color: var(--text); padding: 0 0 20px; }
.login .brand small { color: var(--text-3); }
.login form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Responsive (tablet) ---------- */
@media (max-width: 960px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: #0d2b2e; color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .page { padding: 16px; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 120px 1fr; }
  .hidden-sm { display: none; }
}

/* ---------- Warehouse ---------- */
.wh-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.wh-tab { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; }
.wh-tab:hover { border-color: var(--border-strong); }
.wh-tab.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(15,118,110,.18); }
.wh-tab .label { font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.wh-tab .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.wh-tab .sub { font-size: 12px; color: var(--text-3); }
.scanbar { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.scanbar .input { height: 42px; font-size: 16px; max-width: 420px; }
.actionbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--primary-soft); border-bottom: 1px solid #cde9e5; flex-wrap: wrap; }
.tbl td.cb, .tbl th.cb { width: 36px; padding-right: 0; }
.tbl input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.tbl tr.selected td { background: #eef8f6; }
.qr-box { display: flex; gap: 16px; align-items: flex-start; }
.qr-box .qr { width: 120px; height: 120px; flex-shrink: 0; border: 1px solid var(--border); border-radius: 8px; padding: 6px; background: #fff; }
.qr-box .qr svg { width: 100%; height: 100%; display: block; }
@media (max-width: 960px) { .wh-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Label printing ---------- */
#print-root { display: none; }
@media print {
  body { background: #fff !important; }
  body > #app { display: none !important; }
  #print-root { display: block; }
}
.lbl { box-sizing: border-box; overflow: hidden; display: flex; gap: 2mm; padding: 2mm; color: #000; background: #fff;
  font-family: Arial, Helvetica, sans-serif; page-break-after: always; break-after: page; }
.lbl:last-child { page-break-after: auto; break-after: auto; }
.lbl .lq { flex-shrink: 0; }
.lbl .lq svg { width: 100%; height: 100%; display: block; }
.lbl .lt { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.lbl .no { font-weight: 800; }
.lbl .ph { font-weight: 700; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lbl .ad { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lbl .rg { font-weight: 700; }
.lbl .ft { margin-top: auto; display: flex; justify-content: space-between; align-items: flex-end; gap: 2mm; }
.lbl .pk { font-weight: 800; border: 0.4mm solid #000; padding: 0 1.2mm; border-radius: 1mm; white-space: nowrap; }
.lbl .co { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
/* 58 x 40 mm thermal */
.f-t58 .lbl { width: 58mm; height: 40mm; }
.f-t58 .lq { width: 25mm; height: 25mm; }
.f-t58 .no { font-size: 12pt; } .f-t58 .ph { font-size: 7.5pt; } .f-t58 .ad { font-size: 6pt; -webkit-line-clamp: 2; }
.f-t58 .rg { font-size: 7pt; } .f-t58 .pk { font-size: 9pt; } .f-t58 .co { font-size: 5.5pt; }
/* 80 x 50 mm thermal */
.f-t80 .lbl { width: 80mm; height: 50mm; padding: 3mm; gap: 3mm; }
.f-t80 .lq { width: 32mm; height: 32mm; }
.f-t80 .no { font-size: 15pt; } .f-t80 .ph { font-size: 9pt; } .f-t80 .ad { font-size: 7pt; -webkit-line-clamp: 3; }
.f-t80 .rg { font-size: 8.5pt; } .f-t80 .pk { font-size: 11pt; } .f-t80 .co { font-size: 6.5pt; }
/* A4 sheet: 3 x 8 labels of 70 x 37 mm (common self-adhesive sheet) */
.f-a4 .sheet { width: 210mm; height: 297mm; padding: 0; display: grid; grid-template-columns: repeat(3, 70mm);
  grid-auto-rows: 37mm; align-content: start; page-break-after: always; break-after: page; }
.f-a4 .sheet:last-child { page-break-after: auto; break-after: auto; }
.f-a4 .lbl { width: 70mm; height: 37mm; page-break-after: auto; break-after: auto; padding: 2.5mm; border: 0.2mm dashed #bbb; }
.f-a4 .lq { width: 26mm; height: 26mm; }
.f-a4 .no { font-size: 12pt; } .f-a4 .ph { font-size: 7.5pt; } .f-a4 .ad { font-size: 6pt; }
.f-a4 .rg { font-size: 7pt; } .f-a4 .pk { font-size: 9pt; } .f-a4 .co { font-size: 5.5pt; }

/* ---------- Dispatcher ---------- */
.dispatch { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; align-items: start; }
.driver-list { display: flex; flex-direction: column; max-height: 70vh; overflow-y: auto; }
.driver { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: none; border: 0; border-top: 1px solid var(--border); text-align: left; cursor: pointer; width: 100%; }
.driver:hover { background: var(--surface-2); }
.driver.active { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.driver .sub { font-size: 12px; color: var(--text-3); }
.driver .load { display: flex; gap: 4px; flex-shrink: 0; }
.driver .badge { padding: 2px 7px; }
.driver .badge::before { display: none; }
@media (max-width: 1100px) { .dispatch { grid-template-columns: 1fr; } }

/* ---------- Delivery attempts ---------- */
.attempts { display: flex; flex-direction: column; gap: 10px; }
.attempt { display: flex; gap: 14px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: 10px; border-left: 4px solid var(--ok); }
.attempt.failed { border-left-color: var(--danger); }
.attempt-photo img { width: 140px; height: 105px; object-fit: cover; border-radius: 8px; cursor: zoom-in; border: 1px solid var(--border); }
