/* ==========================================================================
   CasaBilancio — Design System & Layout
   ========================================================================== */

:root {
  --bg-canvas: #f5f6f3;
  --bg-surface: #ffffff;
  --bg-subtle: #f0f2ee;
  --bg-hover: #eaede7;
  --border-color: #e2e6de;
  --border-strong: #ced4c8;

  --text-primary: #18221d;
  --text-secondary: #516158;
  --text-muted: #7b8a82;

  --brand-primary: #1b6b50;
  --brand-primary-hover: #14543e;
  --brand-soft: #e6f3ee;

  --income-color: #168057;
  --income-soft: #e5f5ee;
  --expense-color: #cf5236;
  --expense-soft: #fcece8;
  --warning-color: #b7791f;
  --warning-soft: #fdf5e4;
  --danger-color: #c53030;
  --danger-soft: #fde8e8;

  --shadow-sm: 0 1px 2px rgba(24, 34, 29, 0.04);
  --shadow-md: 0 4px 16px rgba(24, 34, 29, 0.06);
  --shadow-lg: 0 14px 38px rgba(24, 34, 29, 0.14);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --sidebar-width: 256px;

  --font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg-canvas: #101513;
  --bg-surface: #171e1b;
  --bg-subtle: #1f2824;
  --bg-hover: #27322d;
  --border-color: #293530;
  --border-strong: #394842;

  --text-primary: #edf3ef;
  --text-secondary: #a6b6ad;
  --text-muted: #76877e;

  --brand-primary: #2ea47a;
  --brand-primary-hover: #38ba8c;
  --brand-soft: rgba(46, 164, 122, 0.15);

  --income-color: #34c28d;
  --income-soft: rgba(52, 194, 141, 0.14);
  --expense-color: #ef7458;
  --expense-soft: rgba(239, 116, 88, 0.15);
  --warning-color: #ebb347;
  --warning-soft: rgba(235, 179, 71, 0.15);
  --danger-color: #f26c6c;
  --danger-soft: rgba(242, 108, 108, 0.16);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 18px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.48;
  -webkit-font-smoothing: antialiased;
}

.num, .kpi-value, .mono-num {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Shell & Sidebar
   ========================================================================== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  padding: 20px 16px;
  transition: transform 0.22s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--brand-primary), #2a8f6c);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(27, 107, 80, 0.24);
}

.brand-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-cta {
  margin-bottom: 18px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand-primary);
  font-weight: 600;
}

.sidebar-summary {
  margin-top: auto;
  margin-bottom: 14px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
}

.mini-stat-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 8px 0;
}

.mini-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12.5px;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

.mini-stat-row strong {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.mini-stat-row.net {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
  margin-bottom: 0;
}

.sidebar-footer {
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

.main-area {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 25;
  background: rgba(245, 246, 243, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

[data-theme="dark"] .topbar {
  background: rgba(16, 21, 19, 0.88);
}

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

.page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.year-picker {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 3px 6px;
  box-shadow: var(--shadow-sm);
}

.year-display {
  font-size: 14px;
  font-weight: 700;
  min-width: 48px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.mobile-only {
  display: none;
}

.mobile-add-btn {
  display: none;
}

/* ==========================================================================
   Views & Cards
   ========================================================================== */
.view-container {
  padding: 22px 28px 40px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.card-desc {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ==========================================================================
   Month Strip
   ========================================================================== */
.month-strip-card {
  padding: 14px 18px;
}

.month-strip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

.month-nav-arrows {
  display: flex;
  align-items: center;
  gap: 10px;
}

.active-month-heading {
  font-size: 16px;
  font-weight: 700;
  min-width: 148px;
  text-align: center;
}

.month-pills {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 6px;
}

.month-pill {
  position: relative;
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 8px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-family: inherit;
  transition: all 0.15s ease;
}

.month-pill:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.month-pill.active {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(27, 107, 80, 0.24);
}

.month-pill-name {
  font-size: 12px;
  font-weight: 700;
}

.month-pill-amt {
  font-size: 10.5px;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
}

.month-pill.has-data::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brand-primary);
}

.month-pill.active.has-data::after {
  background: rgba(255, 255, 255, 0.8);
}

/* ==========================================================================
   KPI Cards
   ========================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  transition: border-color 0.15s;
}

.kpi-card.clickable {
  cursor: pointer;
}

.kpi-card.clickable:hover {
  border-color: var(--brand-primary);
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.kpi-edit-tag {
  font-size: 11px;
  color: var(--brand-primary);
  background: var(--brand-soft);
  padding: 2px 7px;
  border-radius: 99px;
  font-weight: 600;
}

.kpi-value {
  font-size: 25px;
  font-weight: 750;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.kpi-value.positive { color: var(--income-color); }
.kpi-value.negative { color: var(--expense-color); }

.kpi-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.kpi-progress {
  height: 5px;
  background: var(--bg-subtle);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 2px;
}

.kpi-progress-bar {
  height: 100%;
  border-radius: 99px;
  transition: width 0.35s ease;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.badge-positive {
  background: var(--income-soft);
  color: var(--income-color);
}

.badge-negative {
  background: var(--expense-soft);
  color: var(--expense-color);
}

.badge-neutral {
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

/* ==========================================================================
   Two-Column Dashboard & Charts
   ========================================================================== */
.dashboard-two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 20px;
}

.annual-charts-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 20px;
}

.pie-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 20px;
  align-items: center;
  min-height: 250px;
}

.pie-svg-wrap {
  position: relative;
  width: 230px;
  height: 230px;
  margin: 0 auto;
}

.pie-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.pie-slice {
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease;
  transform-origin: 115px 115px;
}

.pie-slice:hover,
.pie-slice.highlighted {
  transform: scale(1.04);
}

.pie-slice.dimmed {
  opacity: 0.38;
}

.pie-center-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
  padding: 24px;
}

.pie-center-caption {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.pie-center-value {
  font-size: 18px;
  font-weight: 750;
  color: var(--text-primary);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.pie-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 290px;
  overflow-y: auto;
  padding-right: 4px;
}

.pie-legend-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.14s;
  font-size: 13px;
}

.pie-legend-item:hover,
.pie-legend-item.highlighted {
  background: var(--bg-subtle);
}

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

.pie-legend-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  font-weight: 500;
}

.pie-legend-pct {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: right;
}

.pie-legend-val {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  min-width: 72px;
  text-align: right;
}

.chart-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 46px 16px;
  color: var(--text-muted);
}

/* Bar Chart */
.bar-chart-wrap {
  width: 100%;
  overflow-x: auto;
}

.bar-chart-svg {
  width: 100%;
  min-width: 480px;
  height: 280px;
  display: block;
}

.bar-group {
  cursor: pointer;
}

.bar-group:hover .bar-hit-bg {
  fill: var(--bg-subtle);
}

.bar-rect {
  transition: opacity 0.15s;
}

.bar-group:hover .bar-rect {
  opacity: 0.88;
}

.chart-legend-inline {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.legend-dot-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.dot-income { background: var(--income-color); }
.dot-expense { background: var(--expense-color); }

/* Tooltip */
.chart-tooltip {
  position: fixed;
  z-index: 90;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--bg-surface);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  box-shadow: var(--shadow-lg);
  min-width: 150px;
  line-height: 1.45;
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
}

/* ==========================================================================
   Tables & Budget Inline Editing
   ========================================================================== */
.table-wrap {
  overflow-x: auto;
}

.budget-table-wrap {
  max-height: 315px;
  overflow-y: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 9px 10px;
  font-size: 11.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 2;
}

.data-table th.num,
.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: var(--bg-subtle);
}

.data-table tfoot td {
  padding: 11px 10px;
  font-weight: 700;
  background: var(--bg-subtle);
  border-top: 2px solid var(--border-strong);
  border-bottom: none;
  position: sticky;
  bottom: 0;
}

.cat-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.cat-budget-bar {
  width: 100%;
  height: 3px;
  background: var(--bg-subtle);
  border-radius: 99px;
  margin-top: 4px;
  overflow: hidden;
}

.cat-budget-fill {
  height: 100%;
  border-radius: 99px;
}

.budget-inline-input {
  width: 78px;
  text-align: right;
  font-family: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  transition: all 0.14s;
}

.budget-inline-input:hover {
  border-color: var(--border-strong);
  background: var(--bg-surface);
}

.budget-inline-input:focus {
  outline: none;
  border-color: var(--brand-primary);
  background: var(--bg-surface);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.diff-positive { color: var(--income-color); font-weight: 600; }
.diff-negative { color: var(--expense-color); font-weight: 600; }
.diff-zero { color: var(--text-muted); }

/* ==========================================================================
   Transactions Controls & Quick Add
   ========================================================================== */
.tx-header {
  align-items: center;
}

.tx-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  padding: 7px 10px 7px 31px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  width: 185px;
}

.search-box input:focus {
  outline: none;
  border-color: var(--brand-primary);
  background: var(--bg-surface);
}

.select-input {
  padding: 7px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.select-input:focus {
  outline: none;
  border-color: var(--brand-primary);
}

.active-filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  background: var(--brand-soft);
  color: var(--brand-primary);
  font-size: 12.5px;
  font-weight: 500;
}

.quick-add-bar {
  display: grid;
  grid-template-columns: auto 135px 115px minmax(160px, 1.4fr) minmax(150px, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 12px;
  margin-bottom: 14px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.quick-type-switch {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.qtype-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.14s;
}

.qtype-btn.active.expense {
  background: var(--expense-soft);
  color: var(--expense-color);
}

.qtype-btn.active.income {
  background: var(--income-soft);
  color: var(--income-color);
}

.tx-cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--bg-subtle);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.tx-type-tag {
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
}

.tx-type-tag.expense {
  background: var(--expense-soft);
  color: var(--expense-color);
}

.tx-type-tag.income {
  background: var(--income-soft);
  color: var(--income-color);
}

.tx-amount-expense {
  color: var(--expense-color);
  font-weight: 650;
}

.tx-amount-income {
  color: var(--income-color);
  font-weight: 650;
}

.actions-col {
  width: 78px;
  text-align: right !important;
}

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

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

.empty-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-desc {
  margin: 0;
  font-size: 13px;
}

/* ==========================================================================
   Annual Tables & Matrix
   ========================================================================== */
.annual-months-table tbody tr {
  cursor: pointer;
}

.matrix-table th,
.matrix-table td {
  padding: 8px 8px;
  font-size: 12px;
}

.matrix-table td.matrix-zero {
  color: var(--text-muted);
  opacity: 0.45;
}

.matrix-table td.matrix-peak {
  background: var(--expense-soft);
  color: var(--expense-color);
  font-weight: 650;
  border-radius: 4px;
}

.matrix-table th:first-child,
.matrix-table td:first-child {
  position: sticky;
  left: 0;
  background: var(--bg-surface);
  z-index: 3;
  min-width: 155px;
  border-right: 1px solid var(--border-color);
}

.matrix-table tfoot td:first-child {
  background: var(--bg-subtle);
}

/* ==========================================================================
   Settings & Categories
   ========================================================================== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

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

.category-swatch {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  flex-shrink: 0;
}

.category-item-name {
  font-weight: 600;
  font-size: 13.5px;
}

.category-item-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

.data-actions-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.data-action-box {
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.data-action-box h4 {
  margin: 0;
  font-size: 14px;
}

.data-action-box p {
  margin: 0 0 auto;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.danger-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-strong);
  background: var(--bg-canvas);
}

.danger-zone h4 {
  margin: 0 0 3px;
  font-size: 14px;
}

.danger-zone p {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.danger-buttons {
  display: flex;
  gap: 8px;
}

/* ==========================================================================
   Buttons, Controls & Forms
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--brand-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--brand-primary-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-color);
}

.btn-ghost:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger-color);
  border-color: transparent;
}

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

.btn-link {
  border: none;
  background: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.14s;
}

.icon-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.icon-btn-sm {
  width: 28px;
  height: 28px;
}

.icon-btn.danger:hover {
  background: var(--danger-soft);
  color: var(--danger-color);
}

.kbd-hint {
  margin-left: auto;
  font-family: inherit;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.2);
}

.segmented-control {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 9px;
  padding: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.14s;
}

.seg-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.form-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13.5px;
}

.form-input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.color-input {
  height: 38px;
  padding: 3px;
  cursor: pointer;
}

/* ==========================================================================
   Modals & Toasts
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(16, 22, 19, 0.48);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalIn 0.16s ease-out;
}

.modal-sm {
  max-width: 390px;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-helper {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mtype-btn {
  padding: 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 650;
  cursor: pointer;
}

.mtype-btn.active.expense {
  background: var(--expense-soft);
  border-color: var(--expense-color);
  color: var(--expense-color);
}

.mtype-btn.active.income {
  background: var(--income-soft);
  border-color: var(--income-color);
  color: var(--income-color);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 6px;
}

.modal-footer.space-between {
  justify-content: space-between;
  align-items: center;
}

.btn-group {
  display: flex;
  gap: 8px;
}

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text-primary);
  color: var(--bg-surface);
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.16s ease-out;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .dashboard-two-col,
  .annual-charts-grid {
    grid-template-columns: 1fr;
  }
  .data-actions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .month-pills {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
  .quick-add-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.45);
  }
  .main-area {
    margin-left: 0;
  }
  .mobile-only {
    display: inline-flex;
  }
  .mobile-add-btn {
    display: inline-flex;
  }
  .topbar {
    padding: 12px 16px;
  }
  .view-container {
    padding: 16px;
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .pie-layout {
    grid-template-columns: 1fr;
  }
  .month-pills {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .quick-add-bar {
    grid-template-columns: 1fr;
  }
  .data-actions-grid {
    grid-template-columns: 1fr;
  }
  .form-grid-2 {
    grid-template-columns: 1fr;
  }
}
