/* ==========================================================================
   Design system — professional financial software
   Neutral palette, subtle borders, single accent. Light + dark themes.
   ========================================================================== */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #fafaf9;
  --border: #e4e4e0;
  --border-strong: #d4d4d0;
  --text: #1c1c1a;
  --text-2: #57534e;
  --text-3: #8a857e;
  --accent: #2f5aa8;
  --accent-hover: #274d8f;
  --accent-soft: #eaf0fa;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --success: #1e7e43;
  --success-soft: #e7f4ec;
  --warning: #935f00;
  --warning-soft: #fdf3e3;
  --info: #1d6fa5;
  --info-soft: #e8f3fa;
  --shadow-sm: 0 1px 2px rgba(20, 20, 20, 0.05);
  --shadow-md: 0 4px 12px rgba(20, 20, 20, 0.08);
  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-w: 240px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #161616;
  --surface: #1e1e1e;
  --surface-2: #232323;
  --border: #333331;
  --border-strong: #444442;
  --text: #ececea;
  --text-2: #b5b1ab;
  --text-3: #8a857e;
  --accent: #6d94d6;
  --accent-hover: #85a6de;
  --accent-soft: #26314a;
  --danger: #e06760;
  --danger-soft: #3a2221;
  --success: #57b97f;
  --success-soft: #1d3227;
  --warning: #dfa754;
  --warning-soft: #3a2f1d;
  --info: #5da8d4;
  --info-soft: #1d2f3a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 0.5rem; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 0.75rem; }
code, .mono { font-family: var(--mono); font-size: 0.9em; }
pre.mono { overflow-x: auto; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); white-space: pre; }
.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.small { font-size: 0.85rem; }

/* ---------------- Layout ---------------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 40;
  display: flex;
  flex-direction: column;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 650; font-size: 0.98rem;
  color: var(--text);
}
.sidebar .brand img { max-height: 30px; max-width: 34px; }
.sidebar .brand:hover { text-decoration: none; }
.nav-section { padding: 0.9rem 0.7rem 0.2rem; font-size: 0.7rem; font-weight: 650; letter-spacing: 0.08em; color: var(--text-3); text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.42rem 0.7rem;
  margin: 0 0.45rem;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item svg { width: 17px; height: 17px; flex: none; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.65rem 1.4rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar .search-trigger {
  display: flex; align-items: center; gap: 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.7rem;
  min-width: 240px;
  cursor: pointer;
  font-size: 0.85rem;
}
.topbar .search-trigger kbd {
  margin-left: auto; font-family: var(--mono); font-size: 0.72rem;
  border: 1px solid var(--border); border-radius: 4px; padding: 0 0.3rem; background: var(--surface);
}
.topbar .spacer { flex: 1; }

.content { padding: 1.5rem 1.6rem 3rem; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 200px; }
.page-head .subtitle { color: var(--text-3); margin: 0; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------------- Cards ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
}
.card h3 { display: flex; align-items: center; justify-content: space-between; }
.card-pad-0 { padding: 0; overflow: hidden; }
.card-pad-0 > .card-title { padding: 1rem 1.2rem 0.4rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0.9rem; margin-bottom: 1.2rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.95rem 1.05rem; box-shadow: var(--shadow-sm);
}
.stat .label { font-size: 0.76rem; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-size: 1.45rem; font-weight: 650; margin-top: 0.2rem; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 0.82rem; color: var(--text-3); margin-top: 0.15rem; }
.stat.accent .value { color: var(--accent); }
.stat.danger .value { color: var(--danger); }
.stat.success .value { color: var(--success); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 960px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------------- Tables ---------------- */

.table-scroll { overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; font-size: 0.9rem;
}
table.data th {
  text-align: left; font-size: 0.72rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-3); padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap;
}
table.data td { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data .rowlink { color: var(--text); font-weight: 550; }
table.data td.num, table.data th.num { text-align: right; }

/* ---------------- Badges ---------------- */

.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.02em;
  padding: 0.14rem 0.55rem; border-radius: 999px; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-gray { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge-blue { background: var(--accent-soft); color: var(--accent); }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-amber { background: var(--warning-soft); color: var(--warning); }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.42rem 0.85rem;
  font-size: 0.87rem; font-weight: 550; font-family: inherit;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.93); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 0.24rem 0.6rem; font-size: 0.8rem; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

/* ---------------- Forms ---------------- */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem 1.1rem; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: span 1; } }

.field label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-2); margin-bottom: 0.28rem; }
.field .required { color: var(--danger); }
.field input[type="text"], .field input[type="email"], .field input[type="password"],
.field input[type="number"], .field input[type="date"], .field input[type="tel"], .field input[type="url"],
.field select, .field textarea {
  width: 100%; padding: 0.45rem 0.6rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-size: 0.9rem; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-soft); }
.field .help { font-size: 0.78rem; color: var(--text-3); margin-top: 0.25rem; }
.field .errorlist { color: var(--danger); font-size: 0.8rem; margin: 0.25rem 0 0; padding: 0; list-style: none; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.checkbox-row label { margin: 0; }
.form-actions { display: flex; gap: 0.6rem; margin-top: 1.1rem; align-items: center; }
.form-actions-between { justify-content: space-between; }
.form-inline { margin: 0; }
.is-hidden { display: none; }

/* ---------------- Messages / alerts ---------------- */

.alert { border-radius: var(--radius-sm); padding: 0.65rem 0.85rem; margin-bottom: 0.9rem; font-size: 0.88rem; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: var(--info); }

.demo-banner { background: var(--warning-soft); color: var(--warning); text-align: center; font-weight: 650; font-size: 0.82rem; padding: 0.4rem; border-bottom: 1px solid var(--warning); letter-spacing: 0.06em; }

/* ---------------- Tabs ---------------- */

.tabs { display: flex; gap: 0.2rem; border-bottom: 1px solid var(--border); margin-bottom: 1.1rem; overflow-x: auto; }
.tabs a {
  padding: 0.5rem 0.85rem; color: var(--text-2); font-weight: 550; font-size: 0.88rem;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------------- Wizard steps ---------------- */

.steps { display: flex; gap: 0; margin-bottom: 1.4rem; overflow-x: auto; }
.steps .step { flex: 1; min-width: 110px; text-align: center; font-size: 0.78rem; color: var(--text-3); padding: 0.5rem 0.3rem 0; position: relative; }
.steps .step::before {
  content: attr(data-n); display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; margin: 0 auto 0.3rem;
  background: var(--surface-2); border: 1px solid var(--border-strong); font-weight: 600;
}
.steps .step.active { color: var(--accent); font-weight: 600; }
.steps .step.active::before { background: var(--accent); border-color: var(--accent); color: #fff; }
.steps .step.done { color: var(--success); }
.steps .step.done::before { background: var(--success-soft); border-color: var(--success); color: var(--success); }

/* ---------------- Modal / palette ---------------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 15, 15, 0.45); z-index: 90;
  display: none; align-items: flex-start; justify-content: center; padding: 8vh 1rem 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-md); width: 100%; max-width: 560px; max-height: 80vh; overflow-y: auto;
}
.modal .modal-head { display: flex; align-items: center; justify-content: space-between; padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal .modal-body { padding: 1.1rem; }
.modal .modal-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.9rem 1.1rem; border-top: 1px solid var(--border); }
.modal input.cmdk {
  width: 100%; border: none; background: transparent; padding: 0.9rem 1.1rem; font-size: 1rem; color: var(--text);
  border-bottom: 1px solid var(--border);
}
.modal input.cmdk:focus { outline: none; box-shadow: none; }
.cmdk-list { list-style: none; margin: 0; padding: 0.4rem; }
.cmdk-list li { padding: 0.5rem 0.7rem; border-radius: var(--radius-sm); cursor: pointer; display: flex; justify-content: space-between; }
.cmdk-list li:hover, .cmdk-list li.active { background: var(--accent-soft); }
.cmdk-list .k { color: var(--text-3); font-size: 0.78rem; }

/* ---------------- Auth pages ---------------- */

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 410px; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 1rem; }
.auth-logo img { max-height: 52px; max-width: 220px; }
.auth-card h1 { text-align: center; font-size: 1.25rem; }
.auth-subtitle, .setup-intro { text-align: center; }
.session-warning { margin: 0.8rem 1.4rem 0; }
.cmdk-link { color: inherit; flex: 1; }
.totp-secret { padding-top: 0.55rem; font-weight: 650; overflow-wrap: anywhere; }
.recovery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem 1rem; padding-top: 0.6rem; }
.notification-list { padding: 0 1.2rem; }

/* ---------------- Misc ---------------- */

.pagination { display: flex; gap: 0.35rem; align-items: center; justify-content: flex-end; margin-top: 0.9rem; font-size: 0.85rem; }
.pagination a, .pagination span { padding: 0.28rem 0.6rem; border-radius: var(--radius-sm); border: 1px solid var(--border); color: var(--text-2); }
.pagination a:hover { background: var(--surface-2); text-decoration: none; }
.pagination .current { background: var(--accent); border-color: var(--accent); color: #fff; }

.empty { text-align: center; color: var(--text-3); padding: 2.4rem 1rem; }
.filter-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-bottom: 0.9rem; }
.filter-bar input[type="text"], .filter-bar input[type="search"], .filter-bar select, .filter-bar input[type="date"] {
  padding: 0.4rem 0.6rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: 0.87rem; font-family: inherit;
}
.pill-filters { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.pill-filters a { padding: 0.25rem 0.7rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); font-size: 0.8rem; font-weight: 550; }
.pill-filters a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill-filters a:hover { text-decoration: none; }

.kv { display: grid; grid-template-columns: 190px 1fr; row-gap: 0.45rem; column-gap: 1rem; font-size: 0.9rem; }
.kv dt { color: var(--text-3); font-weight: 550; }
.kv dd { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 0.55rem 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 1rem; font-size: 0.88rem; }
.timeline li:last-child { border-bottom: none; }
.timeline .when { color: var(--text-3); white-space: nowrap; font-size: 0.8rem; }

.progress-bar { height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); }

/* Print */
@media print {
  .sidebar, .topbar, .page-actions, .filter-bar, .no-print { display: none !important; }
  .main { margin-left: 0; }
  .card { box-shadow: none; }
  body { background: #fff; }
}

/* Responsive */
.sidebar-toggle { display: none; }
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.18s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .main { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .topbar .search-trigger { min-width: 0; flex: 1; }
  .content { padding: 1rem 0.9rem 3rem; }
}
