/* OSPortal — mobile-first. Người dùng chính là nhân viên kế hoạch nhà máy OS,
   nhập trên điện thoại, có khi đang đứng ở xưởng. Nên: chữ to, vùng bấm >= 48px,
   không có menu nhiều tầng, không có bảng cuộn ngang ở màn hình nhập. */

:root {
  --bg: #f4f6f8;
  --card: #fff;
  --ink: #14202b;
  --muted: #64748b;
  --line: #dde3ea;
  --brand: #0f4c81;
  --brand-ink: #fff;
  --ok: #167c53;
  --warn: #b45309;
  --err: #b91c1c;
  --ok-bg: #e7f5ee;
  --warn-bg: #fef3c7;
  --err-bg: #fee2e2;
  --r: 12px;
  --tap: 48px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141b; --card: #17212b; --ink: #e7edf3; --muted: #93a4b5;
    --line: #26333f; --ok-bg: #10291f; --warn-bg: #2e2413; --err-bg: #2e1717;
    --ok: #4ade80; --warn: #fbbf24; --err: #f87171;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.boot { padding: 3rem 1rem; text-align: center; color: var(--muted); }

/* ── khung ── */

#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .5rem;
  background: var(--brand); color: var(--brand-ink);
  padding: max(.5rem, env(safe-area-inset-top)) .5rem .5rem;
  min-height: var(--tap);
}
#title { flex: 1; font-weight: 600; font-size: 1.05rem; }

.icon-btn {
  position: relative; min-width: var(--tap); min-height: var(--tap);
  border: 0; background: transparent; color: inherit;
  font-size: 1.25rem; cursor: pointer; border-radius: 8px;
}
.icon-btn:active { background: rgba(255,255,255,.15); }

.badge {
  position: absolute; top: 6px; right: 4px;
  background: var(--err); color: #fff; border-radius: 999px;
  font-size: .7rem; min-width: 18px; padding: 0 4px; line-height: 18px;
}

.offline-bar {
  background: var(--warn-bg); color: var(--warn); text-align: center;
  padding: .5rem; font-size: .875rem; font-weight: 500;
}

main { padding: .75rem .75rem 5rem; max-width: 900px; margin: 0 auto; }

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar button {
  flex: 1; min-height: var(--tap); border: 0; background: transparent;
  color: var(--muted); font-size: .75rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: .35rem 0;
}
#tabbar button span.ico { font-size: 1.2rem; }
#tabbar button[aria-current="page"] { color: var(--brand); font-weight: 600; }

/* ── thẻ ── */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: .875rem; margin-bottom: .75rem;
}
.card.tap { cursor: pointer; }
.card.tap:active { transform: scale(.995); }

.row { display: flex; align-items: center; gap: .5rem; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.mono { font-variant-numeric: tabular-nums; }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

h2 { font-size: 1.05rem; margin: 1.25rem 0 .5rem; }
h2:first-child { margin-top: 0; }
.sub { color: var(--muted); font-size: .8125rem; }
.big { font-size: 1.5rem; font-weight: 700; }

.pill {
  display: inline-block; padding: .15rem .5rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.pill.ok   { background: var(--ok-bg);   color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.err  { background: var(--err-bg);  color: var(--err); }
.pill.mute { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

.bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); }
.bar > i.done { background: var(--ok); }

/* ── nhập liệu ── */

label { display: block; font-size: .8125rem; color: var(--muted); margin-bottom: .25rem; }

input, select, textarea, button.btn {
  width: 100%; min-height: var(--tap); padding: .5rem .75rem;
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand); outline-offset: -1px;
}
/* Bàn phím số trên điện thoại + không cho spinner ăn chỗ bấm */
input[type="number"] { font-size: 1.25rem; text-align: right; font-variant-numeric: tabular-nums; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.field { margin-bottom: .75rem; }

button.btn {
  background: var(--brand); color: var(--brand-ink); border: 0;
  font-weight: 600; cursor: pointer;
}
button.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
button.btn.wide { font-size: 1.0625rem; }
button.btn:disabled { opacity: .5; }

.qty-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .5rem; }
.qty-grid label { text-align: center; }

/* mốc TNA */
.ms { display: flex; align-items: center; gap: .625rem; padding: .625rem 0;
      border-bottom: 1px solid var(--line); }
.ms:last-child { border-bottom: 0; }
.ms .tick {
  width: 32px; height: 32px; flex: none; border-radius: 8px;
  border: 2px solid var(--line); background: transparent;
  font-size: 1rem; line-height: 1; cursor: pointer;
}
.ms.done .tick { background: var(--ok); border-color: var(--ok); color: #fff; }
.ms.late .name { color: var(--err); font-weight: 600; }
.ms.locked .tick { opacity: .35; cursor: not-allowed; }

/* bảng nội bộ — chỉ bảng mới được cuộn ngang, body thì không bao giờ */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .875rem; }
th, td { padding: .4rem .5rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tap) + 1rem);
  transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--bg);
  padding: .625rem 1rem; border-radius: 999px; font-size: .875rem;
  max-width: 90vw; text-align: center;
}
.toast.err { background: var(--err); color: #fff; }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
