:root {
  --brand: #1B6B57;
  --bg: #F6F7F9;
  --bg-soft: #EEF1F4;
  --surface: #FFFFFF;
  --text: #0F172A;
  --muted: #64748B;
  --border: #E2E8F0;
  --pos: #15803D;
  --neg: #DC2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px rgba(15, 23, 42, .04);
}

[data-theme="dark"] {
  --bg: #0B1117;
  --bg-soft: #161F2A;
  --surface: #111821;
  --text: #F1F5F9;
  --muted: #94A3B8;
  --border: #233040;
  --pos: #4ADE80;
  --neg: #F87171;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Figtree', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.skip {
  position: absolute; left: -9999px;
  background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 8px;
}
.skip:focus { left: 12px; top: 12px; z-index: 999; }

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

/* Sidebar */
.sidebar {
  width: 248px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  transition: width .18s ease;
}
.sb-collapsed .sidebar { width: 74px; }
.sb-collapsed .sb-label,
.sb-collapsed .sb-group-title,
.sb-collapsed .brand-name,
.sb-collapsed .sb-soon { display: none; }

.sb-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; font-weight: 700; font-size: 17px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
}
.sb-close { display: none; }

.sb-nav { flex: 1; display: flex; flex-direction: column; gap: 16px; }
.sb-group-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 10px 6px; }
.sb-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-size: 14px; font-weight: 500;
  border: 0; background: transparent; width: 100%; cursor: pointer; text-align: left;
}
.sb-link:hover { background: var(--bg-soft); }
.sb-link.is-active { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); font-weight: 600; }
.sb-soon { margin-left: auto; font-size: 10px; padding: 2px 6px; border-radius: 999px; background: var(--bg-soft); color: var(--muted); }
.sb-bottom { padding-top: 12px; border-top: 1px solid var(--border); }

/* Main Column & Topbar */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.only-mobile { display: none; }
.crumbs { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.crumb-group { font-size: 13px; color: var(--muted); }
.crumb-sep { color: var(--muted); }
.crumb-title { margin: 0; font-size: 17px; font-weight: 700; white-space: nowrap; }

.search {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 10px; height: 38px; width: 280px; max-width: 100%;
}
.search input { border: 0; background: transparent; color: var(--text); outline: none; width: 100%; font-size: 13.5px; }
.search kbd, .btn kbd { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); }

.top-actions { display: flex; align-items: center; gap: 8px; }
.content { padding: 24px; max-width: 1200px; width: 100%; margin: 0 auto; }

/* Buttons & Controls */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 10px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none;
  font-family: inherit; transition: opacity .15s, background .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-primary, .btn-accent { background: var(--brand); color: #fff; }
.btn-primary:hover, .btn-accent:hover { opacity: .92; }
.btn-danger { background: var(--neg); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-soft); }

.icon-btn {
  position: relative;
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn:hover { background: var(--bg-soft); }
.avatar {
  width: 38px; height: 38px; border-radius: 999px; border: 0;
  background: var(--brand); color: #fff; font-weight: 700; cursor: pointer;
}
.badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--neg); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

.when-dark { display: none; }
[data-theme="dark"] .when-light { display: none; }
[data-theme="dark"] .when-dark { display: inline-flex; }

/* Dropdowns */
.dd { position: relative; }
.dd-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  min-width: 220px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.dd-wide { width: 320px; }
.dd-head { padding: 10px 14px; font-weight: 700; font-size: 13px; border-bottom: 1px solid var(--border); }
.dd-head small { display: block; font-weight: 500; color: var(--muted); }
.dd-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  color: var(--text); text-decoration: none; font-size: 13.5px;
  background: transparent; border: 0; cursor: pointer; width: 100%; font-family: inherit;
}
.dd-item:hover { background: var(--bg-soft); }
.note { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; background: transparent; border-left: 0; border-right: 0; border-top: 0; cursor: pointer; }
.note.is-new { background: color-mix(in srgb, var(--brand) 7%, transparent); }
.note-t { font-weight: 600; color: var(--text); }
.note-m { font-size: 12px; color: var(--muted); }

/* Panels, Stats, Tables */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0 0 4px; font-size: 22px; font-weight: 700; }
.muted { color: var(--muted); }
.notice {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 13.5px; margin-bottom: 18px;
}
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.link { color: var(--brand); text-decoration: none; font-size: 13.5px; font-weight: 600; }

.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 24px; font-weight: 700; margin: 4px 0; }
.stat-sub { font-size: 12px; color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.bars { height: 180px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding-top: 12px; }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; }
.bar-pair { width: 100%; height: 145px; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.bar { width: 14px; border-radius: 6px 6px 2px 2px; }
.bar.in { background: var(--brand); }
.bar.out { background: color-mix(in srgb, var(--neg) 75%, transparent); }
.bar-label { font-size: 12px; color: var(--muted); }
.legend { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 999px; display: inline-block; }
.dot.in { background: var(--brand); }
.dot.out { background: var(--neg); }

.checklist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.check-text { display: flex; flex-direction: column; }
.check-text small { color: var(--muted); font-size: 12px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table th.num, .table td.num { text-align: right; }

.tx-icon { display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center; border-radius: 8px; margin-right: 6px; vertical-align: middle; }
.tx-icon.in { background: color-mix(in srgb, var(--pos) 12%, transparent); color: var(--pos); }
.tx-icon.out { background: color-mix(in srgb, var(--neg) 12%, transparent); color: var(--neg); }

/* Tabs & Pills */
.tab-pill {
  display: inline-flex; align-items: center; padding: 8px 14px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; text-decoration: none; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
}
.tab-pill.is-active { background: var(--brand); color: #fff; border-color: var(--brand); }

.pill-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 8px; font-size: 12px; font-weight: 600;
  background: var(--bg-soft); color: var(--text);
}
.pill-dot { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; }

/* Forms & Modals */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; }
.field-label em { font-style: normal; font-weight: 400; color: var(--muted); }
.field input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
.field select,
.field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent);
  border-color: var(--brand);
}
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.modal {
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 24px)); padding: 20px; box-shadow: var(--shadow);
}
.modal-sm { width: min(420px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.modal-foot .hint { margin-right: auto; font-size: 12px; color: var(--muted); }

.qa { display: flex; flex-direction: column; gap: 14px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--bg-soft); padding: 4px; border-radius: 10px; }
.seg label { text-align: center; cursor: pointer; }
.seg input { display: none; }
.seg span { display: block; padding: 7px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.amount { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; padding: 4px 12px; }
.amount span { font-weight: 700; color: var(--muted); margin-right: 8px; }
.amount input { border: 0 !important; font-size: 22px !important; font-weight: 700; padding: 6px 0 !important; outline: none !important; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--bg-soft); color: var(--text); padding: 6px 10px; border-radius: 8px; font-size: 12.5px; cursor: pointer; }
.chip:hover { border-color: var(--brand); }

.keys { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0; }
.keys dt kbd { padding: 3px 8px; border-radius: 6px; background: var(--bg-soft); border: 1px solid var(--border); font-weight: 700; }
.keys dd { margin: 0; font-size: 14px; }

/* Shared Inline Quick-Add List Widget */
.qa-list-inline {
  margin-top: 6px; padding: 10px; border-radius: 10px;
  border: 1px solid var(--brand); background: var(--bg-soft);
}
.qa-list-inline-label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.qa-list-inline-row { display: flex; gap: 6px; align-items: center; }
.qa-list-inline-input { flex: 1; min-width: 0; padding: 7px 10px !important; font-size: 13px !important; }
.qa-list-inline-msg { font-size: 12px; margin-top: 5px; min-height: 16px; }
.qa-list-inline-msg.is-error { color: var(--neg); }
.qa-list-inline-msg.is-info { color: var(--brand); }

/* Flashes & Toasts */
.flash-success { background: color-mix(in srgb, var(--pos) 10%, var(--surface)); border-color: color-mix(in srgb, var(--pos) 35%, transparent); }
.flash-error   { background: color-mix(in srgb, var(--neg) 10%, var(--surface)); border-color: color-mix(in srgb, var(--neg) 35%, transparent); }
.flash-warning { background: color-mix(in srgb, #D97706 12%, var(--surface)); border-color: color-mix(in srgb, #D97706 40%, transparent); }
.flash-info    { background: var(--surface); border-color: var(--border); }

.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: var(--surface);
  padding: 11px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow); max-width: 340px;
}
.toast-success { background: var(--brand); color: #fff; }
.toast-error { background: var(--neg); color: #fff; }

@media (max-width: 900px) {
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: -270px; z-index: 60; transition: left .2s ease; }
  .sidebar.is-open { left: 0; }
  .sb-close, .only-mobile { display: inline-flex; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; }
  .search, .hide-sm { display: none; }
  .row2 { grid-template-columns: 1fr; }
  .topbar { padding: 10px 14px; }
  .content { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
