/* ============================================================
   Vision IT Portal — Design system
   Palette: cool slate/ink + a single petrol-teal accent, used
   only for the active nav state and primary actions — never as
   decoration. Status is always colour + a word, never colour alone.
   ============================================================ */

:root {
  --ink: #1A2332;
  --ink-soft: #4B5768;
  --bg: #F3F5F7;
  --surface: #FFFFFF;
  --border: #DBE1E8;
  --border-strong: #C3CBD6;

  --brand: #0E6E6E;
  --brand-dark: #0A5555;
  --sidebar-bg: #14202B;
  --sidebar-ink: #C6D0DA;
  --sidebar-active: #17403F;

  --ok-bg: #E7F5EC; --ok-fg: #1F7A46;
  --warn-bg: #FBF0DD; --warn-fg: #9A6512;
  --danger-bg: #FBE9E7; --danger-fg: #A6321E;
  --info-bg: #E7F0FA; --info-fg: #2A5F94;
  --neutral-bg: #EAECEF; --neutral-fg: #566173;

  --radius: 5px;
  --font-ui: 'Inter', -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
}

/* Dark theme — follows system preference by default, or the manual toggle (data-theme, saved in localStorage). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #E4E8ED; --ink-soft: #97A5B2;
    --bg: #10171F; --surface: #182430;
    --border: #2A3844; --border-strong: #3C4C59;
    --brand: #17B3B3; --brand-dark: #0E8A8A;
    --sidebar-bg: #0A1119; --sidebar-active: #123534;
    --ok-bg: #163826; --ok-fg: #74DE9E;
    --warn-bg: #3A2E12; --warn-fg: #F0C36D;
    --danger-bg: #3A1E1A; --danger-fg: #F3968A;
    --info-bg: #16283A; --info-fg: #82B7EC;
    --neutral-bg: #212B35; --neutral-fg: #B2BCC6;
  }
}
:root[data-theme="dark"] {
  --ink: #E4E8ED; --ink-soft: #97A5B2;
  --bg: #10171F; --surface: #182430;
  --border: #2A3844; --border-strong: #3C4C59;
  --brand: #17B3B3; --brand-dark: #0E8A8A;
  --sidebar-bg: #0A1119; --sidebar-active: #123534;
  --ok-bg: #163826; --ok-fg: #74DE9E;
  --warn-bg: #3A2E12; --warn-fg: #F0C36D;
  --danger-bg: #3A1E1A; --danger-fg: #F3968A;
  --info-bg: #16283A; --info-fg: #82B7EC;
  --neutral-bg: #212B35; --neutral-fg: #B2BCC6;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
code, .mono { font-family: var(--font-mono); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  padding: 18px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 10px;
}
.sidebar .brand-mark {
  width: 30px; height: 30px; border-radius: 6px;
  background: var(--brand); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.sidebar .brand-text { font-size: 13px; line-height: 1.25; color: #fff; }
.sidebar .brand-text small { display: block; color: var(--sidebar-ink); font-weight: 400; }

.nav-group { margin: 14px 0 4px; padding: 0 18px; font-size: 11px; color: #7C8A98; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px; color: var(--sidebar-ink); font-size: 13.5px;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.04); text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; border-left-color: var(--brand); }
.nav-sub { padding-left: 40px; font-size: 13px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 24px; position: sticky; top: 0; z-index: 5;
}
.topbar form.search { flex: 1; max-width: 420px; }
.topbar .search input {
  width: 100%; padding: 7px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); font-size: 13.5px;
}
.topbar .user-chip { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-soft); }
.topbar .user-chip .role { color: var(--brand); font-weight: 600; }
.notif-dot {
  position: absolute; top: -4px; right: -4px;
  background: var(--danger-fg); color: #fff; border-radius: 999px;
  font-size: 10px; font-weight: 700; line-height: 1; padding: 3px 4px; min-width: 14px; text-align: center;
}

.content { padding: 22px 24px 40px; max-width: 1320px; width: 100%; margin: 0 auto; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-head .crumbs { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 4px; }
.page-head .actions { display: flex; gap: 8px; }

/* ---------- Panels & tables (flat, hairline — not the rounded-card kit) ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
}
.panel > .panel-head {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.panel > .panel-body { padding: 16px; }

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.kpi a { color: inherit; display: block; }
.kpi a:hover { text-decoration: none; border-color: var(--border-strong); }
.kpi .value { font-size: 26px; font-weight: 700; line-height: 1; margin-bottom: 6px; }
.kpi .label { font-size: 12.5px; color: var(--ink-soft); }
.kpi.accent .value { color: var(--brand); }
.kpi.warn .value { color: var(--warn-fg); }
.kpi.danger .value { color: var(--danger-fg); }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-weight: 600; color: var(--ink-soft);
  padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
  background: #FAFBFC;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:hover td { background: #FAFBFC; }
.table-wrap { overflow-x: auto; }
.table-scroll-hint { display: none; }

/* ---------- Badges (colour + word, never colour alone) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-danger { background: var(--danger-bg); color: var(--danger-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }

/* ---------- Forms ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field-hint { font-size: 12px; color: var(--ink-soft); margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=file], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  font-family: inherit; font-size: 13.5px; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--ink-soft); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: var(--danger-fg); border-color: var(--danger-fg); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--ink-soft); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab:hover { text-decoration: none; color: var(--ink); }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li { position: relative; padding: 0 0 18px 20px; }
.timeline li::before {
  content: ''; position: absolute; left: -6px; top: 3px;
  width: 10px; height: 10px; border-radius: 50%; background: var(--brand); border: 2px solid #fff;
}
.timeline .t-date { font-size: 12px; color: var(--ink-soft); font-family: var(--font-mono); }
.timeline .t-title { font-weight: 600; margin: 2px 0; }
.timeline .t-note { font-size: 13px; color: var(--ink-soft); }

/* ---------- Alerts / flash ---------- */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 13.5px; border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); color: var(--ok-fg); border-color: #cdeed9; }
.alert-error { background: var(--danger-bg); color: var(--danger-fg); border-color: #f5d3cd; }
.alert-info { background: var(--info-bg); color: var(--info-fg); border-color: #d3e3f5; }

/* ---------- Login page ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--sidebar-bg); }
.login-card { width: 360px; background: var(--surface); border-radius: 8px; padding: 30px 28px; }
.login-card .brand-mark { width: 40px; height: 40px; border-radius: 8px; background: var(--brand); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.login-card h1 { font-size: 18px; }
.login-card p.sub { color: var(--ink-soft); font-size: 13px; margin: 0 0 20px; }
.login-demo { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--ink-soft); }

/* ---------- Utility ---------- */
.muted { color: var(--ink-soft); }
.small { font-size: 12.5px; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.flex { display: flex; align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-soft); }
.empty-state h3 { color: var(--ink); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: -240px; z-index: 20; transition: left .15s ease; box-shadow: 2px 0 12px rgba(0,0,0,0.2); }
  .sidebar.open { left: 0; }
  .app-shell { display: block; }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .topbar #sidebarToggle { display: inline-flex !important; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .page-head .actions, .tabs, form:not(.print-keep), .btn,
  .panel-body form, #themeToggle, .notif-dot { display: none !important; }
  body { background: #fff; color: #000; font-size: 12px; }
  .app-shell, .main, .content { display: block; width: 100%; padding: 0; margin: 0; }
  .panel { border: 1px solid #999; box-shadow: none; break-inside: avoid; margin-bottom: 10px; }
  .panel-head { background: #fff; border-bottom: 1px solid #999; }
  table.data th { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: #000; text-decoration: none; }
  .badge { border: 1px solid currentColor; background: #fff !important; color: #000 !important; }
  .timeline { border-left-color: #999; }
  .timeline li::before { background: #000; }
}
