:root {
  --navy: #0f2a4f;
  --navy-2: #12325e;
  --side: #0d2546;
  --blue: #1f73e0;
  --blue-soft: #e8f1fd;
  --cyan: #22c3e6;
  --bg: #f2f5f9;
  --card: #ffffff;
  --line: #e3e9f1;
  --line-2: #eef2f7;
  --ink: #0f2a4f;
  --ink-2: #5b6b82;
  --ink-3: #8a97a8;
  --good: #0ca30c;
  --good-ink: #08700a;
  --warn: #fab219;
  --bad: #d03b3b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 42, 79, .04), 0 2px 8px rgba(15, 42, 79, .04);
  --font: "Segoe UI", Inter, system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 14px; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }
.ic { width: 20px; height: 20px; flex: none; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% 0%, #163a6e 0%, var(--side) 60%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.brand { font-weight: 800; font-size: 26px; letter-spacing: -.3px; }
.brand b { color: var(--cyan); font-weight: 800; }
.login-card .brand { color: var(--navy); }
.login-card .sub { color: var(--ink-2); margin: 2px 0 24px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 13px; color: var(--ink-2); }
.input, select.input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid #d5dde8; border-radius: 8px; background: #fff; outline: none; }
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(31,115,224,.15); }
textarea.input { height: auto; padding: 10px 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 8px;
  border: 1px solid #d5dde8; background: #fff; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { background: #f6f8fb; }
.btn .ic { width: 18px; height: 18px; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1966c9; }
.btn.danger { color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; height: 44px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 4px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100%; background: linear-gradient(90deg, var(--side) 236px, transparent 236px); }
.side { background: linear-gradient(180deg, #102c54 0%, var(--side) 100%); color: #dbe6f5; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side .brand { color: #fff; padding: 22px 22px 0; }
.side .brand-sub { padding: 2px 22px 22px; color: #b9c8de; font-size: 15px; }
.nav { display: grid; gap: 4px; padding: 0 8px; }
.nav a { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-radius: 8px; color: #dbe6f5; font-size: 15px; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: var(--blue); color: #fff; box-shadow: 0 4px 12px rgba(31,115,224,.35); }
.nav .ic { width: 22px; height: 22px; }
.side-report { padding: 14px 8px 0; margin-top: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.side-report button + button { margin-top: 6px; }
.side-report button { width: 100%; display: flex; align-items: center; gap: 14px; padding: 11px 16px; border-radius: 8px; border: 1px dashed rgba(255,255,255,.25); background: transparent; color: #dbe6f5; cursor: pointer; font-size: 15px; }
.side-report button:hover { background: rgba(255,255,255,.06); }
.side-report .ic { width: 22px; height: 22px; }
.modal h3 { display: flex; align-items: center; gap: 10px; }
.modal { max-width: 520px; }
.side-foot { margin-top: auto; padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.me { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.12); display: grid; place-items: center; font-weight: 700; color: #fff; }
.me .name { font-weight: 600; color: #fff; }
.role { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #9fb4d1; }
.side-actions { display: flex; gap: 6px; }
.side-actions button { flex: 1; background: rgba(255,255,255,.07); border: 0; color: #dbe6f5; height: 32px; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 12.5px; }
.side-actions button:hover { background: rgba(255,255,255,.14); }
.side-actions .ic { width: 16px; height: 16px; }

.main { min-width: 0; padding: 22px 26px 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.topbar h1 { margin: 0; font-size: 27px; font-weight: 750; letter-spacing: -.4px; }
.topbar .subtitle { color: var(--ink-2); margin-top: 4px; font-size: 15px; }
.topbar .grow { flex: 1; min-width: 220px; }
.ctrl { display: grid; gap: 5px; }
.ctrl label { font-size: 13px; color: var(--ink-2); }
.ctrl .input { width: 200px; height: 38px; }
.pill-live { align-self: center; background: #e3eefc; color: #1d5fb5; font-size: 11.5px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; padding: 7px 12px; border-radius: 7px; display: inline-flex; align-items: center; gap: 8px; }
.pill-live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px rgba(12,163,12,.18); }
.mobile-menu { display: none; }

.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; background: #fff7e3; border: 1px solid #f6dd9b; color: #6d4c00; margin-bottom: 16px; }
.banner .ic { color: #b47b00; }
.banner.info { background: #eaf2fd; border-color: #c9ddf8; color: #1d4f91; }
.banner.info .ic { color: var(--blue); }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.section { margin-bottom: 18px; }
.section > h2, .card h2 { margin: 0 0 14px; font-size: 19px; font-weight: 700; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.card-head .hint { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.card-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.ic-circle { width: 36px; height: 36px; border-radius: 50%; background: var(--blue-soft); color: var(--blue); display: grid; place-items: center; flex: none; }
.head-ic { width: 30px; height: 30px; color: var(--blue); }
.head-ic.warn { color: var(--bad); }
.head-ic.waste { color: #e2502c; }

.kpis { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)) minmax(380px, 2.4fr); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 18px 18px 16px; display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: start; }
.kpi .ic-wrap { width: 46px; height: 46px; border-radius: 50%; background: var(--blue-soft); display: grid; place-items: center; color: var(--blue); }
.kpi .ic-wrap .ic { width: 24px; height: 24px; }
.kpi .ic-wrap.solid { background: var(--blue); color: #fff; }
.kpi .t { font-weight: 700; font-size: 16px; margin-top: 12px; white-space: nowrap; }
.kpi .v { grid-column: 1 / -1; font-size: 38px; font-weight: 750; line-height: 1.1; margin: 12px 0 2px 2px; letter-spacing: -.5px; }
.kpi .l { grid-column: 1 / -1; color: var(--ink-2); font-size: 13px; margin-left: 2px; }
.kpi .meta { grid-column: 1 / -1; color: var(--ink-3); font-size: 12px; margin: 6px 0 0 2px; }
.kpi.final { grid-template-columns: auto auto 1fr; }
.kpi.final .split { grid-row: 1 / span 3; grid-column: 3; display: grid; grid-template-columns: repeat(3, 1fr); align-self: center; border-left: 1px solid var(--line); margin-left: 14px; }
.kpi.final .split div { text-align: center; padding: 4px 6px; }
.kpi.final .split .sl { color: var(--ink-2); font-size: 12.5px; }
.kpi.final .split .sv { font-size: 22px; font-weight: 700; margin-top: 6px; }
.kpi.final .v { grid-column: 1 / span 2; }
.kpi.final .l { grid-column: 1 / span 2; }

.stage-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 1.3fr); gap: 12px; } /* 2 rows; D/S & Polarizer wider for Rejects + Repaired */
.stage-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-width: 0; }
.stage-card .sh { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.stage-card .sh .ic-wrap { width: 34px; height: 34px; border-radius: 50%; background: var(--blue-soft); color: var(--blue); display: grid; place-items: center; }
.stage-card .sh .ic { width: 19px; height: 19px; }
.stage-card .sh b { font-size: 15px; }
.stage-card .sh .tot { margin-left: auto; color: var(--ink-2); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.tot-pill { background: var(--blue-soft); color: var(--blue); font-weight: 700; font-size: 15px; padding: 3px 12px; border-radius: 999px; min-width: 40px; text-align: center; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { background: #f3f6fa; color: var(--ink); font-weight: 600; text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; }
.tbl .muted { color: var(--ink-3); }
.tbl-wrap { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tbl-scroll { overflow-x: auto; }

.charts-row { display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.chart-box { position: relative; height: 270px; }
.chart-box.is-empty canvas { display: none; }
.chart-box.is-empty::after { content: 'No data recorded'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-3); }
.legend-inline { display: flex; gap: 14px; color: var(--ink-2); font-size: 13px; }
.legend-inline i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

.footer { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 14px 4px 18px; color: var(--ink-2); border-top: 1px solid var(--line); font-size: 13.5px; }
.footer .wa-ic { width: 26px; height: 26px; border-radius: 50%; background: #25d366; color: #fff; display: grid; place-items: center; }
.footer .wa-ic .ic { width: 16px; height: 16px; }
.footer b { color: var(--ink); font-weight: 600; }
.footer .right { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--ink); }

/* ---------- entry grid ---------- */
.grid-tbl { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
.grid-tbl th, .grid-tbl td { border-bottom: 1px solid var(--line-2); padding: 0; height: 36px; white-space: nowrap; }
.grid-tbl thead th { background: #f3f6fa; font-weight: 600; padding: 0 8px; position: sticky; top: 0; z-index: 1; border-bottom: 1px solid var(--line); }
.grid-tbl .name { padding: 0 10px; min-width: 130px; font-weight: 600; position: sticky; left: 0; background: #fff; z-index: 1; }
.grid-tbl thead .name { background: #f3f6fa; z-index: 2; }
.grid-tbl .metric { padding: 0 10px; color: var(--ink-2); min-width: 90px; }
.grid-tbl .model { min-width: 120px; }
.grid-tbl .tot { text-align: right; padding: 0 12px; font-weight: 700; background: #f8fafc; min-width: 64px; }
.grid-tbl td.v, .grid-tbl td.model { border-left: 1px solid var(--line-2); }
.grid-tbl tfoot .name { background: #f3f6fa; }
.grid-tbl tfoot td { background: #f3f6fa; font-weight: 700; border-top: 1px solid var(--line); }
.grid-tbl tfoot td.v { text-align: center; }
.grid-tbl td.v { text-align: center; min-width: 54px; }
.grid-tbl td.v input, .grid-tbl td.model input { width: 100%; height: 35px; border: 0; background: transparent; text-align: center; outline: none; font-variant-numeric: tabular-nums; }
.grid-tbl td.model input { text-align: left; padding: 0 10px; }
.grid-tbl td.v input:focus, .grid-tbl td.model input:focus { background: #eaf2fd; box-shadow: inset 0 0 0 2px var(--blue); }
.grid-tbl td.v input.saving { background: #fff8e0; }
.grid-tbl td.v input.saved { background: #e9f8ea; transition: background 1.2s; }
.grid-tbl td.v input.error { background: #fde8e8; }
.grid-tbl tr.group-start td { border-top: 1px solid var(--line); }
.grid-tbl tr.inactive .name { color: var(--ink-3); font-style: italic; }
.grid-tbl .zero { color: #c3ccd8; }
.grid-tbl tr.cat td { background: #fafbfd; font-weight: 700; color: var(--ink-2); padding: 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; height: 30px; }
.save-state { font-size: 12.5px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.save-state.ok { color: var(--good-ink); }
.save-state.err { color: var(--bad); }

.two-col > *, .three-col > *, .charts-row > *, .kpis > *, .stat-row > * { min-width: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stat-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { padding: 14px 16px; }
.stat .sl { color: var(--ink-2); font-size: 13px; }
.stat .sv { font-size: 28px; font-weight: 750; margin-top: 6px; letter-spacing: -.3px; }
.stat .ss { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.status-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.status-chip.good { background: #e6f6e6; color: var(--good-ink); }
.status-chip.bad { background: #fde8e8; color: #a52a2a; }
.status-chip.neutral { background: #eef2f7; color: var(--ink-2); }
.status-chip.warn { background: #fff4d6; color: #7a5400; }
.checks { margin: 0; padding-left: 18px; color: #7a5400; }
.checks li { margin: 3px 0; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { border: 1px solid var(--line); background: #fff; height: 34px; padding: 0 14px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--ink-2); }
.tabs button.on { background: var(--navy); border-color: var(--navy); color: #fff; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.check-row { display: flex; gap: 8px; flex-wrap: wrap; }
.check-row label { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); padding: 6px 10px; border-radius: 8px; cursor: pointer; background: #fff; }
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.toggle input { width: 18px; height: 18px; }
.preview-img { max-width: 100%; border: 1px solid var(--line); border-radius: 10px; display: block; }
.help { color: var(--ink-2); font-size: 13px; line-height: 1.5; }
.help code { background: #f1f4f8; padding: 1px 5px; border-radius: 4px; }

/* ---------- data entry panel ---------- */
.entry-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; align-items: start; }
.entry-layout > * { min-width: 0; }
.hour-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.hour-chip { position: relative; min-width: 72px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 700; font-size: 15px; cursor: pointer; color: var(--ink); }
.hour-chip:hover { border-color: var(--blue); }
.hour-chip.on { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 4px 12px rgba(31,115,224,.3); }
.hour-chip i { position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.entry-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.entry-tabs button { display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.entry-tabs button .ic { width: 18px; height: 18px; }
.entry-tabs button.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.entry-tabs button b { background: var(--blue-soft); color: var(--blue); border-radius: 999px; font-size: 12px; padding: 1px 8px; }
.entry-tabs button.on b { background: rgba(255,255,255,.18); color: #fff; }
.entry-list { display: grid; gap: 2px; }
.entry-row { display: flex; align-items: center; gap: 14px; padding: 10px 4px; border-bottom: 1px solid var(--line-2); }
.entry-row:last-child { border-bottom: 0; }
.entry-row .er-name { flex: 1; font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.er-model { height: 32px; width: 120px; border: 1px solid var(--line); border-radius: 7px; padding: 0 8px; font-size: 13px; font-weight: 400; }
.er-cat { margin: 12px 0 2px; font-size: 12px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .6px; }
.entry-row.multi { align-items: flex-start; flex-direction: column; gap: 10px; padding: 14px 4px; }
.er-fields { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: center; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper .st-l { color: var(--ink-2); font-size: 13px; font-weight: 600; min-width: 64px; }
.st-b { width: 44px; height: 44px; border-radius: 10px; border: 1px solid #d5dde8; background: #f6f8fb; font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink); }
.st-b:active { background: var(--blue-soft); }
.st-i { width: 72px; height: 44px; border: 1px solid #d5dde8; border-radius: 10px; text-align: center; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; outline: none; }
.st-i:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(31,115,224,.15); }
.qc-total { background: var(--blue-soft); color: var(--blue); padding: 10px 14px; border-radius: 10px; font-weight: 600; }
.qc-total b { font-size: 18px; margin-left: 6px; }
.entry-bar { position: sticky; bottom: 12px; display: flex; align-items: center; gap: 10px; padding: 12px 14px; margin-bottom: 18px; box-shadow: 0 8px 24px rgba(15,42,79,.12); }
.entry-bar #pendTxt { margin-right: auto; }
.entry-bar .pend { color: #b45f00; font-weight: 700; }
.entry-bar .btn { height: 44px; }
@media (max-width: 1100px) { .entry-layout { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .stepper .st-l { min-width: 0; } .entry-row { flex-wrap: wrap; } .st-b { width: 40px; }
  .entry-tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; } .entry-bar { flex-wrap: wrap; } .entry-bar #pendTxt { width: 100%; } .entry-bar .btn { flex: 1; } }

.at-badge.sum-badge { color: #5b3fb0; background: #ece6fb; }
.grid-tbl td.calc { color: #5b3fb0; font-weight: 600; background: #faf8ff; }
.at-badge { display: inline-block; margin-left: 8px; font-size: 10.5px; font-weight: 700; letter-spacing: .3px; color: #0b6b78; background: #dff4f6; border-radius: 5px; padding: 2px 6px; vertical-align: middle; }
.entry-row.at .at-val { min-width: 72px; height: 44px; border-radius: 10px; background: #eef7f8; color: #0b6b78; display: grid; place-items: center; font-size: 20px; font-weight: 700; margin-right: 50px; }
.entry-row.at .help { font-weight: 400; }

.er-target { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 400; color: var(--ink-2); background: #f3f6fa; border-radius: 7px; padding: 3px 8px; }
.er-target b { color: var(--ink); }
.er-target .status-chip { padding: 1px 7px; }
.grid-tbl .tgt { width: 72px; min-width: 72px; max-width: 72px; text-align: center; padding: 0 4px; font-weight: 600; color: var(--ink); background: #fbfcfe; border-left: 1px solid var(--line-2); }
.grid-tbl thead .tgt { background: #f3f6fa; }
.grid-tbl tfoot .tgt { background: #f3f6fa; }
.grid-tbl td.tgt input { width: 100%; height: 35px; border: 0; background: transparent; text-align: center; font-weight: 600; outline: none; }
.grid-tbl td.tgt input:focus { background: #eaf2fd; box-shadow: inset 0 0 0 2px var(--blue); }
.grid-tbl .name { min-width: 170px; }
.grid-tbl td.ach { text-align: center; padding: 0 8px; background: #f8fafc; min-width: 76px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(9, 22, 43, .5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 420px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h3 { margin: 0 0 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.toast { position: fixed; right: 18px; bottom: 18px; background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 60; max-width: 420px; }
.toast.err { background: #a52a2a; }

/* ---------- responsive ---------- */
@media (max-width: 1500px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .kpi.final { grid-column: span 3; }
  .stat-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1520px) { .stage-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1180px) { .stage-grid { grid-template-columns: 1fr; } }
@media (max-width: 1100px) {
  .charts-row, .two-col, .three-col { grid-template-columns: 1fr; }
  .stage-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; background: none; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .mobile-menu { display: inline-flex; }
  .main { padding: 14px 16px 0; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi.final { grid-column: span 2; grid-template-columns: auto 1fr; }
  .kpi.final .split { grid-row: auto; grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); margin: 12px 0 0; padding-top: 10px; }
  .kpi .v { font-size: 30px; }
  .stage-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .ctrl .input { width: 160px; }
  .topbar h1 { font-size: 22px; }
}

/* count mode per stage (Team & Lists → Airtable link) */
.count-mode { border: 1px solid var(--line, #e3e8ef); border-radius: 10px; padding: 12px 14px; background: #fafcfe; }
.cm-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.cm-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.cm-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: #fff; border: 1px solid #e3e8ef; cursor: pointer; }
.cm-item > span:first-child { flex: 1; font-weight: 600; }
.cm-item em { font-style: normal; font-size: 12px; color: #6b7a90; min-width: 66px; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 11px; background: #c9d2de; transition: background .15s; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked + i { background: #2a7ad6; }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 2px solid #2a7ad6; outline-offset: 2px; }
.switch input:disabled + i { opacity: .6; }

.tbl td.prep { color: #0e8a5f; }

.evo-status { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; padding: 10px 12px; border: 1px solid #e3e8ef; border-radius: 10px; background: #fafcfe; }

.grid-tbl tr.sum-row td { background: #f2fbf7; color: #0e6b4a; font-weight: 700; }
.grid-tbl tr.sum-row td.metric { color: #0e6b4a; }
.grid-tbl tfoot tr.sum-row td { color: #0e6b4a; }

/* Overview: Final QC card from QC inspection */
.kpi.final.qcf { grid-template-columns: auto 1fr; }
.qcf-grid { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); margin-top: 14px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.qcf-c { text-align: center; padding: 8px 4px 10px; border-left: 1px solid var(--line); display: flex; flex-direction: column; justify-content: space-between; }
.qcf-c:first-child { border-left: 0; }
.qcf-c .sl { color: var(--ink-2); font-size: 12px; line-height: 1.25; min-height: 30px; display: grid; place-items: center; }
.qcf-c .sv { font-size: 24px; font-weight: 750; margin-top: 4px; }
.qcf-c.ready { background: var(--blue-soft); }
.qcf-c.ready .sl { color: var(--blue); font-weight: 600; }
.qcf-c.ready .sv { color: var(--blue); }
.qcf-c.rej .sv { color: #d4572a; }
.kpi.final.qcf .meta { margin-top: 10px; }
@media (max-width: 760px) { .kpi.final.qcf { grid-template-columns: auto 1fr; } .qcf-c .sv { font-size: 20px; } .qcf-c .sl { font-size: 11px; } }

.cap-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0 0 14px; background: #fafcfe; }
.cap-fixed pre { margin: 4px 0 0; padding: 8px 10px; background: #fff; border: 1px dashed var(--line); border-radius: 8px; font-size: 12.5px; white-space: pre-wrap; color: var(--ink); }
.cap-box textarea.input { height: auto; min-height: 110px; padding-top: 8px; resize: vertical; font-family: inherit; }

/* owner's manual PCs on Airtable rows */
.grid-tbl td.adj-ok { cursor: pointer; }
.grid-tbl td.adj-ok:hover { background: #eef5ff; box-shadow: inset 0 0 0 1px #9cc2f0; }
.grid-tbl td.adjd { background: #fff7e6; }
.grid-tbl td.adjd sup, sup.adj-demo { color: #b26a00; font-weight: 700; font-size: 10px; margin-left: 2px; }
.adj-sum { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 10px; margin: 6px 0 14px; overflow: hidden; }
.adj-sum div { text-align: center; padding: 8px 4px; border-left: 1px solid var(--line); }
.adj-sum div:first-child { border-left: 0; }
.adj-sum span { display: block; font-size: 12px; color: var(--ink-2); }
.adj-sum b { font-size: 22px; }

.hist-qcf { margin: 4px 0 14px; max-width: 760px; }

/* LCD Technical Repair page */
.rp-top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 8px 16px; font: inherit; color: var(--ink-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--blue); color: #fff; font-weight: 600; }
.rp-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.rp-card { padding: 16px 18px; display: flex; flex-direction: column; }
.rp-h { display: flex; align-items: center; gap: 10px; font-size: 15.5px; }
.rp-v { font-size: 36px; font-weight: 750; letter-spacing: -.5px; margin: 10px 0 8px; }
.rp-card.good .rp-v { color: #1a7f4e; } .rp-card.bad .rp-v { color: #c0392b; } .rp-card.warn .rp-v { color: #b26a00; }
.rp-split:empty { display: none; }
.rp-split { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); padding-top: 8px; gap: 10px; }
.rp-split span { display: block; font-size: 12px; color: var(--ink-2); }
.rp-split b { font-size: 20px; }
.rp-foot { margin-top: auto; padding-top: 10px; font-size: 12px; color: var(--ink-3); }
.rp-bar { height: 6px; border-radius: 3px; background: #e7edf4; margin-top: 6px; overflow: hidden; }
.rp-bar i { display: block; height: 100%; background: #1a9e64; border-radius: 3px; }
@media (max-width: 1100px) { .rp-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .rp-cards { grid-template-columns: 1fr; } }

.grid-tbl tfoot td.foot-tgt { font-weight: 700; }

/* Top achiever of the day (end of shift) */
.ach-overlay { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: rgba(9, 24, 48, .55); opacity: 0; pointer-events: none; transition: opacity .4s; padding: 16px; }
.ach-overlay.show { opacity: 1; pointer-events: auto; }
.ach-card { width: min(560px, 100%); background: #fff; border-radius: 22px; padding: 30px 32px 24px; text-align: center; position: relative;
  box-shadow: 0 0 0 4px #f5b301, 0 24px 60px rgba(0,0,0,.35); animation: achPulse 1.6s ease-in-out infinite; transform: scale(.92); transition: transform .4s; }
.ach-overlay.show .ach-card { transform: scale(1); }
@keyframes achPulse { 0%, 100% { box-shadow: 0 0 0 4px #f5b301, 0 0 0 0 rgba(245,179,1,.55), 0 24px 60px rgba(0,0,0,.35); }
  50% { box-shadow: 0 0 0 4px #ffd34d, 0 0 0 18px rgba(245,179,1,0), 0 24px 60px rgba(0,0,0,.35); } }
@media (prefers-reduced-motion: reduce) { .ach-card { animation: none; } }
.ach-badge { width: 76px; height: 76px; margin: -70px auto 10px; border-radius: 50%; background: linear-gradient(135deg, #ffd34d, #f5a300); color: #6b4300; display: grid; place-items: center; box-shadow: 0 8px 22px rgba(245,163,0,.45); }
.ach-badge .ic { width: 40px; height: 40px; stroke-width: 2; }
.ach-kicker { text-transform: uppercase; letter-spacing: .14em; font-size: 13px; font-weight: 700; color: #b77900; }
.ach-name { font-size: 44px; font-weight: 800; color: var(--navy, #0f2a4f); line-height: 1.1; margin-top: 6px; }
.ach-stage { color: var(--ink-2); font-size: 16px; margin-top: 4px; }
.ach-nums { display: grid; grid-template-columns: repeat(3, 1fr); margin: 20px 0 6px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.ach-nums div { padding: 12px 6px; border-left: 1px solid var(--line); }
.ach-nums div:first-child { border-left: 0; }
.ach-nums span { display: block; font-size: 12.5px; color: var(--ink-2); }
.ach-nums b { font-size: 30px; font-weight: 800; color: var(--navy, #0f2a4f); }
.ach-nums .hi { background: #fff8e1; } .ach-nums .hi b { color: #1a7f4e; }
.ach-next { margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.ach-foot { margin-top: 8px; font-size: 12px; color: var(--ink-3); }
@media (max-width: 520px) { .ach-name { font-size: 32px; } .ach-nums b { font-size: 24px; } .ach-card { padding: 26px 18px 18px; } }

/* ===== Admin Panel ===== */
.admin-tabs a { display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 600; color: var(--ink-2); white-space: nowrap; text-decoration: none; }
.admin-tabs a .ic { width: 18px; height: 18px; }
.admin-tabs a:hover { border-color: #b9c6d8; color: var(--ink); }
.admin-tabs a.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.adm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.adm-tile { display: flex; align-items: flex-start; gap: 14px; text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s; }
.adm-tile:hover { border-color: #b9c6d8; box-shadow: 0 4px 14px rgba(15,42,79,.08); }
.adm-ic { width: 46px; height: 46px; flex: none; border-radius: 12px; display: grid; place-items: center; background: var(--blue-soft); color: var(--blue); }
.adm-ic .ic { width: 24px; height: 24px; }
.adm-txt { flex: 1; min-width: 0; }
.adm-txt h3 { margin: 0 0 4px; }
.adm-txt p { margin: 0 0 10px; color: var(--ink-2); font-size: 13.5px; line-height: 1.45; }
.adm-go { color: var(--blue); font-weight: 600; font-size: 13px; white-space: nowrap; align-self: center; }
.ach-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#achForm .actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.ach-how { margin: 0; padding-left: 20px; color: var(--ink-2); } .ach-how li { line-height: 1.55; margin-bottom: 8px; } .ach-how b { color: var(--ink); }
@media (max-width: 900px) { .adm-grid { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .admin-tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; } .ach-form-row { grid-template-columns: 1fr; } .adm-go { display: none; } }

/* ===== D/S & Polarizer: Rejects / Repaired ===== */
.q-rej { color: #b53a1e; font-weight: 600; }
.q-rep { color: #1a7f4e; font-weight: 600; }
td.q-rej.zero, td.q-rep.zero { color: #c3ccd8; font-weight: 400; }
.q-tbl tfoot td { font-weight: 700; background: #f4f7fb; border-top: 1px solid var(--line); }
.q-tbl th, .q-tbl td { padding: 7px 6px; }
.q-tbl th { white-space: nowrap; }
.q-tbl td:first-child, .q-tbl th:first-child { padding-left: 9px; }
.q-tbl { font-size: 12.5px; }
.stage-card .tbl-wrap:has(.q-tbl) { overflow-x: auto; }

/* ===== Overview stage cards: compact so all five fit in one row on a wide screen ===== */
.stage-grid { gap: 10px; }
.stage-grid .stage-card { padding: 9px; }
.stage-grid .tbl { font-size: 12.5px; }
.stage-grid .tbl th, .stage-grid .tbl td { padding: 6px 4px; }
.stage-grid .tbl th { white-space: nowrap; font-size: 12px; }
.stage-grid .tbl th:first-child, .stage-grid .tbl td:first-child { padding-left: 8px; }
.stage-grid .tbl th:last-child, .stage-grid .tbl td:last-child { padding-right: 7px; }
.stage-grid .status-chip { padding: 2px 6px; font-size: 11.5px; }
.stage-grid .stage-card .sh { margin-bottom: 8px; }
/* wide screens (e.g. 1920 px TV): all five stage cards in one row, D/S & Polarizer a bit wider for Rejects + Repaired */
@media (min-width: 1820px) {
  .stage-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.45fr) minmax(0, 1.45fr) minmax(0, 1fr) minmax(0, 1fr); }
}

/* separate task inside a stage (Assembly: thermal paste) */
.side-task { margin-top: 10px; }
.side-task .side-h { font-size: 12.5px; font-weight: 700; color: var(--ink); margin: 0 0 6px 2px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.side-task .side-h span { font-weight: 400; color: var(--ink-2); font-size: 12px; }
.side-task .tbl-wrap { border-style: dashed; }
.grid-side { margin-top: 14px; }

/* Airtable sync progress bar */
.sync-prog { width: 260px; max-width: 100%; }
.sync-prog .sp-top { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 600; color: #7a5400; }
.sync-prog .sp-top b { color: var(--ink); font-size: 14px; }
.sync-prog .sp-bar { height: 8px; border-radius: 999px; background: #fff1cc; overflow: hidden; margin: 4px 0 3px; }
.sync-prog .sp-bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #f5a300, #eda100); transition: width .6s ease; }
.sync-prog .sp-sub { font-size: 11.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
