/* ============================================================
   GB Automobiles ERP — shared stylesheet
   Mobile-first (staff use phones). Neutral palette, saffron accent.
   No external fonts, no CDNs.
   ============================================================ */

:root {
  --bg: #f4f3f0;
  --card: #ffffff;
  --ink: #1d1d20;
  --mut: #6c6c72;
  --line: #e4e2dd;
  --accent: #e8590c;
  --accent-hi: #d14e08;
  --accent-ink: #ffffff;
  --accent-soft: #fdeee3;
  --ok: #1e7f4f;      --ok-bg: #e2f3ea;
  --warn: #9a6700;    --warn-bg: #fcf0da;
  --bad: #bd3a2b;     --bad-bg: #fce8e5;
  --info: #24589c;    --info-bg: #e7eef9;
  --neu: #5c5c62;     --neu-bg: #ececec;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 15, 8, 0.08);
  --topbar-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --card: #1e1e22;
    --ink: #ededf0;
    --mut: #9b9ba3;
    --line: #2d2d33;
    --accent: #f0661c;
    --accent-hi: #f97a33;
    --accent-ink: #ffffff;
    --accent-soft: #38220f;
    --ok: #4cc38a;    --ok-bg: #132a1d;
    --warn: #e5b567;  --warn-bg: #2d2410;
    --bad: #ef7264;   --bad-bg: #331713;
    --info: #7aa7e0;  --info-bg: #16233a;
    --neu: #a8a8b0;   --neu-bg: #2a2a2f;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }

/* Money / numbers: always tabular */
.num, td.num, .stat-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.mut { color: var(--mut); }
.small { font-size: .8rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }

/* ---------------- Layout ---------------- */
.container, main#content {
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 12px 90px;
}

/* ---------------- Top bar ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--card);
  border-bottom: 2px solid var(--accent);
  box-shadow: var(--shadow);
}

.topbar .brand {
  font-weight: 700;
  font-size: 1rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .brand .brand-sub {
  font-weight: 500;
  font-size: .72rem;
  color: var(--mut);
  margin-left: 6px;
}

.role-badge {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}

.burger {
  background: none;
  border: none;
  padding: 8px;
  margin-left: -8px;
  cursor: pointer;
  color: var(--ink);
  display: flex;
  align-items: center;
}
.burger svg { display: block; }

/* ---------------- Nav drawer ---------------- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
  z-index: 60;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(280px, 82vw);
  background: var(--card);
  z-index: 70;
  transform: translateX(-102%);
  transition: transform .2s ease;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 18px rgba(0, 0, 0, 0.25);
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.drawer-head .org { font-weight: 700; }
.drawer-head .who { font-size: .8rem; color: var(--mut); margin-top: 2px; }

.drawer-nav { flex: 1; overflow-y: auto; padding: 8px 0; }

.drawer-nav a {
  display: flex;
  align-items: center;
  padding: 11px 18px;
  color: var(--ink);
  font-weight: 500;
  border-left: 3px solid transparent;
}
.drawer-nav a:hover { background: var(--accent-soft); text-decoration: none; }
.drawer-nav a.active {
  border-left-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

.drawer-foot {
  border-top: 1px solid var(--line);
  padding: 12px 16px;
}

/* ---------------- Cards ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 14px;
}
.card > h2:first-child { margin-bottom: 10px; }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.card-head h2 { margin: 0; }

/* Stat grid (cockpit "today" cards) */
.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  margin-bottom: 14px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.stat .stat-label {
  font-size: .74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--mut);
}
.stat .stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  margin-top: 2px;
  text-align: left;
}
.stat .stat-sub { font-size: .78rem; color: var(--mut); margin-top: 2px; }

/* ---------------- Status pills ---------------- */
.pill {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
  text-transform: capitalize;
  color: var(--neu);
  background: var(--neu-bg);
}
.pill-ok   { color: var(--ok);   background: var(--ok-bg); }
.pill-warn { color: var(--warn); background: var(--warn-bg); }
.pill-bad  { color: var(--bad);  background: var(--bad-bg); }
.pill-info { color: var(--info); background: var(--info-bg); }
.pill-accent { color: var(--accent); background: var(--accent-soft); }

/* ---------------- Alerts strip ---------------- */
.alert {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-weight: 600;
  font-size: .88rem;
  margin-bottom: 8px;
}
.alert.alert-bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  font-size: .9rem;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  min-height: 40px;
}
.btn:hover { border-color: var(--mut); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); }

.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-sm { padding: 5px 11px; min-height: 32px; font-size: .8rem; border-radius: 8px; }
.btn-block { width: 100%; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------------- Forms ---------------- */
label.fld { display: block; margin-bottom: 12px; }
label.fld > span {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--mut);
  margin-bottom: 4px;
}

input, select, textarea {
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 70px; }

/* ---------------- Tables (collapse to cards on phones) ---------------- */
.tbl-wrap { overflow-x: auto; }

table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
.tbl th {
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--mut);
  padding: 8px 10px;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
.tbl th.num { text-align: right; }
.tbl td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.tbl tbody tr:hover { background: var(--accent-soft); }

@media (max-width: 720px) {
  .tbl thead { display: none; }
  .tbl, .tbl tbody { display: block; }
  .tbl tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 4px 12px;
  }
  .tbl tbody tr:hover { background: var(--card); }
  .tbl td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    border: none;
    padding: 7px 0;
    text-align: right;
  }
  .tbl td::before {
    content: attr(data-label);
    font-size: .74rem;
    font-weight: 600;
    color: var(--mut);
    text-align: left;
    flex-shrink: 0;
  }
  .tbl td:not(:last-child) { border-bottom: 1px dashed var(--line); }
}

/* ---------------- Modal ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1rem; }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.3rem; line-height: 1; color: var(--mut); padding: 4px 8px;
}
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

@media (max-width: 540px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: var(--radius) var(--radius) 0 0; }
}

/* ---------------- Toast ---------------- */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: max-content;
  max-width: 92vw;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  font-size: .88rem;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  animation: toast-in .18s ease;
  max-width: 92vw;
}
.toast-ok  { background: var(--ok); color: #fff; }
.toast-err { background: var(--bad); color: #fff; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------------- Empty states ---------------- */
.empty {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 22px 16px;
  text-align: center;
  color: var(--mut);
  font-size: .9rem;
}

/* ---------------- Misc ---------------- */
.list-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: none; }

details.json-detail summary {
  cursor: pointer;
  font-size: .8rem;
  color: var(--accent);
  font-weight: 600;
}
details.json-detail pre {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-size: .75rem;
  overflow-x: auto;
  margin: 8px 0 0;
}

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 2px solid var(--line);
  margin-bottom: 14px;
}
.tabs button {
  font: inherit;
  font-weight: 600;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  padding: 8px 14px;
  color: var(--mut);
  cursor: pointer;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.chart-card svg { width: 100%; height: auto; display: block; }

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 22px;
}
.login-card h1 { text-align: center; }
.login-card .sub { text-align: center; color: var(--mut); font-size: .82rem; margin-bottom: 20px; }
.login-err {
  background: var(--bad-bg);
  color: var(--bad);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: 12px;
  display: none;
}
.login-err.show { display: block; }
