@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('/assets/fonts/manrope-latin.woff2') format('woff2');
}

:root {
  --bg: #F6F5F0;
  --bg-rail: #ECEAE2;
  --surface: #FFFFFF;
  --surface-subtle: #F9F8F4;
  --surface-amber: #FFF8EB;
  --surface-emerald: #EDF8F3;
  --surface-coral: #FEF2F0;
  --border: #DFDDD4;
  --border-strong: #C9C5B8;

  --text: #141A18;
  --text-secondary: #4D5753;
  --text-muted: #5F6965;

  --emerald: #0D6E52;
  --emerald-hover: #0A5841;
  --emerald-ink: #084C38;
  --coral: #C2412D;
  --coral-ink: #9A2F1E;
  --amber: #B45309;
  --amber-ink: #78350F;

  --shadow-dialog: 0 22px 48px -12px rgba(20, 26, 24, 0.24);
  --shadow-fab: 0 8px 20px -4px rgba(13, 110, 82, 0.35);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --sidebar-w: 244px;
  --bottom-nav-h: 68px;
  --font-sans: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #0F1419;
  --bg-rail: #151C24;
  --surface: #1A232D;
  --surface-subtle: #1F2A36;
  --surface-amber: #292113;
  --surface-emerald: #112A22;
  --surface-coral: #2E1A18;
  --border: #2A3542;
  --border-strong: #394859;

  --text: #EEF2F0;
  --text-secondary: #B7C2BE;
  --text-muted: #8FA09A;

  --emerald: #34D399;
  --emerald-hover: #10B981;
  --emerald-ink: #6EE7B7;
  --coral: #F87171;
  --coral-ink: #FCA5A5;
  --amber: #FBBF24;
  --amber-ink: #FDE68A;

  --shadow-dialog: 0 24px 56px -12px rgba(0, 0, 0, 0.65);
  --shadow-fab: 0 10px 24px -4px rgba(0, 0, 0, 0.55);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  overflow-x: clip;
  caret-color: var(--emerald);
  transition: background-color 180ms ease, color 180ms ease;
}

::selection {
  background: color-mix(in srgb, var(--emerald) 24%, transparent);
  color: var(--text);
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

a[href], button, summary, select, input[type="checkbox"], input[type="radio"], label[for] {
  cursor: pointer;
}

button:disabled, input:disabled, select:disabled, textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

:focus-visible {
  outline: 2px solid var(--emerald);
  outline-offset: 2px;
}

.num {
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* App shell layout */
.app-shell {
  display: flex;
  min-height: 100dvh;
}

.side-rail {
  display: none;
  flex-direction: column;
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-rail);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100dvh;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  flex-shrink: 0;
  display: block;
}

.brand-title {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.rail-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  text-align: left;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.rail-btn:hover {
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--text);
}

.rail-btn[aria-current="page"] {
  background: var(--surface);
  color: var(--emerald);
  border-color: var(--border);
  font-weight: 700;
}

.rail-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--bottom-nav-h) + 20px);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.top-bar-brand-mobile {
  display: flex;
  align-items: center;
  gap: 9px;
}

.page-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.main-content {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 16px 28px;
  flex: 1;
}

/* Mobile bottom navigation */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  align-items: center;
  padding: 4px 6px env(safe-area-inset-bottom);
}

.bottom-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 48px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 4px 2px;
  border-radius: var(--radius-sm);
}

.bottom-nav-btn[aria-current="page"] {
  color: var(--emerald);
  font-weight: 700;
}

.bottom-nav-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border: 0;
  border-radius: 14px;
  background: var(--emerald);
  color: #FFFFFF;
  box-shadow: var(--shadow-fab);
}

[data-theme="dark"] .bottom-nav-add {
  color: #091712;
}

/* Buttons & inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  transition: background-color 150ms ease, border-color 150ms ease, transform 120ms ease;
}

.btn:hover {
  background: var(--surface-subtle);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #FFFFFF;
}

[data-theme="dark"] .btn-primary {
  color: #071A13;
}

.btn-primary:hover {
  background: var(--emerald-hover);
  border-color: var(--emerald-hover);
}

.btn-danger {
  background: var(--surface-coral);
  border-color: color-mix(in srgb, var(--coral) 45%, transparent);
  color: var(--coral-ink);
}

.btn-sm {
  min-height: 44px;
  padding: 0 12px;
  font-size: 0.82rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.icon-btn:hover {
  background: var(--surface-subtle);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.input::placeholder, .textarea::placeholder {
  color: var(--text-muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.checkbox-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--emerald);
  flex-shrink: 0;
}

/* Surfaces & structural layouts */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  min-width: 0;
}

.panel-amber {
  background: var(--surface-amber);
  border-color: color-mix(in srgb, var(--amber) 35%, var(--border));
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 26px 0 12px;
}

.section-head:first-child {
  margin-top: 0;
}

.section-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.015em;
}

/* Hero Cash Ledger (asymmetric split) */
.hero-ledger {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.hero-primary {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.hero-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.hero-amount {
  margin: 4px 0 0;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--emerald-ink);
  overflow-wrap: anywhere;
}

.hero-subline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 18px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.hero-metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.metric-cell {
  min-width: 0;
}

.metric-cell-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.metric-cell-value {
  margin-top: 3px;
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.val-in { color: var(--emerald-ink); }
.val-out { color: var(--coral-ink); }
.val-amber { color: var(--amber-ink); }

/* Period filter pills */
.filter-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.chip-btn {
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
}

.chip-btn[aria-pressed="true"] {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #FFFFFF;
}

[data-theme="dark"] .chip-btn[aria-pressed="true"] {
  color: #071A13;
}

/* Charts grid */
.charts-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 16px;
}

.chart-box {
  position: relative;
  height: 270px;
  width: 100%;
  min-width: 0;
}

.chart-box-sm {
  position: relative;
  height: 220px;
  width: 100%;
  min-width: 0;
}

/* Category breakdown interactive list */
.cat-split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: center;
}

.cat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.cat-item-btn {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface-subtle);
  color: var(--text);
  font-family: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cat-item-btn:hover {
  border-color: var(--border-strong);
}

.cat-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.88rem;
}

.cat-name-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 700;
  flex: 1;
}

.cat-name-text {
  overflow-wrap: anywhere;
}

.cat-item-top > .num {
  white-space: nowrap;
  flex-shrink: 0;
}

.cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.progress-track {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
}

/* Separate pockets 3-strip */
.pockets-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 16px;
}

.pocket-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  width: 100%;
  min-height: 68px;
  font-family: inherit;
}

.pocket-link:hover {
  border-color: var(--border-strong);
  background: var(--surface-subtle);
}

.pocket-meta {
  min-width: 0;
}

.pocket-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.pocket-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.pocket-amount {
  font-size: 1.05rem;
  font-weight: 800;
  white-space: nowrap;
}

/* Ledger rows & tables */
.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.day-group {
  margin-bottom: 18px;
}

.day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 4px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.ledger-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  min-width: 0;
}

.ledger-main {
  min-width: 0;
  flex: 1;
}

.ledger-title {
  font-weight: 700;
  font-size: 0.94rem;
  overflow-wrap: anywhere;
}

.ledger-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.ledger-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.ledger-amount {
  font-weight: 800;
  font-size: 0.96rem;
  white-space: nowrap;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Status labels (functional only) */
.status-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.tag-emerald {
  background: var(--surface-emerald);
  color: var(--emerald-ink);
  border-color: color-mix(in srgb, var(--emerald) 30%, transparent);
}

.tag-amber {
  background: var(--surface-amber);
  color: var(--amber-ink);
  border-color: color-mix(in srgb, var(--amber) 35%, transparent);
}

.tag-coral {
  background: var(--surface-coral);
  color: var(--coral-ink);
  border-color: color-mix(in srgb, var(--coral) 30%, transparent);
}

/* Sawit tables & waterfall */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th, .data-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.data-table th {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-secondary);
}

.data-table td.num, .data-table th.num {
  text-align: right;
  white-space: nowrap;
}

.waterfall-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.92rem;
}

.waterfall-row:last-child {
  border-bottom: 0;
  font-weight: 800;
  padding-top: 12px;
}

/* Native <dialog> modal */
dialog.app-dialog {
  margin: auto;
  width: min(94vw, 490px);
  max-height: 90dvh;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  padding: 20px;
  box-shadow: var(--shadow-dialog);
}

dialog.app-dialog::backdrop {
  background: rgba(15, 20, 25, 0.55);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.preview-box {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 14px;
  font-size: 0.88rem;
}

/* Login view */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 22px;
}

/* States: skeleton, empty, error, toast */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--surface-subtle) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
}

.sk-title { height: 28px; width: 65%; margin-bottom: 14px; }
.sk-line { height: 18px; width: 90%; margin-bottom: 10px; }
.sk-btn { height: 44px; width: 100%; }
.sk-card { height: 140px; width: 100%; margin-bottom: 16px; }
.sk-chart { height: 260px; width: 100%; margin-bottom: 16px; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.state-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 28px 20px;
  text-align: center;
}

.state-box h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 800;
}

.state-box p {
  margin: 0 0 14px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.alert-err {
  background: var(--surface-coral);
  border: 1px solid color-mix(in srgb, var(--coral) 40%, transparent);
  color: var(--coral-ink);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.toast-region {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(92vw, 360px);
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: var(--shadow-dialog);
}

.toast.toast-err {
  background: var(--coral);
  color: #FFFFFF;
}

/* Tablet & Desktop breakpoints */
@media (min-width: 768px) {
  .side-rail {
    display: flex;
  }
  .bottom-nav, .top-bar-brand-mobile, .top-bar-actions {
    display: none;
  }
  .main-wrap {
    padding-bottom: 0;
  }
  .top-bar {
    padding: 14px 28px;
  }
  .main-content {
    padding: 22px 28px 40px;
  }
  .hero-ledger {
    grid-template-columns: 1.15fr 1fr;
    gap: 24px;
    padding: 24px;
  }
  .hero-primary {
    padding-bottom: 0;
    padding-right: 24px;
    border-bottom: 0;
    border-right: 1px solid var(--border);
  }
  .hero-amount {
    font-size: 2.35rem;
  }
  .pockets-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .toolbar {
    grid-template-columns: 2fr repeat(4, minmax(0, 1fr));
  }
  .cat-split {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1024px) {
  .charts-row {
    grid-template-columns: 1.35fr 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
