/* Hasbil design tokens -------------------------------------------------- */
:root {
  --brand-navy: #0b3a66;
  --brand-teal: #0e9f9a;
  --brand-mint: #7cf2dd;
  --ink: #0b2a4a;
  --ink-muted: #5b6b7f;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-muted: #eef2f7;
  --border: #dde4ee;
  --primary: #0b3a66;
  --primary-hover: #0a2f52;
  --primary-ink: #ffffff;
  --success: #0f8a5f;
  --success-bg: #e3f6ee;
  --warning: #a25b00;
  --warning-bg: #fff1dc;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --info: #0b6aa8;
  --info-bg: #e5f2fb;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(11, 42, 74, 0.06), 0 4px 16px rgba(11, 42, 74, 0.06);
  --sidebar: #0b2a4a;
  --sidebar-ink: #c8d6e6;
  --sidebar-active: rgba(124, 242, 221, 0.14);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6edf5;
    --ink-muted: #9aabbf;
    --bg: #0d1724;
    --surface: #132235;
    --surface-muted: #1a2c42;
    --border: #253a54;
    --primary: #2f8fd6;
    --primary-hover: #4aa2e3;
    --success-bg: #12372c;
    --success: #4fd1a0;
    --warning-bg: #3b2a10;
    --warning: #f2b45a;
    --danger-bg: #3d1a17;
    --danger: #ff8a7a;
    --info-bg: #10304a;
    --info: #7cc3f5;
    --sidebar: #08121e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

/* Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85em; }
.muted { color: var(--ink-muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Shell ----------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-ink); padding: 20px 14px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; }
.sidebar .logo img { height: 34px; display: block; }
.sidebar .badge-env { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--brand-mint); margin-top: 6px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: var(--sidebar-ink); padding: 9px 12px; border-radius: var(--radius-sm); display: flex; justify-content: space-between; align-items: center; }
.nav a:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--brand-mint); }
.nav .count { background: var(--brand-mint); color: var(--sidebar); font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; }
.main { min-width: 0; padding: 0 32px 48px; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 16px 0; border-bottom: 1px solid var(--border); margin-bottom: 24px; gap: 16px; }
.topbar .who { display: flex; align-items: center; gap: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--brand-navy), var(--brand-teal)); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header p { margin: 4px 0 0; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; gap: 12px; }
  .main { padding: 0 16px 32px; }
}

/* Surfaces -------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card > h2:first-child { margin-bottom: 14px; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat { padding: 18px 20px; }
.stat .value { font-size: 1.7rem; font-weight: 700; }
.stat .label { color: var(--ink-muted); font-size: 0.85rem; }
dl.details { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
dl.details dt { color: var(--ink-muted); }
dl.details dd { margin: 0; }

/* 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: middle; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-muted); }
td.actions { text-align: right; white-space: nowrap; }
.empty { text-align: center; padding: 32px; color: var(--ink-muted); }

/* Badges ---------------------------------------------------------------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--surface-muted); color: var(--ink-muted); }
.badge.success, .badge.active, .badge.approved { background: var(--success-bg); color: var(--success); }
.badge.warning, .badge.pending, .badge.invited, .badge.grace, .badge.not_started { background: var(--warning-bg); color: var(--warning); }
.badge.danger, .badge.disabled, .badge.revoked, .badge.rejected, .badge.expired, .badge.suspended, .badge.none, .badge.closed { background: var(--danger-bg); color: var(--danger); }
.badge.info, .badge.superseded { background: var(--info-bg); color: var(--info); }

/* Forms ----------------------------------------------------------------- */
form.stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 0.9rem; }
.field .hint { color: var(--ink-muted); font-size: 0.8rem; }
.field .error { color: var(--danger); font-size: 0.82rem; }
input[type='text'], input[type='email'], input[type='password'], input[type='date'], input[type='number'], input[type='search'], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-teal); outline-offset: 1px; border-color: transparent; }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.checkbox { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.checkbox input { margin-top: 4px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; margin: 0; }
legend { font-weight: 700; padding: 0 6px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type='search'] { max-width: 320px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; border-bottom: 2px solid transparent; color: var(--ink-muted); }
.tabs a.active { border-color: var(--brand-teal); color: var(--ink); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* Buttons --------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: 0.9rem; border-radius: var(--radius-sm); padding: 8px 14px; border: 1px solid transparent; cursor: pointer; background: var(--primary); color: var(--primary-ink); text-decoration: none; }
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-muted); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.success { background: var(--success); color: #fff; }
.btn.link { background: none; color: var(--primary); padding: 0; border: none; }
.btn.small { padding: 5px 10px; font-size: 0.8rem; }
.btn.block { width: 100%; }
.btn[disabled], .htmx-request .btn[type='submit'] { opacity: 0.6; pointer-events: none; }
form.inline { display: inline; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Alerts ---------------------------------------------------------------- */
.alert { border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; border: 1px solid transparent; }
.alert.success { background: var(--success-bg); color: var(--success); }
.alert.error { background: var(--danger-bg); color: var(--danger); }
.alert.info { background: var(--info-bg); color: var(--info); }
.alert.warning { background: var(--warning-bg); color: var(--warning); }

/* Auth pages ------------------------------------------------------------ */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1200px 600px at 10% -10%, rgba(14, 159, 154, 0.18), transparent 60%),
  radial-gradient(900px 500px at 110% 110%, rgba(11, 58, 102, 0.22), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 32px; }
.auth-card .logo { display: block; height: 40px; margin: 0 auto 24px; }
.auth-card h1 { text-align: center; font-size: 1.25rem; }
.auth-card .sub { text-align: center; color: var(--ink-muted); margin-bottom: 20px; }
.auth-footer { text-align: center; color: var(--ink-muted); font-size: 0.8rem; margin-top: 18px; }
.qr { display: block; width: 200px; height: 200px; margin: 0 auto 12px; background: #fff; padding: 8px; border-radius: 8px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 0; list-style: none; }
.codes li { font-family: ui-monospace, Menlo, monospace; background: var(--surface-muted); padding: 6px 10px; border-radius: 6px; text-align: center; }
.pagination { display: flex; justify-content: flex-end; margin-top: 12px; }
.license-banner { margin-bottom: 20px; }
.text-right { text-align: right; }
.spaced { margin-bottom: 16px; }
.spaced-top { margin-top: 12px; }
.nav-section { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: #7f93ab; padding: 14px 12px 4px; }
.sidebar { overflow-y: auto; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }
.lines td { vertical-align: top; padding: 6px; }
.lines input, .lines select { padding: 6px 8px; font-size: 0.9rem; }
.lines .w-code { width: 180px; }
.lines .w-qty { width: 110px; }
.lines .w-unit { width: 100px; }
.lines .w-cost { width: 120px; }
.lines .w-lot { width: 130px; }
.lines .product-label { font-size: 0.82rem; color: var(--ink-muted); margin-top: 4px; }
.lines .line-error { font-size: 0.8rem; color: var(--danger); margin-top: 4px; }
.row-remove { background: none; border: none; color: var(--ink-muted); cursor: pointer; font-size: 1.1rem; padding: 6px; }
.row-remove:hover { color: var(--danger); }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { min-width: 120px; }
.subtle-row td { background: var(--surface-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
details.editor summary { cursor: pointer; color: var(--primary); }
details.editor[open] { background: var(--surface-muted); border-radius: var(--radius-sm); padding: 10px; }
.lines .w-price { width: 110px; }
.lines .w-pct { width: 70px; }
.lines .w-unit select { min-width: 96px; }
.lines .w-pct select, .lines .w-pct input { min-width: 64px; }
.totals { margin-left: auto; min-width: 280px; }
.totals td { border: none; padding: 4px 8px; }
.totals tr.grand td { font-weight: 700; border-top: 1px solid var(--border); }
.progress-cell { font-size: 0.8rem; color: var(--ink-muted); }
.actions-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
/* Printable documents */
.print-page { max-width: 900px; margin: 0 auto; background: #fff; color: #111; padding: 32px; font-size: 13px; }
.print-page table { font-size: 12px; }
.print-page th, .print-page td { border-bottom: 1px solid #ddd; padding: 6px 8px; }
.print-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.print-head img { height: 36px; }
.print-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 20px; }
.print-box { border: 1px solid #ddd; border-radius: 6px; padding: 12px; }
.print-only { display: none; }
@media print {
  .no-print, .sidebar, .topbar { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  body { background: #fff; }
  .print-only { display: block; }
  .print-page { padding: 0; }
}

/* Navigation: grouped sidebar, menu filter, favorites, quick-search palette, user menu ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.icon { width: 17px; height: 17px; flex: none; }
.sidebar { gap: 16px; }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sidebar-body { display: flex; flex-direction: column; gap: 12px; flex: 1; min-height: 0; }
.nav-toggle { display: none; font: inherit; font-size: 0.85rem; color: #fff; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.14); border-radius: var(--radius-sm); padding: 6px 12px; cursor: pointer; }
.nav-search { display: flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: var(--radius-sm); padding: 6px 8px 6px 10px; color: #7f93ab; }
.nav-search:focus-within { border-color: var(--brand-mint); }
.nav-search .icon { width: 15px; height: 15px; }
.nav-search input { flex: 1; min-width: 0; background: none; border: none; outline: none; padding: 2px 0; color: #fff; font: inherit; font-size: 0.88rem; }
.nav-search input::placeholder { color: #7f93ab; }
.nav-search input::-webkit-search-cancel-button { filter: invert(1); opacity: 0.6; }
kbd { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; opacity: 0.7; white-space: nowrap; }
.nav-kbd { cursor: pointer; }
.nav { flex: 1; }
.nav a { justify-content: flex-start; gap: 10px; }
.nav a > span:not(.count) { flex: 1; }
.nav-row { position: relative; }
.nav-row > a { padding-right: 30px; }
.nav-star { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: #7f93ab; font-size: 13px; line-height: 1; padding: 5px; border-radius: 4px; opacity: 0; }
.nav-row:hover .nav-star, .nav-star:focus-visible, .nav-star[aria-pressed="true"] { opacity: 1; }
.nav-star[aria-pressed="true"] { color: var(--brand-mint); }
.nav-star:hover { color: #fff; }
.nav-group > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); cursor: pointer; color: var(--sidebar-ink); user-select: none; }
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-group > summary:focus-visible, .nav a:focus-visible, .nav-star:focus-visible, .nav-toggle:focus-visible { outline: 2px solid var(--brand-mint); outline-offset: 1px; }
.nav-group[data-nav-active] > summary { color: #fff; }
.nav-group > summary .grow { flex: 1; }
.nav-group .chevron { width: 14px; height: 14px; opacity: 0.6; }
.nav-group[open] > summary .chevron { transform: rotate(90deg); }
.nav-sub { display: flex; flex-direction: column; gap: 1px; padding: 2px 0 6px 18px; }
.nav-sub a { padding-top: 6px; padding-bottom: 6px; font-size: 0.92rem; }
.nav-block { display: flex; flex-direction: column; gap: 1px; }
.nav-subtitle { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: #7f93ab; padding: 8px 12px 2px; }
.nav-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, 0.08); flex: none; }
.nav-favorites a .icon { color: var(--brand-mint); width: 14px; height: 14px; }
.nav-empty { color: #7f93ab; font-size: 0.85rem; padding: 8px 12px; margin: 0; }
.sidebar .nav-section { padding-top: 12px; }

.search-open { gap: 8px; }
.search-open .icon { width: 15px; height: 15px; }
.user-menu { position: relative; }
.user-menu > summary { list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer; border-radius: 999px; padding: 2px 2px 2px 10px; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover { background: var(--surface-muted); }
.user-menu > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.user-menu-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 230px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(11, 42, 74, 0.16); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.user-menu-panel a { color: var(--ink); }
.user-menu-panel form { margin: 0; }

.palette { width: min(560px, calc(100vw - 32px)); max-height: min(560px, calc(100vh - 96px)); margin: 72px auto auto; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(5, 15, 28, 0.35); }
.palette[open] { display: flex; flex-direction: column; }
.palette::backdrop { background: rgba(5, 15, 28, 0.45); }
.palette-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--ink-muted); }
.palette-head input { flex: 1; min-width: 0; border: none; outline: none; background: none; font: inherit; font-size: 1rem; color: var(--ink); padding: 6px 0; }
.palette-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.palette-list a { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--ink); text-decoration: none; }
.palette-list a > span:first-child { display: flex; align-items: center; gap: 10px; }
.palette-list a .icon { width: 15px; height: 15px; color: var(--ink-muted); }
.palette-list a[aria-selected="true"], .palette-list a:hover { background: var(--surface-muted); }
.palette-list a[aria-selected="true"] { box-shadow: inset 3px 0 0 var(--brand-teal); }
.palette-empty, .palette-hint { margin: 0; padding: 10px 16px; }
.palette-hint { border-top: 1px solid var(--border); }

@media (max-width: 860px) {
  .js .nav-toggle { display: inline-block; }
  .js .sidebar:not(.nav-open) .sidebar-body { display: none; }
  .nav-star { opacity: 1; }
  .user-name, .search-open kbd { display: none; }
}

/* ---------------------------------------------------------------- shipments, driver screen */
.driver-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.driver-card { display: flex; flex-direction: column; gap: 6px; color: inherit; text-decoration: none; }
a.driver-card:hover { border-color: var(--primary); }
.driver-card .btn { align-self: flex-start; margin-top: 6px; }
.signature-pad { width: 100%; max-width: 600px; height: auto; aspect-ratio: 60 / 22; border: 1px dashed var(--border); border-radius: 8px; background: #fff; touch-action: none; }
.proof-preview { max-width: 240px; border-radius: 8px; border: 1px solid var(--border); }
.proofs { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.proofs img { max-height: 160px; max-width: 280px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
table.compact td { padding: 4px 8px; }

/* ---------------------------------------------------------------- personnel */
.big-number { font-size: 2rem; font-weight: 700; margin: 4px 0; }
table.timesheet { font-size: 12px; }
table.timesheet th, table.timesheet td { padding: 4px 3px; }
table.timesheet .ts-name { white-space: nowrap; position: sticky; left: 0; background: var(--surface); }
table.timesheet .ts-day { text-align: center; min-width: 26px; }
table.timesheet .ts-rest { color: var(--ink-muted); background: var(--surface-muted); }
table.timesheet .ts-leave { color: var(--primary); font-weight: 600; }
table.timesheet .ts-absent { color: var(--danger); font-weight: 700; }
table.timesheet .ts-none { color: var(--ink-muted); }
ul.timeline { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
