:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #101828;
  --ink-soft: #5b6470;
  --ink-faint: #8a93a0;
  --border: #e4e7ec;
  --primary: #0f766e;
  --primary-dark: #0b5c56;
  --primary-soft: #eafaf7;
  --accent: #1d4ed8;
  --danger: #d92d20;
  --danger-bg: #fef2f1;
  --warn: #b25e09;
  --warn-bg: #fef6e7;
  --ok: #17803d;
  --ok-bg: #ecfbf1;
  --plum: #9333ea;
  --sidebar-bg: #0c2e2b;
  --sidebar-bg-2: #123f3a;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-size: 15px; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0 0 8px; letter-spacing: -0.01em; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }
svg { display: block; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: #fff; color: var(--ink); font-weight: 600; font-size: 14px;
  min-height: 42px; transition: background .12s, border-color .12s;
}
.btn:hover { border-color: #c7ccd4; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: #f1f3f6; }
.btn-block { width: 100%; }
.btn-lg { min-height: 50px; font-size: 15.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { flex-shrink: 0; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
}
.login-visual {
  background: radial-gradient(120% 140% at 0% 0%, #14746c 0%, #0b3d3a 45%, #082825 100%);
  color: #eafaf6; padding: 56px 56px; display: flex; flex-direction: column; justify-content: center; gap: 14px;
}
.login-visual-mark { width: 60px; height: 60px; border-radius: 16px; background: rgba(255,255,255,.12); display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.login-visual-title { font-size: 34px; font-weight: 800; letter-spacing: .02em; margin: 0; }
.login-visual-sub { font-size: 16px; color: #b7ded7; margin: 0 0 18px; }
.login-visual-org { font-size: 13px; color: #7fb8ae; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; margin-bottom: 20px; }
.login-visual-points { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; max-width: 380px; }
.login-visual-points li { position: relative; padding-left: 22px; font-size: 14px; color: #d6efea; line-height: 1.5; }
.login-visual-points li::before { content: ""; position: absolute; left: 0; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: #34d399; }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--panel); }
.login-card { width: 100%; max-width: 360px; }
.login-title { font-size: 22px; }
.login-sub { color: var(--ink-soft); margin-bottom: 22px; font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field span { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em; }
.field input, .field select, .field textarea {
  padding: 11px 14px; border-radius: var(--radius-sm); border: 1.5px solid var(--border); background: #fbfbfc;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.form-error { margin-top: 12px; padding: 10px 14px; background: var(--danger-bg); color: var(--danger); border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600; }

@media (max-width: 860px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-visual { display: none; }
}

/* ---------- App shell ---------- */
.app-shell { min-height: 100vh; display: flex; }
.sidebar {
  width: 224px; flex-shrink: 0; background: var(--sidebar-bg); color: #cfe6e1;
  display: flex; flex-direction: column; padding: 18px 12px; gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 8px 18px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, #14b8a6, #0b3d3a); display: flex; align-items: center; justify-content: center; color: #fff; flex-shrink: 0; }
.brand-title { font-weight: 800; font-size: 14.5px; color: #fff; letter-spacing: .03em; }
.brand-sub { font-size: 11px; color: #8fb9b1; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; background: transparent; border: none; color: #b7d6cf;
  padding: 10px 12px; border-radius: 10px; font-weight: 600; font-size: 13.5px; text-align: left;
}
.nav-item .ico { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: #fff; color: var(--sidebar-bg); }
.nav-item.active .ico { opacity: 1; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: #fff; border-bottom: 1px solid var(--border); padding: 14px 24px; flex-wrap: wrap;
}
.view-title { font-size: 18px; font-weight: 800; color: var(--ink); }
.mobile-nav-btn { display: none; background: none; border: none; color: var(--ink-soft); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { background: var(--primary-soft); color: var(--primary-dark); padding: 8px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }
.device-chip { display: inline-flex; align-items: center; gap: 6px; background: #f1f3f6; color: var(--ink-soft); border: 1px dashed #c7ccd4; padding: 7px 12px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.device-chip:hover { background: #e9ecf0; }
.duration-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--ink-faint); font-weight: 600; }
.scan-step { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 800; color: var(--primary); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 8px; }
.scan-step-num { width: 20px; height: 20px; border-radius: 50%; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; flex-shrink: 0; }
.operator-line { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--primary-soft); color: var(--primary-dark); border-radius: var(--radius-sm); font-size: 13px; font-weight: 700; margin-bottom: 14px; }

.view-area { flex: 1; padding: 24px; max-width: 1180px; width: 100%; margin: 0 auto; }
.panel { background: var(--panel); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.panel h2 { font-size: 16.5px; }
.panel-sub { color: var(--ink-soft); font-size: 13.5px; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
tr:hover td { background: #fafbfc; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-san_sang { background: var(--ok-bg); color: var(--ok); }
.badge-dang_dung { background: #eef3ff; color: var(--accent); }
.badge-dang_xu_ly { background: var(--warn-bg); color: var(--warn); }
.badge-dang_say { background: #fbf0ff; color: var(--plum); }
.badge-luu_kho { background: #f1f3f6; color: #364152; }
.badge-hong_ngung_dung { background: var(--danger-bg); color: var(--danger); }
.badge-pass { background: var(--ok-bg); color: var(--ok); }
.badge-fail { background: var(--danger-bg); color: var(--danger); }

/* ---------- Scan ---------- */
.scan-box { text-align: center; padding: 36px 20px; }
.scan-input {
  font-size: 20px; padding: 16px; text-align: center; border-radius: var(--radius); border: 2px dashed var(--primary);
  width: 100%; max-width: 480px; margin: 0 auto; display: block; background: var(--primary-soft); color: var(--primary-dark); font-weight: 600;
}
.scan-input::placeholder { color: #6fada4; font-weight: 500; }
.scan-hint-icon { width: 40px; height: 40px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.icon-btn { display: inline-flex; align-items: center; gap: 8px; }

.checkpoint-chip { display: inline-flex; align-items: center; gap: 8px; margin: 4px 0; padding: 8px 18px; background: var(--primary); color: #fff; border-radius: 999px; font-weight: 700; font-size: 13.5px; }
.stepper { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 16px 0; }
.step-dot { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: #eef0f3; color: var(--ink-faint); font-size: 11.5px; font-weight: 700; }
.step-dot.done { background: var(--ok); color: #fff; }
.step-dot.current { background: var(--primary); color: #fff; box-shadow: 0 0 0 3px rgba(15,118,110,.2); }

.checklist-item { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 9px; background: #fafbfc; text-align: left; }
.checklist-item.checked { border-color: var(--ok); background: var(--ok-bg); }
.toggle { width: 50px; height: 28px; border-radius: 999px; background: #d3d8de; position: relative; border: none; flex-shrink: 0; }
.toggle.on { background: var(--ok); }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle.on::after { transform: translateX(22px); }

.hardstop-banner { display: flex; align-items: flex-start; gap: 10px; padding: 14px 18px; border-radius: var(--radius-sm); background: var(--danger-bg); color: var(--danger); font-weight: 600; font-size: 13.5px; margin-bottom: 16px; border: 1.5px solid #fbd5d0; text-align: left; }
.ok-banner { display: flex; align-items: flex-start; gap: 10px; padding: 14px 18px; border-radius: var(--radius-sm); background: var(--ok-bg); color: var(--ok); font-weight: 600; font-size: 13.5px; margin-bottom: 16px; border: 1.5px solid #bdeed0; text-align: left; }
.hardstop-banner .ico, .ok-banner .ico { flex-shrink: 0; margin-top: 1px; }

.metric { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.metric-label { font-size: 11.5px; color: var(--ink-faint); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.metric-value { font-size: 30px; font-weight: 800; margin-top: 6px; color: var(--ink); }

.label-sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.label-card { border: 1px dashed #b6bcc4; border-radius: 8px; padding: 10px; text-align: center; }
.label-card img { width: 100%; height: auto; }
.label-card .code { font-weight: 800; font-size: 13px; margin-top: 4px; }
.label-card .meta { font-size: 10px; color: var(--ink-soft); }

.toast-host { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 999; }
.toast { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-md); max-width: 360px; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn { padding: 9px 16px; border-radius: var(--radius-sm); border: 1.5px solid var(--border); background: #fff; font-weight: 600; font-size: 13.5px; color: var(--ink-soft); }
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

@media (max-width: 900px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow-md); }
  .sidebar.open { transform: translateX(0); }
  .mobile-nav-btn { display: inline-flex; }
  .view-area { padding: 14px; }
  .label-sheet { grid-template-columns: repeat(2, 1fr); }
}

@media print {
  .sidebar, .topbar, .toast-host, .no-print { display: none !important; }
  body { background: #fff; }
  .app-shell { display: block; }
  .view-area { padding: 0; max-width: none; }
  .label-sheet { grid-template-columns: repeat(3, 1fr); }
}
