:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e3e6ec;
  --brand: #0f5ea8; --brand-ink: #fff; --brand-soft: #e7f0fa;
  --ok: #1f8a4c; --ok-soft: #e4f4ea; --warn: #b26a00; --warn-soft: #fff3df; --bad: #c0362c; --bad-soft: #fdeceb;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,30,50,.06), 0 1px 8px rgba(20,30,50,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: #12233a; color: #c9d4e3; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.side .logo { color: #fff; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
.side .logo small { display: block; font-weight: 400; font-size: 12px; color: #8ea2bd; }
.side nav a { display: block; color: #c9d4e3; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.side nav a:hover { background: rgba(255,255,255,.06); }
.side nav a.active { background: var(--brand); color: #fff; }
.side .who { position: absolute; bottom: 16px; left: 12px; right: 12px; font-size: 12px; color: #8ea2bd; padding: 0 10px; }
.side .who button { margin-top: 6px; }
main { padding: 22px 26px 60px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.top .grow { flex: 1 1 260px; }
.menu-btn { display: none; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 24px; font-weight: 700; margin-top: 2px; }
.tile .s { font-size: 12px; color: var(--muted); }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; white-space: nowrap; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.item { min-width: 200px; }
.nw { white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7f9fc; }
tfoot td { font-weight: 700; background: #fafbfc; }
.sub { color: var(--muted); font-size: 12px; }

/* controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover { border-color: #c7ccd6; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.danger { color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }
button.link { border: 0; background: none; color: var(--brand); padding: 0; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); align-items: end; }
.form .wide { grid-column: 1 / -1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* badges & bars */
.b { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #eef0f4; color: var(--muted); }
.b.ok { background: var(--ok-soft); color: var(--ok); }
.b.warn { background: var(--warn-soft); color: var(--warn); }
.b.bad { background: var(--bad-soft); color: var(--bad); }
.b.info { background: var(--brand-soft); color: var(--brand); }
.bar { height: 8px; background: #eceff3; border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.bar.ok > i { background: var(--ok); }

/* drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(15,25,40,.35); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--panel); z-index: 21; overflow-y: auto; padding: 20px; box-shadow: -8px 0 30px rgba(0,0,0,.15); }
.drawer .close { float: right; }
.drawer.wide { width: min(1080px, 100%); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* Excel-like entry sheet */
.sheet-wrap { border: 1px solid #c9ced8; border-radius: 6px; max-height: 60vh; overflow: auto; }
table.sheet { border-collapse: collapse; }
table.sheet th { background: #fff200; color: #111; font-size: 13px; font-weight: 700; text-align: center; border: 1px solid #c9ced8; padding: 8px 6px; }
table.sheet td { border: 1px solid #dfe3ea; padding: 0; vertical-align: middle; }
table.sheet td.n, table.sheet td.sub { padding: 6px 8px; }
table.sheet input { width: 100%; border: 0; border-radius: 0; padding: 8px; background: transparent; }
table.sheet input.n { text-align: right; }
table.sheet input:focus { outline: 2px solid var(--brand); outline-offset: -2px; background: #f4f9ff; }
table.sheet tfoot td { padding: 8px; font-weight: 700; background: #fafbfc; }

/* Shareable report image (rendered off-screen, then captured) */
.report-host { position: fixed; left: -12000px; top: 0; }
.report { display: inline-block; min-width: 820px; background: #fff; color: #1d2433; padding: 28px 30px 20px; font: 14px/1.4 "Segoe UI", system-ui, Roboto, sans-serif; }
.rp-head { display: flex; align-items: center; gap: 16px; padding-bottom: 14px; border-bottom: 3px solid #0f5ea8; margin-bottom: 16px; }
.rp-brand { background: #0f5ea8; color: #fff; font-weight: 800; letter-spacing: .12em; padding: 8px 12px; border-radius: 6px; font-size: 15px; }
.rp-titles { flex: 1; }
.rp-title { font-size: 21px; font-weight: 700; }
.rp-sub { color: #6b7385; font-size: 13px; margin-top: 2px; }
.rp-date { color: #6b7385; font-size: 13px; white-space: nowrap; }
.rp-kpis { display: flex; gap: 10px; margin-bottom: 16px; }
.rp-kpi { flex: 1; border: 1px solid #e3e6ec; border-radius: 8px; padding: 9px 12px; background: #f8fafc; }
.rp-kpi .k { font-size: 11px; color: #6b7385; text-transform: uppercase; letter-spacing: .04em; }
.rp-kpi .v { font-size: 19px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.rp-kpi .v.ok { color: #1f8a4c; } .rp-kpi .v.bad { color: #c0362c; } .rp-kpi .v.warn { color: #b26a00; }
table.rp { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 14px; }
table.rp th { background: #12233a; color: #fff; font-weight: 600; padding: 8px 10px; text-align: left; white-space: nowrap; }
table.rp td { padding: 7px 10px; border-bottom: 1px solid #e8ebf0; vertical-align: top; }
table.rp tr:nth-child(even) td { background: #f7f9fc; }
table.rp tr.tot td { background: #eaf1fb; font-weight: 700; border-top: 2px solid #0f5ea8; }
table.rp .nw { white-space: nowrap; }
table.rp .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rp-note { color: #6b7385; font-size: 11px; margin-top: 2px; }
.rp-chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef0f4; color: #4a5263; white-space: nowrap; }
.rp-chip.ok { background: #e4f4ea; color: #1f8a4c; } .rp-chip.warn { background: #fff1d6; color: #9a5c00; }
.rp-chip.bad { background: #fdeceb; color: #c0362c; } .rp-chip.info { background: #e7f0fa; color: #0f5ea8; } .rp-chip.blue { background: #e3ecfb; color: #2848a8; }
.rp-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.rp-h { font-weight: 700; font-size: 13px; color: #0f5ea8; text-transform: uppercase; letter-spacing: .04em; margin: 4px 0 6px; }
.rp-foot { color: #98a0b0; font-size: 11px; text-align: right; border-top: 1px solid #e3e6ec; padding-top: 8px; margin-top: 4px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #12233a; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; box-shadow: var(--shadow); }
.toast.err { background: var(--bad); }
.empty { color: var(--muted); padding: 18px; text-align: center; }
pre.wa { background: #f0f7ee; border: 1px solid #d4e8cf; padding: 12px; border-radius: 8px; white-space: pre-wrap; font: 13px/1.45 ui-monospace, Consolas, monospace; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .panel { width: min(360px, 100%); }

.grid > * { min-width: 0; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  /* Phones: 16px text stops iPhone zooming into fields, and buttons are big enough for a thumb */
  input, select, textarea { font-size: 16px; }
  button, .btn { min-height: 38px; }
  button.small { min-height: 34px; padding: 6px 10px; font-size: 13px; }
  button.link { min-height: 0; }
  table.sheet input { font-size: 15px; }
  .top h1 { font-size: 18px; }
  /* Packing entries become small cards: platform + item on top, numbers and actions below */
  table.pack tr { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.pack td { border: 0; padding: 0; }
  table.pack td.lbl { flex: 1 1 60%; }
  .panel > .row { gap: 8px; }
  /* Editable PO lines: one card per line, each field labelled */
  table.cards tr:first-child { display: none; }
  table.cards tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.cards td { border: 0; padding: 0; text-align: left; }
  table.cards td.item { grid-column: 1 / -1; min-width: 0; }
  table.cards td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; color: var(--muted); }
  table.cards td input, table.cards td select { width: 100% !important; }
  table.cards td[data-l="Remark"] { grid-column: 1 / -1; }
  .side { position: fixed; z-index: 30; left: 0; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  main { padding: 16px; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2 { grid-template-columns: 1fr; }
}
