/* TNV Điều Hành — giao diện nền trắng (mặc định sáng, kể cả khi máy bật chế độ tối; giao diện tối chỉ bật khi người dùng tự chọn ở
   Tài khoản › Giao diện). Logo Tuấn Nam VP (chữ TN chrome trên nền đá) đặt như 1 thẻ ảnh.
   Đỏ thương hiệu (#ba0f09, website tuannamplastics.com) chỉ dùng cho dấu nhận diện và nút Báo sự cố; đỏ trạng thái (#c81e1e) cho cảnh báo.
   Font hệ thống (không tải font ngoài — CSP chỉ cho phép nguồn từ máy chủ). */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eceef2;
  --border: #e2e5ea;
  --border-strong: #cdd2da;
  --ink: #14161a;
  --dim: #464d5a;
  --faint: #687080;

  --graphite: #17191e;
  --graphite-2: #20232a;
  --graphite-3: #2c3038;
  --graphite-ink: #e9ebef;
  --graphite-dim: #a3a9b5;

  --primary: #1f2329;
  --primary-hover: #343942;
  --primary-ink: #ffffff;
  --brand: #ba0f09;
  --brand-hover: #9b0c07;
  --brand-soft: #fdeceb;

  --info: #1d5fd1;
  --info-soft: #e6efff;
  --info-ink: #1a4fae;
  --good: #15803d;
  --good-soft: #dcf5e4;
  --good-ink: #146c35;
  --warn: #b45309;
  --warn-soft: #fdf1d6;
  --warn-ink: #8a4106;
  --bad: #c81e1e;
  --bad-soft: #fde4e4;
  --bad-ink: #a61818;
  --violet: #6d28d9;
  --violet-soft: #efe9fe;
  --violet-ink: #5b21b6;
  --teal: #0f766e;
  --teal-soft: #d5f5f0;
  --teal-ink: #0d6159;
  --muted-soft: #eceef2;
  --muted-ink: #5b6270;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(17, 20, 26, 0.05), 0 2px 10px rgba(17, 20, 26, 0.05);
  --shadow-lg: 0 18px 50px rgba(17, 20, 26, 0.22);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --code: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0e0f12;
    --surface: #16181c;
    --surface-2: #1b1e23;
    --surface-3: #23262d;
    --border: #2a2e35;
    --border-strong: #3a3f48;
    --ink: #e8eaee;
    --dim: #b4bac5;
    --faint: #8b929e;
    --graphite: #0b0c0e;
    --graphite-2: #14161a;
    --graphite-3: #1f2228;
    --primary: #e3e6ea;
    --primary-hover: #ffffff;
    --primary-ink: #14161a;
    --brand-soft: #3a1210;
    --info: #6aa1ff;
    --info-soft: #172640;
    --info-ink: #9cc0ff;
    --good: #3fbf6d;
    --good-soft: #132b1c;
    --good-ink: #7ddc9d;
    --warn: #e9a23b;
    --warn-soft: #33250f;
    --warn-ink: #f2c47a;
    --bad: #f05252;
    --bad-soft: #3a1416;
    --bad-ink: #ff9b9b;
    --violet: #a78bfa;
    --violet-soft: #251c3d;
    --violet-ink: #c4b5fd;
    --teal: #2dd4bf;
    --teal-soft: #0f2d2a;
    --teal-ink: #7eeadb;
    --muted-soft: #23262d;
    --muted-ink: #a3a9b5;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0e0f12;
  --surface: #16181c;
  --surface-2: #1b1e23;
  --surface-3: #23262d;
  --border: #2a2e35;
  --border-strong: #3a3f48;
  --ink: #e8eaee;
  --dim: #b4bac5;
  --faint: #8b929e;
  --graphite: #0b0c0e;
  --graphite-2: #14161a;
  --graphite-3: #1f2228;
  --primary: #e3e6ea;
  --primary-hover: #ffffff;
  --primary-ink: #14161a;
  --brand-soft: #3a1210;
  --info: #6aa1ff;
  --info-soft: #172640;
  --info-ink: #9cc0ff;
  --good: #3fbf6d;
  --good-soft: #132b1c;
  --good-ink: #7ddc9d;
  --warn: #e9a23b;
  --warn-soft: #33250f;
  --warn-ink: #f2c47a;
  --bad: #f05252;
  --bad-soft: #3a1416;
  --bad-ink: #ff9b9b;
  --violet: #a78bfa;
  --violet-soft: #251c3d;
  --violet-ink: #c4b5fd;
  --teal: #2dd4bf;
  --teal-soft: #0f2d2a;
  --teal-ink: #7eeadb;
  --muted-soft: #23262d;
  --muted-ink: #a3a9b5;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--info-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0; }
.mono { font-family: var(--code); font-size: 0.92em; }
.dim { color: var(--dim); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.tight { gap: 6px; }
.spacer { flex: 1; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
svg.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- khởi động */
.boot { position: fixed; inset: 0; display: flex; flex-direction: column; gap: 16px; align-items: center; justify-content: center; background: var(--surface); color: var(--faint); }
.boot img { width: 180px; border-radius: 12px; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- đăng nhập */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(360px, 520px); background: var(--surface); }
.auth-hero { display: flex; flex-direction: column; justify-content: center; align-items: flex-start; padding: 56px clamp(28px, 5vw, 72px); color: var(--ink); background: var(--surface-2); border-right: 1px solid var(--border); }
.auth-hero .hero-logo { width: min(440px, 100%); aspect-ratio: 768 / 450; object-fit: cover; border-radius: 18px; box-shadow: 0 18px 44px rgba(17, 20, 26, 0.18); margin-bottom: 30px; }
.auth-hero h1 { font-size: 30px; color: var(--ink); max-width: 540px; }
.auth-hero p { color: var(--dim); margin-top: 10px; max-width: 540px; }
.auth-hero .bullets { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.auth-hero .bullets span { padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--dim); font-size: 13px; }
.auth-panel { background: var(--surface); display: flex; flex-direction: column; justify-content: center; padding: 40px clamp(20px, 5vw, 56px); gap: 22px; }
.auth-panel .brand-line { display: flex; align-items: center; gap: 12px; }
.auth-panel .brand-line img { width: 64px; height: 38px; object-fit: cover; border-radius: 8px; }
.auth-panel .brand-line b { display: block; font-size: 17px; }
.auth-panel .brand-line small { color: var(--faint); }
.auth-panel form { display: flex; flex-direction: column; gap: 14px; }
.auth-foot { color: var(--faint); font-size: 12.5px; }
.qr-box { display: flex; gap: 16px; align-items: center; padding: 12px; border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.qr-box img { width: 140px; height: 140px; background: #fff; border-radius: 8px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font-family: var(--code); }
.codes span { padding: 6px 8px; background: var(--surface-3); border-radius: 6px; text-align: center; }

/* ---------------------------------------------------------------- khung chính */
/* Đường kẻ phân cách cột menu kéo dài hết trang khi trang dài hơn màn hình. */
.shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); background: linear-gradient(90deg, var(--surface) calc(var(--sidebar-w) - 1px), var(--border) calc(var(--sidebar-w) - 1px) var(--sidebar-w), var(--bg) var(--sidebar-w)); }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
  background: var(--surface); color: var(--ink); border-right: 1px solid var(--border);
}
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; text-decoration: none !important; color: inherit; }
.sb-brand img { width: 70px; height: 42px; object-fit: cover; border-radius: 8px; box-shadow: 0 0 0 1px var(--border); }
.sb-brand b { display: block; font-size: 15px; letter-spacing: 0.01em; color: var(--ink); }
.sb-brand small { display: block; color: var(--faint); font-size: 11.5px; }
.sb-incident { margin: 4px 14px 10px; }
.sb-nav { display: flex; flex-direction: column; padding: 6px 10px 12px; gap: 2px; }
.sb-group { margin: 12px 10px 4px; color: var(--faint); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.sb-link {
  position: relative; display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px; color: var(--dim);
  text-decoration: none !important; font-size: 14.5px; font-weight: 500;
}
.sb-link:hover { background: var(--surface-3); color: var(--ink); }
.sb-link.active { background: var(--surface-3); color: var(--ink); font-weight: 650; }
.sb-link.active::before { content: ''; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.sb-link .count { margin-left: auto; }
.sb-foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); }
.sb-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; color: inherit; text-decoration: none !important; }
.sb-user:hover { background: var(--surface-3); }
.sb-user b { display: block; font-size: 13.5px; color: var(--ink); }
.sb-user small { display: block; font-size: 12px; color: var(--faint); }

.count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 700; background: var(--surface-3); color: var(--dim); }
.count.red { background: var(--bad); color: #fff; }
.count.amber { background: #d97706; color: #fff; }
.count.light { background: var(--surface-3); color: var(--dim); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 22px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar .tb-title { font-size: 17px; font-weight: 650; }
.topbar .tb-mark { display: none; }
.topbar .tb-mark img { width: 46px; height: 28px; object-fit: cover; border-radius: 6px; }
.iconbtn {
  position: relative; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--dim); cursor: pointer;
}
.iconbtn:hover { background: var(--surface-3); color: var(--ink); }
.iconbtn .dot { position: absolute; top: 4px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 2px solid var(--bg); }
.iconbtn.pulse .dot { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(200, 30, 30, 0.55); } 50% { box-shadow: 0 0 0 6px rgba(200, 30, 30, 0); } }
.page { padding: 22px; max-width: 1360px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.page-head .sub { color: var(--faint); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- thanh dưới (điện thoại) */
.tabbar { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); background: var(--bg); }
  .sidebar { display: none; }
  .topbar { padding: 0 10px 0 14px; height: calc(var(--topbar-h) - 4px + var(--safe-t)); padding-top: var(--safe-t); }
  .topbar .tb-mark { display: block; }
  .topbar .tb-title { font-size: 16px; }
  .page { padding: 14px 14px calc(var(--tabbar-h) + 20px + var(--safe-b)); gap: 14px; }
  h1 { font-size: 19px; }
  .tabbar {
    position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgba(17, 20, 26, 0.06);
  }
  .tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--faint); font-size: 11px; font-weight: 600; text-decoration: none !important; background: none; border: 0; cursor: pointer; }
  .tab svg.ic { width: 22px; height: 22px; }
  .tab.active { color: var(--ink); }
  .tab.active svg.ic { stroke-width: 2.4; }
  .tab .count { position: absolute; top: 6px; left: calc(50% + 6px); height: 18px; min-width: 18px; font-size: 10.5px; }
  .tab.sos { color: var(--brand); }
  .tab.sos .sos-btn { width: 52px; height: 52px; margin-top: -22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; background: var(--brand); box-shadow: 0 6px 18px rgba(186, 15, 9, 0.35), 0 0 0 4px var(--surface); }
  .tab.sos .sos-btn svg.ic { width: 26px; height: 26px; }
}

/* ---------------------------------------------------------------- nút, ô nhập */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 0 15px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  text-decoration: none !important; transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.brand, .btn.sos { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.brand:hover, .btn.sos:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.good:hover { filter: brightness(0.95); }
.btn.danger { color: var(--bad-ink); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.warn { color: var(--warn-ink); border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.btn.warn:hover { background: var(--warn-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--dim); }
.btn.ghost:hover { background: var(--surface-3); color: var(--ink); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.lg { min-height: 48px; padding: 0 20px; font-size: 15.5px; border-radius: 12px; }
.btn.block { width: 100%; }
.sb-incident .btn { width: 100%; min-height: 44px; }
@media (max-width: 860px) { .btn { min-height: 44px; } .btn.sm { min-height: 36px; } }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 600; color: var(--dim); }
label.field > small, .hint { font-weight: 400; color: var(--faint); font-size: 12.5px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font-size: 15px; font-weight: 400;
}
textarea.input { min-height: 84px; resize: vertical; line-height: 1.45; }
.input:focus { outline: none; border-color: var(--info); box-shadow: 0 0 0 3px color-mix(in srgb, var(--info) 22%, transparent); }
.input.invalid { border-color: var(--bad); }
@media (max-width: 860px) { .input, select.input { min-height: 46px; font-size: 16px; } }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
.check { display: inline-flex; align-items: center; gap: 9px; font-weight: 500; color: var(--ink); cursor: pointer; font-size: 14.5px; }
.check input { width: 19px; height: 19px; accent-color: var(--primary); }
.seg { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--surface-3); gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 13.5px; color: var(--dim); cursor: pointer; min-height: 34px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg.prio button.on[data-v='khan'] { background: var(--bad); color: #fff; }
.seg.prio button.on[data-v='cao'] { background: #d97706; color: #fff; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; cursor: pointer; color: var(--dim); }
.quick button:hover { border-color: var(--border-strong); color: var(--ink); }

/* ---------------------------------------------------------------- thẻ, bảng */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15.5px; }
.card-body { padding: 16px; }
.card-foot { padding: 10px 16px; border-top: 1px solid var(--border); }
.cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1080px) { .cols { grid-template-columns: minmax(0, 1fr); } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); text-decoration: none !important; color: inherit; }
.kpi:hover { border-color: var(--border-strong); }
.kpi .k-label { font-size: 13px; color: var(--faint); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi .k-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.kpi .k-sub { font-size: 12.5px; color: var(--faint); }
.kpi.bad .k-value { color: var(--bad); }
.kpi.warn .k-value { color: var(--warn); }
.kpi.good .k-value { color: var(--good); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 650; color: var(--faint); font-size: 12.5px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; }
.table td:first-child { min-width: 9em; }

.chip { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12.5px; font-weight: 650; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; background: var(--muted-soft); color: var(--muted-ink); }
.chip.sm { height: 21px; font-size: 11.5px; padding: 0 7px; }
.chip svg.ic { width: 13px; height: 13px; }
.chip.info { background: var(--info-soft); color: var(--info-ink); }
.chip.good { background: var(--good-soft); color: var(--good-ink); }
.chip.warn { background: var(--warn-soft); color: var(--warn-ink); }
.chip.bad { background: var(--bad-soft); color: var(--bad-ink); }
.chip.violet { background: var(--violet-soft); color: var(--violet-ink); }
.chip.teal { background: var(--teal-soft); color: var(--teal-ink); }
.chip.primary { background: var(--primary); color: var(--primary-ink); }
.chip.solid-bad { background: var(--bad); color: #fff; }
.chip.outline { background: transparent; border: 1px solid var(--border-strong); color: var(--dim); }
.chip.grp { background: transparent; border: 1px solid currentColor; }

.avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 700; color: #fff; background: #59606c; }
.avatar.sm { width: 24px; height: 24px; font-size: 10.5px; }
.avatar.lg { width: 44px; height: 44px; font-size: 16px; }

.empty { padding: 34px 16px; text-align: center; color: var(--faint); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty svg.ic { width: 34px; height: 34px; stroke-width: 1.5; color: var(--border-strong); }
.empty b { color: var(--dim); font-size: 15px; }
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); background: var(--info-soft); color: var(--info-ink); border: 1px solid color-mix(in srgb, var(--info) 25%, transparent); }
.notice.warn { background: var(--warn-soft); color: var(--warn-ink); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.notice.bad { background: var(--bad-soft); color: var(--bad-ink); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.notice.good { background: var(--good-soft); color: var(--good-ink); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.notice .grow p { color: inherit; opacity: 0.9; font-size: 13.5px; margin-top: 2px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a, .tabs button { padding: 10px 12px; border: 0; background: none; color: var(--faint); font-weight: 650; font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none !important; display: inline-flex; align-items: center; gap: 6px; }
.tabs a.on, .tabs button.on { color: var(--ink); border-bottom-color: var(--brand); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters .input { width: auto; min-width: 150px; min-height: 38px; padding: 6px 10px; font-size: 14px; }
.filters .search { flex: 1 1 220px; min-width: 180px; }
@media (max-width: 860px) { .filters .input { flex: 1 1 140px; min-height: 42px; } }

/* ---------------------------------------------------------------- danh sách việc */
.tasklist { display: flex; flex-direction: column; }
.task-item { position: relative; display: flex; gap: 12px; padding: 13px 16px 13px 18px; border-bottom: 1px solid var(--border); cursor: pointer; color: inherit; text-decoration: none !important; }
.task-item:last-child { border-bottom: 0; }
.task-item:hover { background: var(--surface-2); }
.task-item::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 4px 4px 0; background: transparent; }
.task-item.p-khan::before { background: var(--bad); }
.task-item.p-cao::before { background: #d97706; }
.task-item.late::before { background: var(--bad); }
.task-item .ti-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.task-item .ti-title { font-weight: 650; font-size: 15px; line-height: 1.35; }
.task-item .ti-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--faint); }
.task-item .ti-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; text-align: right; }
.task-item .ti-actions { display: flex; gap: 6px; }
.due { font-size: 13px; font-weight: 650; white-space: nowrap; color: var(--dim); display: inline-flex; align-items: center; gap: 4px; }
.due svg.ic { width: 14px; height: 14px; }
.due.late { color: var(--bad); }
.due.soon { color: var(--warn); }
.due.done { color: var(--good); }
.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.progress.good > i { background: var(--good); }
@media (max-width: 640px) {
  .task-item { flex-direction: column; gap: 8px; padding: 12px 14px 12px 16px; }
  .task-item .ti-side { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; width: 100%; text-align: left; }
  .task-item .ti-actions { width: 100%; }
  .task-item .ti-actions .btn { flex: 1; }
}

/* ---------------------------------------------------------------- chi tiết việc */
.detail-head { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.detail-head h1 { font-size: 21px; }
.action-bar { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 860px) {
  .action-bar.sticky { position: fixed; z-index: 35; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); padding: 10px 12px; background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.08); }
  .action-bar.sticky .btn { flex: 1 1 0; }
  .page.has-actions { padding-bottom: calc(var(--tabbar-h) + 96px + var(--safe-b)); }
}
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 18px; }
.fact { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.fact .f-label { font-size: 12px; font-weight: 650; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; }
.fact .f-value { font-size: 14.5px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.fact .due { white-space: normal; }
.desc { white-space: pre-wrap; color: var(--dim); }
.checklist { display: flex; flex-direction: column; }
.cl-item { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px dashed var(--border); }
.cl-item:last-child { border-bottom: 0; }
.cl-item input { width: 21px; height: 21px; accent-color: var(--good); flex: none; }
.cl-item.done .cl-text { text-decoration: line-through; color: var(--faint); }
.cl-item .cl-text { flex: 1; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.gallery a { display: block; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-3); border: 1px solid var(--border); }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs .th { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; background: var(--surface-3); }
.thumbs .th img { width: 100%; height: 100%; object-fit: cover; }
.thumbs .th button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.6); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.thumbs .th button svg.ic { width: 13px; height: 13px; }

.timeline { display: flex; flex-direction: column; }
.ev { display: flex; gap: 11px; padding: 10px 0; }
.ev + .ev { border-top: 1px solid var(--border); }
.ev .ev-ic { width: 30px; height: 30px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; background: var(--surface-3); color: var(--dim); }
.ev .ev-ic svg.ic { width: 15px; height: 15px; }
.ev.comment .ev-ic { background: var(--info-soft); color: var(--info-ink); }
.ev.alert .ev-ic { background: var(--bad-soft); color: var(--bad-ink); }
.ev.status .ev-ic { background: var(--good-soft); color: var(--good-ink); }
.ev .ev-body { flex: 1; min-width: 0; }
.ev .ev-who { font-size: 13px; color: var(--faint); }
.ev .ev-who b { color: var(--ink); font-weight: 650; }
.ev .ev-text { white-space: pre-wrap; margin-top: 2px; word-break: break-word; }
.ev.comment .ev-text { background: var(--surface-2); border: 1px solid var(--border); padding: 8px 11px; border-radius: 4px 12px 12px 12px; display: inline-block; max-width: 100%; }
.composer { display: flex; flex-direction: column; gap: 8px; }
.composer .row .input { min-height: 42px; }

/* ---------------------------------------------------------------- cảnh báo */
.alert-card { display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.alert-card:last-child { border-bottom: 0; }
.alert-card .al-ic { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex: none; background: var(--warn-soft); color: var(--warn-ink); }
.alert-card.critical .al-ic { background: var(--bad); color: #fff; }
.alert-card.critical.unacked .al-ic { animation: pulse 1.4s ease-in-out infinite; }
.alert-card.resolved { opacity: 0.65; }
.alert-card .al-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.alert-card .al-title { font-weight: 650; }
.alert-card .al-meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--faint); align-items: center; }
.alert-card .al-actions { display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 640px) { .alert-card { flex-wrap: wrap; } .alert-card .al-actions { width: 100%; } .alert-card .al-actions .btn { flex: 1; } }

/* Lớp phủ cảnh báo khẩn: hiện đè, có âm thanh, giữ tới khi người dùng bấm. */
.sos-overlay { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 18px; background: rgba(60, 4, 4, 0.72); backdrop-filter: blur(3px); animation: fadein 0.15s; }
.sos-box { width: min(520px, 100%); background: var(--surface); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow-lg); }
.sos-top { padding: 18px 20px; background: var(--bad); color: #fff; display: flex; gap: 12px; align-items: center; }
.sos-top svg.ic { width: 30px; height: 30px; animation: shake 0.9s ease-in-out infinite; }
.sos-top b { font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.9; }
.sos-top h2 { font-size: 18px; color: #fff; margin-top: 2px; }
.sos-body { padding: 16px 20px; color: var(--dim); white-space: pre-wrap; }
.sos-foot { padding: 14px 20px 18px; display: flex; gap: 10px; flex-wrap: wrap; }
.sos-foot .btn { flex: 1 1 140px; min-height: 48px; }
.sos-more { padding: 0 20px 12px; font-size: 13px; color: var(--faint); }
@keyframes shake { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------------------------------------------------------------- thông báo */
.bell-panel { position: fixed; z-index: 60; top: calc(var(--topbar-h) + 4px + var(--safe-t)); right: 14px; width: min(420px, calc(100vw - 20px)); max-height: min(70vh, 640px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
.bell-panel .bp-list { overflow-y: auto; }
.noti { display: flex; gap: 11px; padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; color: inherit; text-decoration: none !important; }
.noti:hover { background: var(--surface-2); }
.noti.unread { background: color-mix(in srgb, var(--info-soft) 55%, var(--surface)); }
.noti .n-ic { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex: none; background: var(--surface-3); color: var(--dim); }
.noti .n-ic.warn { background: var(--warn-soft); color: var(--warn-ink); }
.noti .n-ic.critical { background: var(--bad); color: #fff; }
.noti .n-ic.info { background: var(--info-soft); color: var(--info-ink); }
.noti .n-main { flex: 1; min-width: 0; }
.noti .n-title { font-weight: 650; font-size: 14px; line-height: 1.35; }
.noti .n-body { font-size: 13px; color: var(--dim); margin-top: 2px; overflow-wrap: anywhere; }
.noti .n-time { font-size: 12px; color: var(--faint); margin-top: 3px; }
.noti .n-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--info); flex: none; margin-top: 6px; }

.toasts { position: fixed; z-index: 150; top: calc(var(--topbar-h) + 8px + var(--safe-t)); right: 14px; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 20px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--graphite-2); color: #f2f3f5; box-shadow: var(--shadow-lg); animation: slidein 0.18s ease-out; cursor: default; }
.toast.clickable { cursor: pointer; }
.toast .t-title { font-weight: 650; font-size: 14px; }
.toast .t-body { font-size: 13px; color: #c2c7cf; margin-top: 2px; }
.toast.ok { background: #14532d; }
.toast.err { background: #7f1d1d; }
.toast.warn { background: #78350f; }
.toast button.x { margin-left: auto; background: none; border: 0; color: inherit; opacity: 0.7; cursor: pointer; padding: 0; }
@keyframes slidein { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------------------------------------------------------- hộp thoại */
dialog.modal { padding: 0; border: 0; border-radius: 16px; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 40px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
dialog.modal.wide { width: min(880px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(8, 10, 14, 0.55); }
.modal form, .modal > .m-wrap { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.m-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.m-head h2 { font-size: 17px; }
.m-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.m-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.m-error { color: var(--bad-ink); background: var(--bad-soft); padding: 9px 12px; border-radius: 10px; font-size: 14px; }
@media (max-width: 640px) {
  dialog.modal, dialog.modal.wide { width: 100vw; max-width: 100vw; max-height: 94vh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .modal form, .modal > .m-wrap { max-height: 94vh; }
  .m-foot { padding-bottom: calc(12px + var(--safe-b)); }
  .m-foot .btn { flex: 1 1 0; }
}

/* Chọn người (tìm kiếm). */
.picker { position: relative; }
.picker .pk-list { position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px); max-height: 260px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow-lg); }
.picker .pk-opt { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; }
.picker .pk-opt:hover, .picker .pk-opt.hl { background: var(--surface-3); }
.picker .pk-opt small { color: var(--faint); display: block; font-size: 12px; }
.tokens { display: flex; gap: 6px; flex-wrap: wrap; }
.token { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border-radius: 999px; background: var(--surface-3); font-size: 13px; }
.token button { width: 20px; height: 20px; border-radius: 50%; border: 0; background: transparent; color: var(--faint); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.token button:hover { background: var(--border); color: var(--ink); }

/* Báo sự cố: ô chọn loại lớn, dễ bấm khi đang đeo găng. */
.kinds { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kind { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; padding: 14px; border-radius: 14px; border: 2px solid var(--border); background: var(--surface); cursor: pointer; text-align: left; font-weight: 650; min-height: 92px; color: var(--ink); }
.kind svg.ic { width: 26px; height: 26px; color: var(--brand); }
.kind.on { border-color: var(--brand); background: var(--brand-soft); }

/* Luồng sản xuất. */
.stepper { display: flex; gap: 0; overflow-x: auto; padding: 4px 2px 10px; }
.st { flex: 1 0 116px; display: flex; flex-direction: column; align-items: center; gap: 7px; position: relative; text-align: center; padding: 0 4px; }
.st::before { content: ''; position: absolute; top: 15px; left: -50%; right: 50%; height: 3px; background: var(--border); z-index: 0; }
.st:first-child::before { display: none; }
.st .dotc { position: relative; z-index: 1; width: 32px; height: 32px; border-radius: 50%; background: var(--surface-3); border: 2px solid var(--border-strong); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--faint); }
.st .dotc svg.ic { width: 16px; height: 16px; }
.st.xong .dotc { background: var(--good); border-color: var(--good); color: #fff; }
.st.xong::before { background: var(--good); }
.st.dang .dotc { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent); }
.st.dang::before { background: var(--good); }
.st.ng .dotc { border-style: dashed; }
.st.ng.dang .dotc, .st.fail .dotc { background: var(--bad); border-color: var(--bad); color: #fff; }
.st .st-label { font-size: 12px; font-weight: 600; color: var(--dim); line-height: 1.25; }
.st .st-sub { font-size: 11.5px; color: var(--faint); }
.run-steps { display: flex; flex-direction: column; }
.run-step { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; padding: 10px 0; }
.run-step + .run-step { border-top: 1px dashed var(--border); }
.run-step .dotc { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--surface-3); color: var(--faint); font-size: 12px; font-weight: 700; }
.run-step.xong .dotc { background: var(--good); color: #fff; }
.run-step.dang .dotc { background: var(--primary); color: var(--primary-ink); }
.run-step.huy .dotc { background: var(--muted-soft); }

/* Biểu đồ cột chồng (Báo cáo): việc xong đúng hạn / trễ hạn theo ngày. Màu đã kiểm mù màu (validate_palette, sáng + tối). */
:root { --chart-ok: #2563eb; --chart-late: #c81e1e; --chart-grid: #e7e9ee; }
:root[data-theme='dark'] { --chart-ok: #5b8def; --chart-late: #ef5a5a; --chart-grid: #2a2e35; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) { --chart-ok: #5b8def; --chart-late: #ef5a5a; --chart-grid: #2a2e35; } }
.chart { position: relative; }
.bars { position: relative; display: flex; align-items: flex-end; gap: 2px; height: 160px; padding-top: 8px; border-bottom: 1px solid var(--border-strong); background-image: linear-gradient(var(--chart-grid) 1px, transparent 1px); background-size: 100% 25%; background-position: 0 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column-reverse; gap: 2px; min-width: 3px; height: 100%; cursor: default; }
.bars .bar i { display: block; flex: none; }
.bars .bar i:last-child { border-radius: 4px 4px 0 0; }
.bars .bar i.ok { background: var(--chart-ok); }
.bars .bar i.late { background: var(--chart-late); }
.bars .bar:hover i { filter: brightness(1.12); }
.axis-x { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--faint); margin-top: 4px; }
.chart-tip { position: absolute; z-index: 5; pointer-events: none; padding: 8px 10px; border-radius: 8px; background: var(--graphite-2); color: #f2f3f5; font-size: 12.5px; box-shadow: var(--shadow-lg); white-space: nowrap; transform: translate(-50%, -100%); }
.chart-tip i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--faint); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.meter { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.meter .progress { flex: 1; }

/* Ma trận phân quyền. */
.perm-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 14px; align-items: center; }
.perm-grid .seg button { padding: 5px 9px; font-size: 12.5px; min-height: 30px; }
.settings-list { display: flex; flex-direction: column; gap: 14px; }

/* Ảnh xem lớn. */
.lightbox { position: fixed; inset: 0; z-index: 220; background: rgba(0, 0, 0, 0.9); display: flex; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.install-tip { display: flex; gap: 12px; align-items: center; }
.install-tip img { width: 44px; height: 44px; border-radius: 10px; }
.kbd { font-family: var(--code); font-size: 12px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-strong); background: var(--surface-2); }
.offline-bar { position: fixed; z-index: 190; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 12px + var(--safe-b)); padding: 8px 14px; border-radius: 999px; background: var(--graphite-2); color: #fff; font-size: 13px; box-shadow: var(--shadow-lg); }
@media (min-width: 861px) { .offline-bar { bottom: 18px; } }
@media print { .sidebar, .topbar, .tabbar, .action-bar, .btn { display: none !important; } .shell { display: block; } }

@media (max-width: 860px) { .only-desktop { display: none !important; } }

@media (max-width: 860px) {
  .auth { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .auth-hero { padding: calc(22px + var(--safe-t)) 18px 18px; border-right: 0; border-bottom: 1px solid var(--border); }
  .auth-hero .hero-logo { width: 190px; border-radius: 14px; margin-bottom: 14px; box-shadow: 0 10px 26px rgba(17, 20, 26, 0.16); }
  .auth-hero h1 { font-size: 21px; }
  .auth-panel .brand-line img { display: none; }
  .auth-hero p, .auth-hero .bullets { display: none; }
  .auth-panel { padding: 24px 18px calc(24px + var(--safe-b)); justify-content: flex-start; }
}
@media (max-width: 640px) {
  .notice { flex-wrap: wrap; }
  .notice > .btn { width: 100%; }
}
