/* 10 Mile Supply — Office
   Layout: navy brand rail (logo + nav) on the left, work area on the right,
   records open in a right-hand drawer. Rail folds into a top bar on phones. */
:root {
  --navy: #1B2A4A;          /* logo navy */
  --navy-2: #24365D;
  --navy-ink: #FFFFFF;
  --navy-muted: #A9B4CC;
  --bg: #F3F4F7;
  --surface: #FFFFFF;
  --surface-2: #EDEFF4;
  --line: #D9DDE6;
  --fg: #151C2C;
  --muted: #5E677A;
  --accent: #1B2A4A;
  --accent-ink: #FFFFFF;
  --focus: #3D6BC4;
  --blue: #1F5BB0;   --blue-soft: #E2EBF8;
  --amber: #8F5B00;  --amber-soft: #FAEFD7;
  --green: #0F6E3E;  --green-soft: #DDF1E5;
  --red: #B42318;    --red-soft: #FBE4E1;
  --n-soft: #E9ECF2;
  --scrim: rgba(12, 18, 32, .42);
  --shadow: 0 18px 48px rgba(16, 26, 48, .22);
  --display: "Montserrat", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --body: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --navy: #111B31; --navy-2: #1A2743; --navy-ink: #EEF2FA; --navy-muted: #8E9AB5;
    --bg: #0C111D; --surface: #141B2A; --surface-2: #1B2335; --line: #2A3349;
    --fg: #E6EAF3; --muted: #97A1B7; --accent: #9DB6E8; --accent-ink: #0C1424; --focus: #8CB0F5;
    --blue: #8FB6F2; --blue-soft: #1B2B47; --amber: #E7B45A; --amber-soft: #352914;
    --green: #6ED39C; --green-soft: #15301F; --red: #F4918A; --red-soft: #3B1C1A; --n-soft: #232B3E;
    --scrim: rgba(0,0,0,.55); --shadow: 0 18px 48px rgba(0,0,0,.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --navy: #111B31; --navy-2: #1A2743; --navy-ink: #EEF2FA; --navy-muted: #8E9AB5;
  --bg: #0C111D; --surface: #141B2A; --surface-2: #1B2335; --line: #2A3349;
  --fg: #E6EAF3; --muted: #97A1B7; --accent: #9DB6E8; --accent-ink: #0C1424; --focus: #8CB0F5;
  --blue: #8FB6F2; --blue-soft: #1B2B47; --amber: #E7B45A; --amber-soft: #352914;
  --green: #6ED39C; --green-soft: #15301F; --red: #F4918A; --red-soft: #3B1C1A; --n-soft: #232B3E;
  --scrim: rgba(0,0,0,.55); --shadow: 0 18px 48px rgba(0,0,0,.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.45 var(--body); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--display); text-wrap: balance; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.num, td.n, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
small { color: var(--muted); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Brand mark ---------- */
.mark { width: 40px; height: 40px; flex: none; color: currentColor; }
.mark text { font-family: var(--display); font-weight: 600; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--navy-ink); text-decoration: none; }
.word { font-family: var(--display); font-weight: 600; letter-spacing: .08em; line-height: 1.05; font-size: 17px; }
.word small { display: block; color: var(--navy-muted); font-size: 10px; letter-spacing: .22em; font-weight: 600; margin-top: 3px; }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100%; }
.rail {
  background: var(--navy); color: var(--navy-ink);
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; gap: 22px;
  padding-block: calc(22px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: 14px;
}
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav .sep { height: 1px; background: rgba(255,255,255,.12); margin: 10px 6px; }
.nav button {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: none; border: 0; color: var(--navy-muted); text-align: left;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13.5px;
}
.nav button:hover { color: var(--navy-ink); background: var(--navy-2); }
.nav button[aria-current="page"] { color: var(--navy-ink); background: var(--navy-2); box-shadow: inset 3px 0 0 var(--navy-ink); }
.nav .count { font-family: var(--mono); font-size: 11px; background: rgba(255,255,255,.12); color: var(--navy-ink); padding: 1px 7px; border-radius: 99px; }
.me { margin-top: auto; border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.me b { color: var(--navy-ink); font-weight: 600; }
.me small { color: var(--navy-muted); word-break: break-all; }
.me button { align-self: flex-start; background: none; border: 1px solid rgba(255,255,255,.22); color: var(--navy-ink); border-radius: 7px; padding: 4px 10px; cursor: pointer; font-size: 12px; }

.main { min-width: 0; padding-block: calc(22px + env(safe-area-inset-top, 0px)) 48px; padding-left: 28px; padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.main > * { max-width: 1320px; }
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.top h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.top .sub { color: var(--muted); margin-top: 4px; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search { width: 240px; max-width: 100%; }

@media (max-width: 880px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; gap: 12px; padding-block: calc(14px + env(safe-area-inset-top, 0px)) 10px; padding-right: max(16px, env(safe-area-inset-right, 0px)); flex-direction: column; }
  .rail .brand .mark { width: 32px; height: 32px; }
  .nav { flex-direction: row; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .nav button { white-space: nowrap; }
  .nav .sep { display: none; }
  .nav button[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--navy-ink); }
  .me { display: none; }
  .main { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-top: 18px; }
  .search { width: 100%; }
  .tools { width: 100%; }
}

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.12); }
.btn.danger { color: var(--red); }
.btn.danger.armed { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: none; border-color: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
input, select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 7px;
  padding: 8px 10px; min-height: 38px;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); }
label.f { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
label.f > span { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
label.f > span em { color: var(--red); font-style: normal; }
.fgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.fgrid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .fgrid { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Chips, pills ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 5px 12px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .c { font-family: var(--mono); font-size: 11.5px; margin-left: 4px; opacity: .8; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.t-n { background: var(--n-soft); color: var(--muted); }
.t-b { background: var(--blue-soft); color: var(--blue); }
.t-a { background: var(--amber-soft); color: var(--amber); }
.t-g { background: var(--green-soft); color: var(--green); }
.t-r { background: var(--red-soft); color: var(--red); }
.late { color: var(--red); font-weight: 700; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
table.list { width: 100%; border-collapse: collapse; min-width: 720px; }
table.list th {
  text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  font-weight: 700; padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; cursor: pointer; user-select: none;
}
table.list th.n, table.list td.n { text-align: right; }
table.list th .arr { opacity: .7; margin-left: 3px; }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover td { background: var(--surface-2); }
table.list td b { font-weight: 600; display: block; }
table.list td small { display: block; margin-top: 1px; }
td.id { font-family: var(--mono); font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.empty { padding: 44px 24px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty h3 { color: var(--fg); font-size: 17px; }
.empty p { max-width: 46ch; margin: 0; }

/* ---------- Dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; text-align: left; }
.kpi:hover { border-color: var(--muted); }
.kpi .k { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.kpi .v { font-family: var(--display); font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .s { color: var(--muted); font-size: 12.5px; }
.dash { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; min-width: 0; }
.panel h2 { font-size: 15px; font-weight: 700; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel h2 small { font-family: var(--body); font-weight: 500; font-size: 12.5px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.att { display: flex; flex-direction: column; }
.att button { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 10px; align-items: center; text-align: left; background: none; border: 0; border-top: 1px solid var(--line); padding: 10px 2px; cursor: pointer; }
.att button:first-child { border-top: 0; }
.att button:hover .t { text-decoration: underline; }
.att .dot { width: 8px; height: 8px; border-radius: 50%; }
.att .dot.r { background: var(--red); } .att .dot.a { background: var(--amber); } .att .dot.b { background: var(--blue); } .att .dot.g { background: var(--green); }
.att .t { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att small { display: block; font-weight: 400; }
.att .amt { font-family: var(--mono); font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.quiet { color: var(--muted); padding: 6px 0; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar { display: grid; grid-template-columns: 96px minmax(0, 1fr) 96px; gap: 10px; align-items: center; font-size: 13px; }
.bar .track { height: 12px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 4px; min-width: 2px; }
.bar .amt { text-align: right; font-family: var(--mono); font-size: 12.5px; }
.flow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.flow b { color: var(--fg); background: var(--surface-2); border-radius: 6px; padding: 3px 8px; font-weight: 600; }
@media (max-width: 1080px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .dash { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 460px) { .kpis { grid-template-columns: minmax(0, 1fr); } .bar { grid-template-columns: 78px minmax(0, 1fr) 84px; } }

/* ---------- Drawer ---------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(800px, 100vw); z-index: 50;
  background: var(--bg); box-shadow: var(--shadow); display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); padding-right: env(safe-area-inset-right, 0px);
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.d-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 22px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.d-head .eyebrow { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.d-head h2 { font-size: 20px; font-weight: 700; margin-top: 2px; }
.d-head .meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.d-body { flex: 1; overflow-y: auto; padding: 18px 22px 28px; display: flex; flex-direction: column; gap: 22px; }
.d-body fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.d-sec h3 { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.d-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 12px 22px; border-top: 1px solid var(--line); background: var(--surface); }
.d-foot .grp { display: flex; gap: 8px; flex-wrap: wrap; }
.unsaved { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--amber-soft); color: var(--amber); border-radius: 8px; padding: 8px 12px; font-weight: 600; }
.x { background: none; border: 0; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.x:hover { color: var(--fg); background: var(--surface-2); }
@media (max-width: 560px) { .d-head, .d-body, .d-foot { padding-left: 16px; padding-right: 16px; } }

/* Line items */
.lines-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table.lines { width: 100%; border-collapse: collapse; min-width: 680px; }
table.lines th { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
table.lines td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
table.lines tr:last-child td { border-bottom: 0; }
table.lines input, table.lines select { min-height: 34px; padding: 6px 7px; }
table.lines .w-prod { width: 19%; } table.lines .w-qty { width: 12%; } table.lines .w-unit { width: 9%; } table.lines .w-money { width: 11%; }
table.lines td.ext { text-align: right; font-family: var(--mono); font-size: 12.5px; white-space: nowrap; padding-right: 10px; }
table.lines input[type=number] { text-align: right; font-family: var(--mono); }
.icon { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon:hover { color: var(--red); background: var(--red-soft); }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 12px; }
.totals div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.totals span { display: block; font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.totals b { font-family: var(--mono); font-size: 16px; font-variant-numeric: tabular-nums; }
.totals .grand { background: var(--accent); border-color: var(--accent); }
.totals .grand span, .totals .grand b { color: var(--accent-ink); }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 8px; }

.rel { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.rel button { display: grid; grid-template-columns: 82px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; background: none; border: 0; border-top: 1px solid var(--line); padding: 9px 12px; text-align: left; cursor: pointer; }
.rel button:first-child { border-top: 0; }
.rel button:hover { background: var(--surface-2); }
.rel .id { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.rel .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rel .amt { font-family: var(--mono); font-size: 12.5px; }
@media (max-width: 560px) { .rel button { grid-template-columns: 70px minmax(0, 1fr) auto; } .rel .amt { display: none; } }

/* Toast + banners */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(22px + env(safe-area-inset-bottom, 0px)); z-index: 80; background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 9px; font-weight: 600; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.err { background: var(--red); color: #fff; }
.banner { background: var(--amber-soft); color: var(--amber); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; font-weight: 600; }
.loading { color: var(--muted); padding: 40px 0; }

/* Settings */
.settings { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 980px) { .settings { grid-template-columns: minmax(0, 1fr); } }
.team { display: flex; flex-direction: column; gap: 8px; }
.team div { display: flex; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.team div:first-child { border-top: 0; padding-top: 0; }

/* ---------- Login page ---------- */
.login { min-height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.login .side { background: var(--navy); color: var(--navy-ink); display: flex; flex-direction: column; justify-content: space-between; padding-block: 48px; padding-left: max(40px, env(safe-area-inset-left, 0px)); padding-right: 40px; }
.login .side .mark { width: 120px; height: 120px; }
.login .side h1 { font-size: 40px; font-weight: 600; letter-spacing: .12em; margin-top: 26px; }
.login .side p { color: var(--navy-muted); max-width: 36ch; }
.login .side .foot { color: var(--navy-muted); font-size: 12.5px; }
.login .pane { display: flex; align-items: center; justify-content: center; padding-block: 40px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.login form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login form h2 { font-size: 22px; font-weight: 700; }
.login .msg { border-radius: 8px; padding: 10px 12px; font-weight: 600; font-size: 13.5px; }
.login .msg.err { background: var(--red-soft); color: var(--red); }
.login .msg.ok { background: var(--green-soft); color: var(--green); }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 0; align-self: flex-start; font-size: 13px; }
@media (max-width: 800px) {
  .login { grid-template-columns: minmax(0, 1fr); }
  .login .side { padding-block: 28px; padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); flex-direction: row; align-items: center; gap: 16px; }
  .login .side .mark { width: 56px; height: 56px; }
  .login .side h1 { font-size: 24px; margin: 0; }
  .login .side p, .login .side .foot { display: none; }
}
