:root {
  --navy: #10243a;
  --navy-2: #1b3d5c;
  --orange: #f26b21;
  --orange-soft: #fff1e8;
  --bg: #f4f7fb;
  --ink: #142433;
  --muted: #5d6d7c;
  --card: #ffffff;
  --line: #e3eaf1;
  --shadow: 0 10px 30px rgba(16, 36, 58, 0.06);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body.signed-in #login-screen { display: none !important; }
body:not(.signed-in) #app { display: none !important; }
body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.logo-frame { display: block; flex: 0 0 auto; background: white; }
.logo { display: block; height: 48px; width: auto; background: white; }
.logo-frame-lg { margin: 0 auto 8px; }
.logo-lg { height: 84px; margin: 0 auto; }
.logo-sm { height: 28px; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(242, 107, 33, 0.08), transparent 28%),
    var(--bg);
}
.login-card {
  width: min(440px, 100%);
  background: white;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 28px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card h1 { margin: 8px 0 4px; font-size: 28px; }
.login-card .lede { text-align: center; }
.brand-line { margin: 0; color: var(--orange); font-weight: 700; letter-spacing: 0.01em; }
.login-card label { display: block; text-align: left; font-size: 13px; font-weight: 650; margin: 14px 0 6px; }
.login-card input { width: 100%; }
.login-card button[type="submit"] { width: 100%; margin-top: 16px; }

input, select, .ghost, .primary {
  border-radius: 10px;
  border: 1px solid var(--line);
  background: white;
  padding: 10px 12px;
}
.primary, .login-card button[type="submit"] {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
  font-weight: 700;
}
.primary:hover, .login-card button[type="submit"]:hover { background: var(--navy-2); }
.ghost:hover { border-color: var(--navy); }
.row-button { padding: 6px 10px; }
.lede, .message { color: var(--muted); }
.message { min-height: 1.2em; }

header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 12px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand strong { display: block; font-size: 16px; }
.brand p { margin: 2px 0 0; color: var(--orange); font-size: 13px; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
#sign-out { padding: 8px 12px; }

main { padding: 24px 28px 88px; max-width: 1280px; margin: 0 auto; }
.page-head, .page-actions { display: flex; align-items: center; gap: 12px; }
.page-head { justify-content: space-between; margin-bottom: 16px; }
.page-actions { flex-wrap: wrap; justify-content: flex-end; }
.page-actions button { white-space: nowrap; flex: 0 0 auto; }
#detail-screen .page-head { justify-content: flex-start; }
.page-head h2 { margin: 0; font-size: 28px; }
.page-head .lede { margin: 4px 0 0; }

.kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  text-align: left;
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
}
.kpi strong { display: block; font-size: 26px; line-height: 1.1; }
.kpi span { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); font-weight: 650; }
.kpi.active {
  border-color: var(--navy);
  box-shadow: inset 3px 0 0 var(--orange), var(--shadow);
}
.kpi:hover { border-color: var(--navy-2); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 14px;
}
.filters label { display: grid; gap: 6px; min-width: 140px; }
.filters label > span { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }
.filters .grow { flex: 1 1 280px; }
.filters input, .filters select, .maker-button { width: 100%; }
#clear-filters { height: 42px; }

.maker-select { position: relative; min-width: 190px; }
.maker-button {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) right 16px center / 6px 6px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) right 12px center / 6px 6px no-repeat,
    white;
  padding-right: 32px;
}
.maker-button[aria-expanded="true"] { border-color: var(--navy); }
.maker-logo { width: 22px; height: 22px; display: grid; place-items: center; flex: 0 0 auto; }
.maker-logo svg { width: 22px; height: 22px; display: block; }
.maker-logo img { width: 36px; height: 20px; object-fit: contain; display: block; }
.maker-menu {
  position: absolute;
  z-index: 8;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.maker-menu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 8px;
  text-align: left;
}
.maker-menu button[aria-selected="true"],
.maker-menu button:hover { background: #f4f7fb; }

.table-wrap {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: auto;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
.list-table { table-layout: fixed; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list-table .mono, .list-table .nowrap { white-space: nowrap; }
.list-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th button {
  padding: 0;
  border: 0;
  background: none;
  font-weight: 750;
  color: var(--muted);
}
th button[aria-sort="ascending"]::after { content: " ↑"; color: var(--navy); }
th button[aria-sort="descending"]::after { content: " ↓"; color: var(--navy); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7fbff; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; }
.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef3f8;
  color: var(--navy);
  font-weight: 700;
  text-transform: capitalize;
}
.pill.checked_in { background: var(--orange-soft); color: #9a3d08; }
.pill.parked { background: #e7f6ee; color: #0f6b3c; }
.pill.inspected { background: #e8f1ff; color: #1d4e89; }
.pill.checked_out { background: #f3f4f6; color: #4b5563; }
.pill.dispatched, .pill.loaded, .pill.staged { background: #efeaff; color: #4c1d95; }
.empty { color: var(--muted); white-space: normal; padding: 28px 14px; }

.detail-grid { display: grid; grid-template-columns: 320px 1fr; gap: 16px; }
.panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.barcode {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 26px;
  margin: 4px 0 12px;
  word-break: break-all;
}
.facts { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.photo {
  padding: 0;
  border: 1px solid var(--line);
  background: #f7f9fb;
  border-radius: 12px;
  overflow: hidden;
  text-align: left;
}
.photo img { width: 100%; height: 140px; object-fit: cover; display: block; }
.photo p { margin: 0; padding: 8px 10px 10px; font-size: 13px; }

footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  color: var(--muted);
  padding: 8px 28px;
  font-size: 13px;
  border-top: 1px solid var(--line);
}

#photo-dialog {
  border: 0;
  border-radius: 16px;
  padding: 12px;
  max-width: min(920px, 96vw);
}
#photo-dialog img { width: 100%; height: auto; display: block; }
#photo-dialog::backdrop { background: rgba(16, 36, 58, 0.72); }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 800px) {
  header, .page-head { flex-wrap: wrap; align-items: center; }
  .list-table th, .list-table td { padding: 10px 8px; }
  .detail-grid { align-items: flex-start; }
  .kpis, .detail-grid { grid-template-columns: 1fr 1fr; }
  main, header, footer { padding-left: 16px; padding-right: 16px; }
  footer { position: static; }
  main { padding-bottom: 28px; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr 1fr; }
}

.app-nav { display: flex; gap: 8px; }
.app-nav button { padding: 8px 14px; border-radius: 999px; background: white; border: 1px solid var(--line); }
.app-nav .nav-current { background: var(--navy); color: white; border-color: var(--navy); }

.invoice-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.invoice-card h3 { margin: 0 0 12px; font-size: 16px; }
.invoice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.invoice-grid label, .line-grid label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.invoice-grid input, .invoice-grid select, .invoice-grid textarea,
.line-grid input, .line-grid select, .line-grid textarea { width: 100%; }
textarea { min-height: 72px; resize: vertical; border-radius: 10px; border: 1px solid var(--line); padding: 10px 12px; }
.span-2 { grid-column: 1 / -1; }
.line-card { border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.line-grid { display: grid; grid-template-columns: 1.4fr 1fr 140px; gap: 12px; }
.chassis-row { display: flex; gap: 8px; margin-top: 8px; }
.chassis-row input { flex: 1; }
.tax-choice { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.totals { display: grid; gap: 6px; justify-items: end; }
.totals strong { font-size: 22px; }
.invoice-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; align-items: center; background: white; padding: 12px 0 4px; border-top: 1px solid var(--line); }
.invoice-actions .lede { margin: 0; flex: 1 1 220px; }
.entry-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.entry-row p { margin: 0; flex: 1; line-height: 1.45; }
.entry-edit { flex: none; }
.entry-active { background: #f4f8fb; border-radius: 10px; }
.line-table { width: 100%; table-layout: fixed; }
.item-table th:nth-child(1),
.item-table th:nth-child(2) { width: 18%; }
.item-table th:nth-child(3) { width: 22%; }
.item-table th:nth-child(4) { width: 14%; }
.item-table th:nth-child(5) { width: 14%; }
.item-table th:nth-child(6) { width: 14%; }
.line-table th { padding-left: 6px; padding-right: 6px; }
.line-table th, .line-table td { vertical-align: middle; white-space: normal; }
.line-table th.col-qty, .line-table th.col-tax { text-align: center; }
.line-table th.col-amount, .line-table td.line-amount { text-align: right; }
.line-table input, .line-table textarea { width: 100%; min-width: 0; }
.line-table textarea {
  min-height: 38px;
  height: 38px;
  resize: none;
  overflow: hidden;
  padding: 8px 10px;
  line-height: 1.4;
}
.qty { display: flex; align-items: center; justify-content: center; gap: 4px; }
.qty input { width: 36px; flex: 0 0 36px; text-align: center; padding-left: 2px; padding-right: 2px; }
.qty-button { width: 28px; height: 32px; padding: 0; }
.tax-cell { text-align: center; }
.deduction-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.deduction-head h3 { margin: 0; }
.deduction-table { max-width: 640px; min-width: 0; }
.entry-actions { display: flex; gap: 8px; }
#invoice-print-layer {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #eef2f6;
  display: flex;
  flex-direction: column;
}
#invoice-print-layer .print-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: white;
  border-bottom: 1px solid var(--line);
}
#invoice-print-layer .print-pages {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
#invoice-print-layer canvas { width: min(210mm, 100%); height: auto; background: white; box-shadow: var(--shadow); }
@media print {
  @page { size: A4 portrait; margin: 0; }
  body > *:not(#invoice-print-layer) { display: none !important; }
  #invoice-print-layer { position: static; display: block; background: white; }
  #invoice-print-layer .print-bar { display: none !important; }
  #invoice-print-layer .print-pages { display: block; padding: 0; overflow: visible; }
  #invoice-print-layer canvas {
    width: 210mm;
    height: 297mm;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }
}
.danger { background: white; color: #9a3d08; border-color: #f0c2a8; }
.confirm-dialog {
  border: 0;
  border-radius: 16px;
  padding: 22px;
  width: min(440px, calc(100% - 32px));
  box-shadow: 0 18px 50px rgba(16, 36, 58, 0.24);
}
.confirm-dialog::backdrop { background: rgba(16, 36, 58, 0.72); }
.confirm-dialog h3 { margin: 0 0 8px; }
.confirm-dialog label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.dialog-actions { display: flex; gap: 8px; margin-top: 16px; }
.check-line, .invoice-grid label.check-line { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.banner {
  background: var(--orange-soft);
  color: #9a3d08;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.status-draft { background: #eef3f8; }
.status-issued { background: #e7f6ee; color: #0f6b3c; }
.status-cancelled { background: #f3f4f6; color: #4b5563; }
@media (max-width: 800px) {
  .invoice-grid, .line-grid, .entry-form { grid-template-columns: 1fr; }
  header { flex-wrap: wrap; }
}
