/* =====================================================================
   PSVT Service Desk — application stylesheet
   Layered on top of Bootstrap 5.

   THEMING
   Every colour is a semantic token. Light values live on :root, dark
   values are redefined in two places:
     [data-theme="dark"]                          → explicit dark choice
     @media (prefers-color-scheme: dark) on :root:not([data-theme="light"])
                                                  → "Auto" following the OS
   Nothing else in this file hardcodes a colour, so adding a theme means
   redefining tokens and nothing more.
   ===================================================================== */

/* ---------------------------------------------------------------------
   LIGHT (default)
   --------------------------------------------------------------------- */
:root {
  /* brand */
  --brand:          #1e3a8a;
  --brand-600:      #1d4ed8;
  --brand-700:      #172554;
  --brand-fg:       #ffffff;
  --gold:           #c9a227;
  --gold-soft:      #f3e5b3;

  /* surfaces */
  --bg:             #f5f7fb;
  --surface:        #ffffff;
  --surface-2:      #f8fafc;
  --surface-3:      #eef2f7;
  --sidebar-bg:     #0f1f3d;
  --sidebar-fg:     rgba(255,255,255,.78);
  --sidebar-fg-dim: rgba(255,255,255,.40);
  --sidebar-active:  rgba(59,130,246,.20);
  --sidebar-hover:  rgba(255,255,255,.07);

  /* text */
  --text:           #0f172a;
  --text-2:         #334155;
  --text-muted:     #64748b;

  /* lines */
  --border:         #e2e8f0;
  --border-strong:  #cbd5e1;

  /* status — soft background + readable foreground */
  --st-blue-bg:     #dbeafe;  --st-blue-fg:   #1d4ed8;
  --st-amber-bg:    #fef3c7;  --st-amber-fg:  #b45309;
  --st-green-bg:    #d1fae5;  --st-green-fg:  #047857;
  --st-red-bg:      #fee2e2;  --st-red-fg:    #b91c1c;
  --st-grey-bg:     #e8edf3;  --st-grey-fg:   #52606d;
  --st-purple-bg:   #ede9fe;  --st-purple-fg: #6d28d9;
  --st-teal-bg:     #ccfbf1;  --st-teal-fg:   #0f766e;

  /* chart series (kept distinguishable in both themes) */
  --c1: #2563eb;  --c2: #22c55e;  --c3: #f59e0b;
  --c4: #8b5cf6;  --c5: #94a3b8;  --c6: #ef4444;
  --grid-line: #eef2f7;

  /* effects */
  --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
  --shadow:    0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 30px rgba(15,23,42,.12);

  /* metrics */
  --sidebar-w:      252px;
  --sidebar-w-mini: 74px;
  --header-h:       62px;
  --radius:         12px;
  --radius-sm:      8px;
}

/* ---------------------------------------------------------------------
   DARK — explicit choice
   --------------------------------------------------------------------- */
[data-theme="dark"] {
  --brand:          #3b82f6;
  --brand-600:      #60a5fa;
  --brand-700:      #1e40af;
  --brand-fg:       #ffffff;
  --gold:           #d4af37;
  --gold-soft:      #3a3320;

  --bg:             #0b1220;
  --surface:        #131c2e;
  --surface-2:      #182236;
  --surface-3:      #1e2a42;
  --sidebar-bg:     #0a1120;
  --sidebar-fg:     rgba(255,255,255,.74);
  --sidebar-fg-dim: rgba(255,255,255,.36);
  --sidebar-active: rgba(59,130,246,.22);
  --sidebar-hover:  rgba(255,255,255,.06);

  --text:           #e8eef8;
  --text-2:         #c2cde0;
  --text-muted:     #8b9bb4;

  --border:         #26334d;
  --border-strong:  #3a4a66;

  --st-blue-bg:     #17294a;  --st-blue-fg:   #7dabff;
  --st-amber-bg:    #3a2f14;  --st-amber-fg:  #f0b429;
  --st-green-bg:    #12331f;  --st-green-fg:  #4ade80;
  --st-red-bg:      #3a1a1d;  --st-red-fg:    #f87171;
  --st-grey-bg:     #232f45;  --st-grey-fg:   #9fb0c7;
  --st-purple-bg:   #291f4a;  --st-purple-fg: #b39dfa;
  --st-teal-bg:     #0f3330;  --st-teal-fg:   #45d6c0;

  --c1: #60a5fa;  --c2: #4ade80;  --c3: #fbbf24;
  --c4: #a78bfa;  --c5: #7c8ba3;  --c6: #f87171;
  --grid-line: #223049;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.40);
  --shadow:    0 1px 3px rgba(0,0,0,.45), 0 1px 2px rgba(0,0,0,.30);
  --shadow-lg: 0 12px 34px rgba(0,0,0,.55);

  color-scheme: dark;
}

/* ---------------------------------------------------------------------
   DARK — "Auto" following the operating system.
   Applies unless the user explicitly chose Light.
   --------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --brand:          #3b82f6;
    --brand-600:      #60a5fa;
    --brand-700:      #1e40af;
    --gold:           #d4af37;
    --gold-soft:      #3a3320;

    --bg:             #0b1220;
    --surface:        #131c2e;
    --surface-2:      #182236;
    --surface-3:      #1e2a42;
    --sidebar-bg:     #0a1120;
    --sidebar-fg:     rgba(255,255,255,.74);
    --sidebar-fg-dim: rgba(255,255,255,.36);
    --sidebar-active: rgba(59,130,246,.22);
    --sidebar-hover:  rgba(255,255,255,.06);

    --text:           #e8eef8;
    --text-2:         #c2cde0;
    --text-muted:     #8b9bb4;

    --border:         #26334d;
    --border-strong:  #344566;

    --st-blue-bg:     #17294a;  --st-blue-fg:   #7dabff;
    --st-amber-bg:    #3a2f14;  --st-amber-fg:  #f0b429;
    --st-green-bg:    #12331f;  --st-green-fg:  #4ade80;
    --st-red-bg:      #3a1a1d;  --st-red-fg:    #f87171;
    --st-grey-bg:     #232f45;  --st-grey-fg:   #9fb0c7;
    --st-purple-bg:   #291f4a;  --st-purple-fg: #b39dfa;
    --st-teal-bg:     #0f3330;  --st-teal-fg:   #45d6c0;

    --c1: #60a5fa;  --c2: #4ade80;  --c3: #fbbf24;
    --c4: #a78bfa;  --c5: #7c8ba3;  --c6: #f87171;
    --grid-line: #223049;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.40);
    --shadow:    0 1px 3px rgba(0,0,0,.45), 0 1px 2px rgba(0,0,0,.30);
    --shadow-lg: 0 12px 34px rgba(0,0,0,.55);

    color-scheme: dark;
  }
}

/* =====================================================================
   BASE
   ===================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial,
               "Noto Sans Khmer", "Khmer OS Battambang",
               "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  min-height: 100vh;
  transition: background-color .18s ease, color .18s ease;
}

/* Khmer needs more line height; Chinese is fine at the default. */
body.lang-kh, .khmer, :lang(km) {
  font-family: "Noto Sans Khmer", "Khmer OS Battambang", "Segoe UI", sans-serif;
  line-height: 1.85;
}
body.lang-zh, :lang(zh) {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC",
               "Hiragino Sans GB", "Segoe UI", sans-serif;
}

a { text-decoration: none; color: var(--brand-600); }
a:hover { color: var(--brand); }
hr { border-color: var(--border); opacity: 1; }

::selection { background: var(--brand); color: #fff; }

/* Bootstrap surface overrides so components follow the theme */
.bg-white     { background: var(--surface) !important; }
.text-muted   { color: var(--text-muted) !important; }
.text-dark    { color: var(--text) !important; }
.border       { border-color: var(--border) !important; }
.bg-light     { background: var(--surface-3) !important; color: var(--text-2) !important; }
.dropdown-menu {
  background: var(--surface); border-color: var(--border);
  box-shadow: var(--shadow-lg); border-radius: var(--radius-sm);
}
.dropdown-item { color: var(--text-2); border-radius: 6px; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--surface-3); color: var(--text); }
.dropdown-item.active, .dropdown-item:active { background: var(--brand); color: #fff; }
.dropdown-header { color: var(--text-muted); }
.dropdown-divider { border-color: var(--border); }
.modal-content { background: var(--surface); color: var(--text); border-color: var(--border); }
.modal-header, .modal-footer { border-color: var(--border); }
.btn-close { filter: var(--close-filter, none); }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(1) brightness(2); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) .btn-close {
    filter: invert(1) grayscale(1) brightness(2);
  }
}

/* =====================================================================
   LAYOUT
   ===================================================================== */
.app-header {
  position: fixed; inset: 0 0 auto 0; height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .6rem;
  padding: 0 .9rem; z-index: 1040;
}

.app-brand {
  display: flex; align-items: center; gap: .65rem;
  width: calc(var(--sidebar-w) - 1.5rem);
  color: var(--text); white-space: nowrap; overflow: hidden;
  transition: width .2s ease;
}
.app-brand:hover { color: var(--text); }
.brand-text { line-height: 1.15; }
.brand-name { font-weight: 800; font-size: .98rem; letter-spacing: -.01em; }
.brand-sub  { font-size: .68rem; color: var(--text-muted); }

.logo-mark {
  width: 38px; height: 38px; border-radius: 10px; flex: 0 0 38px;
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
  color: var(--gold);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .68rem; letter-spacing: .5px; line-height: 1;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}

.app-sidebar {
  position: fixed; top: var(--header-h); bottom: 0; left: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  overflow-y: auto; overflow-x: hidden;
  z-index: 1035;
  transition: transform .22s ease, width .2s ease;
  display: flex; flex-direction: column;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent;
}
.app-sidebar::-webkit-scrollbar { width: 6px; }
.app-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 3px; }

.app-main {
  margin-left: var(--sidebar-w);
  padding: calc(var(--header-h) + 1.15rem) 1.15rem 3rem;
  min-height: 100vh;
  transition: margin-left .2s ease;
}

/* ---------- collapsed (desktop mini rail) ---------- */
body.sidebar-mini .app-sidebar { width: var(--sidebar-w-mini); }
body.sidebar-mini .app-main    { margin-left: var(--sidebar-w-mini); }
body.sidebar-mini .app-brand   { width: calc(var(--sidebar-w-mini) - 1.5rem); }
body.sidebar-mini .brand-text,
body.sidebar-mini .nav-section,
body.sidebar-mini .app-sidebar .nav-link span,
body.sidebar-mini .app-sidebar .nav-link .badge,
body.sidebar-mini .sidebar-footer .foot-text,
body.sidebar-mini .collapse-label { display: none; }
body.sidebar-mini .app-sidebar .nav-link { justify-content: center; padding-inline: 0; }
body.sidebar-mini .nav-section { display: block; height: 12px; padding: 0; }

/* =====================================================================
   SIDEBAR NAV
   ===================================================================== */
.nav-section {
  color: var(--sidebar-fg-dim);
  font-size: .67rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase;
  padding: 1.05rem 1.15rem .35rem;
}

.app-sidebar .nav-link {
  color: var(--sidebar-fg);
  padding: .58rem 1.15rem;
  display: flex; align-items: center; gap: .72rem;
  border-left: 3px solid transparent;
  font-size: .875rem; border-radius: 0;
}
.app-sidebar .nav-link i { width: 18px; text-align: center; font-size: 1.02rem; flex: 0 0 18px; }
.app-sidebar .nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.app-sidebar .nav-link.active {
  background: var(--sidebar-active);
  border-left-color: var(--brand-600);
  color: #fff; font-weight: 600;
}
.app-sidebar .nav-link .badge {
  margin-left: auto; font-weight: 600; font-size: .68rem;
  background: rgba(255,255,255,.14); color: #fff;
}
.app-sidebar .nav-link.active .badge { background: var(--brand-600); }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,.08);
  padding: .7rem 1.15rem;
}
.sidebar-collapse-btn {
  background: none; border: 0; width: 100%;
  color: var(--sidebar-fg-dim); font-size: .78rem;
  display: flex; align-items: center; gap: .7rem;
  padding: .35rem 0; letter-spacing: .06em; text-transform: uppercase;
}
.sidebar-collapse-btn:hover { color: #fff; }
.sidebar-collapse-btn i { width: 18px; text-align: center; font-size: 1rem; }

/* backdrop behind the off-canvas sidebar on small screens */
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(2,6,23,.55);
  z-index: 1030; opacity: 0; pointer-events: none; transition: opacity .2s ease;
  backdrop-filter: blur(2px);
}
.sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); width: 280px; }
  .app-sidebar.show { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .app-main { margin-left: 0; padding-inline: .8rem; }
  .app-brand { width: auto; }
  body.sidebar-mini .app-main { margin-left: 0; }
  .sidebar-footer .sidebar-collapse-btn { display: none; }
}

/* =====================================================================
   CARDS & PAGE HEADINGS
   ===================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  color: var(--text);
}
.card-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-weight: 650;
  padding: .8rem 1rem;
  border-radius: var(--radius) var(--radius) 0 0 !important;
}
.card-footer { background: var(--surface); border-top: 1px solid var(--border); }

.page-title { font-size: 1.4rem; font-weight: 750; color: var(--text); margin: 0; letter-spacing: -.015em; }
.page-sub   { color: var(--text-muted); font-size: .85rem; margin: .18rem 0 0; }

/* ---------- welcome banner ---------- */
.welcome-bar {
  display: flex; flex-wrap: wrap; gap: 1rem;
  align-items: center; justify-content: space-between;
  margin-bottom: 1.15rem;
}
.welcome-title { font-size: 1.42rem; font-weight: 750; color: var(--text); margin: 0; letter-spacing: -.015em; }
.welcome-sub   { color: var(--text-muted); font-size: .875rem; margin: .2rem 0 0; }
.welcome-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* =====================================================================
   KPI TILES
   ===================================================================== */
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
  height: 100%; display: flex; align-items: flex-start; gap: .85rem;
  box-shadow: var(--shadow-sm);
}
.kpi-icon {
  width: 52px; height: 52px; border-radius: 50%; flex: 0 0 52px;
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.kpi-body { min-width: 0; }
.kpi-label { color: var(--text-muted); font-size: .8rem; font-weight: 500; margin-bottom: .15rem; }
.kpi-value { font-size: 1.75rem; font-weight: 750; color: var(--text); line-height: 1.15; letter-spacing: -.02em; }
.kpi-value.sm { font-size: 1.3rem; }
.kpi-foot { font-size: .74rem; color: var(--text-muted); margin-top: .1rem; }

.trend { font-size: .78rem; font-weight: 650; display: inline-flex; align-items: center; gap: .12rem; }
.trend-up   { color: var(--st-green-fg); }
.trend-down { color: var(--st-red-fg); }
.trend-flat { color: var(--text-muted); }

.bg-soft-primary { background: var(--st-blue-bg);   color: var(--st-blue-fg); }
.bg-soft-warning { background: var(--st-amber-bg);  color: var(--st-amber-fg); }
.bg-soft-success { background: var(--st-green-bg);  color: var(--st-green-fg); }
.bg-soft-danger  { background: var(--st-red-bg);    color: var(--st-red-fg); }
.bg-soft-info    { background: var(--st-teal-bg);   color: var(--st-teal-fg); }
.bg-soft-purple  { background: var(--st-purple-bg); color: var(--st-purple-fg); }
.bg-soft-navy    { background: var(--st-grey-bg);   color: var(--st-grey-fg); }

/* =====================================================================
   TABLES
   ===================================================================== */
.table {
  font-size: .875rem; margin-bottom: 0;
  --bs-table-bg: transparent;
  --bs-table-color: var(--text);
  color: var(--text);
}
.table > thead > tr > th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; padding: .7rem .8rem;
}
.table > tbody > tr > td {
  padding: .7rem .8rem; vertical-align: middle;
  border-bottom-color: var(--border); color: var(--text);
}
.table > tbody > tr:last-child > td { border-bottom: 0; }
.table-hover > tbody > tr:hover > * { background: var(--surface-2); color: var(--text); }
.table-light, .table-light > * { background: var(--surface-2) !important; color: var(--text) !important; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.doc-no {
  font-family: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
  font-size: .8rem; font-weight: 650; white-space: nowrap; color: var(--text);
}
a.doc-no { color: var(--brand-600); }

.cell-title { font-weight: 600; color: var(--text); }
.cell-sub   { font-size: .76rem; color: var(--text-muted); }

/* Keep list tables on one line per row: the wrapper scrolls sideways
   rather than squeezing every column into an unreadable stack. */
.table-list { min-width: 860px; }
.table-list .truncate {
  display: block; max-width: 260px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.table-list .truncate-sm { max-width: 180px; }
.table-list .truncate-lg { max-width: 340px; }

/* Narrower variant for tables that sit inside a dashboard column. */
.table-compact { min-width: 660px; }
.table-compact .truncate { max-width: 190px; }
.table-compact > thead > tr > th,
.table-compact > tbody > tr > td { padding: .6rem .55rem; }

@media (max-width: 767.98px) {
  .table-cards.table-list { min-width: 0; }
  .table-cards .truncate,
  .table-cards .truncate-sm,
  .table-cards .truncate-lg { max-width: none; white-space: normal; }
}

/* person cell — avatar + name */
.person { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.person .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* =====================================================================
   BADGES
   ===================================================================== */
.badge-status {
  display: inline-block; padding: .24rem .58rem;
  border-radius: 999px; font-size: .72rem; font-weight: 650;
  line-height: 1.45; white-space: nowrap;
}
.badge-open      { background: var(--st-blue-bg);   color: var(--st-blue-fg); }
.badge-progress  { background: var(--st-amber-bg);  color: var(--st-amber-fg); }
.badge-waiting   { background: var(--st-purple-bg); color: var(--st-purple-fg); }
.badge-resolved  { background: var(--st-green-bg);  color: var(--st-green-fg); }
.badge-closed    { background: var(--st-grey-bg);   color: var(--st-grey-fg); }
.badge-draft     { background: var(--st-grey-bg);   color: var(--st-grey-fg); }
.badge-pending   { background: var(--st-amber-bg);  color: var(--st-amber-fg); }
.badge-approved  { background: var(--st-green-bg);  color: var(--st-green-fg); }
.badge-rejected  { background: var(--st-red-bg);    color: var(--st-red-fg); }
.badge-review    { background: var(--st-blue-bg);   color: var(--st-blue-fg); }
.badge-low       { background: var(--st-grey-bg);   color: var(--st-grey-fg); }
.badge-medium    { background: var(--st-amber-bg);  color: var(--st-amber-fg); }
.badge-high      { background: var(--st-red-bg);    color: var(--st-red-fg); }
.badge-teal      { background: var(--st-teal-bg);   color: var(--st-teal-fg); }

.dot-legend { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: 0 0 9px; }

/* =====================================================================
   BUTTONS
   ===================================================================== */
.btn { border-radius: var(--radius-sm); font-weight: 550; }
.btn-sm { font-size: .8rem; border-radius: 7px; }

.btn-navy, .btn-primary {
  background: var(--brand); border-color: var(--brand); color: var(--brand-fg);
}
.btn-navy:hover, .btn-navy:focus, .btn-primary:hover, .btn-primary:focus {
  background: var(--brand-700); border-color: var(--brand-700); color: #fff;
}
[data-theme="dark"] .btn-navy:hover { background: var(--brand-600); border-color: var(--brand-600); }

.btn-gold { background: var(--gold); border-color: var(--gold); color: #23200f; font-weight: 650; }
.btn-gold:hover { background: #b8931f; border-color: #b8931f; color: #23200f; }

.btn-soft-primary { background: var(--st-blue-bg); color: var(--st-blue-fg); border: 0; font-weight: 600; }
.btn-soft-primary:hover { background: var(--st-blue-bg); color: var(--st-blue-fg); filter: brightness(.95); }

.btn-outline-secondary {
  color: var(--text-2); border-color: var(--border-strong); background: var(--surface);
}
.btn-outline-secondary:hover, .btn-outline-secondary.active {
  background: var(--surface-3); color: var(--text); border-color: var(--border-strong);
}
.btn-light { background: var(--surface-3); border-color: transparent; color: var(--text-2); }
.btn-light:hover { background: var(--surface-3); color: var(--text); filter: brightness(.96); }

/* =====================================================================
   FORMS
   ===================================================================== */
.form-label { font-size: .8rem; font-weight: 600; color: var(--text-2); margin-bottom: .3rem; }
.form-control, .form-select {
  font-size: .875rem; background: var(--surface); color: var(--text);
  border-color: var(--border-strong); border-radius: var(--radius-sm);
}
.form-control:focus, .form-select:focus {
  background: var(--surface); color: var(--text);
  border-color: var(--brand-600); box-shadow: 0 0 0 3px rgba(37,99,235,.14);
}
.form-control::placeholder { color: var(--text-muted); opacity: .8; }
.form-control:disabled, .form-control[readonly] { background: var(--surface-3); color: var(--text-muted); }
.input-group-text { background: var(--surface-3); border-color: var(--border-strong); color: var(--text-muted); }
.form-check-input { background-color: var(--surface); border-color: var(--border-strong); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-text { color: var(--text-muted); }
.required::after { content: " *"; color: var(--st-red-fg); }

/* dark-mode date pickers and dropdown arrows */
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1) brightness(1.6); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1) brightness(1.6);
  }
}

/* =====================================================================
   TABS
   ===================================================================== */
.nav-tabs { border-bottom: 1px solid var(--border); padding: 0 .35rem; }
.nav-tabs .nav-link {
  border: 0; border-bottom: 2px solid transparent;
  color: var(--text-muted); font-weight: 600; font-size: .875rem;
  padding: .75rem .95rem; border-radius: 0;
}
.nav-tabs .nav-link:hover { color: var(--text); border-bottom-color: var(--border-strong); }
.nav-tabs .nav-link.active {
  background: transparent; color: var(--brand-600);
  border-bottom-color: var(--brand-600);
}

/* =====================================================================
   LOGIN
   ===================================================================== */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0a1120 0%, #16305a 55%, #1d4a76 100%);
  padding: 1.25rem;
}
.login-card {
  width: 100%; max-width: 960px; background: var(--surface);
  border-radius: 16px; overflow: hidden; box-shadow: 0 24px 60px rgba(0,0,0,.4);
  display: grid; grid-template-columns: 1fr 1fr;
}
.login-side {
  background: linear-gradient(160deg, #16305a 0%, #0a1120 100%);
  color: #fff; padding: 2.5rem;
  display: flex; flex-direction: column; justify-content: center;
}
.login-side h1 { font-size: 1.55rem; font-weight: 750; }
.login-side .lead-sm { color: rgba(255,255,255,.72); font-size: .9rem; }
.login-side ul { list-style: none; padding: 0; margin: 1.5rem 0 0; }
.login-side li { padding: .32rem 0; color: rgba(255,255,255,.88); font-size: .875rem; }
.login-side li i { color: var(--gold); margin-right: .5rem; }
.login-form { padding: 2.5rem; }

@media (max-width: 767.98px) {
  .login-card { grid-template-columns: 1fr; max-width: 460px; }
  .login-side { display: none; }
  .login-form { padding: 1.75rem 1.35rem; }
}

/* =====================================================================
   APPROVAL TIMELINE
   ===================================================================== */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 13px; top: 6px; bottom: 6px;
  width: 2px; background: var(--border);
}
.timeline li { position: relative; padding: 0 0 1.1rem 2.4rem; }
.timeline li:last-child { padding-bottom: 0; }
.timeline .dot {
  position: absolute; left: 0; top: 1px;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem; background: var(--surface-3); color: var(--text-muted);
  border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border);
}
.timeline .dot.approved { background: var(--st-green-bg); color: var(--st-green-fg); box-shadow: 0 0 0 1px var(--st-green-fg); }
.timeline .dot.rejected { background: var(--st-red-bg);   color: var(--st-red-fg);   box-shadow: 0 0 0 1px var(--st-red-fg); }
.timeline .dot.active   { background: var(--gold); color: #23200f; box-shadow: 0 0 0 3px var(--gold-soft); }
.timeline .step-name { font-weight: 620; color: var(--text); }
.timeline .step-meta { font-size: .78rem; color: var(--text-muted); }

/* =====================================================================
   COMMENTS & AVATARS
   ===================================================================== */
.comment { display: flex; gap: .75rem; padding: .8rem 0; border-bottom: 1px dashed var(--border); }
.comment:last-child { border-bottom: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 36px;
  background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem; line-height: 1; user-select: none;
}
.avatar-sm { width: 28px; height: 28px; flex: 0 0 28px; font-size: .68rem; }
.avatar-lg { width: 72px; height: 72px; flex: 0 0 72px; font-size: 1.6rem; }
/* deterministic tints so the same person keeps the same colour */
.avatar.c0 { background: var(--c1); } .avatar.c1 { background: var(--c2); color: #06301a; }
.avatar.c2 { background: var(--c3); color: #3a2a05; } .avatar.c3 { background: var(--c4); }
.avatar.c4 { background: var(--c5); } .avatar.c5 { background: var(--c6); }
.comment-system .avatar { background: var(--st-grey-fg); }
.comment-body { font-size: .875rem; white-space: pre-wrap; color: var(--text-2); }
.comment-meta { font-size: .76rem; color: var(--text-muted); }

/* =====================================================================
   MISC
   ===================================================================== */
.progress { height: 8px; background: var(--surface-3); border-radius: 999px; }
.progress-bar { border-radius: 999px; }
.bg-success { background: var(--st-green-fg) !important; }
.bg-warning { background: var(--st-amber-fg) !important; }
.bg-danger  { background: var(--st-red-fg) !important; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 2.2rem; opacity: .4; display: block; margin-bottom: .6rem; }

.stat-line { display: flex; justify-content: space-between; gap: 1rem; font-size: .82rem; padding: .28rem 0; }
.stat-line .k { color: var(--text-muted); }
.stat-line .v { font-weight: 620; color: var(--text); text-align: right; }

.chart-box { position: relative; height: 268px; }
.chart-box.tall { height: 320px; }

.alert { border-radius: var(--radius-sm); border-width: 1px; }
.alert-light { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.alert-warning { background: var(--st-amber-bg); color: var(--st-amber-fg); border-color: transparent; }
.alert-danger  { background: var(--st-red-bg);   color: var(--st-red-fg);   border-color: transparent; }
.alert-success { background: var(--st-green-bg); color: var(--st-green-fg); border-color: transparent; }
.alert-info    { background: var(--st-blue-bg);  color: var(--st-blue-fg);  border-color: transparent; }
.bg-warning-subtle { background: var(--st-amber-bg) !important; color: var(--st-amber-fg) !important; }

.pagination .page-link {
  background: var(--surface); border-color: var(--border); color: var(--text-2);
}
.pagination .page-link:hover { background: var(--surface-3); color: var(--text); }
.pagination .page-item.active .page-link { background: var(--brand); border-color: var(--brand); color: #fff; }

.list-group-item { background: var(--surface); border-color: var(--border); color: var(--text); }

code { color: var(--st-red-fg); background: var(--surface-3); padding: .1rem .3rem; border-radius: 4px; }

/* legend rows next to a doughnut */
.legend-list { list-style: none; margin: 0; padding: 0; }
.legend-list li {
  display: flex; align-items: center; gap: .5rem;
  padding: .3rem 0; font-size: .84rem; color: var(--text-2);
}
.legend-list .pct { margin-left: auto; font-weight: 650; color: var(--text); }

/* =====================================================================
   MOBILE — tables become stacked cards
   ===================================================================== */
@media (max-width: 767.98px) {
  body { font-size: 14px; }
  .page-title, .welcome-title { font-size: 1.2rem; }
  .kpi { padding: .8rem; gap: .7rem; }
  .kpi-icon { width: 42px; height: 42px; flex: 0 0 42px; font-size: 1.1rem; }
  .kpi-value { font-size: 1.35rem; }
  .kpi-value.sm { font-size: 1.05rem; }
  .chart-box { height: 240px; }
  .welcome-actions { width: 100%; }
  .welcome-actions .btn { flex: 1 1 auto; }

  /* Any table marked .table-cards reflows into one card per row.
     Each cell shows its column name from the data-label attribute. */
  .table-cards > thead { display: none; }
  .table-cards, .table-cards > tbody, .table-cards > tbody > tr, .table-cards > tbody > tr > td {
    display: block; width: 100%;
  }
  .table-cards > tbody > tr {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: .6rem; padding: .3rem .1rem;
  }
  .table-cards > tbody > tr > td {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    border: 0; padding: .38rem .8rem; text-align: right;
  }
  .table-cards > tbody > tr > td::before {
    content: attr(data-label);
    font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .04em; color: var(--text-muted);
    text-align: left; flex: 0 0 auto;
  }
  .table-cards > tbody > tr > td:empty { display: none; }
  .table-cards > tbody > tr > td.cell-main {
    display: block; text-align: left;
    border-bottom: 1px solid var(--border); padding-bottom: .5rem; margin-bottom: .25rem;
  }
  .table-cards > tbody > tr > td.cell-main::before { display: block; margin-bottom: .15rem; }
  .table-cards .person { justify-content: flex-end; }
  .table-cards tfoot td { display: table-cell; }

  /* comfortable tap targets */
  .btn, .form-control, .form-select { min-height: 40px; }
  .btn-sm { min-height: 34px; }
  .table-cards .btn-sm { min-height: 32px; }
}

@media (max-width: 575.98px) {
  .app-main { padding-inline: .6rem; }
  .card-header { padding: .7rem .8rem; }

  /* The header runs out of room once every control is shown, and a
     half-clipped logo looks broken — drop the brand, keep the controls. */
  .app-brand { display: none; }
  .app-header { padding-inline: .55rem; gap: .4rem; }
}

/* =====================================================================
   PRINT
   ===================================================================== */
@media print {
  .app-header, .app-sidebar, .sidebar-backdrop, .no-print { display: none !important; }
  .app-main { margin: 0; padding: 0; }
  body { background: #fff; color: #000; font-size: 12px; }
  .card { border: none; box-shadow: none; }
  .print-sheet { max-width: 100%; }
  a { color: #000; }
  @page { size: A4; margin: 14mm; }
}

.print-sheet { background: var(--surface); padding: 2rem; }
.print-header { border-bottom: 3px double var(--brand); padding-bottom: 1rem; margin-bottom: 1.5rem; }
.sign-block { border-top: 1px solid var(--text-muted); margin-top: 3.2rem; padding-top: .4rem; font-size: .8rem; text-align: center; }

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