:root{
  --bg:#0f1115; --panel:#161922; --border:#2a2f3b; --text:#e9eef5; --muted:#a8b0bd;
  --accent:#5b8cff; --accent-2:#2e6bff; --danger:#e06666;
}
*{box-sizing:border-box}
html,body{margin:0; padding:0; background:var(--bg); color:var(--text); font:14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Apple Color Emoji","Segoe UI Emoji";}
a{color:var(--accent); text-decoration:none}
a:hover{color:var(--accent-2)}
.container{max-width:1100px; margin:24px auto; padding:0 16px}

/* Top nav */
.topnav{position:sticky; top:0; z-index:10; background:rgba(15,17,21,.9); backdrop-filter:saturate(180%) blur(6px);
  border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; gap:12px; padding:10px 16px}
.topnav a{margin-right:12px}
.topnav .brand{font-weight:700; color:var(--text); margin-right:16px}

/* Buttons */
.btn{border:1px solid var(--border); background:transparent; color:var(--text); padding:6px 10px; border-radius:8px; cursor:pointer}
.btn:hover{border-color:var(--accent)}
.btn.primary{background:var(--accent); border-color:var(--accent); color:#fff}
.btn.primary:hover{background:var(--accent-2); border-color:var(--accent-2)}
.btn.danger{border-color:var(--danger); color:#fff; background:var(--danger)}
.btn-ghost{background:transparent}

/* Cards / panels */
.card{background:var(--panel); border:1px solid var(--border); border-radius:12px; overflow:hidden}
.card + .card{margin-top:16px}
.card-header,.card-footer{display:flex; align-items:center; justify-content:space-between; padding:10px 12px; border-bottom:1px solid var(--border)}
.card-footer{border-top:1px solid var(--border); border-bottom:0; color:var(--muted)}
.panel{background:var(--panel); border:1px solid var(--border); border-radius:12px}

/* Tables */
.table-wrap{padding:0 8px 10px}
.list-table{width:100%; border-collapse:collapse}
.list-table th,.list-table td{padding:10px 8px; border-top:1px solid var(--border); vertical-align:top}
.list-table thead th{border-top:0; color:#cfd5df; text-align:left}
.list-table .actions{white-space:nowrap}
.table-wrap.compact .list-table th,.table-wrap.compact .list-table td{padding:6px 8px}
.ta-center{text-align:center} .ta-right{text-align:right}
th.th-center{text-align:center !important} th.th-right{text-align:right !important}
.muted{color:var(--muted)} .small{font-size:.9em}

/* Search form (header-left areas often use this) */
form.search{display:flex; align-items:center; gap:8px}
form.search input[type="text"],
form.search input[type="date"],
form.search select{
  background: var(--bg);
  border: 1px solid var(--hairline);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 8px;
}

/* Messages */
.messages{list-style:none; padding:0; margin:0 0 12px}
.msg{padding:10px 12px; border:1px solid var(--border); border-radius:8px; background:#10131a}
.msg.success{border-color:#2d8f5e; background:#0e1b16}
.msg.error{border-color:var(--danger); background:#1f0f10}
.msg.warning{border-color:#bfa64b; background:#1b1710}

/* Dashboard grid */
.dashboard-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(360px,1fr)); gap:16px}

/* Drawer (used by list pages) */
.drawer {position:fixed; inset:0; display:none}
.drawer.open{display:block}
.drawer .sheet{position:absolute; right:0; top:0; bottom:0; width:420px; max-width:100%; background:var(--panel);
  border-left:1px solid var(--border); padding:14px}
.drawer .sheet h3{margin:0 0 10px}
.form-grid{display:grid; grid-template-columns:1fr; gap:10px}
.form-grid input, .form-grid select, .form-grid textarea{width:100%; background:#0c0f14; border:1px solid var(--border); color:var(--text); padding:8px 10px; border-radius:8px}
.form-grid .checkbox{display:flex; align-items:center; gap:8px}
.drawer-actions{display:flex; gap:8px; justify-content:flex-end; margin-top:10px}

/* Responsive priority columns (pri-1 always visible, higher numbers hide earlier) */
@media (max-width: 900px){
  .pri-4{display:none}
}
@media (max-width: 760px){
  .pri-3{display:none}
}
@media (max-width: 620px){
  .pri-2{display:none}
}

/* Light (default) */
:root {
  --bg: #ffffff;
  --text: #0f172a;
  --card: #ffffff;
  --muted: #64748b;
  --hairline: #e5e7eb;
  --table-stripe: #f8fafc;
}

/* Dark */
[data-theme="dark"] {
  --bg: #0b0f19;
  --text: #e5e7eb;
  --card: #111827;
  --muted: #94a3b8;
  --hairline: #1f2937;
  --table-stripe: #0f172a;
}

/* Use the variables (adjust if you already have these rules) */
html, body { background: var(--bg); color: var(--text); }
.card { background: var(--card); }
.card-header, .card-footer { border-color: var(--hairline); }
.table-wrap .list-table tr:nth-child(odd) { background: var(--table-stripe); }
.muted { color: var(--muted); }
.topnav { border-bottom: 1px solid var(--hairline); }
.list-table th, .list-table td { border-color: var(--hairline); }

/* === THEME VARIABLES === */
/* Light (default) */
:root {
  --bg: #ffffff;
  --text: #0f172a;
  --card: #ffffff;
  --muted: #64748b;
  --hairline: #e5e7eb;
  --table-stripe: #f8fafc;
}

/* Dark */
[data-theme="dark"] {
  --bg: #0b0f19;
  --text: #e5e7eb;
  --card: #111827;
  --muted: #94a3b8;
  --hairline: #1f2937;
  --table-stripe: #0f172a;
}

/* === APPLY THE VARIABLES (override existing rules if needed) === */
html, body { background: var(--bg); color: var(--text); }

/* Top bar */
.topnav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--hairline);
}
.topnav a, .topnav .btn { color: var(--text); }

/* Right side of the nav: keep items on one line */
.topnav .nav-right { display: flex; align-items: center; gap: 8px; }
.topnav .nav-right form { display: inline; margin: 0; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--hairline); }
.card-header, .card-footer { border-color: var(--hairline); }

/* Tables */
.list-table { width: 100%; border-collapse: collapse; }
.list-table th, .list-table td { border-bottom: 1px solid var(--hairline); }
.table-wrap .list-table tr:nth-child(odd) { background: var(--table-stripe); }

/* Utilities */
.muted { color: var(--muted); }

/* Buttons (basic) */
.btn { border: 1px solid var(--hairline); background: var(--card); }
.btn.primary { background: #3b82f6; border-color: #3b82f6; color: #fff; }
.btn.btn-ghost { background: transparent; border-color: transparent; }


body.no-scroll { overflow: hidden; }

/* --- Theme-aware message styles --- */
:root {
  --msg-bg:        #f8fafc;  /* light slate */
  --msg-border:    #e5e7eb;
  --msg-success-bg:#ecfdf5;  /* mint */
  --msg-success-br:#86efac;
  --msg-error-bg:  #fef2f2;  /* rose */
  --msg-error-br:  #fca5a5;
  --msg-warn-bg:   #fffbeb;  /* amber */
  --msg-warn-br:   #facc15;
}

[data-theme="dark"] {
  --msg-bg:        #0f172a;
  --msg-border:    #1f2937;
  --msg-success-bg:rgba(16,185,129,.14);
  --msg-success-br:#065f46;
  --msg-error-bg:  rgba(239,68,68,.14);
  --msg-error-br:  #7f1d1d;
  --msg-warn-bg:   rgba(245,158,11,.16);
  --msg-warn-br:   #92400e;
}

.messages { list-style:none; padding:0; margin:16px 0; }
.msg {
  padding:10px 12px;
  border:1px solid var(--msg-border);
  border-radius:10px;
  background:var(--msg-bg);
  color:var(--text);
}

/* Variants */
.msg.success { background:var(--msg-success-bg); border-color:var(--msg-success-br); }
.msg.error   { background:var(--msg-error-bg);   border-color:var(--msg-error-br); }
.msg.warning { background:var(--msg-warn-bg);    border-color:var(--msg-warn-br); }

/* --- KPI row -------------------------------------------------------------- */
.kpi-row{
  display:grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(220px,1fr);
  gap:12px;
  overflow-x:auto;           /* small screens can scroll horizontally */
  padding-bottom:4px;
}

.kpi-card{
  background: var(--card);
  color: var(--text);
  border:1px solid var(--hairline);
  border-radius:12px;
  padding:12px 14px;
  min-width:220px;
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
}

.kpi-title{
  font-size:.9rem;
  color: var(--muted);
  display:flex; align-items:center; gap:8px;
}

.kpi-value{
  margin-top:4px;
  font-weight:700;
  font-size:1.35rem;
  letter-spacing:.2px;
}

.kpi-actions{
  margin-top:8px;
  display:flex; gap:8px; flex-wrap:wrap;
}

.yesno { display:inline-block; min-width:1.25em; text-align:center; }
.yesno.yes  { color: #16a34a; }   /* green */
.yesno.no   { color: #64748b; }   /* muted */
.yesno.none { color: #94a3b8; }   /* more muted */

.list-toolbar{display:flex;align-items:center;gap:8px;margin-bottom:12px;position:relative;z-index:2;}
.list-toolbar .push-right{margin-left:auto;}

.list-toolbar { position: relative; z-index: 2; }

.btn-select {
  border: 1px solid var(--border, #e5e7eb);
  background: var(--bg, #fff);
  color: var(--fg, #111);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-select:focus {
  outline: none;
  border-color: var(--primary, #3b82f6);
}

/* Card sizing */
.form-card {
  max-width: 620px;
  margin-inline: 0;
}

/* Grid + spacing */
.form-grid {
  display: grid;
  gap: 14px;
  padding: 14px;
}
@media (min-width: 520px) {
  .form-grid { padding: 18px; gap: 16px; }
}

/* Field block */
.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

/* Input wrapper with inline Show/Hide button */
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.input-wrap .input,
.input-wrap input[type="password"],
.input-wrap input[type="text"] {
  width: 100%;
  padding: 10px 88px 10px 12px;      /* room for toggle */
  border: 1px solid var(--border, #2b2f39);
  border-radius: 10px;
  background: var(--surface, #0b1020);
  color: var(--text, #e6e6e6);
}
[data-theme="light"] .input-wrap .input,
[data-theme="light"] .input-wrap input {
  background: #fff; color: #111; border-color: #e5e7eb;
}

.input-wrap .toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: .875rem;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted-foreground, #9aa4b2);
  cursor: pointer;
}
.input-wrap .toggle:hover {
  background: var(--hover, rgba(255,255,255,.06));
}

/* Help + errors */
.help {
  margin-top: 6px;
  font-size: .85rem;
  color: var(--muted-foreground, #9aa4b2);
}
.alert-error, .field .errorlist {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(220, 38, 38, .12);
  color: #fca5a5;
  border: 1px solid rgba(220, 38, 38, .35);
}

/* Actions row */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px dashed var(--hairline, #2a2f3a);
}
[data-theme="light"] .form-actions {
  border-top-color: #e5e7eb;
}

/* Card */
.form-card { max-width: 680px; margin: 0; padding: 18px; }
.form-card.--elev { box-shadow: 0 6px 24px rgba(0,0,0,.18); }

/* Layout */
.form-grid { display: grid; gap: 14px; }
@media (min-width: 560px) { .form-grid { gap: 16px; } }

.field label { display:block; font-weight:600; margin: 2px 0 6px; }

/* Inputs */
.input-wrap { position: relative; }
.input-wrap input {
  width:100%;
  padding: 12px 40px 12px 12px;
  border:1px solid var(--hairline, #2a2f3a);
  border-radius:12px;
  background: var(--surface, #0c1222);
  color: var(--text, #e6e6e6);
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.input-wrap input:focus {
  border-color: var(--primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59,130,246,.25);
}
[data-theme="light"] .input-wrap input {
  background: #fff; color:#111; border-color:#e5e7eb;
}

/* Eye toggle */
.icon-btn {
  position:absolute; right:8px; top:50%; transform:translateY(-50%);
  width:28px; height:28px; display:grid; place-items:center;
  border-radius:8px; border:1px solid transparent; background:transparent;
  color: var(--muted-foreground,#9aa4b2); cursor:pointer;
}
.icon-btn:hover { background: var(--hover, rgba(255,255,255,.06)); }
.icon-btn.on { color: var(--primary,#60a5fa); }

/* Help & errors */
.help { margin-top:6px; font-size:.875rem; color: var(--muted-foreground,#9aa4b2); }
.field .errorlist { list-style:none; padding:0; margin:.5rem 0 0; }
.field .errorlist li {
  background: rgba(220,38,38,.12); color:#fca5a5; border:1px solid rgba(220,38,38,.35);
  padding:8px 10px; border-radius:8px;
}

/* Strength meter */
.pw-meter { height:8px; background:transparent; margin-top:8px; border-radius:6px; }
.pw-meter span {
  display:block; height:100%; width:var(--w,0%); border-radius:6px;
  background: linear-gradient(90deg, #ef4444, #f59e0b, #10b981);
  transition: width .25s ease;
}

/* Match text */
.pw-match { margin-top:6px; }
.pw-match.ok { color:#10b981; }
.pw-match.bad { color:#ef4444; }

/* Actions */
.form-actions {
  display:flex; justify-content:flex-end; gap:.5rem;
  margin-top: 8px; padding-top: 10px;
  border-top:1px dashed var(--hairline, #2a2f3a);
}
[data-theme="light"] .form-actions { border-top-color:#e5e7eb; }
/* ==== Password form refinements ==== */
.form-card.narrow { 
  max-width: 560px;     /* overall card width */
  padding: 18px 16px;
}

/* add a bit more air between fields */
.pw-form.form-grid { 
  gap: 18px; 
}

/* make the actual input row narrower than the card */
.pw-form .field .input-wrap { 
  max-width: 520px;     /* input width */
  position: relative; 
}

/* ensure the input leaves room for the icon on the right */
.pw-form .input-wrap input {
  padding-right: 44px;  /* space for eye icon */
  height: 42px;         /* consistent height */
  line-height: 42px;
}

/* place the eye button inside the input, on the right */
.pw-form .icon-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted-foreground,#9aa4b2);
  cursor: pointer;
}
.pw-form .icon-btn:hover { 
  background: var(--hover, rgba(255,255,255,.06)); 
}
.pw-form .icon-btn.on { 
  color: var(--primary,#60a5fa); 
}

/* space for help/errors below each field */
.pw-form .help,
.pw-form .field .errorlist { 
  margin-top: 8px; 
}

/* actions row spacing */
.pw-form .form-actions { 
  margin-top: 6px; 
  padding-top: 12px; 
  gap: .6rem;
}

/* --- General container layout --- */
.container {
  max-width: 1100px;       /* limit total page width */
  margin: 0 auto;           /* center horizontally */
  padding: 1rem;            /* nice breathing room */
  display: block;
}

/* Dashboard specific */
.dashboard-grid {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* KPI row responsive centering */
.kpi-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;  /* center KPI cards */
  text-align: center;
}

.kpi-card {
  flex: 1 1 220px;
  padding: 1rem;
  border-radius: 12px;
  background: var(--surface, #111827);
  border: 1px solid var(--hairline, #2a2f3a);
}

/* Tables centered with consistent width */
.card {
  margin: 0 auto;           /* center within container */
  width: 100%;
  max-width: 1000px;
}

.table-wrap {
  overflow-x: auto;
}

/* Let dropdowns render outside the top bar if needed */
.topnav { overflow: visible; }

/* Align panels correctly per side */
.nav-left  .nav-menu .menu-panel { left: 0;  right: auto; }  /* open to the right */
.nav-right .nav-menu .menu-panel { right: 0; left:  auto; }  /* open to the left */

/* Keep panels within the viewport on narrow screens */
@media (max-width: 480px) {
  .menu-panel {
    max-width: calc(100vw - 16px);
    inset-inline-start: 0;  /* logical left for safety */
  }
}

/* Dark mode text color for menu items (force, don't rely on UA defaults) */
[data-theme="dark"] .menu-panel,
[data-theme="dark"] .menu-panel a,
[data-theme="dark"] .menu-panel form button {
  color: #e5e7eb !important;
}

/* Optional: a touch more contrast on hover in dark mode */
[data-theme="dark"] .menu-panel a:hover,
[data-theme="dark"] .menu-panel form button:hover {
  background: rgba(255,255,255,.08);
}

/* ---------------------------
   THEME TOKENS
   --------------------------- */
:root,
[data-theme="light"] {
  --bg: #ffffff;
  --text: #0f172a;                /* slate-900 */
  --surface: #ffffff;             /* cards / panels */
  --hairline: #e5e7eb;            /* borders */
  --border: #e5e7eb;
  --hover: rgba(0,0,0,.06);
  --muted-foreground: #6b7280;    /* slate-500 */
  --primary: #3b82f6;             /* blue-500 */
}

[data-theme="dark"] {
  --bg: #0b1220;                  /* page background */
  --text: #e5e7eb;                /* slate-200 */
  --surface: #0f172a;             /* cards / panels */
  --hairline: #2a2f3a;            /* borders */
  --border: #2a2f3a;
  --hover: rgba(255,255,255,.08);
  --muted-foreground: #9aa4b2;    /* slate-400 */
  --primary: #60a5fa;             /* blue-400 */
}

/* Page base */
html, body { background: var(--bg); color: var(--text); }

/* Container centering (from earlier step) */
.container { max-width: 1100px; margin: 0 auto; padding: 1rem; }

/* ---------------------------
   CARDS / PANELS / MENUS
   --------------------------- */
.card,
.kpi-card,
.menu-panel {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--hairline) !important;
}

/* KPI titles/values readable in both themes */
.kpi-card .kpi-title { color: var(--muted-foreground); }
.kpi-card .kpi-value { color: var(--text); }

/* ---------------------------
   TABLES (Accounts / Transactions)
   --------------------------- */
.list-table th,
.list-table td {
  color: var(--text);
}
.list-table thead th {
  border-color: var(--hairline);
}
.table-wrap { overflow-x: auto; }

/* ---------------------------
   INPUTS / SELECTS
   --------------------------- */
input[type="text"],
input[type="password"],
select,
.btn-select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary), transparent 75%);
}

/* the small actions dropdowns */
.btn-select {
  padding: 6px 10px;
  border-radius: 8px;
}

/* ---------------------------
   NAV MENUS (fix dark text & cropping)
   --------------------------- */
.topnav { overflow: visible; }
.nav-left  .nav-menu .menu-panel { left: 0; right: auto; }
.nav-right .nav-menu .menu-panel { right: 0; left: auto; }

[data-theme="dark"] .menu-panel a,
[data-theme="dark"] .menu-panel form button {
  color: #e5e7eb !important;
}
[data-theme="light"] .menu-panel a,
[data-theme="light"] .menu-panel form button {
  color: #0f172a !important;
}
.menu-panel a:hover,
.menu-panel form button:hover {
  background: var(--hover);
}
