/* ============================================================ *
 *  QC LAB PORTAL — light / corporate design system            *
 *  White sidebar, airy surfaces, single brand-colour knob      *
 *  (--brand injected per tenant; tints derived via color-mix). *
 * ============================================================ */

:root {
  --brand:      #214b73;
  --brand-2:    #316a87;

  --brand-d:    color-mix(in srgb, var(--brand) 82%, #000);
  --brand-soft: color-mix(in srgb, var(--brand) 12%, #fff);
  --brand-100:  color-mix(in srgb, var(--brand) 20%, #fff);

  --ink:       #1a2435;
  --ink-2:     #46536b;
  --muted:     #7a869c;
  --bg:        #f3f6fb;
  --surface:   #ffffff;
  --surface-2: #f8fafd;
  --line:      #e7ecf4;
  --line-2:    #eff2f8;

  --ok:    #15a05a;  --ok-bg:   #e7f6ee;
  --bad:   #dc2b2b;  --bad-bg:  #fcecec;
  --warn:  #d9870b;  --warn-bg: #fdf2dd;
  --info:  #2b59c8;  --info-bg: #eaf0fc;

  --r:    12px;  --r-sm: 9px;  --r-xs: 7px;
  --sh-1: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.05);
  --sh-2: 0 4px 16px rgba(16,24,40,.07);
  --sh-3: 0 12px 32px rgba(16,24,40,.14);
  --ring: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);

  --side-w: 264px;
  --top-h:  62px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 13.5px; line-height: 1.5; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { letter-spacing: -0.01em; }
::selection { background: var(--brand-soft); }
table.data td, .kpi .val, .live-stats, .readings-grid input, .num { font-variant-numeric: tabular-nums; }

/* ============================== SIDEBAR (light) ============================== */
body.has-sidebar { min-height: 100vh; }
.sidebar {
  width: var(--side-w); position: fixed; inset: 0 auto 0 0; z-index: 60;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 11px; padding: 0 20px; height: var(--top-h);
  border-bottom: 1px solid var(--line-2);
}
.sidebar-brand .brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 auto; overflow: hidden;
  background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; letter-spacing: .3px;
}
.sidebar-brand .brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-brand .brand-logo-img { max-height: 34px; max-width: 184px; object-fit: contain; }
.sidebar-brand .brand-name { color: var(--ink); font-weight: 650; font-size: 14px; line-height: 1.1; }
.sidebar-brand .brand-sub  { color: var(--muted); font-size: 11.5px; margin-top: 1px; }

.sidebar-nav { flex: 1; padding: 12px 12px; overflow-y: auto; }
.sidebar-nav .nav-group {
  text-transform: uppercase; font-size: 10.5px; letter-spacing: .7px; font-weight: 700;
  color: var(--muted); padding: 16px 10px 7px;
}
.sidebar-nav .nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; margin-bottom: 2px;
  color: var(--ink-2); font-size: 13.5px; font-weight: 500; border-radius: var(--r-sm);
  transition: background .12s, color .12s;
}
.sidebar-nav .nav-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.sidebar-nav .nav-item.active { background: var(--brand-soft); color: var(--brand-d); font-weight: 600; }
.sidebar-nav .nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; color: var(--muted); }
.sidebar-nav .nav-item:hover svg { color: var(--ink-2); }
.sidebar-nav .nav-item.active svg { color: var(--brand); }

.sidebar-footer { border-top: 1px solid var(--line-2); padding: 10px 12px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 6px 6px 10px; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto;
  background: var(--brand-soft); color: var(--brand-d);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.user-meta .user-name { color: var(--ink); font-size: 13px; font-weight: 600; line-height: 1.1; }
.user-meta .user-role { color: var(--muted); font-size: 11px; letter-spacing: .3px; margin-top: 1px; }
.sidebar-logout {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px;
  color: var(--ink-2); font-size: 13px; border-radius: var(--r-sm); font-weight: 500;
}
.sidebar-logout:hover { background: var(--surface-2); color: var(--bad); text-decoration: none; }
.sidebar-logout svg { width: 16px; height: 16px; }

/* ============================== MAIN / TOPBAR ============================== */
.main-wrap { margin-left: var(--side-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar-mini {
  height: var(--top-h); background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 26px; position: sticky; top: 0; z-index: 40;
}
.topbar-mini .hamburger { display: none; background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--ink-2); padding: 4px 8px; }
.topbar-mini .topbar-title { flex: 1; font-weight: 650; font-size: 16px; color: var(--ink); letter-spacing: -0.01em; }
.topbar-mini .topbar-logo { height: 26px; max-width: 160px; object-fit: contain; }
.topbar-mini .topbar-actions { display: flex; align-items: center; gap: 8px; }

.bell { position: relative; cursor: pointer; padding: 8px; border-radius: 10px; color: var(--ink-2); display: flex; }
.bell:hover { background: var(--surface-2); color: var(--brand); }
.bell svg, .bell-icon { width: 19px; height: 19px; }
.bell-count {
  position: absolute; top: 3px; right: 3px; background: var(--bad); color: #fff; font-size: 10px;
  border-radius: 10px; padding: 0 5px; min-width: 16px; height: 16px; line-height: 16px; text-align: center; font-weight: 700;
  box-shadow: 0 0 0 2px var(--surface);
}
.bell-dropdown {
  display: none; position: absolute; top: 100%; right: 0; margin-top: 10px;
  background: #fff; color: var(--ink); min-width: 344px; border: 1px solid var(--line);
  box-shadow: var(--sh-3); border-radius: var(--r); z-index: 100; max-height: 440px; overflow-y: auto;
}
.bell-dropdown.open { display: block; }
.bell-dropdown .head { padding: 13px 15px; border-bottom: 1px solid var(--line-2); font-weight: 650; display: flex; justify-content: space-between; align-items: center; }
.bell-dropdown .item { padding: 11px 15px; border-bottom: 1px solid var(--line-2); }
.bell-dropdown .item.unread { background: var(--brand-soft); }
.bell-dropdown .item .t { font-weight: 600; font-size: 13px; }
.bell-dropdown .item .m { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.bell-dropdown .item .d { font-size: 11px; color: var(--muted); margin-top: 4px; }
.bell-dropdown .empty { padding: 26px; text-align: center; color: var(--muted); }

.container { max-width: 1380px; margin: 0 auto; padding: 26px 26px 40px; width: 100%; flex: 1; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 700; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.app-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; padding: 16px 26px; text-align: center; margin-left: var(--side-w); }

/* ============================== CARDS ============================== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh-1); margin-bottom: 20px; }
.card .card-head { padding: 15px 18px; border-bottom: 1px solid var(--line-2); font-weight: 650; font-size: 14.5px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card .card-body { padding: 18px; }

/* ============================== KPI ============================== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh-1);
  padding: 18px; transition: transform .12s, box-shadow .12s; }
.kpi:hover { transform: translateY(-2px); box-shadow: var(--sh-2); }
.kpi .lbl { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .val { font-size: 27px; font-weight: 700; margin-top: 9px; letter-spacing: -0.02em; color: var(--ink); }
.kpi.pass .val { color: var(--ok); }   .kpi.fail .val { color: var(--bad); }

/* ============================== TABLES ============================== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 11px 18px; text-align: left; vertical-align: middle; }
table.data th {
  background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data td { font-size: 13px; border-bottom: 1px solid var(--line-2); color: var(--ink); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--brand); }
table.data th.sortable .arr { color: var(--muted); font-size: 9px; margin-left: 4px; }
table.data th.sorted, table.data th.sorted .arr { color: var(--brand); }

/* ============================== TOOLBAR ============================== */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 18px;
  border-bottom: 1px solid var(--line-2); background: var(--surface); border-radius: var(--r) var(--r) 0 0; }
.toolbar .search { position: relative; flex: 1; min-width: 200px; max-width: 320px; }
.toolbar .search input { width: 100%; padding: 9px 12px 9px 34px; border: 1px solid var(--line); border-radius: 20px; font-size: 13px; background: var(--surface-2); color: var(--ink); }
.toolbar .search input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); background: #fff; }
.toolbar .search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; }
.toolbar select { height: 38px; padding: 0 30px 0 12px; border: 1px solid var(--line); border-radius: var(--r-sm); font-size: 13px; color: var(--ink-2); cursor: pointer;
  -webkit-appearance: none; appearance: none; background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a869c' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center; }
.toolbar select:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.toolbar .spacer { flex: 1; }
.toolbar .count { color: var(--muted); font-size: 12.5px; }
.toolbar .count b { color: var(--ink); }

/* ============================== PAGINATION ============================== */
.pagination { display: flex; align-items: center; gap: 5px; padding: 13px 18px; border-top: 1px solid var(--line-2); flex-wrap: wrap; }
.pagination .pg { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; height: 32px; padding: 0 9px;
  border: 1px solid var(--line); border-radius: var(--r-xs); color: var(--ink-2); font-size: 12.5px; font-weight: 600; background: #fff; }
.pagination .pg:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.pagination .pg.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pagination .pg.disabled { opacity: .4; pointer-events: none; }
.pagination .info { color: var(--muted); font-size: 12px; margin-left: auto; }

/* ============================== FORMS ============================== */
.form-row { margin-bottom: 15px; }
.form-row label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 12.5px; color: var(--ink-2); }
.form-row input[type=text], .form-row input[type=email], .form-row input[type=password],
.form-row input[type=number], .form-row input[type=date], .form-row input[type=search],
.form-row select, .form-row textarea, input[type=text], input[type=password], input[type=email], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-sm);
  font-size: 13.5px; font-family: inherit; color: var(--ink); background: #fff;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus,
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.form-row input::placeholder, textarea::placeholder { color: #aab4c4; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }

/* ============================== BUTTONS ============================== */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  height: 40px; padding: 0 17px; border-radius: 10px; border: 1px solid transparent;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 13.5px; cursor: pointer;
  font-family: inherit; box-shadow: var(--sh-1); transition: background .12s, box-shadow .12s, transform .04s;
}
.btn:hover { background: var(--brand-d); color: #fff; text-decoration: none; box-shadow: var(--sh-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.secondary { background: #fff; color: var(--ink-2); border-color: var(--line); box-shadow: none; }
.btn.secondary:hover { background: var(--surface-2); color: var(--ink); }
.btn.ghost { background: #fff; color: var(--brand); border-color: var(--line); box-shadow: none; }
.btn.ghost:hover { background: var(--brand-soft); color: var(--brand-d); }
.btn.success { background: var(--ok); } .btn.success:hover { background: #128a4c; }
.btn.danger  { background: var(--bad); } .btn.danger:hover  { background: #be2222; }
.btn.small { height: 30px; padding: 0 11px; font-size: 12px; border-radius: var(--r-xs); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================== FLASH ============================== */
.flash { padding: 13px 16px; border-radius: var(--r-sm); margin-bottom: 16px; font-size: 13.5px; border: 1px solid transparent; display: flex; gap: 10px; }
.flash.success { background: var(--ok-bg);  color: #0f7a44; border-color: color-mix(in srgb, var(--ok) 28%, #fff); }
.flash.error   { background: var(--bad-bg); color: #b81e1e; border-color: color-mix(in srgb, var(--bad) 28%, #fff); }
.flash.warning { background: var(--warn-bg);color: #9a5e06; border-color: color-mix(in srgb, var(--warn) 28%, #fff); }
.flash.info    { background: var(--info-bg);color: #1d3f96; border-color: color-mix(in srgb, var(--info) 24%, #fff); }

/* ============================== TAGS / CHIPS ============================== */
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 20px; background: #eef1f6; color: #54607a; font-size: 11px; font-weight: 600; }
.tag.dyed { background: #f3e8fb; color: #7b2cbf; }
.tag.plain { background: var(--brand-soft); color: var(--brand-d); }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; background: #eef1f6; color: #54607a; }
.chip.flag { background: var(--warn-bg); color: #9a5e06; }
.chip.ok   { background: var(--ok-bg);  color: #0f7a44; }
.chip.bad  { background: var(--bad-bg); color: #b81e1e; }
.chip.info { background: var(--info-bg);color: #1d3f96; }

/* ============================== TABS / SETTINGS NAV ============================== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a { padding: 11px 16px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--brand); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.split { display: grid; grid-template-columns: 240px 1fr; gap: 22px; align-items: start; }
.sectnav { position: sticky; top: calc(var(--top-h) + 16px); }
.sectnav a { display: flex; align-items: center; gap: 9px; padding: 10px 13px; border-radius: var(--r-sm); color: var(--ink-2); font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.sectnav a:hover { background: var(--surface-2); color: var(--brand); text-decoration: none; }
.sectnav a.active { background: var(--brand-soft); color: var(--brand-d); }
@media (max-width: 820px){ .split { grid-template-columns: 1fr; } .sectnav { position: static; } }

/* ============================== MODAL ============================== */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(16,24,40,.5); z-index: 200; align-items: center; justify-content: center; padding: 20px; }
.modal-bg.open { display: flex; }
.modal { background: #fff; border-radius: var(--r); box-shadow: var(--sh-3); width: 100%; max-width: 480px; overflow: hidden; }
.modal .m-head { padding: 16px 20px; border-bottom: 1px solid var(--line-2); font-weight: 700; font-size: 15px; }
.modal .m-body { padding: 20px; }
.modal .m-foot { padding: 14px 20px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); }

/* ============================== EMPTY STATE ============================== */
.empty-state { text-align: center; padding: 52px 20px; color: var(--muted); }
.empty-state .em-ico { font-size: 30px; opacity: .45; }
.empty-state .em-title { font-size: 15px; font-weight: 650; color: var(--ink-2); margin-top: 10px; }

/* ============================== LOGIN ============================== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(1100px 520px at 50% -10%, color-mix(in srgb, var(--brand) 22%, #eef2f8), var(--bg)); }
.login-box { background: #fff; padding: 38px; border-radius: 16px; width: 392px; box-shadow: var(--sh-3); border: 1px solid var(--line); }
.login-box h1 { font-size: 21px; margin: 0 0 4px; }
.login-box .sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-box .btn { width: 100%; height: 44px; font-size: 14px; }

/* ============================== READINGS / PARAM BLOCK ============================== */
.readings-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; margin-top: 8px; }
.readings-grid input { padding: 7px 4px; text-align: center; font-size: 12px; }
.param-block { background: var(--surface-2); padding: 15px; border: 1px solid var(--line); border-radius: var(--r-sm); margin-bottom: 14px; }
.param-block .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.param-block .head .name { font-weight: 650; }
.param-block .head .unit { color: var(--muted); font-size: 12px; }
.live-stats { margin-top: 9px; font-size: 12px; color: var(--ink-2); display: flex; gap: 14px; flex-wrap: wrap; }
.live-stats .stat { background: #fff; padding: 5px 11px; border-radius: var(--r-xs); border: 1px solid var(--line); }
.live-stats .stat b { color: var(--ink); }
.result-tbl td.verdict { font-weight: 700; }

/* ============================== UTILITIES ============================== */
.mt-0 { margin-top: 0; } .mt-12 { margin-top: 12px; } .mt-20 { margin-top: 20px; } .mb-0 { margin-bottom: 0; }
.text-muted { color: var(--muted); } .text-center { text-align: center; } .text-right { text-align: right; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
small { font-size: 11.5px; }
code { background: var(--surface-2); border: 1px solid var(--line-2); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* ============================== SIDEBAR THEME VARIANTS ============================== */
[data-sidebar="light"] .sidebar { background: var(--surface-2); }

[data-sidebar="dark"] .sidebar { background: #0f1b2e;
  background-image: linear-gradient(180deg, color-mix(in srgb, var(--brand) 26%, #0f1b2e), #0f1b2e 30%);
  border-right-color: rgba(255,255,255,.06); }
[data-sidebar="dark"] .sidebar-brand { border-bottom-color: rgba(255,255,255,.08); }
[data-sidebar="dark"] .brand-name { color: #fff; }
[data-sidebar="dark"] .brand-sub  { color: #6b7f9c; }
[data-sidebar="dark"] .nav-group  { color: #61748f; }
[data-sidebar="dark"] .nav-item   { color: #aebed4; }
[data-sidebar="dark"] .nav-item svg { color: #61748f; }
[data-sidebar="dark"] .nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
[data-sidebar="dark"] .nav-item:hover svg { color: #aebed4; }
[data-sidebar="dark"] .nav-item.active { background: color-mix(in srgb, var(--brand) 88%, #000); color: #fff; }
[data-sidebar="dark"] .nav-item.active svg { color: #fff; }
[data-sidebar="dark"] .sidebar-footer { border-top-color: rgba(255,255,255,.08); }
[data-sidebar="dark"] .user-name { color: #fff; }
[data-sidebar="dark"] .user-role { color: #6b7f9c; }
[data-sidebar="dark"] .user-avatar { background: color-mix(in srgb, var(--brand) 40%, #0f1b2e); color: #fff; }
[data-sidebar="dark"] .sidebar-logout { color: #aebed4; }
[data-sidebar="dark"] .sidebar-logout:hover { background: rgba(255,255,255,.06); color: #fff; }

/* ============================== RESPONSIVE ============================== */
@media (max-width: 940px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--sh-3); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap, .app-footer { margin-left: 0; }
  .topbar-mini .hamburger { display: block; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
