:root {
  --bg: #f3f5f1;
  --surface: #ffffff;
  --surface-2: #f7f8f5;
  --ink: #17201b;
  --muted: #69736d;
  --line: #e3e8e2;
  --brand: #b8ee38;
  --brand-deep: #17201b;
  --green: #268d5b;
  --green-soft: #e8f6ee;
  --blue: #356bc4;
  --blue-soft: #eaf1fc;
  --orange: #c76b1d;
  --orange-soft: #fff1df;
  --red: #b94242;
  --shadow: 0 16px 40px rgba(23, 32, 27, .07);
  --radius: 20px;
  --radius-sm: 12px;
}

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

html { color-scheme: light; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body.auth-pending { overflow: hidden; }
.app-locked { display: none !important; }
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(184,238,56,.17), transparent 32%),
    radial-gradient(circle at 85% 80%, rgba(53,107,196,.12), transparent 30%),
    var(--brand-deep);
}
.login-screen.hidden { display: none; }
.login-card { width: min(430px, 100%); padding: 34px; border: 1px solid rgba(255,255,255,.12); border-radius: 26px; background: #fff; box-shadow: 0 32px 90px rgba(0,0,0,.28); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 38px; }
.login-brand strong, .login-brand small { display: block; }
.login-brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.login-copy h1 { font-size: 32px; }
.login-copy > p:not(.eyebrow) { margin: 12px 0 24px; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.login-form input { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; outline: none; background: var(--surface); color: var(--ink); }
.login-form input:focus { border-color: #8aa944; box-shadow: 0 0 0 3px rgba(184,238,56,.23); }
.login-button { width: 100%; min-height: 48px; margin-top: 2px; }
.login-button:disabled { cursor: wait; opacity: .65; }
.login-error { min-height: 18px; margin: -4px 0 0; color: var(--red); font-size: 12px; }
.login-security { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 26px 0 0; color: var(--muted); font-size: 11px; }
.login-security .status-dot { margin: 0; }

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid #7ea028;
  outline-offset: 3px;
}

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 246px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 28px 22px;
  background: var(--brand-deep);
  color: #f5f8f5;
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 42px; }
.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--brand);
  color: var(--brand-deep);
  font-weight: 800;
  font-size: 20px;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; letter-spacing: -.01em; }
.brand small { margin-top: 2px; color: #aab6af; font-size: 12px; }

.primary-nav { display: grid; gap: 8px; }
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #aeb8b2;
  text-align: left;
  transition: background .16s ease, color .16s ease;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--brand); color: var(--brand-deep); font-weight: 700; }
.nav-icon { width: 22px; font-size: 18px; text-align: center; }

.storage-note {
  margin-top: auto;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 14px;
  color: #dbe2de;
}
.status-dot { width: 8px; height: 8px; margin-top: 4px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px rgba(184,238,56,.12); }
.storage-note strong, .storage-note small { display: block; }
.storage-note strong { font-size: 12px; }
.storage-note small { margin-top: 4px; color: #89968e; font-size: 11px; }
.account-card { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding: 12px 14px; border: 1px solid rgba(255,255,255,.1); border-radius: 14px; }
.account-card strong, .account-card small { display: block; }
.account-card strong { font-size: 12px; }
.account-card small { margin-top: 3px; color: #89968e; font-size: 10px; }
.account-card button { padding: 5px 7px; border: 0; background: transparent; color: #c8d1cc; font-size: 11px; font-weight: 700; }
.account-card button:hover { color: #fff; text-decoration: underline; }

.main-content { min-width: 0; padding: 30px clamp(20px, 4vw, 54px) 70px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.topbar-controls { display: flex; align-items: flex-end; gap: 14px; }
.month-picker { display: grid; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.month-picker input { min-height: 42px; padding: 0 11px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--ink); font-weight: 700; }
.route-hidden { display: none !important; }
.permission-hidden { display: none !important; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(26px, 4vw, 36px); letter-spacing: -.04em; line-height: 1.05; }
h2 { margin-bottom: 0; font-size: 18px; letter-spacing: -.02em; }
h3 { margin-bottom: 6px; font-size: 16px; }
.eyebrow { margin-bottom: 8px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }

.topbar-actions, .toolbar-actions, .dialog-actions { display: flex; align-items: center; gap: 10px; }
.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.button:active { transform: translateY(1px); }
.button-primary { background: var(--brand-deep); color: #fff; }
.button-primary:hover { background: #29352e; }
.button-secondary { border-color: var(--line); background: var(--surface); }
.button-secondary:hover, .button-ghost:hover { background: #e9ede8; }
.button-ghost { border-color: transparent; color: var(--muted); }
.icon-button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 24px;
}
.text-button, .danger-link {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
}
.text-button:hover { text-decoration: underline; }
.danger-link { color: var(--red); text-align: left; }

.page { display: none; animation: page-in .22s ease; }
.page.active { display: block; }
@keyframes page-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card, .panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.metric-card { min-height: 148px; display: flex; flex-direction: column; padding: 20px; }
.metric-card.metric-dark { border-color: var(--brand-deep); background: var(--brand-deep); color: #fff; }
.metric-card.metric-warning { background: #fffaf2; }
.metric-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 700; }
.metric-dark .metric-heading { color: #b8c2bc; }
.metric-icon { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--brand); color: var(--brand-deep); font-weight: 800; }
.soft-green { background: var(--green-soft); color: var(--green); }
.soft-blue { background: var(--blue-soft); color: var(--blue); }
.soft-orange { background: var(--orange-soft); color: var(--orange); }
.metric-value { display: block; margin: auto 0 7px; font-size: clamp(21px, 2.1vw, 28px); letter-spacing: -.04em; white-space: nowrap; }
.metric-card small { color: var(--muted); font-size: 11px; }
.metric-dark small { color: #9eaaa3; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .7fr); gap: 18px; margin-bottom: 18px; }
.panel { padding: 22px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.panel-heading.compact { align-items: center; margin-bottom: 16px; }
.period-chip, .count-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.count-chip { min-width: 30px; justify-content: center; padding: 0 8px; background: var(--brand); color: var(--brand-deep); }

.bar-chart { display: grid; gap: 20px; padding: 8px 0 4px; }
.bar-row { display: grid; gap: 9px; }
.bar-label { display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 12px; }
.bar-label strong { color: var(--ink); font-size: 13px; }
.bar-track { height: 13px; overflow: hidden; border-radius: 999px; background: #edf0ec; }
.bar-fill { display: block; width: 0; height: 100%; border-radius: inherit; transition: width .45s ease; }
.bar-fill.sent { background: var(--brand-deep); }
.bar-fill.received { background: var(--brand); }
.reconcile-line { display: flex; justify-content: space-between; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.reconcile-line strong { color: var(--green); }

.alert-panel { display: flex; gap: 16px; background: var(--orange-soft); border-color: #f6d9b7; box-shadow: none; }
.alert-symbol { flex: 0 0 auto; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: #ffd9ad; color: var(--orange); font-weight: 900; }
.alert-panel p:not(.eyebrow) { margin: 10px 0 18px; color: #785b3e; font-size: 13px; line-height: 1.55; }

.activity-list { display: grid; }
.activity-item { display: grid; grid-template-columns: 42px minmax(0,1fr) auto; align-items: center; gap: 12px; padding: 13px 0; border-top: 1px solid var(--line); }
.activity-item:first-child { border-top: 0; padding-top: 0; }
.activity-item:last-child { padding-bottom: 0; }
.activity-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); font-weight: 900; }
.activity-icon.in { background: var(--green-soft); color: var(--green); }
.activity-main strong, .activity-main small { display: block; }
.activity-main small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.activity-amount { text-align: right; font-weight: 800; white-space: nowrap; }
.activity-amount.in { color: var(--green); }

.section-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.section-copy { margin: 0; color: var(--muted); }
.exchange-summary { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 1px; overflow: hidden; margin-bottom: 18px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--line); }
.exchange-summary > div { padding: 16px 18px; background: var(--surface); }
.exchange-summary span, .exchange-summary strong { display: block; }
.exchange-summary span { color: var(--muted); font-size: 11px; }
.exchange-summary strong { margin-top: 7px; font-size: 18px; white-space: nowrap; }

.split-tables { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, .75fr); gap: 18px; align-items: start; }
.table-panel { min-width: 0; padding: 20px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 10px 9px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; letter-spacing: .04em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 12px 9px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbf9; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted-cell { color: var(--muted); }
.row-note { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.edit-row, .delete-row { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: #77827b; font-size: 18px; }
.action-label { display: none; }
.edit-row:hover { background: var(--blue-soft); color: var(--blue); }
.delete-row:hover { background: #feecec; color: var(--red); }
.table-empty td { padding: 32px 10px; color: var(--muted); text-align: center; }

.profit-positive { color: var(--green); font-weight: 800; }
.profit-negative { color: var(--red); font-weight: 800; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.settings-card { display: grid; gap: 20px; align-content: start; }
.password-form { display: grid; gap: 16px; }
.settings-card label, .dialog-form label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.settings-card input, .dialog-form input, .dialog-form select, .dialog-form textarea {
  width: 100%;
  min-height: 43px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
}
.dialog-form textarea { resize: vertical; }
.settings-card input:focus, .dialog-form input:focus, .dialog-form select:focus, .dialog-form textarea:focus { border-color: #8aa944; box-shadow: 0 0 0 3px rgba(184,238,56,.23); }
.settings-card small { color: var(--muted); font-weight: 400; line-height: 1.45; }
.settings-copy { margin: 0; color: var(--muted); line-height: 1.6; }
.form-message { min-height: 18px; margin: -2px 0 0; font-size: 12px; }
.form-message.error { color: var(--red); }
.form-message.success { color: var(--green); }
.logout-wide { width: 100%; }

dialog { width: min(520px, calc(100% - 24px)); max-height: calc(100vh - 28px); padding: 0; overflow: auto; border: 0; border-radius: 22px; background: var(--surface); color: var(--ink); box-shadow: 0 30px 90px rgba(17,25,20,.25); }
dialog::backdrop { background: rgba(17,25,20,.48); backdrop-filter: blur(4px); }
.dialog-form { display: grid; gap: 16px; padding: 24px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 2px; }
.conditional-fields { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.conditional-fields.hidden { display: none; }
.calculation-preview { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 11px; background: var(--green-soft); color: var(--green); }
.calculation-preview span { font-size: 11px; font-weight: 700; }
.calculation-preview strong { color: var(--ink); }
.dialog-actions { justify-content: flex-end; padding-top: 5px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; padding: 12px 16px; border-radius: 11px; background: var(--brand-deep); color: #fff; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1180px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .split-tables { grid-template-columns: 1fr; }
}

@media (max-width: 960px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: auto 0 0; z-index: 10; width: auto; height: auto; padding: 7px max(8px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); border-top: 1px solid rgba(255,255,255,.1); }
  .brand, .storage-note, .account-card { display: none; }
  .primary-nav { display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; }
  .nav-item { min-height: 54px; flex-direction: column; justify-content: center; gap: 3px; padding: 7px 4px; font-size: 10px; text-align: center; touch-action: manipulation; }
  .nav-item span { display: block; }
  .nav-icon { width: auto; font-size: 16px; }
  .main-content { padding: 22px 16px 100px; }
  .topbar { align-items: center; margin-bottom: 22px; }
  .topbar-controls { gap: 8px; }
  .topbar-actions .button-ghost { display: none; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .toast { bottom: 88px; }
}

@media (max-width: 480px) {
  .login-screen { padding: 14px; }
  .login-card { padding: 26px 22px; border-radius: 22px; }
  .login-form input { min-height: 48px; font-size: 16px; }
}

@media (max-width: 720px) {
  body { font-size: 14px; }
  .main-content { padding: max(16px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) calc(92px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .topbar { display: grid; align-items: start; gap: 16px; margin-bottom: 18px; }
  .topbar-controls { width: 100%; display: grid; align-items: stretch; gap: 10px; }
  .month-picker { width: 100%; }
  .month-picker input { width: 100%; min-height: 48px; font-size: 16px; }
  .topbar-actions { width: 100%; }
  .topbar-actions .button-primary { min-width: 0; width: 100%; min-height: 46px; padding: 0 16px; font-size: 14px; }
  .topbar-actions .button-primary span { font-size: 20px; }
  .metrics-grid { grid-template-columns: 1fr; gap: 10px; }
  .metric-card { min-height: 104px; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto 1fr; padding: 15px 16px; border-radius: 16px; }
  .metric-heading { grid-column: 1 / -1; align-items: center; font-size: 11px; }
  .metric-icon { width: 28px; height: 28px; }
  .metric-value { max-width: 100%; align-self: end; margin: 14px 0 0; overflow: visible; font-size: clamp(20px, 6.2vw, 26px); white-space: normal; overflow-wrap: anywhere; }
  .metric-card small { max-width: 145px; align-self: end; justify-self: end; margin: 14px 0 2px 12px; text-align: right; line-height: 1.35; }
  .panel { padding: 16px; border-radius: 17px; }
  .bar-label { min-width: 0; }
  .bar-label strong { font-size: 11px; }
  .panel-heading { margin-bottom: 17px; }
  .period-chip { display: none; }
  .activity-item { grid-template-columns: 38px minmax(0,1fr); }
  .activity-amount { grid-column: 2; text-align: left; }
  .section-toolbar { align-items: flex-start; }
  .section-copy { display: none; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .button { flex: 1; min-height: 46px; padding-inline: 10px; }
  .exchange-summary { grid-template-columns: 1fr; }
  .exchange-summary > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 14px; }
  .exchange-summary span { max-width: 48%; line-height: 1.35; }
  .exchange-summary strong { margin-top: 0; font-size: 15px; text-align: right; }
  .table-panel { padding: 16px 12px; }
  .table-wrap { overflow: visible; }
  table, tbody { display: block; width: 100%; }
  thead { display: none; }
  tbody { display: grid; gap: 12px; }
  tbody tr { display: block; padding: 7px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
  tbody td { display: grid; grid-template-columns: minmax(92px, .85fr) minmax(0, 1.15fr); align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); text-align: right; white-space: normal; }
  tbody td::before { content: attr(data-label); color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
  tbody td:last-child { border-bottom: 0; }
  tbody td:nth-last-child(2) { border-bottom: 0; }
  .row-note { max-width: none; overflow: visible; overflow-wrap: anywhere; text-overflow: clip; white-space: normal; }
  .table-actions-cell { display: block; padding: 9px 0 3px; }
  .table-actions-cell::before, .table-actions-cell:empty { display: none; }
  .row-actions { justify-content: stretch; gap: 8px; }
  .edit-row, .delete-row { width: auto; height: 42px; flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px; background: var(--surface-2); font-size: 17px; font-weight: 700; }
  .action-label { display: inline; font-size: 12px; }
  tbody tr.table-empty { display: block; padding: 0; border: 0; }
  tbody tr.table-empty td { display: block; padding: 24px 8px; border: 0; text-align: center; }
  tbody tr.table-empty td::before { display: none; }
  .conditional-fields { grid-template-columns: 1fr; }
  dialog { width: 100%; max-width: none; max-height: calc(100dvh - 8px); margin: auto 0 0; border-radius: 22px 22px 0 0; }
  .dialog-form { padding: 19px max(16px, env(safe-area-inset-right)) calc(19px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .dialog-form input, .dialog-form select, .dialog-form textarea { min-height: 48px; font-size: 16px; }
  .settings-card input { min-height: 48px; font-size: 16px; }
  .dialog-actions .button { min-height: 46px; flex: 1; padding-inline: 10px; }
  .toast { right: 14px; bottom: 88px; left: 14px; text-align: center; }
}

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