:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --border: #e3e6eb;
  --text: #1c2430; --muted: #6b7686; --accent: #2457c5; --accent-soft: #e8eefb;
  --good: #1f8a4c; --good-soft: #e5f4ea; --bad: #c43a31; --bad-soft: #fbe9e7;
  --warn: #b7791f; --warn-soft: #fdf3e1; --side: #16202e; --side-text: #c9d1dc;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --surface: #19202a; --surface-2: #1e2631; --border: #2b3542;
    --text: #e4e8ee; --muted: #93a0b2; --accent: #6d9bff; --accent-soft: #1f2c47;
    --good: #4cc27f; --good-soft: #17301f; --bad: #ff7b70; --bad-soft: #3a1d1b;
    --warn: #e2a94b; --warn-soft: #362a14; --side: #0c1117; --side-text: #aab4c2;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 "Inter", "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.layout { display: flex; min-height: 100vh; }
.side { width: 220px; background: var(--side); color: var(--side-text); padding: 18px 12px; flex-shrink: 0; }
.side .brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; letter-spacing: .2px; }
.side .brand small { display: block; color: var(--side-text); font-weight: 400; font-size: 12px; }
.side nav a { display: block; color: var(--side-text); padding: 8px 10px; border-radius: 6px; margin-bottom: 2px; }
.side nav a:hover, .side nav a.on { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.side .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; opacity: .55; padding: 14px 10px 4px; }
.side .user { margin-top: 24px; padding: 10px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; }
.side .user a { color: var(--side-text); }
.main { flex: 1; min-width: 0; padding: 22px 28px 40px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select, input[type=text], input[type=search], input[type=number], input[type=date], input[type=url], input[type=password], input[type=file], textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 9px; max-width: 100%;
}
textarea { width: 100%; }
.btn { display: inline-block; font: inherit; font-weight: 550; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 18px; }
.grid > * { min-width: 0; }   /* bảng rộng trong lưới không kéo giãn trang (iPhone bị thu nhỏ) */
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: 2fr 1fr; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .lbl { color: var(--muted); font-size: 12px; }
.tile .val { font-size: 26px; font-weight: 650; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile .foot { font-size: 12px; color: var(--muted); }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); } .muted { color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.good { background: var(--good-soft); } .pill.bad { background: var(--bad-soft); }
.pill.warn { background: var(--warn-soft); } .pill.muted { background: var(--surface-2); }
.pill.auto { background: var(--accent-soft); color: var(--accent); }
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.t th, table.t td { padding: 7px 9px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
table.t td.n, table.t th.n { text-align: right; }
table.t tr:hover td { background: var(--surface-2); }
table.t tr.total td { font-weight: 650; background: var(--surface-2); }
table.t tr.sec td { background: var(--accent-soft); font-weight: 600; }
.sheet td.cell { padding: 3px; min-width: 64px; }
.sheet input.cell { width: 64px; text-align: right; padding: 3px 5px; }
.sheet input.cell.auto { background: var(--accent-soft); border-color: transparent; }
.sheet .kname { min-width: 260px; max-width: 360px; white-space: pre-line; }
.sheet .formula { font-size: 12px; color: var(--muted); white-space: pre-line; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--good); }
.bar > span.bad { background: var(--bad); }
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 9px 12px; border-radius: 6px; margin-bottom: 6px; background: var(--accent-soft); }
.messages li.success { background: var(--good-soft); } .messages li.error { background: var(--bad-soft); }
.messages li.warning { background: var(--warn-soft); }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-weight: 550; margin-bottom: 4px; }
.form-row .help { font-size: 12px; color: var(--muted); }
.form-row .err { color: var(--bad); font-size: 12px; }
.form-row ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.form-row ul label { font-weight: 400; display: inline; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.chart-box { position: relative; height: 260px; }
.grade { font-size: 40px; font-weight: 700; line-height: 1; }
.login { max-width: 360px; margin: 10vh auto; }
.heat td.h { text-align: right; }
.heat td.breach { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.note { font-size: 12px; color: var(--muted); }
/* ---------- Mobile / PWA ---------- */
.mbar, .scrim { display: none; }
.install-btn { width: 100%; margin-top: 16px; background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.15); }
@media (max-width: 960px) {
  .mbar { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 30;
    background: var(--side); color: #fff; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .mbar-title { flex: 1; color: #fff; font-weight: 700; font-size: 16px; }
  .mbar-title:hover { text-decoration: none; }
  .mbar-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
    border: 0; border-radius: 8px; background: transparent; color: #fff; cursor: pointer; }
  .mbar-btn:active { background: rgba(255,255,255,.1); }
  .side { position: fixed; top: 0; bottom: 0; left: 0; width: 270px; z-index: 50; overflow-y: auto;
    transform: translateX(-100%); transition: transform .2s ease; padding-top: calc(18px + env(safe-area-inset-top)); }
  body.nav-open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
  body.nav-open .scrim { display: block; }
  body.nav-open { overflow: hidden; }
  .side nav a { padding: 11px 12px; font-size: 15px; }
  .main { padding: 14px 12px calc(28px + env(safe-area-inset-bottom)); }
  .g2, .g3, .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .topbar h1 { font-size: 18px; }
  .filters select, .filters input[type=search] { flex: 1 1 auto; min-width: 0; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile .val { font-size: 22px; }
  .card { padding: 14px 12px; }
  .chart-box { height: 220px; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.t th, table.t td { padding: 7px 7px; }
  select, input, textarea { font-size: 16px; }   /* iOS không tự zoom khi chạm ô nhập */
}
.kpi-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; background: var(--surface); }
.kpi-card.del { opacity: .45; }
.kpi-card .kgrid { display: grid; gap: 8px 12px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.kpi-card .kgrid > div { min-width: 0; }
.kpi-card label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 2px; }
.kpi-card input[type=text], .kpi-card input[type=number], .kpi-card select, .kpi-card textarea { width: 100%; }
.kpi-card .err { color: var(--bad); font-size: 12px; }
.s1 { grid-column: span 1; } .s2 { grid-column: span 2; } .s3 { grid-column: span 3; } .s4 { grid-column: span 4; } .s6 { grid-column: span 6; }
.kpi-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; }
.chk { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 16px; }
.chk label { font-weight: 400; }
.sticky-bar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 10px 0; display: flex; gap: 10px; align-items: center; z-index: 5; }
@media (max-width: 960px) { .kpi-card .kgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .s1,.s2,.s3,.s4,.s6 { grid-column: span 2; } }

/* Trang danh sách vi phạm */
a.drill { color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; }
a.drill:hover { color: var(--accent); }
td.nw { white-space: nowrap; }
table.report td.wide { min-width: 280px; max-width: 520px; }
table.report thead th { position: sticky; top: 0; background: var(--surface-2); z-index: 1; }

/* Mục tiêu cần đạt */
.star { color: #f5b301; font-size: 1.05em; }
table.targets tr.st-on_track td:first-child, table.targets tr.st-achieved td:first-child { box-shadow: inset 3px 0 0 var(--good); }
table.targets tr.st-need td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.targets tr.st-impossible td:first-child, table.targets tr.st-missed td:first-child { box-shadow: inset 3px 0 0 var(--bad); }

/* Hướng dẫn cài app trên iPhone */
.ios-help { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55); display: flex; flex-direction: column;
  justify-content: flex-end; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.ios-help[hidden] { display: none; }
.ios-card { background: var(--surface); color: var(--text); border-radius: 14px; padding: 18px; max-width: 420px; margin: 0 auto; width: 100%; }
.ios-card ol { padding-left: 20px; margin: 0 0 14px; } .ios-card li { margin-bottom: 8px; }
.ios-arrow { text-align: center; color: #fff; font-size: 26px; margin-top: 6px; animation: bob 1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(6px); } }

/* Planner */
a.tile-link { color: inherit; display: block; transition: border-color .15s; }
a.tile-link:hover { text-decoration: none; border-color: var(--accent); }
a.tile-link.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.val.good { color: var(--good); } .val.muted { color: var(--muted); }
td.warn { color: var(--warn); }
.pill.lbl-pill { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-weight: 500; }

/* Đăng nhập Microsoft */
.ms-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 10px; font-size: 15px; }
.ms-btn:hover { text-decoration: none; }
.local-login { margin-top: 18px; } .local-login summary { cursor: pointer; margin-bottom: 10px; }
.resched { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 9px; background: var(--warn-soft); color: var(--warn); font-size: 11px; font-weight: 600; cursor: help; }
