:root {
  /* Màu thương hiệu VAITECH: xanh đậm chữ logo làm màu chủ đạo, xanh nhạt vòng cung cho viền tiêu điểm */
  --bg: #f3f6fb; --side: #e9eff7; --side-hover: #dbe5f2; --surface: #ffffff; --surface-2: #f6f8fc; --fg: #172036; --muted: #5a6680;
  --head: #4d607a; --line: #dde5f0; --accent: #0a4f9e; --accent-bg: #e5eefb; --accent-fg: #ffffff; --focus: #0ea5e9;
  --run: #17804a; --run-bg: #e3f5ea; --idle: #a15f00; --idle-bg: #fdf1dc;
  --alarm: #b42318; --alarm-bg: #fdecec; --off: #5f6672; --off-bg: #eceef2; --none: #8a919d; --none-bg: #f1f2f4;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1520; --side: #141c2a; --side-hover: #1d2738; --surface: #18212f; --surface-2: #1f2a3b; --fg: #e6edf7; --muted: #9daac0;
    --head: #8fa6c3; --line: #2a3649; --accent: #4aa8f0; --accent-bg: #13294a; --accent-fg: #07111f; --focus: #7cc4ff;
    --run: #4cc584; --run-bg: #173826; --idle: #f0b04a; --idle-bg: #3a2c12;
    --alarm: #ff6b6b; --alarm-bg: #3f1b1b; --off: #a7aeba; --off-bg: #2a2f39; --none: #737a88; --none-bg: #23272f;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1520; --side: #141c2a; --side-hover: #1d2738; --surface: #18212f; --surface-2: #1f2a3b; --fg: #e6edf7; --muted: #9daac0;
  --head: #8fa6c3; --line: #2a3649; --accent: #4aa8f0; --accent-bg: #13294a; --accent-fg: #07111f; --focus: #7cc4ff;
  --run: #4cc584; --run-bg: #173826; --idle: #f0b04a; --idle-bg: #3a2c12;
  --alarm: #ff6b6b; --alarm-bg: #3f1b1b; --off: #a7aeba; --off-bg: #2a2f39; --none: #737a88; --none-bg: #23272f;
  --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 "IBM Plex Sans", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Noto Sans", "Microsoft YaHei", sans-serif; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button, select, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- khung */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
/* Thanh menu: nền xanh đậm của logo, chữ trắng; tên nhóm in đậm xanh nhạt; mục đang mở nền trắng chữ xanh đậm */
.side { --nav-bg: #0a2f5c; --nav-bg2: #0d3a70; --nav-fg: #e8f0fb; --nav-head: #7cc8f5; --nav-line: rgba(255, 255, 255, .14);
  background: linear-gradient(180deg, var(--nav-bg2) 0%, var(--nav-bg) 100%); color: var(--nav-fg);
  padding: 14px 12px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .25) transparent; }
.brand { font-weight: 700; font-size: 16px; padding: 4px 8px 10px; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-fg); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.nav-group { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--nav-line); }
.nav-group:first-child { border-top: 0; margin-top: 4px; padding-top: 0; }
.nav-head { font-size: 12.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--nav-head); padding: 6px 12px 4px; }
.nav-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; margin: 2px 0; border-radius: 9px;
  color: var(--nav-fg); text-decoration: none; font-size: 15px; font-weight: 500; border-left: 4px solid transparent; transition: background .15s; }
.nav-item:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav-item:focus-visible { outline: 2px solid var(--nav-head); outline-offset: 1px; }
.nav-item[aria-current="page"] { background: #fff; color: #0a2f5c; border-left-color: #0ea5e9; font-weight: 700; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.nav-item .soon { font-size: 11px; color: var(--nav-head); }
.pill { min-width: 24px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.pill.red { background: #ef4444; color: #fff; box-shadow: 0 0 0 2px rgba(255, 255, 255, .85); }
.pill.gray { background: var(--side-hover); color: var(--muted); }
.side-foot { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid var(--nav-line); font-size: 13px; background: rgba(0, 0, 0, .15); border-radius: 10px; }
.side-foot .who { font-weight: 700; font-size: 14px; color: #fff; }
.side-foot .role { color: var(--nav-head); font-size: 12px; }
.side-foot .acts { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.side-foot .btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .45); }
.side-foot .btn:hover { background: rgba(255, 255, 255, .12); border-color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .side { --nav-bg: #0a1424; --nav-bg2: #0e1d35; } }
:root[data-theme="dark"] .side { --nav-bg: #0a1424; --nav-bg2: #0e1d35; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.top h1 { font-size: 19px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .clock { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; }
.btn.menu-btn { display: none; font-size: 18px; }
.view { padding: 20px 24px 48px; max-width: 1440px; width: 100%; }
.scrim { display: none; }

@media (max-width: 960px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 272px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .app.nav-open .side { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 25; }
  .btn.menu-btn { display: inline-flex; }
  .top { padding: 10px 16px; }
  .view { padding: 16px 16px 40px; }
  .top .clock { display: none; }
}

/* ---------- điện thoại (iPhone / Android) */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, a, .btn, .kpi, summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
@media (max-width: 760px) {
  /* iPhone tự phóng to trang khi chạm ô nhập chữ nhỏ hơn 16px */
  .input, .select, textarea, input[type="search"], input[type="text"], input[type="number"], select { font-size: 16px; }
  /* Tai thỏ, thanh vuốt: chừa lề an toàn */
  .top { padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); gap: 8px; }
  .top h1 { font-size: 17px; }
  .view { padding: 12px max(12px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  #banner { padding: 0 12px !important; }
  .side { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  /* Nút đủ lớn để bấm bằng ngón tay */
  .btn { min-height: 40px; }
  .btn.sm { min-height: 34px; padding: 4px 10px; }
  .seg-ctl button { padding: 8px 12px; font-size: 13px; }
  .lang-switch button { padding: 6px 8px; }
  .card-h { padding: 10px 12px; }
  .card-h h2 { font-size: 14px; }
  .toolbar .grow, .toolbar input[type="search"] { flex: 1 1 100%; }
  .banner { font-size: 13px; padding: 8px 12px; }
  .banner summary { cursor: pointer; font-weight: 600; }
}

/* ---------- thành phần chung */
.btn { font-size: 13px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); cursor: pointer; min-height: 34px; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.danger { border-color: var(--alarm); color: var(--alarm); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { font-size: 12px; padding: 3px 10px; min-height: 28px; }
.seg-ctl { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-ctl button { border: 0; background: var(--surface); padding: 5px 10px; cursor: pointer; font-size: 12px; }
.seg-ctl button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.input, .select, textarea.input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); min-height: 36px; }
.input.inline, .select.inline { width: auto; }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 13px; }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.err { background: var(--alarm-bg); color: var(--alarm); }
.banner.warn { background: var(--idle-bg); }
.banner.info { background: var(--accent-bg); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-h h2 { font-size: 15px; margin: 0; }
.card-b { padding: 16px; }
.sub { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }
.warn { color: var(--alarm); font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 24px 16px; color: var(--muted); text-align: center; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g2e { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g2, .g2e { grid-template-columns: minmax(0, 1fr); } }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.b-RUN { color: var(--run); background: var(--run-bg); } .b-IDLE { color: var(--idle); background: var(--idle-bg); }
.b-ALARM { color: var(--alarm); background: var(--alarm-bg); } .b-OFFLINE { color: var(--off); background: var(--off-bg); }
.b-NONE { color: var(--none); background: var(--none-bg); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); }

.table-wrap { overflow-x: auto; }
table.t { border-collapse: collapse; width: 100%; }
table.t th, table.t td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t td.num { white-space: nowrap; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
table.t td.nw, table.t th.nw { white-space: nowrap; }
table.t tr.row { cursor: pointer; }
table.t tr.row:hover td { background: var(--surface-2); }
table.t tr.sel td { background: var(--accent-bg); }
table.t tr:last-child td { border-bottom: 0; }
/* Bảng danh mục: chữ dài xuống dòng theo từ (không bẻ mã), cột thao tác dính bên phải khi bảng rộng hơn khung */
table.t.crud th, table.t.crud td { padding: 8px 10px; }
table.t.crud td.wrap { white-space: normal; min-width: 170px; max-width: 280px; }
table.t.crud .acts { position: sticky; right: 0; z-index: 1; white-space: nowrap; text-align: right; background: var(--surface); box-shadow: -6px 0 8px -6px rgba(0,0,0,.18); }
table.t.crud th.acts { background: var(--surface-2); }
table.t.crud tr.row:hover td.acts { background: var(--surface-2); }
table.t.crud tr.sel td.acts { background: var(--accent-bg); }
table.t.crud tr.urgent > td.acts { background: color-mix(in srgb, var(--alarm) 7%, var(--surface)); }
/* Ảnh minh chứng QC: ảnh nhỏ trong form QC và trong lịch sử bản vẽ */
.qc-thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.qc-thumb { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.qc-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.qc-thumb .sub { font-size: 10px; padding: 2px; word-break: break-all; }
.qc-thumb .btn[data-phdel] { position: absolute; top: 0; right: 0; min-height: 0; padding: 0 6px; line-height: 20px; background: rgba(0,0,0,.55); color: #fff; border: 0; border-radius: 0 0 0 6px; }
.qc-ph .toolbar label.btn { cursor: pointer; }
.list li .qc-thumbs { margin-top: 6px; }
/* Thanh cuộn ngang nổi ở đáy màn hình cho bảng rộng đang xem (đáy bảng còn khuất bên dưới) */
.hscroll { position: fixed; bottom: 0; z-index: 30; height: 16px; overflow-x: auto; overflow-y: hidden; background: color-mix(in srgb, var(--surface) 85%, transparent); border-top: 1px solid var(--line); }
.hscroll > div { height: 1px; }
@media print { .hscroll { display: none !important; } }

/* chỉ số */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpis.chips { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.kpis.chips .kpi .v { font-size: 22px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); text-align: left; }
button.kpi { cursor: pointer; }
/* Ô số liệu đang chọn: nền màu đậm, chữ trắng, nhìn là biết đang lọc theo ô nào */
.kpi[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.kpi[aria-pressed="true"] .l, .kpi[aria-pressed="true"] .v, .kpi[aria-pressed="true"] .h { color: var(--accent-fg) !important; }
button.kpi:hover:not([aria-pressed="true"]) { border-color: var(--accent); }
button.kpi:focus:not(:focus-visible) { outline: none; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi .h { color: var(--muted); font-size: 11px; }
.kpi.RUN .v { color: var(--run); } .kpi.IDLE .v { color: var(--idle); } .kpi.ALARM .v { color: var(--alarm); }
.kpi.OFFLINE .v { color: var(--off); } .kpi.NONE .v { color: var(--none); }

/* thanh ngang (Pareto, tỷ lệ chạy) */
.hbars { list-style: none; margin: 0; padding: 0; }
.hbars li { display: grid; grid-template-columns: minmax(110px, 34%) minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 6px 0; font-size: 13px; }
.hbars .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbars .track { height: 12px; background: var(--surface-2); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.hbars .fill { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.hbars .fill.warn-fill { background: var(--idle); }
.hbars .fill.bad-fill { background: var(--alarm); }
.hbars .val { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }

/* dòng thời gian trạng thái */
.bar { position: relative; height: 26px; border-radius: 6px; background: var(--none-bg); overflow: hidden; }
.bar.thin { height: 14px; border-radius: 4px; }
.seg { position: absolute; top: 0; bottom: 0; }
.seg.RUN { background: var(--run); } .seg.IDLE { background: var(--idle); } .seg.ALARM { background: var(--alarm); } .seg.OFFLINE { background: var(--off); }
.ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 4px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; background: var(--c); }

/* danh sách cảnh báo / lần dừng */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 160px; }
.rsel { font-size: 12px; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); max-width: 100%; min-height: 30px; }
.rsel.need { border-color: var(--idle); box-shadow: 0 0 0 1px var(--idle) inset; }

/* ô máy (xưởng trực tiếp) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--none); border-radius: 10px; padding: 12px 14px; cursor: pointer; text-align: left; width: 100%; box-shadow: var(--shadow); }
.tile.RUN { border-left-color: var(--run); } .tile.IDLE { border-left-color: var(--idle); } .tile.ALARM { border-left-color: var(--alarm); } .tile.OFFLINE { border-left-color: var(--off); }
.tile.sel { box-shadow: 0 0 0 2px var(--accent); }
.tile .top-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.tile .name { font-weight: 700; font-size: 15px; }
.tile dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 8px 0 0; font-size: 13px; }
.tile dt { color: var(--muted); } .tile dd { margin: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* TV */
body.tv { background: #0b1220; color: #eef3f2; }
body.tv .side, body.tv .top { display: none; }
body.tv .app { grid-template-columns: minmax(0, 1fr); }
body.tv .view { max-width: none; padding: 18px 22px; }
.tv-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.tv-head h1 { margin: 0; font-size: clamp(22px, 2.4vw, 40px); }
.tv-head .clock { font-size: clamp(20px, 2.2vw, 36px); font-variant-numeric: tabular-nums; font-weight: 700; }
.tv-sum { display: flex; gap: 22px; flex-wrap: wrap; font-size: clamp(14px, 1.3vw, 22px); color: #b7c4c1; }
.tv-sum b { color: #fff; font-size: 1.3em; }
.tv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(260px, 22vw, 420px), 1fr)); gap: 16px; }
.tv-tile { border-radius: 14px; padding: clamp(14px, 1.4vw, 24px); background: #16213a; border-top: 10px solid #555; }
.tv-tile.RUN { border-top-color: #2fbf71; } .tv-tile.IDLE { border-top-color: #f0a830; } .tv-tile.OFFLINE { border-top-color: #7d8590; }
.tv-tile.ALARM { border-top-color: #ff4d4f; background: #3a1414; animation: tvblink 1.6s ease-in-out infinite; }
@keyframes tvblink { 50% { background: #521a1a; } }
@media (prefers-reduced-motion: reduce) { .tv-tile.ALARM { animation: none; } }
.tv-tile .n { font-size: clamp(22px, 2vw, 36px); font-weight: 700; line-height: 1.15; }
.tv-tile .tv-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.tv-tile .ip { font-family: ui-monospace, Consolas, monospace; font-size: clamp(13px, 1vw, 18px); color: #d6e2f0; background: #22314d; border-radius: 6px; padding: 2px 8px; white-space: nowrap; }
.tv-tile .m { color: #8fa6c3; font-size: clamp(12px, .95vw, 16px); margin-top: 2px; }
.tv-tile .d .w { grid-column: 1 / -1; }
.tv-tile .d span { display: block; color: #9fb2cc; }
.tv-tile .d b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-head .tv-n { font-size: .5em; font-weight: 600; color: #9fb2cc; margin-left: 8px; }
.tv-tile .s { font-size: clamp(18px, 1.6vw, 28px); font-weight: 700; margin-top: 2px; }
.tv-tile.RUN .s { color: #4cd68a; } .tv-tile.IDLE .s { color: #ffc15a; } .tv-tile.ALARM .s { color: #ff7a7a; } .tv-tile.OFFLINE .s { color: #aab2bd; }
.tv-tile .d { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin-top: 12px; font-size: clamp(13px, 1.1vw, 19px); color: #c5d2e3; }
.tv-tile .d b { display: block; color: #fff; font-size: 1.35em; font-variant-numeric: tabular-nums; }
.tv-tile .f { margin-top: 10px; font-family: ui-monospace, Consolas, monospace; color: #ff9b9b; font-size: clamp(13px, 1vw, 18px); }
.tv-exit { position: fixed; right: 12px; bottom: 12px; opacity: .25; }
.tv-exit:hover, .tv-exit:focus-visible { opacity: 1; }

/* hộp thoại, thông báo */
.dlg-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.dlg-back.open { display: flex; }
.dlg { background: var(--surface); border-radius: 12px; width: min(480px, 100%); padding: 20px; max-height: calc(100vh - 32px); overflow-y: auto; }
.dlg h3 { margin: 0 0 12px; font-size: 16px; }
.dlg .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; }

/* đăng nhập */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 20px; margin: 10px 0 4px; }
.auth-card .err { color: var(--alarm); font-size: 13px; min-height: 20px; margin: 4px 0; }

/* trang đợt sau */
.soon-card { max-width: 760px; }
.soon-card ul { margin: 8px 0 0; padding-left: 20px; }
.soon-card li { margin: 4px 0; }

/* họp ca */
.actions-tbl input.input { min-height: 32px; padding: 4px 8px; }
@media print {
  .side, .top, .no-print, .toast { display: none !important; }
  .app { display: block; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; break-inside: avoid; }
  .view { padding: 0; }
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* biểu đồ cột sản lượng (một chuỗi) */
.cols { display: flex; align-items: flex-end; gap: 2px; height: 180px; padding: 8px 0 0; border-bottom: 1px solid var(--line); }
.cols .c { flex: 1 1 0; min-width: 4px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; cursor: default; }
.cols .c i { display: block; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 1px; }
.cols .c:hover i, .cols .c:focus i { background: var(--focus); outline: 2px solid var(--accent-bg); }
.cols-x { display: flex; gap: 2px; font-size: 11px; color: var(--muted); }
.cols-x span { flex: 1 1 0; min-width: 4px; text-align: center; overflow: hidden; white-space: nowrap; }
.oee-v { font-variant-numeric: tabular-nums; font-weight: 700; }

/* hỏi đáp AI */
.chat { display: flex; flex-direction: column; gap: 12px; }
.chat .msg { max-width: 860px; padding: 10px 14px; border-radius: 12px; line-height: 1.55; font-size: 14px; }
.chat .msg.q { align-self: flex-end; background: var(--accent-bg); }
.chat .msg.a { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.chat .msg.a ul { margin: 4px 0; padding-left: 20px; }
.chat .msg .src { margin-top: 8px; font-size: 12px; color: var(--muted); }
.chat-in { display: flex; gap: 8px; position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; }
.chat-in textarea { flex: 1; min-height: 44px; resize: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.chips button { border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.chips button:hover { border-color: var(--accent); }
.hbars .track, .hbars .fill { display: block; }
.bulkbar { margin: 0; padding: 8px 16px; background: var(--accent-bg); border-top: 1px solid var(--line); gap: 8px; align-items: center; flex-wrap: wrap; }
.bulkbar[hidden] { display: none; }
.select.inline.on { border-color: var(--accent); background: var(--accent-bg); font-weight: 600; }
.card.attn.on { border-color: var(--alarm); }
.card.attn.on .card-h h2 { color: var(--alarm); }
.card.attn .hint { margin-top: 2px; }
.card.flash { box-shadow: 0 0 0 3px var(--alarm); transition: box-shadow .3s; }
.card.attn { scroll-margin-top: 80px; }
.tv-tile .job { margin-top: 10px; padding: 8px 10px; border-radius: 10px; background: #1d2c4a; font-size: clamp(13px, 1.05vw, 18px); color: #c5d2e3; }
.tv-tile .job > span { display: block; color: #9fb2cc; font-size: .85em; }
.tv-tile .job > b { display: block; color: #fff; font-size: clamp(20px, 1.8vw, 32px); font-family: ui-monospace, Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-tile .job .rw { font-style: normal; font-family: inherit; font-size: .55em; color: #ff9b9b; vertical-align: middle; }
.tv-tile .job .pn { color: #e3ebf5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-tile .job .od { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-tile .job .od b { color: #fff; }
.tv-tile .job.none { background: transparent; border: 1px dashed #36486a; color: #7d8ba3; }
.gc { position: relative; }
.gc-list { height: calc(100vh - 300px); min-height: 320px; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.gc-msg { display: flex; gap: 8px; align-items: flex-start; max-width: 78%; }
.gc-msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.gc-b { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; min-width: 120px; }
.gc-msg.mine .gc-b { background: var(--accent-bg); border-color: var(--accent); }
.gc-who { font-size: 13px; margin-bottom: 2px; } .gc-who span { color: var(--head); font-size: 12px; }
.gc-t { white-space: normal; overflow-wrap: anywhere; font-size: 15px; }
.gc-meta { font-size: 12px; color: var(--head); margin-top: 4px; }
.gc-meta .linkbtn { background: none; border: 0; padding: 0 2px; color: var(--accent); cursor: pointer; font-size: 12px; }
.gc-day { text-align: center; font-size: 12px; color: var(--head); margin: 6px 0; } .gc-day span { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }
.gc-form { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); align-items: flex-end; }
.gc-form textarea { flex: 1; resize: vertical; min-height: 44px; }
.gc-form .btn { min-height: 44px; }
.gc-new { position: absolute; right: 24px; bottom: 80px; box-shadow: var(--shadow); }
@media (max-width: 640px) { .gc-msg { max-width: 92%; } .gc-list { height: calc(100vh - 260px); } }
.gc-form { position: sticky; bottom: 0; background: var(--surface); z-index: 2; border-radius: 0 0 12px 12px; }
.tv-orders { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(320px, 30vw, 620px), 1fr)); gap: 16px; }
.tv-ord { background: #16213a; border-radius: 14px; padding: clamp(14px, 1.3vw, 22px); border-left: 8px solid #2fbf71; font-size: clamp(14px, 1.15vw, 20px); color: #c5d2e3; }
.tv-ord.late { border-left-color: #ff4d4f; background: #2a1717; }
.tv-ord .ot { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; }
.tv-ord .ot b { color: #fff; font-size: clamp(22px, 2vw, 36px); font-family: ui-monospace, Consolas, monospace; }
.tv-ord .ot .cust { color: #e3ebf5; } .tv-ord .ot .due { margin-left: auto; font-weight: 700; color: #ffc15a; }
.tv-ord.late .top .due { color: #ff7a7a; }
.tv-ord .nums { margin-top: 6px; } .tv-ord .chips { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.tv-bar { position: relative; height: clamp(18px, 1.8vw, 30px); background: #22314d; border-radius: 8px; overflow: hidden; margin-top: 10px; }
.tv-bar span { position: absolute; inset: 0 auto 0 0; background: #2fbf71; } .tv-bar.late span { background: #ff6b6b; }
.tv-bar em { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-style: normal; font-weight: 700; color: #fff; font-size: .9em; text-shadow: 0 1px 2px #000; }
.tv-chip { display: inline-block; padding: 2px 10px; border-radius: 999px; background: #22314d; color: #e3ebf5; font-size: .85em; white-space: nowrap; }
.tv-chip b { color: #fff; }
.tv-chip.s-machining { background: #1f4d36; } .tv-chip.s-qc { background: #5a4417; } .tv-chip.s-rework { background: #5c1f1f; }
.tv-chip.s-done { background: #1c4a5a; } .tv-chip.s-delivered { background: #33393f; color: #aab2bd; } .tv-chip.s-todo { background: #22314d; }
.tv-table { width: 100%; border-collapse: separate; border-spacing: 0 8px; font-size: clamp(14px, 1.15vw, 21px); color: #c5d2e3; }
.tv-table th { text-align: left; color: #9fb2cc; font-weight: 600; padding: 0 12px; }
.tv-table td { background: #16213a; padding: 10px 12px; vertical-align: middle; }
.tv-table td:first-child { border-radius: 10px 0 0 10px; } .tv-table td:last-child { border-radius: 0 10px 10px 0; }
.tv-table td b { color: #fff; font-size: 1.2em; } .tv-table td div { color: #8fa6c3; font-size: .85em; }
.tv-table td.pg { min-width: 180px; } .tv-table td.pg .tv-bar { margin-top: 0; }
.tv-table tr.late td { background: #2a1717; } .tv-table tr.late td.nw { color: #ff7a7a; font-weight: 700; }
.tv-empty { text-align: center; color: #8fa6c3; font-size: clamp(20px, 2vw, 34px); padding: 12vh 0; }
/* GẤP: đơn / bản vẽ gấp tô đỏ ở mọi màn */
.urgent-b { font-weight: 800; letter-spacing: .03em; }
.card.urgent, .urgent-wrap > .card { border: 2px solid var(--alarm); }
.card.urgent > .card-h, .urgent-wrap > .card > .card-h { background: color-mix(in srgb, var(--alarm) 10%, transparent); }
tr.urgent > td { background: color-mix(in srgb, var(--alarm) 7%, transparent); }
tr.urgent > td:first-child { box-shadow: inset 4px 0 var(--alarm); }
li.urgent { background: color-mix(in srgb, var(--alarm) 8%, transparent); box-shadow: inset 4px 0 var(--alarm); }
.ug { font-style: normal; font-weight: 800; color: #fff; background: #e5484d; border-radius: 6px; padding: 1px 8px; margin-right: 8px; letter-spacing: .04em; }
.tv-tile .job.urgent { background: #4a1c1c; box-shadow: inset 0 0 0 2px #ff4d4f; }
.tv-tile .job .ug { font-size: .85em; }
/* Trang của tôi */
.me-profile .card-b { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.me-avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-fg); display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; flex: none; }
.me-name { font-size: 20px; font-weight: 700; }
.me-acts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.me-sec { font-size: 15px; margin: 18px 0 8px; }
.me-job { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.me-job-top { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 2px; }
.me-code { font-size: 18px; font-weight: 700; }
.me-job .me-acts .btn { min-height: 44px; }
.me-hist .me-day { font-weight: 700; color: var(--head); background: var(--surface-2); }
.me-ev { align-items: flex-start; }
.me-time { min-width: 44px; }
.me-ico { width: 24px; text-align: center; } .me-ico.bad { filter: hue-rotate(300deg); }
@media (max-width: 640px) { .me-job .me-acts { width: 100%; } .me-job .me-acts .btn { flex: 1; } }
/* Việc cần làm */
.wk-sec { margin-bottom: 18px; }
.wk-sec > h2 { font-size: 16px; margin: 8px 0 10px; display: flex; align-items: center; gap: 8px; }
.wk-n { display: inline-flex; min-width: 24px; height: 24px; padding: 0 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); align-items: center; justify-content: center; font-size: 13px; }
.wk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.wk-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.wk-card.running { border-left: 6px solid var(--run); }
.wk-card.urgent { border: 2px solid var(--alarm); }
.wk-tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.wk-due { font-size: 13px; color: var(--head); white-space: nowrap; } .wk-due.late { color: var(--alarm); font-weight: 700; }
.wk-code { font-size: 22px; font-weight: 800; margin-top: 4px; letter-spacing: .01em; overflow-wrap: anywhere; }
.wk-name { font-size: 15px; }
.wk-meta { font-size: 13px; color: var(--head); }
.wk-where { color: var(--fg); font-weight: 600; }
.wk-why { font-size: 13px; color: var(--alarm); background: color-mix(in srgb, var(--alarm) 8%, transparent); border-radius: 8px; padding: 6px 10px; margin-top: 4px; }
.wk-acts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.wk-btn { min-height: 52px; font-size: 17px; flex: 1 1 140px; justify-content: center; }
.wk-empty { padding: 40px 16px; font-size: 16px; }
.me-worklink { display: block; text-decoration: none; color: inherit; }
.me-worklink .card-b { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.wk-card.muted-card { opacity: .85; box-shadow: none; background: var(--surface-2); }
/* Tiến độ bản vẽ: thanh 4 bước (phát lệnh → gia công → QC → giao) */
/* Bản vẽ sản xuất: cột cố định để các khung đơn / đợt thẳng hàng nhau */
.tk-table { min-width: 1180px; table-layout: fixed; width: 100%; }
.tk-table td { vertical-align: top; overflow-wrap: anywhere; }
.tk-table .c-ck { width: 34px; } .tk-table .c-part { width: 24%; } .tk-table .c-qty { width: 48px; } .tk-table .c-step { width: 250px; }
.tk-table .c-mach { width: 20%; } .tk-table .c-qc { width: 14%; } .tk-table .c-del { width: 11%; } .tk-table .c-due { width: 100px; } .tk-table .c-act { width: 60px; }
/* Bản vẽ sản xuất trên điện thoại: ô số liệu gọn 4 cột, bảng thành thẻ (mỗi bản vẽ một thẻ) */
@media (max-width: 760px) {
  .tk-help { display: none; }
  .tk-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
  .tk-kpis .kpi { padding: 6px 8px; border-radius: 10px; box-shadow: none; min-width: 0; }
  .tk-kpis .kpi { display: flex; flex-direction: column; justify-content: space-between; }
  .tk-kpis .kpi .l { font-size: 11px; line-height: 1.2; min-height: 2.4em; }
  .tk-kpis .kpi .v { font-size: 20px; }
  .tk-bar { gap: 6px; }
  .tk-bar select { flex: 1 1 40%; min-width: 0; }
  .tk-bar .btn { flex: 1 1 auto; justify-content: center; }
  :not(.tk-picked) > .tk-bar [data-printsel], :not(.tk-picked) > .tk-bar [data-qcsel] { display: none; }
  .tk-table .tk-row > td.td-empty { display: none; }  /* QC / giao hàng chưa có gì: ẩn cho thẻ ngắn */
  .tk-table { min-width: 0; table-layout: auto; }
  .tk-table colgroup, .tk-table thead { display: none; }
  .tk-table, .tk-table tbody, .tk-table tr.tk-detail, .tk-table tr.tk-detail > td { display: block; width: auto; }
  .tk-table .tk-row { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 4px 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .tk-table .tk-row > td { display: block; padding: 0; border: 0; min-width: 0; text-align: left; white-space: normal; }
  .tk-table .tk-row > td[data-label]::before { content: attr(data-label); display: block; font-size: 10px; line-height: 1.4; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
  .tk-row .td-ck { grid-column: 1; grid-row: 1; padding-top: 2px; }
  .tk-row .td-part { grid-column: 2; grid-row: 1 / 3; }
  .tk-table .tk-row .td-qty { grid-column: 3; grid-row: 1; text-align: right; }
  .tk-table .tk-row .td-due { grid-column: 3; grid-row: 2; text-align: right; }
  .tk-row .td-step { grid-column: 2 / 4; grid-row: 3; }
  .tk-row .td-mach { grid-column: 2 / 4; grid-row: 4; }
  .tk-row .td-qc { grid-column: 2 / 4; grid-row: 5; }
  .tk-row .td-del { grid-column: 2 / 4; grid-row: 6; }
  .tk-row .td-act { grid-column: 1; grid-row: 3; }
  .tk-row .td-act .btn { padding: 2px; min-height: 30px; }
  .tk-row .ql-pdf { margin-top: 6px; }
  .tk-steps li { min-width: 0; font-size: 11px; padding: 3px 2px; }
  .tk-detail > td { padding: 8px 12px 12px; }
  .tk-table .tk-dur strong { font-size: 15px; }
}
.tk-row { cursor: pointer; }
.tk-row:hover > td { background: var(--surface-2); }
.tk-detail > td { background: var(--surface-2); padding: 8px 16px 14px; }
.tk-steps { list-style: none; display: flex; gap: 3px; margin: 6px 0 0; padding: 0; }
.tk-steps li { flex: 1 1 0; min-width: 52px; font-size: 11px; text-align: center; padding: 2px 4px; border-radius: 4px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.tk-steps li.ok { background: color-mix(in srgb, var(--run) 18%, transparent); color: var(--fg); border-color: color-mix(in srgb, var(--run) 45%, transparent); }
.tk-steps li.cur { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 700; }
.tk-steps li.bad { background: var(--alarm); color: #fff; border-color: var(--alarm); font-weight: 700; }
.sub.bad, td.bad { color: var(--alarm); font-weight: 600; }
/* TV: thanh chuyển trang */
.tv-nav { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: -4px 0 14px; }
.tv-navbtn, .tv-tab { background: #16213a; color: #e3ebf5; border: 1px solid #2e4166; border-radius: 10px; padding: 8px 16px; font-size: clamp(14px, 1.1vw, 20px); cursor: pointer; min-height: 44px; }
.tv-navbtn:hover, .tv-tab:hover, .tv-navbtn:focus-visible, .tv-tab:focus-visible { border-color: #38bdf8; outline: none; }
.tv-tab[aria-pressed="true"] { background: #0a4f9e; border-color: #0a4f9e; color: #fff; font-weight: 700; }
.tv-hold { color: #9fb2cc; font-size: clamp(12px, .95vw, 16px); }
/* Thương hiệu VAITECH CNC */
.brand-logo { width: 34px; height: 34px; flex: none; border-radius: 8px; background: #fff; padding: 2px; }
.brand-a { color: #0b3d7a; font-weight: 800; letter-spacing: .02em; }
.brand-b { color: #0ea5e9; font-weight: 800; }
.auth-logo { display: block; width: min(260px, 70%); height: auto; margin: 0 auto 6px; }
.auth-brand { text-align: center; font-weight: 800; font-size: 20px; color: #0b3d7a; letter-spacing: .04em; margin-bottom: 12px; }
.auth-brand span { color: #0ea5e9; }
.tv-logo { height: 1.15em; width: 1.15em; vertical-align: -0.2em; margin-right: 10px; background: #fff; border-radius: 8px; padding: 2px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-a, :root:not([data-theme="light"]) .auth-brand { color: #e6f0ff; } }
/* Logo nguyên bản (chữ VAITECH nằm trong bánh răng) */
.brand { padding: 4px 8px 12px; }
.brand .brand-logo { width: 100%; max-width: 190px; height: auto; border-radius: 10px; background: #fff; padding: 6px 10px; box-sizing: border-box; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.tv-logo { height: 1.6em; width: auto; vertical-align: middle; margin-right: 12px; background: #fff; border-radius: 10px; padding: 4px 10px; }
/* Logo nguyên bản + chữ VAITECH CNC */
.brand { flex-direction: column; align-items: flex-start; gap: 6px; }
.brand-name { font-size: 17px; letter-spacing: .03em; padding-left: 2px; }
.tv-brand { color: #fff; font-weight: 800; letter-spacing: .03em; vertical-align: middle; }
.tv-brand b { color: #38bdf8; }
/* Việc cần làm QC: tích chọn để giao nhiều bản vẽ */
.wk-sec > h2 .wk-all { font-size: 14px; font-weight: 500; margin-left: 12px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.wk-sec > h2 .btn { margin-left: auto; min-height: 44px; font-size: 15px; }
.wk-pick { display: inline-flex; align-items: center; margin-right: 2px; cursor: pointer; }
.wk-pick input, .wk-all input { width: 22px; height: 22px; accent-color: var(--accent); cursor: pointer; }
.wk-card.picked { box-shadow: 0 0 0 3px var(--accent); }
.dh-filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
/* Nút ngôn ngữ có lá cờ */
.lang-switch button { display: inline-flex; align-items: center; gap: 6px; }
.flag { width: 20px; height: 14px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .15); object-fit: cover; flex: none; }
