:root {
  --brand: #0f766e; --brand-dark: #115e59; --brand-deep: #0b2e2c; --brand-soft: #e0f4f1; --brand-light: #3fb8ac;
  --side-text: #cde6e3; --side-muted: #8bbab5; --avatar: #14675f; --focus: rgba(15, 118, 110, .15);
  --hero-p: #cdeeea; --hero-meta: #9fd3cd;
  --bg: #f2f6f6; --card: #fff; --text: #172a29; --muted: #5f7573; --line: #dbe6e5;
  --ok: #0f6a33; --ok-soft: #e7f5ec;
  --danger: #c0392b; --danger-soft: #fdecea; --warn: #b7791f; --warn-soft: #fdf3dc; --info: #1d6fa5; --info-soft: #e3f1fa;
  --radius: 10px; --shadow: 0 1px 2px rgba(10, 20, 50, .06), 0 2px 10px rgba(10, 20, 50, .05);
  --sidebar-w: 248px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 13px; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero { background: linear-gradient(155deg, var(--brand-deep), var(--brand) 120%); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-hero h1 { font-size: 34px; letter-spacing: -.5px; margin: 28px 0 10px; }
.login-hero p { color: var(--hero-p); max-width: 440px; font-size: 15px; }
.login-hero .meta { color: var(--hero-meta); font-size: 13px; line-height: 1.7; }
.login-card { display: flex; align-items: center; justify-content: center; padding: 32px; }
.login-card form { width: 100%; max-width: 360px; }
.login-card h2 { font-size: 24px; margin-bottom: 4px; }
.mark { display: block; flex: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.slip-brand { display: flex; align-items: center; gap: 14px; }
.login-mobile-logo { display: none; }
@media (max-width: 860px) { .login-mobile-logo { display: block; margin-bottom: 14px; } }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--brand-deep); color: var(--side-text); display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 40; transition: transform .2s; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.brand b { display: block; color: #fff; font-size: 14px; line-height: 1.2; }
.brand span { font-size: 11px; color: var(--side-muted); letter-spacing: .6px; text-transform: uppercase; }
.nav { flex: 1; overflow-y: auto; padding: 8px 10px 16px; }
.nav-head { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--side-muted); padding: 16px 10px 6px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px; color: var(--side-text); margin-bottom: 2px; }
.nav a:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; font-weight: 600; }
.side-user { border-top: 1px solid rgba(255, 255, 255, .08); padding: 12px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--avatar); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.side-user .who { flex: 1; min-width: 0; }
.side-user .who b { display: block; color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user .who span { font-size: 11px; color: var(--side-muted); text-transform: capitalize; }
.icon-btn { background: none; border: 0; color: inherit; cursor: pointer; padding: 6px; border-radius: 6px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: rgba(255, 255, 255, .1); }
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 24px; position: sticky; top: 0; z-index: 30; }
.topbar .crumb { font-size: 12px; color: var(--muted); }
.topbar h1 { font-size: 18px; }
.topbar .spacer { flex: 1; }
.topbar .date { color: var(--muted); font-size: 13px; }
.burger { display: none; color: var(--text); }
.burger:hover { background: var(--bg); }
.page { padding: 24px; max-width: 1400px; width: 100%; }
.scrim { display: none; }

/* ---------- components ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-h h3 { font-size: 15px; }
.card-b { padding: 18px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.btn:hover { background: #f4f7f5; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: #fff; color: var(--danger); border-color: #efc4be; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; justify-content: center; padding: 11px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); align-items: center; }
.toolbar .grow { flex: 1; min-width: 200px; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; border: 1px solid #cfd9d3; border-radius: 8px; padding: 8px 11px; background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus); }
input[readonly], select:disabled { background: #f1f4f2; color: #55645b; }
textarea { resize: vertical; min-height: 64px; }
label.f { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 5px; color: #34473c; }
label.f .req { color: var(--danger); }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(3, 1fr); } .g4 { grid-template-columns: repeat(4, 1fr); }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .span4 { grid-column: 1 / -1; }
.checkline { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.checkline input { width: 16px; height: 16px; accent-color: var(--brand); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 10px 14px; background: #f8faf9; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid #edf1ee; vertical-align: top; }
tbody tr:hover { background: #fafcfb; }
tbody tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-top: 1px solid var(--line); color: var(--muted); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.b-green { background: var(--ok-soft); color: var(--ok); }
.b-red { background: var(--danger-soft); color: var(--danger); }
.b-amber { background: var(--warn-soft); color: var(--warn); }
.b-blue { background: var(--info-soft); color: var(--info); }
.b-grey { background: #eceff1; color: #52606a; }
.b-purple { background: #efe7fb; color: #6a3fb0; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px; }
.alert.err { background: var(--danger-soft); color: var(--danger); border: 1px solid #f3c6c0; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: #7a5410; border: 1px solid #efd9a3; }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.stat { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.stat .ico { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.stat .ico.blue { background: var(--info-soft); color: var(--info); } .stat .ico.amber { background: var(--warn-soft); color: var(--warn); } .stat .ico.purple { background: #efe7fb; color: #6a3fb0; }
.stat .num { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: 12.5px; }
.dash-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; margin-bottom: 16px; }
.bars { display: flex; align-items: flex-end; gap: 12px; height: 160px; padding: 6px 6px 0; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.bar i { display: block; width: 100%; max-width: 44px; background: linear-gradient(var(--brand), var(--brand-light)); border-radius: 6px 6px 0 0; min-height: 3px; }
.bar i.zero { background: #dfe7e2; }
.bar b { font-size: 12px; } .bar span { font-size: 11px; color: var(--muted); }
.sale-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid #edf1ee; gap: 12px; }
.sale-row:last-child { border: 0; }
.quick { display: flex; gap: 10px; flex-wrap: wrap; }

/* dispatch form */
.sale-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.sale-card { border: 2px solid var(--line); border-radius: 10px; padding: 14px 16px; cursor: pointer; background: #fff; display: flex; gap: 12px; align-items: flex-start; }
.sale-card:hover { border-color: #9fcfb0; }
.sale-card.sel { border-color: var(--brand); background: var(--brand-soft); }
.sale-card.locked { cursor: default; opacity: .55; }
.sale-card.locked.sel { opacity: 1; }
.sale-card input { margin-top: 3px; accent-color: var(--brand); }
.sale-card b { display: block; }
.sale-card span { color: var(--muted); font-size: 12.5px; }
.sec-title { font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--brand-dark); font-weight: 700; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.party-detail { background: #f8faf9; border: 1px dashed #c9d6ce; border-radius: 8px; padding: 10px 14px; margin-top: 10px; font-size: 13px; }
.party-row { display: flex; gap: 8px; }
.party-row input { flex: 1; }
.lines th, .lines td { padding: 7px 8px; }
.lines input, .lines select { padding: 6px 8px; }
.lines td { vertical-align: middle; }
.sticky-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.totals { display: flex; justify-content: flex-end; gap: 28px; padding: 12px 18px; background: #f8faf9; border-top: 1px solid var(--line); font-weight: 600; flex-wrap: wrap; }

/* slip (view + print) */
.slip { padding: 28px 32px; }
.slip-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--brand); padding-bottom: 14px; margin-bottom: 16px; }
.slip-head h2 { font-size: 20px; color: var(--brand-dark); }
.slip-title { text-align: right; }
.slip-title h3 { font-size: 17px; letter-spacing: .5px; text-transform: uppercase; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 22px; margin-bottom: 18px; }
.kv > div > span:first-child { display: block; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; }
.kv div b { font-weight: 600; }
.sign { display: grid; grid-template-columns: repeat(3, 1fr); gap: 30px; margin-top: 60px; text-align: center; color: var(--muted); font-size: 12.5px; }
.sign div { border-top: 1px solid #9aa9a0; padding-top: 6px; }
.print-only { display: none; }

/* modal + toast */
.modal-back { position: fixed; inset: 0; background: rgba(10, 30, 18, .5); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal.narrow { max-width: 440px; }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-h h3 { font-size: 16px; }
.modal-h .icon-btn { color: var(--muted); } .modal-h .icon-btn:hover { background: var(--bg); }
.modal-b { padding: 20px; }
.modal-f { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fafcfb; border-radius: 0 0 12px 12px; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #17382a; color: #fff; padding: 11px 16px; border-radius: 9px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: 360px; animation: pop .2s; }
.toast.err { background: #a32e22; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.spinner { padding: 50px; text-align: center; color: var(--muted); }
.details-cell { max-width: 520px; word-break: break-word; font-size: 13px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(2, 1fr); } .dash-grid { grid-template-columns: 1fr; } .g4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px) {
  .login-wrap { grid-template-columns: 1fr; } .login-hero { display: none; }
  .sidebar { transform: translateX(-100%); }
  .shell.open .sidebar { transform: none; }
  .shell.open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 35; }
  .main { margin-left: 0; } .burger { display: inline-grid; } .topbar { padding: 0 14px; } .page { padding: 14px; }
  .topbar .date { display: none; }
  .g2, .g3, .g4, .sale-cards, .kv { grid-template-columns: 1fr; } .span2, .span3 { grid-column: auto; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; } .stat { padding: 12px; } .stat .num { font-size: 21px; } .stat .ico { display: none; }
  .slip { padding: 16px; } .slip-head { flex-direction: column; } .slip-title { text-align: left; }
}

/* ---------- print ---------- */
@media print {
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar, .no-print, #toasts, .scrim { display: none !important; }
  .main { margin: 0; } .page { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; } .slip { padding: 0; }
  .print-only { display: block; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
