:root {
  --red: #E01E23; --ink: #121212; --grey: #AFAFAF; --bg: #FAFAFA; --blush: #FDF2F2;
  --card: #FFFFFF; --line: #E8E8E8; --muted: #6B6B6B; --ok: #1F8A4C; --warn: #B76E00;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root { --ink: #F2F2F2; --bg: #121212; --card: #1C1C1C; --line: #2C2C2C; --muted: #A0A0A0; --blush: #2A1717; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 Manrope, system-ui, -apple-system, Segoe UI, sans-serif; }
a { color: var(--red); }
button, input, select, textarea { font: inherit; color: inherit; }

/* layout */
.top { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.brand { font-weight: 800; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 10px; height: 22px; background: var(--red); border-radius: 3px; }
.top .who { margin-left: auto; color: var(--muted); font-size: 13px; text-align: right; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 16px; background: var(--card);
  border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 12px 12px 10px; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; white-space: nowrap; cursor: pointer; }
.tabs button.on { color: var(--ink); border-color: var(--red); }
.tabs .count { background: var(--red); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; margin-left: 4px; }

/* cards, stats */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; text-align: left; }
.stat .n { font-size: 22px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat.on { border-color: var(--red); background: var(--blush); }

/* toolbar */
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.bar .grow { flex: 1 1 200px; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--red); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
.hint { font-size: 12px; color: var(--muted); }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 9px; padding: 8px 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.ghost { border-color: transparent; background: none; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

/* list rows */
.list { display: grid; gap: 8px; }
.row { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; cursor: pointer; }
.row:hover { border-color: var(--grey); }
.row .t { font-weight: 700; }
.row .s { font-size: 13px; color: var(--muted); }
.row .r { text-align: right; }
.row .amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* pills */
.pill { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 99px; padding: 2px 9px; background: var(--line); color: var(--ink); }
.pill.submitted { background: #FFF3D6; color: #7A4B00; }
.pill.approved, .pill.paid { background: #DDF3E6; color: #135C33; }
.pill.rejected { background: var(--blush); color: var(--red); }
.pill.replaced { background: var(--line); color: var(--muted); text-decoration: line-through; }
.pill.partly_paid { background: #E3EEFF; color: #1D4A9A; }
.pill.pending { background: #FFF3D6; color: #7A4B00; }
.pill.active { background: #DDF3E6; color: #135C33; }
.pill.inactive { background: var(--line); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .pill.submitted, .pill.pending { background: #3A2C0A; color: #F5C66B; }
  .pill.approved, .pill.paid, .pill.active { background: #11301F; color: #7BD9A3; }
  .pill.partly_paid { background: #132440; color: #8FB4FF; }
}

/* tables */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.scroll { overflow-x: auto; }

/* drawer / modal */
.veil { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: none; }
.veil.on { display: block; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100%); background: var(--bg); z-index: 50;
  transform: translateX(100%); transition: transform .2s; display: flex; flex-direction: column; }
.drawer.on { transform: none; }
.drawer header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.drawer header h2 { margin: 0; font-size: 18px; flex: 1; }
.drawer .body { overflow-y: auto; padding: 16px; flex: 1; }
.section { margin-bottom: 16px; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px 16px; }
.kv div span { display: block; font-size: 12px; color: var(--muted); }
.kv div b { font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.warn { background: var(--blush); color: var(--red); border-radius: 9px; padding: 8px 12px; font-size: 13px; margin: 8px 0; }
.note { background: var(--card); border: 1px dashed var(--line); border-radius: 9px; padding: 8px 12px; font-size: 13px; color: var(--muted); }

/* toast */
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; z-index: 99; font-weight: 600; max-width: calc(100% - 32px); }
.toast.err { background: var(--red); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login h1 { font-size: 22px; margin: 6px 0 2px; }

.hide { display: none !important; }
.right { margin-left: auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* PO table (team console) */
.potable { width: 100%; border-collapse: collapse; font-size: 13.5px; background: var(--card); }
.potable th { position: sticky; top: 0; background: var(--card); text-align: left; font-size: 12px; color: var(--muted);
  font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; }
.potable th.sorted { color: var(--ink); }
.potable td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.potable tr[data-po] { cursor: pointer; }
.potable tr[data-po]:hover td { background: var(--blush); }
.potable .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.potable .sub { color: var(--muted); font-size: 12px; }
.potable .pill { font-size: 11px; margin: 1px 0; }
.tablewrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 260px); }
