:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #12151a;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #d92b2b;
  --good: #17803d;
  --bad: #c02626;
  --chip: #eceef1;
  --chip-on: #12151a;
  --chip-on-ink: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1013;
    --card: #171a1f;
    --ink: #e9ecf1;
    --muted: #8b93a1;
    --line: #262b33;
    --accent: #ff5252;
    --good: #4ade80;
    --bad: #ff6b6b;
    --chip: #232830;
    --chip-on: #e9ecf1;
    --chip-on-ink: #0e1013;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 940px; margin: 0 auto; padding: 10px 12px 24px; }

/* header bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px;
  font-size: 12px;
}
.topbar .side { display: flex; align-items: center; gap: 6px; }
.topbar .name {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-size: 11px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; pointer-events: none; white-space: nowrap;
}
.topbar .fx { font-variant-numeric: tabular-nums; color: var(--ink); }
.topbar .fxage { color: var(--muted); font-size: 11px; }
.topbar button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 3px 4px; font-size: 14px; }
.topbar .add {
  background: var(--chip-on); color: var(--chip-on-ink);
  border-radius: 7px; padding: 5px 9px; font-size: 12px; font-weight: 600;
}
.topbar .add.sec { background: var(--chip); color: var(--ink); }

/* phones: shrink to fit rather than disappear */
@media (max-width: 430px) {
  .topbar { padding: 8px 8px; gap: 4px; }
  .topbar .name { font-size: 10px; letter-spacing: .08em; }
  .topbar .add { padding: 5px 8px; font-size: 11.5px; }
  .topbar .fx { font-size: 11.5px; }
}
@media (max-width: 360px) {
  .topbar .fxage { display: none; }
  .topbar .name { font-size: 9.5px; letter-spacing: .04em; }
}
@media (max-width: 300px) { .topbar .name { display: none; } }

/* summary */
.summary {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 15px;
  box-shadow: var(--shadow);
}
.pl .amount { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.pl.up .amount { color: var(--good); }
.pl.down .amount { color: var(--bad); }
.pl .inr { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.facts {
  margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 4px 16px;
  font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.facts .k { color: var(--muted); }
.who2 { display: flex; gap: 16px; margin-top: 7px; font-size: 13px; font-variant-numeric: tabular-nums; }
.who2 b { font-weight: 650; }
.who2 .neg { color: var(--bad); }
.warn {
  margin-top: 9px; padding: 8px 10px; border-radius: 8px;
  background: #f59e0b1f; border: 1px solid #f59e0b55;
  font-size: 12px; line-height: 1.35; cursor: pointer;
}
.who2 .pos { color: var(--good); }

/* chips: always one lane, scrolls sideways if it must */
.chips {
  display: flex; flex-wrap: nowrap; gap: 5px; margin: 10px 0;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex: 0 0 auto;
}
.chip.on { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); }

/* shipments */
.ships { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.ship {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
  box-shadow: var(--shadow);
}
.ship .no { font-weight: 700; }
.ship .grow { flex: 1; }
.ship .percar { font-variant-numeric: tabular-nums; color: var(--muted); }
.badge { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; padding: 2px 7px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.badge.shipped { background: #f59e0b22; color: #b45309; }
.badge.arrived { background: #16a34a22; color: var(--good); }

/* car list: separate cards, just tighter than before */
.group {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-bottom: 5px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.ghead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.3;
}
.caret { color: var(--muted); font-size: 11px; }
.ghead .nm {
  font-weight: 600; font-size: 13.5px;
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ghead .qty { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ghead .cost { font-variant-numeric: tabular-nums; }
.ghead .mix { white-space: nowrap; font-size: 11.5px; color: var(--muted); }
.ghead .qty { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ghead .cost { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.ghead .mix { font-size: 11.5px; color: var(--muted); }
.units { border-top: 1px solid var(--line); }
.unit {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 30px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  flex-wrap: wrap;
}
.unit:last-child { border-bottom: 0; }
.unit .s { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 26px; }
.unit .c { font-variant-numeric: tabular-nums; min-width: 62px; }
.unit .grow { flex: 1; }
.who { font-size: 10px; padding: 1px 5px; border-radius: 4px; background: var(--chip); color: var(--muted); }

select, input, textarea, button { font: inherit; color: inherit; }
select, input[type=text], input[type=number], input[type=date], textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 13px;
}
input:disabled, select:disabled { opacity: .45; }
.inr-in { width: 92px; font-variant-numeric: tabular-nums; }

.brandtag {
  font-size: 9px; font-weight: 700; letter-spacing: .03em;
  padding: 1px 4px; border-radius: 3px;
  background: var(--chip); color: var(--muted); flex: 0 0 auto;
}
.btn {
  background: var(--chip-on);
  color: var(--chip-on-ink);
  border: 0;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn.sec { background: var(--chip); color: var(--ink); }
.btn.red { background: var(--accent); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }

/* modal */
.mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
  padding: 0;
}
@media (min-width: 640px) { .mask { align-items: center; padding: 20px; } }
.modal {
  background: var(--card);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow: auto;
  border-radius: 16px 16px 0 0;
  padding: 16px;
}
@media (min-width: 640px) { .modal { border-radius: 16px; } }
.modal h2 { margin: 0 0 12px; font-size: 17px; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 3px; }
.field input, .field select, .field textarea { width: 100%; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
textarea { min-height: 130px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

table.grid { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.grid th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 4px; font-weight: 600; }
table.grid td { padding: 2px; border-top: 1px solid var(--line); }
table.grid input { width: 100%; }
.scrollx { overflow-x: auto; }

.picklist { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 9px; }
.pick { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
.pick:last-child { border-bottom: 0; }
.pick input { width: 18px; height: 18px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; position: sticky; bottom: 0; background: var(--card); padding-top: 10px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 10px; }
.err { color: var(--bad); font-size: 13px; margin-top: 8px; min-height: 18px; }
.empty { text-align: center; color: var(--muted); padding: 34px 12px; font-size: 13.5px; }
pre.prompt { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 11.5px; white-space: pre-wrap; margin: 0 0 8px; }

/* tap-to-open card (matches the invite admin pattern) */
.sheet {
  position: relative;
  width: 100%;
  max-width: 430px;
  max-height: 88vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 30px 70px -28px rgba(0, 0, 0, .55);
  padding: 20px 16px 16px;
  animation: sheetIn .2s ease;
}
@keyframes sheetIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.sheet .x {
  position: absolute; top: 9px; right: 9px;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 15px; color: var(--muted); line-height: 1;
}
.sheet .top { padding-right: 38px; }
.sheet .title { font-size: 17px; font-weight: 650; }
.sheet .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.sheet h3 {
  font-size: 10px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); margin: 15px 0 7px; font-weight: 600;
}
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 9px; padding: 9px 12px; font-size: 13.5px; cursor: pointer; flex: 1 1 auto;
  min-width: 88px;
}
.pill.on { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); font-weight: 600; }
.pill.danger { color: var(--bad); border-color: var(--bad); background: transparent; flex: 0 0 auto; }
.breakdown { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.breakdown div { display: flex; justify-content: space-between; padding: 3px 0; }
.breakdown .tot { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; font-weight: 650; }
.breakdown .k { color: var(--muted); }
.sheet .foot { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; display: flex; gap: 8px; }
.tap { cursor: pointer; }
.tap:active { background: var(--bg); }

/* settlements */
.settle { background: var(--card); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; box-shadow: var(--shadow); overflow: hidden; }
.settle .row { display: flex; align-items: center; gap: 9px; padding: 9px 12px; font-size: 13px; border-bottom: 1px solid var(--line); }
.settle .row:last-child { border-bottom: 0; }
.settle .hd { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); background: var(--bg); }
.settle .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.settle .grow { flex: 1; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login .box { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 26px; width: 100%; max-width: 330px; text-align: center; }
.login h1 { font-size: 15px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin: 0 0 18px; font-weight: 600; }
.login input { width: 100%; text-align: center; padding: 10px; margin-bottom: 10px; }
.login .btn { width: 100%; }
