/* =========================================================
   Ledgerly — Design Tokens
   ========================================================= */
:root,
[data-theme="dark"] {
  --bg: #0E1015;
  --bg-elevated: #14171E;
  --surface: #1A1E27;
  --surface-hover: #20242F;
  --border: #272C38;
  --ink: #ECEEF2;
  --ink-soft: #9098A8;
  --ink-faint: #5C6376;

  --primary: #7C6CFF;
  --primary-soft: #948AFF;
  --primary-dim: rgba(124, 108, 255, 0.14);

  --mint: #2DD4A7;
  --mint-dim: rgba(45, 212, 167, 0.14);

  --amber: #F2B05E;
  --amber-dim: rgba(242, 176, 94, 0.14);

  --danger: #F2667A;
  --danger-dim: rgba(242, 102, 122, 0.14);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 0 1px rgba(124, 108, 255, 0.2), 0 8px 30px rgba(124, 108, 255, 0.12);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #F6F5F2;
  --bg-elevated: #FFFFFF;
  --surface: #FFFFFF;
  --surface-hover: #F0EFEA;
  --border: #E5E1D8;
  --ink: #1C1E22;
  --ink-soft: #6B7080;
  --ink-faint: #9BA0AD;

  --primary: #6354E8;
  --primary-soft: #7C6CFF;
  --primary-dim: rgba(99, 84, 232, 0.10);

  --mint: #149A78;
  --mint-dim: rgba(20, 154, 120, 0.10);

  --amber: #C9842E;
  --amber-dim: rgba(201, 132, 46, 0.12);

  --danger: #D5495F;
  --danger-dim: rgba(213, 73, 95, 0.10);

  --shadow-sm: 0 1px 2px rgba(20, 20, 30, 0.05);
  --shadow-md: 0 8px 24px rgba(20, 20, 30, 0.08);
  --shadow-glow: 0 0 0 1px rgba(99, 84, 232, 0.12), 0 8px 24px rgba(99, 84, 232, 0.10);

  color-scheme: light;
}

/* =========================================================
   Base
   ========================================================= */
* { box-sizing: border-box; }

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  transition: background 0.25s ease, color 0.25s ease;
}

h1, h2, h3, .brand {
  font-family: 'Manrope', 'Inter', sans-serif;
  font-weight: 800;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0;
}

a { color: var(--primary-soft); text-decoration: none; }

button { font-family: inherit; }

::selection { background: var(--primary-dim); }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 100px; }

/* =========================================================
   Keyframes
   ========================================================= */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes blobFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -40px) scale(1.08); }
  66% { transform: translate(-20px, 25px) scale(0.95); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes shimmer {
  0% { background-position: -300px 0; }
  100% { background-position: 300px 0; }
}

.fade-up { animation: fadeInUp 0.5s ease both; }

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-soft));
  color: #fff;
  box-shadow: 0 4px 16px rgba(124, 108, 255, 0.28);
}
.btn-primary:hover { box-shadow: 0 6px 22px rgba(124, 108, 255, 0.4); }

.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-hover); }

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  font-size: 16px;
}
.btn-icon:hover { background: var(--surface-hover); color: var(--ink); }

.btn-small { padding: 7px 13px; font-size: 13px; }
.btn-full { width: 100%; }

/* =========================================================
   Form fields
   ========================================================= */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input,
.field select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-family: inherit;
  color: var(--ink);
  background: var(--bg-elevated);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder { color: var(--ink-faint); }

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

/* =========================================================
   Auth pages — split screen
   ========================================================= */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}

.auth-visual {
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 20% 20%, #1C1A33 0%, #0E1015 60%);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 48px;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  animation: blobFloat 14s ease-in-out infinite;
}
.blob-1 { width: 320px; height: 320px; background: var(--primary); top: -60px; left: -60px; }
.blob-2 { width: 280px; height: 280px; background: var(--mint); bottom: -40px; right: -40px; animation-delay: -5s; }
.blob-3 { width: 220px; height: 220px; background: var(--amber); top: 40%; left: 60%; animation-delay: -9s; opacity: 0.35; }

.auth-visual .visual-top { position: relative; z-index: 2; }
.auth-visual .visual-bottom { position: relative; z-index: 2; }

.visual-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Manrope', sans-serif;
  font-weight: 800;
  font-size: 20px;
  color: #fff;
}
.visual-brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 14px var(--mint); }

.visual-headline {
  color: #fff;
  font-size: 32px;
  line-height: 1.25;
  max-width: 380px;
  margin-top: 40px;
}
.visual-sub {
  color: rgba(255,255,255,0.6);
  font-size: 14.5px;
  max-width: 360px;
  margin-top: 14px;
  font-family: 'Inter', sans-serif;
  font-weight: 400;
}

.mini-stat-row {
  display: flex;
  gap: 14px;
  margin-top: 36px;
}
.mini-stat {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  backdrop-filter: blur(6px);
}
.mini-stat .v { color: #fff; font-family: 'Manrope', sans-serif; font-weight: 800; font-size: 18px; }
.mini-stat .l { color: rgba(255,255,255,0.5); font-size: 11.5px; margin-top: 2px; }

.auth-form-side {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  animation: fadeInUp 0.5s ease both;
}

.auth-card .eyebrow {
  color: var(--primary-soft);
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.auth-card h2 { font-size: 26px; margin-bottom: 6px; }
.auth-card .tagline { color: var(--ink-soft); font-size: 14px; margin-bottom: 30px; }

.auth-switch {
  text-align: center;
  font-size: 13.5px;
  color: var(--ink-soft);
  margin-top: 20px;
}

@media (max-width: 860px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
}

/* =========================================================
   Toasts
   ========================================================= */
.toast-stack {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 999;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  box-shadow: var(--shadow-md);
  font-size: 13.5px;
  color: var(--ink);
  min-width: 240px;
  max-width: 340px;
  animation: slideInRight 0.3s ease both;
}
.toast.success { border-left: 3px solid var(--mint); }
.toast.error { border-left: 3px solid var(--danger); }
.toast .icon { font-size: 15px; }

/* =========================================================
   Topbar
   ========================================================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 18px;
}
.topbar .brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 10px var(--mint); }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 6px 14px 6px 6px;
  font-size: 13px;
  color: var(--ink-soft);
}
.user-chip .avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--mint));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 12px;
}

/* =========================================================
   Layout / container
   ========================================================= */
.container {
  max-width: 1140px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-head h1 { font-size: 24px; }
.page-head p { color: var(--ink-soft); font-size: 13.5px; margin-top: 4px; }

/* =========================================================
   Stat cards
   ========================================================= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  animation: fadeInUp 0.5s ease both;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.stat-card .icon-badge {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  margin-bottom: 14px;
}
.stat-card .label { font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card .value { font-family: 'Manrope', sans-serif; font-weight: 800; font-size: 24px; margin-top: 4px; }
.stat-card .delta { font-size: 12px; margin-top: 6px; color: var(--ink-faint); }

.badge-primary { background: var(--primary-dim); color: var(--primary-soft); }
.badge-mint { background: var(--mint-dim); color: var(--mint); }
.badge-amber { background: var(--amber-dim); color: var(--amber); }
.badge-danger { background: var(--danger-dim); color: var(--danger); }

/* =========================================================
   Charts
   ========================================================= */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  animation: fadeInUp 0.55s ease both;
}
.chart-card h3 { font-size: 14.5px; margin-bottom: 4px; }
.chart-card .chart-sub { font-size: 12px; color: var(--ink-soft); margin-bottom: 14px; }
.chart-card .chart-wrap { position: relative; height: 220px; }

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 220px;
  color: var(--ink-faint);
  font-size: 13px;
  text-align: center;
}

/* =========================================================
   Controls bar (search / filter / sort / actions)
   ========================================================= */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 180px;
  position: relative;
}
.search-input input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
}
.search-input input:focus { outline: none; border-color: var(--primary); }
.search-input .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-faint); font-size: 13px; }

.select-pill {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}

.spacer { flex: 1; }

/* =========================================================
   Card / table
   ========================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
  animation: fadeInUp 0.5s ease both;
}

table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  animation: fadeInUp 0.35s ease both;
  transition: background 0.15s ease;
}
tbody tr:hover { background: var(--surface-hover); }

tbody td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
tbody tr:last-child td { border-bottom: none; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 600;
}
.tag .dot { width: 6px; height: 6px; border-radius: 50%; }

.amount-cell { font-weight: 700; font-family: 'Manrope', sans-serif; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--ink-soft);
}
.empty-state .emoji { font-size: 32px; margin-bottom: 10px; }
.empty-state .title { font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.empty-state .sub { font-size: 13px; }

/* =========================================================
   Modal
   ========================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.2s ease both;
}
.modal-overlay.open { display: flex; }

.modal-box {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px;
  margin: 16px;
  box-shadow: var(--shadow-glow);
  animation: scaleIn 0.22s ease both;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-head h3 { font-size: 17px; }

.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-grid .field-full { grid-column: 1 / -1; }

.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }

/* =========================================================
   Loading spinner
   ========================================================= */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* =========================================================
   Error text (inline, used in auth forms)
   ========================================================= */
.error-msg {
  background: var(--danger-dim);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.error-msg.visible { display: block; animation: fadeInUp 0.25s ease both; }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 980px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card .value { font-size: 19px; }
  .container { padding: 18px 14px 48px; }
  .topbar { padding: 14px 16px; }
  .modal-grid { grid-template-columns: 1fr; }
  .row-actions { justify-content: flex-start; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tbody tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    padding: 10px 12px;
  }
  tbody td { border-bottom: none; padding: 6px 0; display: flex; justify-content: space-between; gap: 10px; }
  tbody td:before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-faint);
  }
  .row-actions { justify-content: flex-end; padding-top: 6px; }
}
