/* =========================================================================
   Medialogic Insight — UI styles (Zoho Books–inspired)
   No external fonts or CDNs: system font stack only.
   ========================================================================= */

:root {
  --blue: #408dfb;
  --blue-600: #2c7bf0;
  --blue-50: #ebf3ff;
  --navy: #21263c;
  --navy-2: #2d3350;
  --navy-text: #c9cde0;

  --bg: #ffffff;
  --bg-soft: #f6f7fa;
  --sidebar: #f7f7fa;
  --card: #ffffff;
  --card-head: #fafbfc;
  --border: #e3e6ee;
  --border-strong: #cdd2df;
  --input: #ffffff;

  --text: #21263c;
  --muted: #6b7088;
  --faint: #9aa0b4;

  --green: #1fae6a;
  --green-50: #e7f7ef;
  --red: #ec5453;
  --red-50: #fdeeee;
  --orange: #f2a20f;
  --orange-50: #fff5e3;

  --radius: 6px;
  --radius-lg: 8px;
  --shadow: 0 1px 2px rgba(33, 38, 60, .05);
  --shadow-pop: 0 10px 30px rgba(20, 24, 40, .16);
  --focus: 0 0 0 3px rgba(64, 141, 251, .28);

  --topbar-h: 52px;
  --sidebar-w: 216px;
  --rail-w: 64px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --blue: #5a9dff; --blue-600: #7cb0ff; --blue-50: #1d2a44;
    --navy: #0e1019; --navy-2: #1b1f30; --navy-text: #aab0c6;
    --bg: #12141c; --bg-soft: #171a24; --sidebar: #161924; --card: #1b1e2a; --card-head: #20243282;
    --border: #2c3144; --border-strong: #3b4159; --input: #141722;
    --text: #e5e7ef; --muted: #9ba1b8; --faint: #6f758c;
    --green: #35c584; --green-50: #16301f; --red: #ff6b6a; --red-50: #3a1d22; --orange: #f7b33b; --orange-50: #35291a;
    --shadow: none; --shadow-pop: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --blue: #5a9dff; --blue-600: #7cb0ff; --blue-50: #1d2a44;
  --navy: #0e1019; --navy-2: #1b1f30; --navy-text: #aab0c6;
  --bg: #12141c; --bg-soft: #171a24; --sidebar: #161924; --card: #1b1e2a; --card-head: #20243282;
  --border: #2c3144; --border-strong: #3b4159; --input: #141722;
  --text: #e5e7ef; --muted: #9ba1b8; --faint: #6f758c;
  --green: #35c584; --green-50: #16301f; --red: #ff6b6a; --red-50: #3a1d22; --orange: #f7b33b; --orange-50: #35291a;
  --shadow: none; --shadow-pop: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
h1, h2, h3 { margin: 0; font-weight: 500; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid transparent; background: none; color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-busy { opacity: .55; cursor: not-allowed; }
.btn .ic { width: 16px; height: 16px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-600); }
.btn-ghost { background: var(--card); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-soft); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.95); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; height: 40px; font-size: 15px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.link-btn { background: none; border: 0; padding: 0; color: var(--blue); font: inherit; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 14px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form-inline { grid-template-columns: minmax(0, 320px) max-content; align-items: end; }
.field { display: grid; gap: 5px; }
.field-label { font-size: 13px; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--faint); margin: 0; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select {
  width: 100%; height: 38px; padding: 0 11px;
  background: var(--input); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  font: inherit; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--blue); box-shadow: var(--focus); }
input:disabled { opacity: .6; }
.input-wrap { position: relative; display: block; }
.input-wrap input { padding-right: 40px; }
.input-reveal {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 30px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 4px;
}
.input-reveal.is-on { color: var(--blue); }
.input-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 20px !important; letter-spacing: .25em; text-align: center; height: 46px !important; }
.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--blue); }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px 16px; margin: 0; display: grid; gap: 12px; }
.fieldset legend { padding: 0 6px; font-weight: 600; font-size: 13px; }
.meter { display: block; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--red); transition: width .2s, background .2s; }
.meter[data-level="2"] span { width: 50%; background: var(--orange); }
.meter[data-level="3"] span { width: 75%; background: var(--blue); }
.meter[data-level="4"] span { width: 100%; background: var(--green); }
.meter[data-level="1"] span { width: 25%; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin: 0 0 16px; }

/* ---------- Alerts / pills ---------- */
.alert {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; margin: 0 0 16px;
  border: 1px solid; border-radius: var(--radius); font-size: 13.5px;
}
.alert > span { flex: 1 1 200px; }
.alert-info { background: var(--blue-50); border-color: color-mix(in srgb, var(--blue) 35%, transparent); }
.alert-info > .ic { color: var(--blue); }
.alert-success { background: var(--green-50); border-color: color-mix(in srgb, var(--green) 35%, transparent); }
.alert-success > .ic { color: var(--green); }
.alert-warning { background: var(--orange-50); border-color: color-mix(in srgb, var(--orange) 40%, transparent); }
.alert-warning > .ic { color: var(--orange); }
.alert-error { background: var(--red-50); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.alert-error > .ic { color: var(--red); }
.alert-list { margin: 0; padding-left: 18px; flex: 1; }
.alert-close { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px; }
.pill { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 10px; font-size: 11.5px; font-weight: 600; letter-spacing: .02em; }
.pill-blue { background: var(--blue-50); color: var(--blue); }
.pill-green { background: var(--green-50); color: var(--green); }
.pill-red { background: var(--red-50); color: var(--red); }
.pill-grey { background: var(--bg-soft); color: var(--muted); border: 1px solid var(--border); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }
.note { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; background: var(--bg-soft); border-radius: var(--radius); color: var(--muted); font-size: 13px; }

/* =========================================================================
   Auth pages
   ========================================================================= */
.auth-body { background: var(--bg-soft); min-height: 100vh; }
.auth-wrap { display: grid; grid-template-columns: minmax(340px, 44%) 1fr; min-height: 100vh; }
.auth-brand {
  position: relative; overflow: hidden;
  background: var(--navy);
  background-image:
    radial-gradient(circle at 85% 10%, rgba(64, 141, 251, .28), transparent 42%),
    linear-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .035) 1px, transparent 1px);
  background-size: auto, 32px 32px, 32px 32px;
  color: #fff;
}
.auth-brand-inner { position: relative; height: 100%; padding: 44px 48px; display: flex; flex-direction: column; gap: 28px; }
.brand-lockup { display: inline-flex; align-items: center; gap: 10px; font-size: 18px; letter-spacing: .01em; }
.brand-lockup strong { font-weight: 700; }
.brand-lockup--light { color: #fff; }
.auth-brand-copy { margin-top: auto; max-width: 440px; }
.auth-brand-copy h2 { font-size: 30px; line-height: 1.2; font-weight: 600; margin-bottom: 14px; }
.auth-brand-copy p { color: #b9bfd6; font-size: 15px; }
.auth-brand-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; color: #d6dbee; }
.auth-brand-points li { display: flex; align-items: center; gap: 10px; }
.auth-brand-points .ic { color: var(--blue); }
.auth-brand-chart { display: flex; align-items: flex-end; gap: 10px; height: 90px; margin-top: 8px; opacity: .9; }
.auth-brand-chart span { flex: 1; border-radius: 3px 3px 0 0; background: linear-gradient(180deg, #408dfb, rgba(64, 141, 251, .25)); }
.auth-brand-chart span:nth-child(1) { height: 35%; }
.auth-brand-chart span:nth-child(2) { height: 55%; }
.auth-brand-chart span:nth-child(3) { height: 42%; }
.auth-brand-chart span:nth-child(4) { height: 70%; }
.auth-brand-chart span:nth-child(5) { height: 62%; }
.auth-brand-chart span:nth-child(6) { height: 88%; background: linear-gradient(180deg, #2ec27e, rgba(46, 194, 126, .25)); }
.auth-brand-chart span:nth-child(7) { height: 76%; }

.auth-main { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 20px; }
.auth-card {
  width: 100%; max-width: 440px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 36px 36px 30px; box-shadow: 0 2px 14px rgba(33, 38, 60, .06);
}
.auth-card-brand { display: none; margin-bottom: 22px; color: var(--text); }
.auth-title { font-size: 24px; font-weight: 500; margin-bottom: 4px; }
.auth-sub { color: var(--muted); margin-bottom: 22px; }
.auth-links { text-align: center; margin: 18px 0 0; font-size: 13.5px; }
.auth-foot { color: var(--faint); font-size: 12px; margin-top: 18px; text-align: center; }
.auth-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; background: var(--blue-50); color: var(--blue); margin-bottom: 16px; }
.auth-icon .ic { width: 24px; height: 24px; }
.auth-icon--ok { background: var(--green-50); color: var(--green); }
.auth-icon--warn { background: var(--orange-50); color: var(--orange); }
.auth-help { margin-top: 18px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 14px; }
.auth-help summary { cursor: pointer; color: var(--blue); }
.auth-help p { margin-top: 8px; }
.error-code { font-size: 13px; font-weight: 700; letter-spacing: .1em; color: var(--muted); margin: 0 0 4px; }

/* Install checklist */
.checklist { list-style: none; margin: 0 0 18px; padding: 10px 12px; display: grid; gap: 6px; background: var(--bg-soft); border-radius: var(--radius); font-size: 13px; }
.checklist li { display: flex; gap: 8px; align-items: flex-start; }
.checklist li.ok .ic { color: var(--green); }
.checklist li.bad .ic { color: var(--red); }
.checklist small { color: var(--faint); }

/* TOTP setup + backup codes */
.steps { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 14px; }
.steps li { display: grid; gap: 4px; }
.steps li > span { color: var(--muted); font-size: 13.5px; }
.steps--numbered { list-style: decimal; padding-left: 20px; }
.qr-box { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-top: 8px; padding: 14px; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); }
.qr { width: 168px; height: 168px; background: #fff; padding: 8px; border-radius: 6px; flex: none; }
.qr svg, .qr img { width: 100%; height: 100%; display: block; }
.qr-manual { display: grid; gap: 6px; flex: 1 1 180px; font-size: 12.5px; }
.secret { display: block; padding: 8px 10px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 5px; font-size: 13px; letter-spacing: .06em; word-break: break-all; user-select: all; }
.secret-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.secret-row .secret { flex: 1 1 260px; }
.codes { display: grid; gap: 12px; margin: 4px 0 18px; }
.codes-grid { list-style: none; margin: 0; padding: 14px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 18px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius-lg); counter-reset: c; }
.codes-grid li { counter-increment: c; display: flex; gap: 8px; align-items: baseline; }
.codes-grid li::before { content: counter(c) "."; color: var(--faint); font-size: 12px; width: 20px; text-align: right; }
.codes-grid code { font-size: 15px; letter-spacing: .05em; }
.codes-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* =========================================================================
   App shell
   ========================================================================= */
.app-body { background: var(--bg); }
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 40;
  display: flex; align-items: center; gap: 6px; padding: 0 12px;
  background: var(--navy); color: var(--navy-text);
}
.tb-btn {
  width: 36px; height: 36px; display: grid; place-items: center; flex: none;
  border: 0; border-radius: var(--radius); background: none; color: var(--navy-text); cursor: pointer;
}
.tb-btn:hover:not(:disabled) { background: var(--navy-2); color: #fff; }
.tb-btn:disabled { opacity: .45; cursor: default; }
.tb-brand { display: flex; align-items: center; gap: 8px; color: #fff; font-size: 16px; font-weight: 600; padding: 0 8px 0 2px; width: calc(var(--sidebar-w) - 54px); }
.tb-brand:hover { text-decoration: none; }
.tb-search {
  display: flex; align-items: center; gap: 8px; width: min(380px, 34vw); height: 32px; padding: 0 10px;
  background: var(--navy-2); border: 1px solid rgba(255, 255, 255, .08); border-radius: var(--radius);
}
.tb-search input { height: 30px; padding: 0; border: 0; background: none; color: #fff; font-size: 13px; }
.tb-search input:focus { box-shadow: none; }
.tb-search input::placeholder { color: #8a90a8; }
.tb-spacer { flex: 1; }
.tb-sync { display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 14px; background: rgba(255, 255, 255, .06); font-size: 12px; }
.tb-sync .ic { width: 16px; height: 16px; color: var(--orange); }
.tb-org { font-size: 13px; color: #fff; padding: 0 8px; border-left: 1px solid rgba(255, 255, 255, .14); margin-left: 4px; }
.ic-sun { display: none; }
:root[data-theme="dark"] .ic-moon { display: none; }
:root[data-theme="dark"] .ic-sun { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ic-moon { display: none; }
  :root:not([data-theme="light"]) .ic-sun { display: block; }
}
.tb-user { position: relative; margin-left: 4px; }
.tb-avatar {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .2);
  background: var(--blue); color: #fff; font-family: inherit; font-weight: 600; font-size: 12px; line-height: 1; cursor: pointer; display: grid; place-items: center;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 260px; z-index: 60;
  background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop); padding: 6px;
}
.menu-head { display: flex; gap: 10px; padding: 10px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; }
.menu-name { font-weight: 600; }
.menu-sub { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; word-break: break-all; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px;
  border: 0; border-radius: 5px; background: none; color: var(--text); font: inherit; cursor: pointer; text-align: left;
}
.menu-item:hover { background: var(--bg-soft); text-decoration: none; }
.menu-item .ic { color: var(--muted); }
.menu-item--danger, .menu-item--danger .ic { color: var(--red); }

.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w); z-index: 30;
  display: flex; flex-direction: column;
  background: var(--sidebar); border-right: 1px solid var(--border);
  transition: width .18s ease, transform .2s ease;
}
.nav { flex: 1; overflow-y: auto; padding: 10px 8px; display: grid; align-content: start; gap: 2px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 11px; height: 38px; padding: 0 11px;
  border-radius: var(--radius); color: var(--text); white-space: nowrap; font-size: 13.5px;
}
.nav-item:hover { background: rgba(64, 141, 251, .08); text-decoration: none; }
.nav-item .ic { color: var(--muted); }
.nav-item.is-active { background: var(--blue); color: #fff; }
.nav-item.is-active .ic { color: #fff; }
.nav-item.is-soon { color: var(--faint); cursor: default; }
.nav-item.is-soon:hover { background: none; }
.nav-item.is-soon .ic { color: var(--faint); opacity: .8; }
.nav-soon { margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); border: 1px solid var(--border); padding: 0 5px; border-radius: 3px; line-height: 16px; }
.nav-section { margin: 14px 11px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); white-space: nowrap; overflow: hidden; }
.sidebar-collapse {
  height: 40px; border: 0; border-top: 1px solid var(--border); background: var(--bg-soft); color: var(--muted); cursor: pointer;
  display: grid; place-items: center;
}
.sidebar-collapse:hover { color: var(--text); }
.scrim { display: none; }

.main {
  margin-left: var(--sidebar-w); padding: calc(var(--topbar-h) + 20px) 24px 40px;
  min-height: 100vh; max-width: calc(var(--sidebar-w) + 1240px);
  transition: margin-left .18s ease;
}

/* Collapsed rail (desktop toggle) */
.sb-collapsed .sidebar { width: var(--rail-w); }
.sb-collapsed .main { margin-left: var(--rail-w); max-width: calc(var(--rail-w) + 1240px); }
.sb-collapsed .nav-label, .sb-collapsed .nav-soon { display: none; }
.sb-collapsed .nav-item { justify-content: center; padding: 0; }
.sb-collapsed .nav-section { height: 1px; background: var(--border); color: transparent; margin: 12px 10px; }
.sb-collapsed .sidebar-collapse .ic { transform: rotate(180deg); }

/* ---------- Page header + tabs ---------- */
.page-head {
  display: flex; flex-direction: column; gap: 14px;
  margin: -20px -24px 20px; padding: 18px 24px 0;
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
  border-bottom: 1px solid var(--border);
}
.page-head--plain { padding-bottom: 0; }
.page-head--plain > div:first-child { padding-bottom: 4px; }
.page-head-id { display: flex; align-items: center; gap: 14px; }
.org-badge { width: 48px; height: 48px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); display: grid; place-items: center; }
.page-title { font-size: 20px; font-weight: 500; }
.page-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 22px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 8px 0 10px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-size: 14px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--text); border-bottom-color: var(--blue); }
.tab.is-disabled { color: var(--faint); cursor: default; }

/* ---------- Cards ---------- */
.grid { display: grid; gap: 20px; margin-bottom: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-top { align-items: start; }
.grid > .card { margin-bottom: 0; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden;
}
.card-highlight { border-color: color-mix(in srgb, var(--blue) 45%, var(--border)); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  min-height: 48px; padding: 10px 16px; background: var(--card-head); border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 16px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.card-head h2 .ic { color: var(--muted); }
.card-meta { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 16px; }
.card-foot { padding: 10px 16px; border-top: 1px solid var(--border); font-size: 13px; }
.card-split { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--border); }
.card-split > div { padding: 14px 16px; display: grid; gap: 2px; }
.card-split > div + div { border-left: 1px solid var(--border); }
.kpi-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.kpi-label--blue { color: var(--blue); }
.kpi-label--red { color: var(--red); }
.kpi-value { font-size: 20px; }
.kpi-bar-label { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; display: flex; gap: 6px; align-items: center; }
.kpi-bar { height: 10px; background: var(--bg-soft); border-radius: 2px; overflow: hidden; }
.kpi-bar-fill { display: block; height: 100%; }
.kpi-bar-fill--empty { width: 100%; background: repeating-linear-gradient(-45deg, var(--border) 0 6px, transparent 6px 12px); }
.skeleton { display: inline-block; background: linear-gradient(90deg, var(--border), var(--bg-soft), var(--border)); background-size: 200% 100%; animation: shimmer 1.6s infinite linear; border-radius: 3px; }
.skeleton-text { width: 90px; height: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty-state { position: relative; min-height: 220px; display: grid; place-items: center; }
.empty-chart { position: absolute; inset: 16px; width: calc(100% - 32px); height: calc(100% - 32px); opacity: .5; }
.empty-chart-area { fill: var(--blue-50); }
.empty-chart-line { fill: none; stroke: color-mix(in srgb, var(--blue) 45%, transparent); stroke-width: 2; stroke-dasharray: 5 5; vector-effect: non-scaling-stroke; }
.empty-copy { position: relative; text-align: center; max-width: 440px; background: color-mix(in srgb, var(--card) 88%, transparent); padding: 18px 20px; border-radius: var(--radius-lg); }
.empty-copy .ic { width: 28px; height: 28px; color: var(--blue); margin-bottom: 6px; }
.empty-copy h3 { font-size: 16px; margin-bottom: 6px; }
.empty-copy p { color: var(--muted); font-size: 13px; margin: 0; }

.status-list, .phase-list { list-style: none; margin: 0; padding: 4px 16px; }
.status-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.status-list li:last-child { border-bottom: 0; }
.phase-list { padding: 12px 16px; display: grid; gap: 8px; }
.phase-list li { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.phase-list li span { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11.5px; font-weight: 600; border: 1px solid var(--border-strong); }
.phase-list li.is-done { color: var(--text); }
.phase-list li.is-done span { background: var(--green); border-color: var(--green); color: #fff; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--bg-soft); }
.table .row-bad td:first-child { color: var(--red); }
.t-right { text-align: right; }

/* ---------- Settings ---------- */
.settings-form { display: block; }
.radio-cards { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.radio-card { display: flex; align-items: flex-start; gap: 10px; padding: 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); cursor: pointer; transition: border-color .15s, background .15s; }
.radio-card input { margin-top: 3px; accent-color: var(--blue); }
.radio-card > span { display: grid; gap: 4px; }
.radio-card strong { display: flex; align-items: center; gap: 6px; }
.radio-card small { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.radio-card:has(input:checked) { border-color: var(--blue); background: var(--blue-50); }
.radio-card--warn:has(input:checked) { border-color: var(--red); background: var(--red-50); }
.danger-zone { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.danger-zone summary { cursor: pointer; color: var(--red); font-size: 13.5px; margin-bottom: 10px; }
.edge-status { display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin: 14px 0; border-radius: var(--radius); background: var(--bg-soft); color: var(--muted); font-size: 13px; }
.edge-status.is-ok { background: var(--green-50); color: var(--green); }

/* ---------- Idle warning ---------- */
.idle-warn { position: fixed; inset: auto 16px 16px auto; z-index: 80; }
.idle-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); max-width: 420px; }
.idle-card > .ic { color: var(--orange); width: 24px; height: 24px; }
.idle-card p { margin: 0; color: var(--muted); font-size: 13px; }

/* =========================================================================
   Responsive
   ========================================================================= */

/* Laptop */
@media (max-width: 1279px) {
  .main { padding-left: 20px; padding-right: 20px; }
  .page-head { margin-left: -20px; margin-right: -20px; padding-left: 20px; padding-right: 20px; }
  .tb-org { display: none; }
}

/* Tablet: icon rail by default; burger opens full sidebar as overlay */
@media (max-width: 1023px) {
  .sidebar { width: var(--rail-w); }
  .main, .sb-collapsed .main { margin-left: var(--rail-w); }
  .nav-label, .nav-soon { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-section { height: 1px; background: var(--border); color: transparent; margin: 12px 10px; }
  .sidebar-collapse { display: none; }
  .sb-open .sidebar { width: var(--sidebar-w); box-shadow: var(--shadow-pop); }
  .sb-open .nav-label, .sb-open .nav-soon { display: inline; }
  .sb-open .nav-item { justify-content: flex-start; padding: 0 11px; }
  .sb-open .nav-section { height: auto; background: none; color: var(--faint); margin: 14px 11px 6px; }
  .sb-open .scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(10, 12, 20, .35); z-index: 25; }
  .tb-brand { width: auto; }
  .tb-sync-text { display: none; }
  .radio-cards { grid-template-columns: 1fr; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-card-brand { display: inline-flex; }
}

/* Phone: off-canvas drawer, single column, stacked tables */
@media (max-width: 767px) {
  .sidebar { width: var(--sidebar-w); transform: translateX(-100%); }
  .sb-open .sidebar { transform: none; }
  .nav-label, .nav-soon { display: inline; }
  .nav-item { justify-content: flex-start; padding: 0 11px; }
  .nav-section { height: auto; background: none; color: var(--faint); margin: 14px 11px 6px; }
  .main, .sb-collapsed .main { margin-left: 0; padding: calc(var(--topbar-h) + 16px) 16px 32px; }
  .page-head { margin: -16px -16px 16px; padding: 16px 16px 0; }
  .tb-search { display: none; }
  .tb-sync { padding: 0 8px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid { gap: 16px; margin-bottom: 16px; }
  .card { margin-bottom: 16px; }
  .form-inline { grid-template-columns: 1fr; }
  .card-split { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 17px; }
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 10px 16px; border-bottom: 1px solid var(--border); }
  .table-stack td { padding: 3px 0; border: 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table-stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none; }
  .table-stack td:not([data-label])::before { content: none; }
  .table-stack td.t-right { justify-content: flex-end; }
  .auth-main { padding: 20px 14px; justify-content: flex-start; }
  .auth-card { padding: 26px 20px 22px; border-radius: 8px; }
  .qr-box { justify-content: center; }
  .codes-grid { grid-template-columns: 1fr 1fr; padding: 12px; }
  .idle-warn { inset: auto 10px 10px 10px; }
  .idle-card { max-width: none; }
}

@media (max-width: 380px) {
  .codes-grid { grid-template-columns: 1fr; }
  .tb-btn[aria-label="Notifications"] { display: none; }
}

/* ---------- Print (backup codes) ---------- */
@media print {
  .topbar, .sidebar, .scrim, .auth-brand, .auth-foot, .codes-actions, .check, .btn, .auth-links, .page-head, .card:not(.card-highlight), .grid { display: none !important; }
  .main { margin: 0; padding: 0; }
  body, .auth-body { background: #fff; color: #000; }
  .auth-card, .card { border: 0; box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* =========================================================================
   Phase 2 — users, roles, audit
   ========================================================================= */
.page-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-actions.integrity { font-size: 12.5px; color: var(--muted); }
.page-actions.integrity > span { display: inline-flex; align-items: center; gap: 6px; }
.block { display: block; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.t-center { text-align: center; }
.btn-row--end { justify-content: flex-end; flex-wrap: nowrap; }
.btn-danger-text { color: var(--red); }
.empty-row { text-align: center; color: var(--muted); padding: 28px 16px !important; }
.row-muted td { color: var(--faint); }
.row-muted .avatar { opacity: .5; }

.stat-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.stat-chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--border); border-radius: 16px; background: var(--card); color: var(--muted); font-size: 13px; }
.stat-chip strong { color: var(--text); }
.stat-chip:hover { text-decoration: none; border-color: var(--border-strong); }
.stat-chip.is-active { border-color: var(--blue); color: var(--blue); background: var(--blue-50); }
.stat-chip.is-active strong { color: var(--blue); }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--card-head); }
.toolbar select, .toolbar input[type=text], .toolbar input[type=date] { width: auto; height: 34px; font-size: 13px; }
.toolbar select { max-width: 200px; }
.toolbar-search { display: flex; align-items: center; gap: 6px; flex: 1 1 220px; height: 34px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--input); color: var(--muted); }
.toolbar-search input { border: 0; height: 32px; padding: 0; background: none; }
.toolbar-search input:focus { box-shadow: none; }
.toolbar-search:focus-within { border-color: var(--blue); box-shadow: var(--focus); }
.toolbar-date { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.toolbar-check { align-items: center; font-size: 13px; color: var(--muted); }
.toolbar-check input { margin-top: 0; }
.input-ip { width: 140px !important; }

.user-cell { display: inline-flex; align-items: center; gap: 10px; text-align: left; }
.user-cell small { display: block; color: var(--muted); font-size: 12.5px; }
.avatar { width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--blue-50); color: var(--blue); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.avatar-sm { width: 26px; height: 26px; font-size: 10.5px; }

.layout-split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.layout-split--single { grid-template-columns: minmax(0, 820px); }
.side-stack { display: grid; gap: 20px; }
.side-stack .card { margin-bottom: 0; }
.card-narrow { max-width: 720px; }
.check-card { padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); }
.check-card small { display: block; margin-top: 2px; }
.stepup { border-color: color-mix(in srgb, var(--orange) 50%, var(--border)); }

.action-list { display: grid; padding: 6px; }
.action-item { display: grid; gap: 1px; width: 100%; padding: 10px 12px; border: 0; border-radius: var(--radius); background: none; color: var(--text); text-align: left; font: inherit; cursor: pointer; }
.action-item:hover { background: var(--bg-soft); }
.action-item strong { font-weight: 500; font-size: 13.5px; }
.action-item small { color: var(--muted); font-size: 12px; }
.action-item--danger strong { color: var(--red); }

.mini-log, .member-list { list-style: none; margin: 0; padding: 6px 16px 12px; }
.mini-log li { display: flex; align-items: flex-start; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.mini-log li:last-child { border-bottom: 0; }
.mini-log .dot { margin-top: 6px; }
.mini-log small { display: block; color: var(--muted); font-size: 11.5px; }
.member-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13.5px; flex-wrap: wrap; }

.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 4px; background: var(--bg-soft); border: 1px solid var(--border); font-size: 12px; color: var(--text); white-space: nowrap; }
.chip sup { color: var(--blue); font-weight: 700; margin-left: 1px; }
td .chips { justify-content: flex-start; }

.matrix th, .matrix td { padding: 9px 12px; }
.matrix thead th { position: sticky; top: 0; background: var(--card); z-index: 1; vertical-align: bottom; }
.matrix-col, .matrix-row { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-transform: inherit; letter-spacing: inherit; }
.matrix-col:hover, .matrix-row:hover { color: var(--blue); }
.matrix-row { text-align: left; font-weight: 400; font-size: 13.5px; color: var(--text); }
.matrix-note { display: block; font-size: 10px; text-transform: none; letter-spacing: 0; color: var(--orange); font-weight: 400; }
.matrix-group th { background: var(--bg-soft); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 12px; text-align: left; }
.matrix-module { font-weight: 400; }
.matrix-box { width: 18px; height: 18px; accent-color: var(--blue); cursor: pointer; }
.matrix-na { color: var(--faint); }
.matrix tbody tr:hover { background: var(--bg-soft); }

.table-log td { font-size: 13px; }
.cell-detail { max-width: 360px; color: var(--muted); word-break: break-word; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

@media (max-width: 1279px) {
  .layout-split { grid-template-columns: minmax(0, 1fr) 300px; }
}
@media (max-width: 1023px) {
  .layout-split { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
  .toolbar { padding: 10px 12px; }
  .toolbar select, .toolbar-search, .toolbar input[type=text], .toolbar-date { flex: 1 1 100%; max-width: none; width: 100%; }
  .toolbar-date input { flex: 1; }
  .input-ip { width: 100% !important; }
  .page-actions.integrity { width: 100%; }
  .user-cell { text-align: right; flex-direction: row-reverse; }
  .table-stack td > .chips { justify-content: flex-end; }
  .matrix { min-width: 560px; }
  .cell-detail { max-width: none; }
}
.form-grid { align-items: start; }
.matrix tbody th.matrix-module { text-transform: none; letter-spacing: 0; font-size: 13.5px; color: var(--text); font-weight: 400; }
.table-log .row-bad td:first-child { color: inherit; }
.table-log .row-bad td[data-label="Event"] { color: var(--red); }
