/* ============================================================================
   FinBill Admin — design system
   Fintech operations console. Emerald accent over cool slate neutrals.
   Dual theme: server-driven via [data-theme] on <html>, OS fallback via
   prefers-color-scheme. All values are tokens; components consume tokens only.
   ========================================================================== */

/* ---- Design tokens : LIGHT (default) ------------------------------------ */
:root {
  /* surfaces */
  --bg:            #f5f7fa;
  --bg-grad:       radial-gradient(1200px 600px at 100% -10%, #eef2f7 0%, transparent 60%);
  --surface:       #ffffff;
  --surface-2:     #f1f4f8;
  --surface-3:     #e8edf3;
  --surface-inset: #f7f9fc;

  /* text */
  --text:        #0f172a;
  --text-muted:  #5a677b;
  --text-faint:  #93a1b3;
  --text-invert: #ffffff;

  /* lines */
  --border:        #e3e8ef;
  --border-strong: #cdd5e0;

  /* accent (emerald = money) */
  --accent:        #059669;
  --accent-hover:  #047857;
  --accent-press:  #036148;
  --accent-text:   #047857;            /* readable accent for links/text */
  --accent-ink:    #ffffff;            /* text on accent fill */
  --accent-weak:   #ecfdf5;
  --accent-weak-bd:#a7f3d0;
  --accent-weak-tx:#065f46;
  --ring:          color-mix(in srgb, var(--accent) 38%, transparent);

  /* semantic */
  --ok-bg:#e9faf2; --ok-tx:#06633f; --ok-dot:#10b981;
  --warn-bg:#fff6e6; --warn-tx:#8a5200; --warn-dot:#f59e0b;
  --danger-bg:#fdecec; --danger-tx:#a01818; --danger-dot:#ef4444;
  --info-bg:#eaf1ff; --info-tx:#1d47c4; --info-dot:#3b82f6;
  --neutral-bg:#eef1f5; --neutral-tx:#516074; --neutral-dot:#9aa7b8;

  /* effects */
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 1px rgba(15,23,42,.03);
  --shadow-md: 0 6px 16px -6px rgba(15,23,42,.12), 0 2px 6px -2px rgba(15,23,42,.06);
  --shadow-lg: 0 24px 48px -16px rgba(15,23,42,.22), 0 8px 18px -10px rgba(15,23,42,.12);
  --shadow-pop: 0 12px 32px -8px rgba(15,23,42,.20);

  /* shape scale (locked): inputs/buttons 9px · cards 14px · pills full */
  --r-xs: 6px;
  --r-sm: 9px;
  --r:    12px;
  --r-lg: 16px;
  --r-pill: 999px;

  /* type */
  --font-sans: "Inter var", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code",
               Menlo, Consolas, "Liberation Mono", monospace;

  /* metrics */
  --sidebar-w: 264px;
  --topbar-h:  62px;
  --content-max: 1320px;

  /* z-scale */
  --z-topbar: 50;
  --z-overlay: 55;
  --z-sidebar: 60;

  --tr: 160ms cubic-bezier(.4,0,.2,1);
  color-scheme: light;
}

/* ---- Design tokens : DARK ------------------------------------------------ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0a0e14;
    --bg-grad:       radial-gradient(1200px 620px at 100% -10%, #11202a 0%, transparent 58%);
    --surface:       #111722;
    --surface-2:     #161d29;
    --surface-3:     #1d2634;
    --surface-inset: #0e141d;

    --text:        #e8eef6;
    --text-muted:  #94a3b6;
    --text-faint:  #5d6b7e;
    --text-invert: #0a0e14;

    --border:        #222c3a;
    --border-strong: #314153;

    --accent:        #10b981;
    --accent-hover:  #34d399;
    --accent-press:  #059669;
    --accent-text:   #4ade9f;
    --accent-ink:    #04140e;
    --accent-weak:   rgba(16,185,129,.13);
    --accent-weak-bd:rgba(16,185,129,.34);
    --accent-weak-tx:#6ee7b7;
    --ring:          color-mix(in srgb, var(--accent) 50%, transparent);

    --ok-bg:rgba(16,185,129,.13); --ok-tx:#6ee7b7; --ok-dot:#10b981;
    --warn-bg:rgba(245,158,11,.14); --warn-tx:#fcd34d; --warn-dot:#f59e0b;
    --danger-bg:rgba(239,68,68,.14); --danger-tx:#fca5a5; --danger-dot:#ef4444;
    --info-bg:rgba(59,130,246,.15); --info-tx:#93c5fd; --info-dot:#60a5fa;
    --neutral-bg:rgba(148,163,184,.13); --neutral-tx:#aab6c6; --neutral-dot:#8593a6;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 8px 22px -8px rgba(0,0,0,.55), 0 2px 6px -2px rgba(0,0,0,.4);
    --shadow-lg: 0 28px 56px -18px rgba(0,0,0,.7);
    --shadow-pop: 0 14px 34px -8px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg:            #0a0e14;
  --bg-grad:       radial-gradient(1200px 620px at 100% -10%, #11202a 0%, transparent 58%);
  --surface:       #111722;
  --surface-2:     #161d29;
  --surface-3:     #1d2634;
  --surface-inset: #0e141d;

  --text:        #e8eef6;
  --text-muted:  #94a3b6;
  --text-faint:  #5d6b7e;
  --text-invert: #0a0e14;

  --border:        #222c3a;
  --border-strong: #314153;

  --accent:        #10b981;
  --accent-hover:  #34d399;
  --accent-press:  #059669;
  --accent-text:   #4ade9f;
  --accent-ink:    #04140e;
  --accent-weak:   rgba(16,185,129,.13);
  --accent-weak-bd:rgba(16,185,129,.34);
  --accent-weak-tx:#6ee7b7;
  --ring:          color-mix(in srgb, var(--accent) 50%, transparent);

  --ok-bg:rgba(16,185,129,.13); --ok-tx:#6ee7b7; --ok-dot:#10b981;
  --warn-bg:rgba(245,158,11,.14); --warn-tx:#fcd34d; --warn-dot:#f59e0b;
  --danger-bg:rgba(239,68,68,.14); --danger-tx:#fca5a5; --danger-dot:#ef4444;
  --info-bg:rgba(59,130,246,.15); --info-tx:#93c5fd; --info-dot:#60a5fa;
  --neutral-bg:rgba(148,163,184,.13); --neutral-tx:#aab6c6; --neutral-dot:#8593a6;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 8px 22px -8px rgba(0,0,0,.55), 0 2px 6px -2px rgba(0,0,0,.4);
  --shadow-lg: 0 28px 56px -18px rgba(0,0,0,.7);
  --shadow-pop: 0 14px 34px -8px rgba(0,0,0,.6);
  color-scheme: dark;
}

/* ---- Reset & base ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv02","cv03","cv04","ss01","tnum" 0;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code, .mono { font-family: var(--font-mono); font-size: .86em; }
h1, h2, h3 { color: var(--text); letter-spacing: -.012em; }
h1 { margin: 0 0 1.1rem; font-size: 1.5rem; font-weight: 680; }
h2 { margin: 1.9rem 0 .85rem; font-size: 1.12rem; font-weight: 650; }
p { margin: 0 0 .7rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }
::selection { background: color-mix(in srgb, var(--accent) 26%, transparent); }

svg.icon { width: 1.25em; height: 1.25em; flex: none; stroke-width: 1.75; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 200;
  background: var(--accent); color: var(--accent-ink);
  padding: .6rem 1rem; border-radius: 0 0 var(--r-sm) 0; font-weight: 600;
}
.skip-link:focus { left: 0; text-decoration: none; }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ========================================================================== */
/*  APP SHELL                                                                 */
/* ========================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "sidebar topbar" "sidebar main";
  min-height: 100dvh;
}

/* ---- Sidebar ------------------------------------------------------------ */
.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sidebar__brand {
  display: flex; align-items: center; gap: .65rem;
  height: var(--topbar-h); flex: none;
  padding: 0 1.15rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 1.02rem; letter-spacing: -.02em;
  color: var(--text);
}
.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px; flex: none;
  border-radius: 8px;
  background: linear-gradient(150deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #0b3));
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35), var(--shadow-sm);
}
.brand-mark svg { width: 18px; height: 18px; stroke-width: 2; }
.sidebar__brand b { font-weight: 750; }
.sidebar__brand span { color: var(--text-faint); font-weight: 600; }

.sidebar__nav { display: flex; flex-direction: column; padding: .85rem .65rem; gap: .12rem; flex: 1; }
.nav-group { margin-top: .55rem; }
.nav-group:first-child { margin-top: 0; }
.nav-group__label {
  padding: .5rem .7rem .3rem;
  font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint);
}
.sidebar__link {
  display: flex; align-items: center; gap: .7rem;
  padding: .56rem .7rem;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-weight: 550; font-size: .92rem;
  position: relative;
  transition: background var(--tr), color var(--tr);
}
.sidebar__link svg { color: var(--text-faint); transition: color var(--tr); }
.sidebar__link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar__link:hover svg { color: var(--text-muted); }
.sidebar__link--active {
  background: var(--accent-weak);
  color: var(--accent-weak-tx);
  font-weight: 650;
}
.sidebar__link--active svg { color: var(--accent); }
.sidebar__link--active::before {
  content: ""; position: absolute; left: -.65rem; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.sidebar__foot {
  flex: none; padding: .8rem .9rem;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: .65rem;
}

/* ---- Avatar ------------------------------------------------------------- */
.avatar {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: var(--r-pill);
  background: var(--surface-3); color: var(--text);
  font-size: .78rem; font-weight: 700; letter-spacing: .02em;
  border: 1px solid var(--border);
}
.avatar--accent { background: var(--accent-weak); color: var(--accent-weak-tx); border-color: var(--accent-weak-bd); }
.idblock { min-width: 0; line-height: 1.25; }
.idblock__name { font-weight: 620; font-size: .87rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.idblock__sub { font-size: .74rem; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Topbar ------------------------------------------------------------- */
.topbar {
  grid-area: topbar;
  position: sticky; top: 0; z-index: var(--z-topbar);
  display: flex; align-items: center; gap: .75rem;
  height: var(--topbar-h);
  padding: 0 1.4rem;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__menu { display: none; }
.topbar__brand-m { display: none; align-items: center; gap: .5rem; font-weight: 700; }
.topbar__spacer { flex: 1; }
.topbar__crumb { font-size: .82rem; color: var(--text-faint); font-weight: 550; }
.topbar__crumb b { color: var(--text-muted); font-weight: 650; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text-muted);
  cursor: pointer; transition: background var(--tr), color var(--tr), border-color var(--tr);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.icon-btn:active { transform: translateY(1px); }

/* theme toggle — shows the icon for the CURRENT effective theme
   (sun = light, moon = dark). Cases are mutually exclusive. */
.theme-toggle { position: relative; }
.theme-toggle .icon-sun, .theme-toggle .icon-moon { display: inline-grid; place-items: center; }
.theme-toggle .icon-sun  { display: inline-grid; }   /* default: light */
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: inline-grid; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .icon-sun  { display: none; }
  :root:not([data-theme]) .theme-toggle .icon-moon { display: inline-grid; }
}

/* user chip */
.user-chip {
  display: flex; align-items: center; gap: .6rem;
  padding: .25rem .3rem .25rem .25rem;
}
.user-chip .idblock { display: none; }
@media (min-width: 720px) { .user-chip .idblock { display: block; max-width: 180px; } }
.logout-form { display: inline-flex; }

/* ---- Content ------------------------------------------------------------ */
.content {
  grid-area: main;
  padding: 1.7rem clamp(1rem, 3vw, 2.2rem) 3rem;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  animation: page-in .32s cubic-bezier(.16,1,.3,1) both;
}
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  margin-bottom: 1.3rem;
}
.page-head h1 { margin: 0; }
.page-head__sub { margin: .25rem 0 0; color: var(--text-muted); font-size: .92rem; }
.page-head__actions { display: flex; gap: .5rem; flex-wrap: wrap; flex: none; }

/* ========================================================================== */
/*  METRIC CARDS                                                              */
/* ========================================================================== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.6rem; }
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--tr), border-color var(--tr), transform var(--tr);
}
.metric { display: flex; flex-direction: column; gap: .55rem; }
.metric:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.metric__top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.card__title, .metric__label { color: var(--text-muted); font-size: .82rem; font-weight: 560; }
.metric__icon {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent-weak); color: var(--accent); border: 1px solid var(--accent-weak-bd);
}
.metric__icon--info { background: var(--info-bg); color: var(--info-dot); border-color: transparent; }
.metric__icon--warn { background: var(--warn-bg); color: var(--warn-dot); border-color: transparent; }
.metric__icon--neutral { background: var(--neutral-bg); color: var(--neutral-tx); border-color: transparent; }
.card__value, .metric__value {
  font-size: 1.85rem; font-weight: 720; letter-spacing: -.02em; color: var(--text);
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.metric__foot { font-size: .8rem; color: var(--text-faint); }

/* ========================================================================== */
/*  TABLES                                                                    */
/* ========================================================================== */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.table-wrap--scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .72rem .9rem; text-align: left; vertical-align: middle; }
.table thead th {
  position: sticky; top: 0;
  background: var(--surface-inset);
  color: var(--text-muted);
  font-weight: 600; font-size: .76rem; letter-spacing: .04em; text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody tr { border-bottom: 1px solid var(--border); transition: background var(--tr); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table td code { color: var(--text-muted); }
.table .num { font-variant-numeric: tabular-nums; font-family: var(--font-mono); white-space: nowrap; }
.table .col-actions { text-align: right; white-space: nowrap; }
/* standalone table (no wrapper) still looks right */
.content > .table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); overflow: hidden; }

.text-muted { color: var(--text-faint); }
td.text-muted { text-align: center; padding: 2.2rem 1rem; }

/* empty state */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: .6rem;
  padding: 2.4rem 1rem; color: var(--text-faint); text-align: center;
}
.empty svg { width: 30px; height: 30px; opacity: .7; stroke-width: 1.5; }
.empty p { margin: 0; font-size: .92rem; }

/* ========================================================================== */
/*  BADGES                                                                    */
/* ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .2rem .58rem;
  border-radius: var(--r-pill);
  font-size: .76rem; font-weight: 600; line-height: 1.4;
  background: var(--neutral-bg); color: var(--neutral-tx);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--neutral-dot); flex: none; }
.badge--active, .badge--ok, .badge--completed, .badge--success, .badge--open, .badge--online, .badge--paid { background: var(--ok-bg); color: var(--ok-tx); }
.badge--active::before, .badge--ok::before, .badge--completed::before, .badge--success::before, .badge--open::before, .badge--online::before, .badge--paid::before { background: var(--ok-dot); }
.badge--frozen, .badge--pending, .badge--processing, .badge--hold, .badge--degraded { background: var(--warn-bg); color: var(--warn-tx); }
.badge--frozen::before, .badge--pending::before, .badge--processing::before, .badge--hold::before, .badge--degraded::before { background: var(--warn-dot); }
.badge--blocked, .badge--failed, .badge--rejected, .badge--closed, .badge--offline, .badge--error { background: var(--danger-bg); color: var(--danger-tx); }
.badge--blocked::before, .badge--failed::before, .badge--rejected::before, .badge--closed::before, .badge--offline::before, .badge--error::before { background: var(--danger-dot); }
.badge--info, .badge--new { background: var(--info-bg); color: var(--info-tx); }
.badge--info::before, .badge--new::before { background: var(--info-dot); }

/* role pill (no dot) */
.role-pill { display: inline-flex; padding: .15rem .55rem; border-radius: var(--r-pill); font-size: .74rem; font-weight: 650;
  background: var(--surface-3); color: var(--text-muted); text-transform: capitalize; }
.role-pill--superadmin { background: var(--accent-weak); color: var(--accent-weak-tx); }

/* ========================================================================== */
/*  BUTTONS                                                                   */
/* ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .5rem .9rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: .89rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background var(--tr), border-color var(--tr), transform var(--tr), box-shadow var(--tr), color var(--tr);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn svg { width: 1.05em; height: 1.05em; }
.btn--sm { padding: .34rem .6rem; font-size: .82rem; border-radius: var(--r-xs); }
.btn--block { width: 100%; }
.btn--primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--primary:active { background: var(--accent-press); }
.btn--warning { background: var(--warn-dot); border-color: transparent; color: #2a1800; }
.btn--danger  { background: var(--danger-dot); border-color: transparent; color: #fff; }
.btn--success { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn--ghost   { background: transparent; box-shadow: none; border-color: var(--border); color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--link { background: transparent; border: none; box-shadow: none; color: inherit; padding: 0; font-weight: 600; cursor: pointer; }
.btn--link:hover { text-decoration: underline; background: none; }

/* ========================================================================== */
/*  FORMS                                                                     */
/* ========================================================================== */
.form { display: flex; flex-direction: column; gap: .9rem; max-width: 480px; }
.form__label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; font-weight: 600; color: var(--text); }
.field-hint { font-size: .78rem; color: var(--text-faint); font-weight: 500; }
.input,
.form input, .form textarea, .form select,
.toolbar input, .toolbar select {
  width: 100%;
  padding: .58rem .7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: .92rem;
  transition: border-color var(--tr), box-shadow var(--tr), background var(--tr);
}
.form input::placeholder, .toolbar input::placeholder, .input::placeholder { color: var(--text-faint); }
.form input:focus, .form textarea:focus, .form select:focus,
.toolbar input:focus, .toolbar select:focus, .input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
.form textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
select { cursor: pointer; }

/* input with leading icon */
.input-icon { position: relative; display: block; }
.input-icon svg { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.input-icon input { padding-left: 2.3rem; }

/* toolbar / inline filter bar */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .55rem;
  margin-bottom: 1.1rem;
  padding: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}
.toolbar input, .toolbar select { width: auto; min-width: 140px; flex: 1 1 150px; }
.toolbar .btn { flex: none; }
.toolbar__search { flex: 2 1 240px; }
/* legacy inline form maps to toolbar */
.form--inline { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; max-width: none; margin-bottom: 1.1rem;
  padding: .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.form--inline input, .form--inline select { width: auto; min-width: 140px; flex: 1 1 150px; }
.form--inline .btn { flex: none; }

.actions { display: flex; gap: .6rem; margin: 1.1rem 0 1.5rem; flex-wrap: wrap; }
.inline-form { display: inline-flex; align-items: center; gap: .4rem; }
/* native controls placed outside .form / .toolbar (e.g. table action cells) */
.inline-form select, .inline-form input {
  padding: .34rem .5rem; font: inherit; font-size: .82rem;
  border: 1px solid var(--border-strong); border-radius: var(--r-xs);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.inline-form select:focus, .inline-form input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring);
}

/* ========================================================================== */
/*  FLASH / ALERTS                                                            */
/* ========================================================================== */
.flash {
  display: flex; align-items: flex-start; gap: .65rem;
  padding: .8rem 1rem; margin-bottom: 1rem;
  border-radius: var(--r-sm);
  font-size: .9rem; font-weight: 500;
  border: 1px solid transparent;
  animation: flash-in .3s cubic-bezier(.16,1,.3,1) both;
}
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.flash svg { margin-top: .05rem; flex: none; }
.flash__body { flex: 1; min-width: 0; }
.flash__close { margin: -.2rem -.2rem 0 0; background: none; border: 0; cursor: pointer; color: inherit; opacity: .6; padding: .2rem; border-radius: var(--r-xs); }
.flash__close:hover { opacity: 1; }
.flash--info    { background: var(--info-bg);   color: var(--info-tx);   border-color: color-mix(in srgb, var(--info-dot) 30%, transparent); }
.flash--success { background: var(--ok-bg);     color: var(--ok-tx);     border-color: color-mix(in srgb, var(--ok-dot) 30%, transparent); }
.flash--warning { background: var(--warn-bg);   color: var(--warn-tx);   border-color: color-mix(in srgb, var(--warn-dot) 32%, transparent); }
.flash--error   { background: var(--danger-bg); color: var(--danger-tx); border-color: color-mix(in srgb, var(--danger-dot) 32%, transparent); }

/* ========================================================================== */
/*  PAGINATION                                                                */
/* ========================================================================== */
.pagination { margin-top: 1.2rem; display: flex; gap: .5rem; align-items: center; justify-content: flex-end; }
.pagination__link {
  display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 .5rem;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  color: var(--text); box-shadow: var(--shadow-sm); transition: background var(--tr);
}
.pagination__link:hover { background: var(--surface-2); text-decoration: none; }
.pagination__info { color: var(--text-muted); font-size: .85rem; font-variant-numeric: tabular-nums; }

/* ========================================================================== */
/*  TICKET MESSAGES                                                           */
/* ========================================================================== */
.messages { display: flex; flex-direction: column; gap: .85rem; margin: 0 0 1.5rem; }
.message {
  max-width: 78%;
  padding: .75rem 1rem;
  border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.message--manager, .message--superadmin, .message--staff, .message--admin {
  align-self: flex-end;
  background: var(--accent-weak); border-color: var(--accent-weak-bd);
  border-bottom-right-radius: 4px;
}
.message--user, .message--client { align-self: flex-start; border-bottom-left-radius: 4px; }
.message__meta { color: var(--text-faint); font-size: .76rem; margin-bottom: .35rem; font-weight: 550; }
.message__body { color: var(--text); font-size: .92rem; }

/* ========================================================================== */
/*  AUTH (login) screen                                                       */
/* ========================================================================== */
.layout--auth {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}
.layout--auth::before {
  content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(900px 500px at 15% -5%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
    radial-gradient(800px 600px at 110% 110%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 55%);
}
.auth-shell { position: relative; z-index: 1; display: grid; place-items: center; padding: 2rem 1.25rem; min-height: 100dvh; }
.auth-topbar { position: absolute; top: 0; right: 0; z-index: 2; padding: 1.1rem 1.3rem; }
.auth-card {
  width: 100%; max-width: 408px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 2rem 1.9rem;
  box-shadow: var(--shadow-lg);
  animation: page-in .4s cubic-bezier(.16,1,.3,1) both;
}
.auth-card__brand { display: flex; align-items: center; gap: .7rem; justify-content: center; margin-bottom: .35rem; }
.auth-card__brand b { font-size: 1.18rem; font-weight: 750; letter-spacing: -.02em; }
.brand-dim { font-weight: 600; color: var(--text-faint); }
.auth-card__title { text-align: center; margin: 0 0 .25rem; font-size: 1.3rem; }
.auth-card__hint { text-align: center; color: var(--text-muted); font-size: .9rem; margin: 0 0 1.5rem; }
.form--login { gap: 1rem; max-width: none; }
.form--login .btn--primary { margin-top: .25rem; padding: .65rem; font-size: .95rem; }
.auth-foot { text-align: center; margin-top: 1.4rem; color: var(--text-faint); font-size: .78rem; }

/* ========================================================================== */
/*  ERROR PAGES                                                               */
/* ========================================================================== */
.errorpage { max-width: 540px; margin: 4vh auto; text-align: center; padding: 1rem; }
.errorpage__code {
  font-size: 4.5rem; font-weight: 800; letter-spacing: -.04em; line-height: 1;
  background: linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 50%, var(--text)));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: .5rem;
}
.errorpage h1 { font-size: 1.4rem; }
.errorpage p { color: var(--text-muted); }
.errorpage pre {
  text-align: left; background: var(--surface-inset); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: .9rem; overflow: auto; font-size: .82rem; color: var(--text-muted);
}
.errorpage .btn { margin-top: 1rem; }

/* ========================================================================== */
/*  DETAIL CARD (definition list)                                             */
/* ========================================================================== */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.4rem; margin-bottom: 1.4rem;
}
.deflist { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem 1.6rem; margin: 0; }
.deflist div { display: flex; flex-direction: column; gap: .15rem; }
.deflist dt { color: var(--text-faint); font-size: .76rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.deflist dd { margin: 0; color: var(--text); font-size: .94rem; font-weight: 550; }

/* utilities */
.muted { color: var(--text-faint); }
.stack-sm { display: flex; flex-direction: column; gap: .4rem; }
[hidden] { display: none !important; }

/* ========================================================================== */
/*  RESPONSIVE — sidebar becomes an off-canvas drawer                        */
/* ========================================================================== */
.app__overlay {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  background: rgba(10,14,20,.5);
  backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden; transition: opacity var(--tr), visibility var(--tr);
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas: "topbar" "main";
  }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: var(--z-sidebar);
    width: min(86vw, var(--sidebar-w));
    transform: translateX(-100%);
    transition: transform .26s cubic-bezier(.4,0,.2,1);
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .app__overlay { opacity: 1; visibility: visible; }
  .topbar__menu { display: inline-grid; }
  .topbar__brand-m { display: flex; }
  .page-head { flex-direction: column; align-items: stretch; gap: .7rem; }
  .message { max-width: 90%; }
}

@media (max-width: 520px) {
  .content { padding: 1.2rem 1rem 2.5rem; }
  .card__value, .metric__value { font-size: 1.6rem; }
  h1 { font-size: 1.32rem; }
}

/* prefers no motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* print */
@media print {
  .sidebar, .topbar, .app__overlay, .pagination, .toolbar, .actions { display: none !important; }
  .app { display: block; }
  body { background: #fff; }
  .table-wrap, .card, .panel { box-shadow: none; border-color: #ccc; }
}
