/* ==========================================================================
   Finance Tracker — "Quiet Progress" dark dashboard theme
   ========================================================================== */

:root {
  --bg:        #0F172A;
  --panel:     #1B2338;
  --panel-alt: #222C45;
  --border:    #2E3A55;
  --text:      #E6EDF7;
  --muted:     #8FA0BC;
  --dim:       #162033;

  --violet:  #7C5CFF;
  --blue:    #3B82F6;
  --teal:    #2DD4BF;
  --pink:    #EC4899;
  --green:   #34D399;
  --amber:   #F59E0B;
  --orange:  #F97316;
  --cyan:    #06B6D4;
  --emerald: #10B981;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

body {
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-top: env(safe-area-inset-top, 0px);
}

img { max-width: 100%; }
[hidden] { display: none !important; }

a { color: var(--blue); }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom-on-focus */
}

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

.app-shell {
  width: min(1540px, 100%);
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 18px;
}

.sidebar {
  position: sticky;
  top: 18px;
  align-self: start;
  height: calc(100vh - 36px);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #111A33 0%, #121B31 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.sidebar-kicker {
  margin: 7px 10px 28px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px rgba(52, 211, 153, .75);
}

.workspace {
  min-width: 0;
  padding-bottom: 96px;
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 82px;
  padding: 12px 4px 18px;
  background: transparent;
  border-bottom: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.2px;
}

.sidebar .brand { padding: 2px 10px; font-size: 18px; }
.sidebar .brand .dot { width: 13px; height: 13px; box-shadow: 0 0 16px rgba(45, 212, 191, .6); }

.page-heading h1 { margin: 0; font-size: 27px; line-height: 1.1; letter-spacing: -.03em; }
.page-heading p { margin: 7px 0 0; color: var(--teal); font-size: 12px; }

.brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--violet), var(--teal));
  flex: none;
}

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

.user-chip { display: flex; align-items: center; gap: 9px; padding: 7px 10px; background: rgba(27, 35, 56, .7); border: 1px solid var(--border); border-radius: 999px; }
.user-chip > span { width: 32px; height: 32px; display: grid; place-items: center; color: white; background: linear-gradient(135deg, var(--violet), var(--blue)); border-radius: 50%; font-weight: 800; }
.user-chip div { display: flex; flex-direction: column; padding-right: 4px; }
.user-chip strong { font-size: 12px; }
.user-chip small { color: var(--muted); font-size: 10px; }

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

.tabs {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}

.tab-btn {
  flex: none;
  min-height: 44px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  text-align: left;
}

.tab-btn.active {
  background: linear-gradient(90deg, rgba(59, 130, 246, .18), rgba(45, 212, 191, .08));
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--cyan), inset 0 0 0 1px rgba(59, 130, 246, .25);
}

.nav-icon { width: 22px; color: var(--cyan); text-align: center; font-size: 18px; }

.view { display: none; }
.view.active { display: block; }

/* ---------- Familiar yearly spreadsheet view ---------- */

.yearly-toolbar {
  padding: 18px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.yearly-toolbar h2 { margin: 0 0 5px; font-size: 20px; }
.yearly-toolbar p { margin: 0; color: var(--muted); font-size: 13px; }
.yearly-search { min-width: 230px; }
.yearly-search span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.yearly-search input { width: 100%; min-height: 42px; padding: 9px 12px; color: var(--text); background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); }

.year-pills { display: flex; gap: 8px; margin: 12px 0; overflow-x: auto; padding-bottom: 2px; }
.year-pill { min-width: 72px; min-height: 42px; padding: 0 16px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 999px; font-weight: 700; }
.year-pill.active { color: var(--bg); background: var(--teal); border-color: var(--teal); }

.yearly-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; overflow: hidden; }
.yearly-summary > div { display: flex; flex-direction: column; gap: 7px; padding: 16px 18px; background: var(--panel); }
.yearly-summary span { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.yearly-summary strong { font-size: 20px; }

.yearly-grid-card { margin-top: 12px; overflow: hidden; }
.yearly-grid-wrap { max-height: 68vh; overflow: auto; overscroll-behavior: contain; }
.yearly-grid { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; font-variant-numeric: tabular-nums; }
.yearly-grid th, .yearly-grid td { min-width: 118px; height: 46px; padding: 8px 10px; text-align: right; white-space: nowrap; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.yearly-grid thead th { position: sticky; top: 0; z-index: 4; max-width: 150px; overflow: hidden; text-overflow: ellipsis; color: var(--text); background: #222C45; text-align: center; }
.yearly-grid .month-col { position: sticky; left: 0; z-index: 3; min-width: 92px; color: var(--text); background: #222C45; text-align: left; font-weight: 800; }
.yearly-grid thead .month-col { z-index: 6; }
.yearly-grid .total-col { position: sticky; right: 0; z-index: 3; min-width: 132px; color: var(--amber); background: #202A42; font-weight: 800; }
.yearly-grid thead .total-col { z-index: 6; text-align: center; }
.yearly-grid td { color: var(--text); background: var(--panel); }
.yearly-grid td.has-value { color: #C8F8ED; background: rgba(45, 212, 191, .06); }
.yearly-grid td.zero { color: #5F6D87; background: var(--dim); }
.yearly-grid tbody tr:hover td { background: rgba(59, 130, 246, .10); }
.yearly-grid tfoot th, .yearly-grid tfoot td { position: sticky; bottom: 0; z-index: 4; color: var(--amber); background: #222C45; font-weight: 800; }
.yearly-grid tfoot .month-col { z-index: 6; }
.yearly-grid tfoot .total-col { z-index: 6; }
.yearly-hint { margin: 0; padding: 11px 16px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); }
.yearly-warning { margin-top: 12px; padding: 14px 16px; color: #FCD38D; background: rgba(245, 158, 11, .10); border: 1px solid rgba(245, 158, 11, .35); border-radius: var(--radius-md); font-size: 13px; line-height: 1.5; }

.source-details { margin-top: 12px; overflow: hidden; }
.source-details-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 17px 18px; border-bottom: 1px solid var(--border); }
.source-details-heading h2 { margin: 0 0 5px; font-size: 17px; }
.source-details-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.source-details-heading > span { flex: none; padding: 6px 10px; color: var(--teal); background: rgba(45, 212, 191, .08); border: 1px solid rgba(45, 212, 191, .25); border-radius: 999px; font-size: 12px; font-weight: 800; }

/* ---------- Smart monthly calculators ---------- */
.smart-ledger { margin-top: 24px; }
.smart-ledger-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 14px; padding: 0 4px; }
.smart-ledger-heading h2 { margin: 4px 0 5px; font-size: 22px; }
.smart-ledger-heading p { max-width: 720px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.section-eyebrow { color: var(--teal); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.calculator-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.calculator-tab { display: grid; grid-template-columns: 42px 1fr; grid-template-rows: auto auto; column-gap: 10px; padding: 14px; color: var(--text); text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md); }
.calculator-tab > span { grid-row: 1 / 3; display: grid; place-items: center; width: 42px; height: 42px; background: var(--dim); border-radius: 12px; font-size: 19px; }
.calculator-tab strong { align-self: end; font-size: 14px; }
.calculator-tab small { align-self: start; margin-top: 3px; color: var(--muted); font-size: 11px; }
.calculator-tab.active { border-color: var(--teal); background: linear-gradient(145deg, rgba(45,212,191,.13), rgba(59,130,246,.08)); box-shadow: inset 0 0 0 1px rgba(45,212,191,.15); }
.calculator-panel { overflow: hidden; }
.calculator-toolbar { display: grid; grid-template-columns: 220px minmax(220px, 1fr) auto; gap: 14px; align-items: end; padding: 17px 18px; border-bottom: 1px solid var(--border); }
.calculator-toolbar label > span, .calculator-total span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.calculator-toolbar select, .calculator-toolbar input { width: 100%; min-height: 42px; padding: 9px 12px; color: var(--text); background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.calculator-total { min-width: 190px; padding: 0 4px 3px 18px; border-left: 1px solid var(--border); }
.calculator-total strong { color: var(--teal); font-size: 21px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.detail-list { min-height: 140px; }
.detail-row { width: 100%; display: grid; grid-template-columns: 42px 1fr auto 18px; align-items: center; gap: 11px; padding: 13px 18px; color: var(--text); text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--border); }
.detail-row:hover { background: rgba(59,130,246,.07); }
.detail-row-icon { display: grid; place-items: center; width: 38px; height: 38px; background: var(--dim); border-radius: 11px; }
.detail-row-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.detail-row-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.detail-row-main small { color: var(--muted); font-size: 11px; }
.detail-row-amount { color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums; }
.detail-row-arrow { color: var(--muted); font-size: 22px; }
.calculator-empty { min-height: 140px; display: grid; place-content: center; gap: 7px; padding: 28px; color: var(--muted); text-align: center; }
.calculator-empty strong { color: var(--text); }
.calculator-footer { display: flex; justify-content: space-between; gap: 12px; padding: 11px 18px; color: var(--muted); background: var(--dim); font-size: 11px; }
.detail-number-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-live-total { display: flex; align-items: center; justify-content: space-between; margin-top: 5px; padding: 13px 14px; background: var(--dim); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.detail-live-total span { color: var(--muted); font-size: 12px; }
.detail-live-total strong { color: var(--teal); font-size: 18px; }
.modal-action-spacer { flex: 1; }

/* ---------- Financial planning overview ---------- */
.financial-overview { margin-top: 26px; }
.plan-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.plan-tabs-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.plan-tab { display: flex; min-width: 0; flex-direction: column; gap: 7px; padding: 15px 16px; color: var(--text); text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md); }
.plan-tab span { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.plan-tab strong { overflow: hidden; text-overflow: ellipsis; font-size: 15px; white-space: nowrap; }
.plan-tab.active { border-color: var(--violet); background: linear-gradient(145deg, rgba(124,92,255,.18), rgba(59,130,246,.08)); }
.plan-panel { overflow: hidden; }
.plan-panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 17px 18px; border-bottom: 1px solid var(--border); }
.plan-panel-heading h3 { margin: 0 0 4px; font-size: 17px; }
.plan-panel-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.plan-panel-heading > span { color: var(--teal); font-size: 15px; font-weight: 800; text-align: right; }
.plan-list { max-height: 430px; overflow: auto; }
.plan-row { display: grid; grid-template-columns: 105px minmax(0,1fr) auto; align-items: center; gap: 14px; padding: 13px 18px; border-bottom: 1px solid var(--border); }
.plan-row:last-child { border-bottom: 0; }
.plan-row > span:nth-child(2) { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.plan-row small { color: var(--muted); line-height: 1.35; }
.plan-date { color: var(--muted); font-size: 12px; font-weight: 700; }
.plan-row > strong:last-child { font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.paid-value { color: var(--green); }
.source-detail-wrap { max-height: 62vh; overflow: auto; }
.source-detail-grid { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.source-detail-grid td { min-width: 112px; max-width: 220px; height: 42px; padding: 7px 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.source-detail-grid .detail-text { color: var(--text); background: var(--panel-alt); font-weight: 600; }
.source-detail-grid .detail-number { color: #C8F8ED; background: rgba(45, 212, 191, .06); text-align: right; font-variant-numeric: tabular-nums; }
.source-detail-grid .detail-total { color: var(--amber); font-weight: 800; }
.source-detail-grid .detail-blank { background: var(--dim); }
.source-detail-grid .detail-spacer td { height: 14px; background: var(--bg); }
.source-detail-grid .detail-empty { padding: 28px; color: var(--muted); text-align: center; }

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

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 24px 0 10px;
  font-weight: 700;
}

/* ---------- Date range selector ---------- */

.range-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.range-btn {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.range-btn.active {
  color: var(--bg);
  background: var(--teal);
  border-color: var(--teal);
}

.range-custom {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.range-custom input[type="date"] {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-height: 40px;
}

/* ---------- KPI grid ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.kpi-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.kpi-value.income   { color: var(--green); }
.kpi-value.expense  { color: var(--orange); }
.kpi-value.net.positive { color: var(--emerald); }
.kpi-value.net.negative { color: var(--pink); }
.kpi-value.rate     { color: var(--violet); }

.kpi-sub {
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Chart panel ---------- */

.chart-panel {
  margin-top: 16px;
  padding: 18px;
}

.chart-panel h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.chart-panel p {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--muted);
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.legend {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.legend span.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

/* ---------- Toolbar (transactions view) ---------- */

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-input {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  min-height: 44px;
}

.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

.btn.primary {
  background: linear-gradient(135deg, var(--violet), var(--blue));
  border-color: transparent;
  color: #fff;
}

.btn.danger {
  background: var(--pink);
  border-color: transparent;
  color: #fff;
}

.btn.ghost {
  background: transparent;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.filters-panel {
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

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

.field label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.field select,
.field input {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-height: 40px;
}

.field.amount-range {
  display: flex;
  flex-direction: row;
  gap: 8px;
}
.field.amount-range input { width: 100%; }

.category-multiselect {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
  padding: 8px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.chip {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--dim);
  color: var(--muted);
}

.chip.active {
  background: var(--violet);
  color: #fff;
  border-color: transparent;
}

/* ---------- Transactions table (desktop) ---------- */

.table-wrap {
  margin-top: 12px;
  overflow-x: auto;
}

table.tx-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

table.tx-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

table.tx-table th .arrow {
  opacity: 0.5;
  margin-left: 4px;
}

table.tx-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

table.tx-table tr {
  cursor: pointer;
}

table.tx-table tr:hover td {
  background: var(--panel-alt);
}

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.tag.income  { background: rgba(52, 211, 153, 0.15); color: var(--green); }
.tag.expense { background: rgba(249, 115, 22, 0.15); color: var(--orange); }

.amount-cell.income  { color: var(--green); font-weight: 700; }
.amount-cell.expense { color: var(--pink); font-weight: 700; }

/* ---------- Transactions card list (mobile) ---------- */

.tx-cards { display: none; margin-top: 12px; }

.tx-card {
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tx-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.tx-card-category {
  font-weight: 700;
  font-size: 15px;
}

.tx-card-date {
  font-size: 12px;
  color: var(--muted);
}

.tx-card-amount {
  font-size: 17px;
  font-weight: 800;
}

.tx-card-note {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Pagination ---------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}

.pagination .btn {
  min-height: 40px;
  padding: 0 14px;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 20, 0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--radius-lg); }
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

.modal .field { margin-bottom: 12px; }

.type-toggle {
  display: flex;
  gap: 8px;
}

.type-toggle button {
  flex: 1;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--muted);
  font-weight: 700;
}

.type-toggle button.active[data-type="income"] {
  background: rgba(52, 211, 153, 0.18);
  color: var(--green);
  border-color: var(--green);
}

.type-toggle button.active[data-type="expense"] {
  background: rgba(249, 115, 22, 0.18);
  color: var(--orange);
  border-color: var(--orange);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.modal-actions .btn { flex: 1; }

.form-error {
  color: var(--pink);
  font-size: 13px;
  margin-top: 6px;
  min-height: 16px;
}

/* ---------- Confirm dialog ---------- */

.confirm-box {
  max-width: 360px;
  text-align: center;
}

.confirm-box .confirm-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(236, 72, 153, 0.15);
  color: var(--pink);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  font-size: 22px;
}

.confirm-box p {
  color: var(--muted);
  font-size: 14px;
  margin: 8px 0 18px;
}

/* ---------- Login screen ---------- */

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 24px;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.auth-logo .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--violet), var(--teal));
}

.auth-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.auth-card p.sub {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 20px;
}

.auth-mode-toggle {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}

.auth-mode-toggle button {
  background: none;
  border: none;
  color: var(--blue);
  font-weight: 700;
  padding: 0;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  z-index: 200;
  font-size: 14px;
  max-width: 90vw;
}

.toast.error { border-color: var(--pink); color: var(--pink); }
.toast.success { border-color: var(--green); color: var(--green); }

/* ---------- Empty state ---------- */

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

/* ---------- FAB (mobile add button) ---------- */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--violet), var(--blue));
  color: #fff;
  font-size: 28px;
  border: none;
  box-shadow: 0 10px 30px rgba(124, 92, 255, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

/* ==========================================================================
   Responsive breakpoints
   ========================================================================== */

@media (max-width: 860px) {
  .app-shell { width: 100%; grid-template-columns: 1fr; gap: 10px; padding: 12px; }
  .sidebar { position: static; height: auto; padding: 10px; flex-direction: row; align-items: center; border-radius: var(--radius-md); }
  .sidebar-kicker, .sidebar-footer { display: none; }
  .sidebar .brand { padding: 0 10px; }
  .tabs { margin-left: auto; flex-direction: row; }
  .tab-btn { width: auto; padding: 0 11px; }
  .workspace { padding-bottom: 90px; }
  .topbar { min-height: 70px; padding: 8px 4px 12px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .filters-panel { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .sidebar .brand span.label { display: none; }
  .sidebar .brand { padding: 0 5px; }
  .tabs { flex: 1; justify-content: flex-end; }
  .tab-btn { flex: 1; justify-content: center; padding: 0 6px; font-size: 12px; }
  .nav-icon { display: none; }
  .user-chip div { display: none; }
  .user-chip { padding: 5px; }
  .page-heading h1 { font-size: 23px; }

  .yearly-toolbar { align-items: stretch; flex-direction: column; }
  .yearly-search { min-width: 0; }
  .yearly-summary { grid-template-columns: 1fr; }
  .yearly-summary > div { flex-direction: row; align-items: center; justify-content: space-between; }
  .yearly-grid-wrap { max-height: 62vh; }
  .yearly-grid th, .yearly-grid td { min-width: 105px; }
  .source-details-heading { align-items: flex-start; }
  .source-detail-grid td { min-width: 102px; }
  .smart-ledger-heading { align-items: stretch; flex-direction: column; }
  .smart-ledger-heading .btn { align-self: flex-start; }
  .calculator-tabs { grid-template-columns: 1fr; gap: 8px; }
  .calculator-toolbar { grid-template-columns: 1fr; }
  .calculator-total { padding: 8px 0 0; border-left: 0; border-top: 1px solid var(--border); }
  .calculator-footer { flex-direction: column; }
  .detail-number-grid { grid-template-columns: 1fr; gap: 0; }
  .plan-tabs { grid-template-columns: 1fr 1fr; }
  .plan-row { grid-template-columns: 80px minmax(0,1fr); }
  .plan-row > strong:last-child { grid-column: 2; }
  .plan-panel-heading { align-items: flex-start; flex-direction: column; }

  table.tx-table { display: none; }
  .tx-cards { display: block; }

  .fab { display: flex; }

  .filters-panel { grid-template-columns: 1fr 1fr; }

  .kpi-value { font-size: 20px; }
}

@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-card { padding: 14px; }
}
