:root {
  --color-primary: #f97316;
  --color-primary-dark: #ea580c;
  --color-primary-light: #ffedd5;
  --color-income: #16a34a;
  --color-income-light: #dcfce7;
  --color-expense: #dc2626;
  --color-expense-light: #fee2e2;
  --color-balance: #2563eb;
  --color-balance-light: #dbeafe;
  --color-bg: #f4f6f9;
  --color-card: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

/* ---------- Icon system (inline SVG, replaces emoji glyphs) ---------- */
.icon {
  display: inline-block;
  vertical-align: -0.2em;
  flex-shrink: 0;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  overflow-x: hidden;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 28px 60px;
}
@media (max-width: 640px) {
  .container { padding: 20px 16px 60px; }
}

/* ---------- App shell: sidebar + main content ---------- */
.app-shell { display: flex; align-items: stretch; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-card);
  border-right: 1px solid var(--color-border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 24px; }
.sidebar-brand .logo-box {
  width: 36px; height: 36px; border-radius: 9px; background: var(--color-text);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; flex-shrink: 0;
}
.sidebar-brand .brand-text strong { display: block; font-size: 0.92rem; line-height: 1.2; }
.sidebar-brand .brand-text span { display: block; font-size: 0.7rem; color: var(--color-text-muted); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; color: var(--color-text-muted); font-weight: 500;
  font-size: 0.92rem;
}
.sidebar-nav a .nav-icon { width: 18px; text-align: center; }
.sidebar-nav a:hover { background: var(--color-primary-light); color: var(--color-primary-dark); text-decoration: none; }
.sidebar-nav a.active { background: var(--color-primary); color: #fff; }

.sidebar-footer {
  border-top: 1px solid var(--color-border); margin-top: 14px; padding-top: 14px;
  display: flex; align-items: center; gap: 10px;
}
.sidebar-footer .avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--color-text); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}
.sidebar-footer .user-meta { overflow: hidden; }
.sidebar-footer .user-meta strong { display: block; font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .user-meta span { display: block; font-size: 0.72rem; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .logout-icon { margin-left: auto; color: var(--color-text-muted); font-size: 1.05rem; flex-shrink: 0; }
.sidebar-footer .logout-icon:hover { color: var(--color-expense); }

.sidebar-toggle {
  display: none;
  position: fixed; top: 14px; left: 14px; z-index: 40;
  background: var(--color-card); border: 1px solid var(--color-border);
  border-radius: 8px; padding: 6px 10px; font-size: 1.1rem; cursor: pointer;
}
.sidebar-overlay { display: none; }

@media (max-width: 900px) {
  .sidebar-toggle { display: inline-block; }
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh;
    transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open {
    display: block; position: fixed; inset: 0; background: rgba(15,23,42,0.4); z-index: 25;
  }
}

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

/* ---------- Mini topbar (icons + user menu) ---------- */
.topbar-mini {
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  padding: 14px 28px; background: var(--color-card); border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; z-index: 20;
}
@media (max-width: 900px) {
  /* Account is reachable from the sidebar's own account row now (avatar,
     name, logout) — no need to duplicate it in the header, so free up
     that space on phone/tablet. */
  .topbar-mini { display: none; }
  /* With the header gone, give the page content enough top clearance to
     clear the fixed hamburger button instead of running under it. */
  .main-content .container { padding-top: 56px; }
}
.topbar-icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--color-border);
  background: var(--color-card); display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: var(--color-text-muted); cursor: pointer; position: relative;
}
.topbar-icon-btn .dot { position: absolute; top: 6px; right: 7px; width: 7px; height: 7px; background: var(--color-expense); border-radius: 50%; }

.topbar-user { position: relative; }
.topbar-user-btn {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--color-border);
  border-radius: 999px; padding: 4px 10px 4px 4px; cursor: pointer; background: var(--color-card); font-size: 0.85rem; color: var(--color-text);
}
.topbar-user-btn .avatar-sm {
  width: 28px; height: 28px; border-radius: 50%; background: var(--color-text); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 0.72rem; font-weight: 700;
}
.topbar-user-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 8px); background: var(--color-card);
  border: 1px solid var(--color-border); border-radius: 10px; box-shadow: var(--shadow);
  min-width: 150px; overflow: hidden; z-index: 21;
}
.topbar-user-menu.open { display: block; }
.topbar-user-menu a { display: block; padding: 10px 14px; font-size: 0.88rem; color: var(--color-text); }
.topbar-user-menu a:hover { background: #f8fafc; text-decoration: none; }
.topbar-user-menu a.logout-link { color: var(--color-expense); }

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.95rem;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---------- Cards / layout ---------- */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
@media (max-width: 720px) {
  .grid-3 { grid-template-columns: 1fr; }
}

.stat-card { text-align: left; }
.stat-label { color: var(--color-text-muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 1.8rem; font-weight: 700; margin-top: 6px; }
.stat-income { color: var(--color-income); }
.stat-expense { color: var(--color-expense); }
.stat-balance.positive { color: var(--color-income); }
.stat-balance.negative { color: var(--color-expense); }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.page-header h1 { margin: 0; font-size: 1.5rem; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=tel], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--color-card);
  color: var(--color-text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.15);
}
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 160px; }
.error-text { color: var(--color-expense); font-size: 0.85rem; margin-top: 4px; }

.btn {
  display: inline-block;
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn:hover { background: var(--color-primary-dark); text-decoration: none; }
.btn-secondary { background: #64748b; }
.btn-secondary:hover { background: #475569; }
.btn-danger { background: var(--color-expense); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-block { width: 100%; }

.auth-wrapper {
  max-width: 400px;
  margin: 60px auto;
}
.auth-wrapper .card { padding: 32px; }
.auth-wrapper h1 { text-align: center; margin-top: 0; font-size: 1.4rem; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 0.9rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
th { color: var(--color-text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
tr:hover td { background: #f8fafc; }
.badge { padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.badge-income { background: #dcfce7; color: #166534; }
.badge-expense { background: #fee2e2; color: #991b1b; }
.amount-income { color: var(--color-income); font-weight: 600; }
.amount-expense { color: var(--color-expense); font-weight: 600; }
.actions-cell { text-align: right; }

/* ---------- Row actions (three-dot dropdown) ---------- */
.row-actions { position: relative; display: inline-block; }
.row-actions-trigger {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; border-radius: 8px;
  border: 1px solid transparent; background: transparent;
  color: var(--color-text-muted); cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.row-actions-trigger:hover,
.row-actions-trigger.is-open {
  background: #f1f5f9;
  border-color: var(--color-border);
  color: var(--color-text);
}
.row-actions-trigger:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(249,115,22,0.2);
}
.row-actions-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 150px;
  padding: 6px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: var(--shadow), 0 12px 28px rgba(15,23,42,0.1);
  z-index: 50;
  text-align: left;
  white-space: nowrap;
}
.row-actions-menu.is-open { display: block; }
.row-actions-menu form { margin: 0; }
.row-actions-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 7px;
  background: none;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}
.row-actions-item .icon { flex-shrink: 0; color: var(--color-text-muted); }
.row-actions-item:hover {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  text-decoration: none;
}
.row-actions-item:hover .icon { color: var(--color-primary-dark); }
.row-actions-item.row-actions-item-danger:hover {
  background: var(--color-expense-light);
  color: var(--color-expense);
}
.row-actions-item.row-actions-item-danger:hover .icon { color: var(--color-expense); }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
}
.filter-bar .form-group { margin-bottom: 0; min-width: 150px; }

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

.report-section h2 { font-size: 1.1rem; margin-bottom: 12px; }

.site-footer {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  padding: 20px;
}

/* ---------- Dashboard: quick actions ---------- */
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-income { background: var(--color-income); }
.btn-income:hover { background: #15803d; }
.btn-expense { background: var(--color-expense); }
.btn-expense:hover { background: #b91c1c; }

/* ---------- Dashboard: colored stat cards ---------- */
.stat-card { display: flex; align-items: center; gap: 14px; }
.stat-icon {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}
.stat-icon-income   { background: var(--color-income-light);  color: var(--color-income); }
.stat-icon-expense  { background: var(--color-expense-light); color: var(--color-expense); }
.stat-icon-balance  { background: var(--color-balance-light); color: var(--color-balance); }
.stat-balance { color: var(--color-balance); }
.stat-balance.positive { color: var(--color-balance); }
.stat-balance.negative { color: var(--color-expense); }

/* ---------- Dashboard: two-column layout + chart sizing ---------- */
.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }
.chart-card .chart-wrap { position: relative; height: 280px; }

/* ---------- Dashboard: page header controls ---------- */
.dash-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.date-range-field {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--color-border);
  border-radius: 8px; padding: 8px 12px; background: var(--color-card); font-size: 0.85rem; color: var(--color-text-muted);
}
.date-range-field input[type=date] {
  border: none; padding: 0; font-size: 0.85rem; color: var(--color-text); width: 112px; background: transparent;
}
.date-range-field input[type=date]:focus { box-shadow: none; }
.date-range-field .sep { color: var(--color-text-muted); }

.btn-outline { background: var(--color-card); border: 1px solid var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: #f8fafc; }

.filter-panel-wrap { position: relative; }
.filter-panel {
  display: none; position: absolute; right: 0; top: calc(100% + 8px); background: var(--color-card);
  border: 1px solid var(--color-border); border-radius: 10px; box-shadow: var(--shadow);
  padding: 16px; width: min(280px, calc(100vw - 32px)); z-index: 22;
}
.filter-panel.open { display: block; }
.filter-panel .form-group { margin-bottom: 12px; }
.filter-panel .form-group:last-child { margin-bottom: 0; }

/* ---------- Dashboard: chart header (title + granularity toggle + legend) ---------- */
.chart-card-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.chart-card-head h2 { margin: 0; font-size: 1.05rem; }
.granularity-toggle { display: inline-flex; background: #f1f5f9; border-radius: 8px; padding: 3px; gap: 2px; }
.granularity-toggle button {
  border: none; background: transparent; padding: 5px 11px; border-radius: 6px; font-size: 0.8rem;
  font-weight: 600; color: var(--color-text-muted); cursor: pointer;
}
.granularity-toggle button.active { background: var(--color-primary); color: #fff; }
.inline-legend { display: flex; align-items: center; gap: 16px; font-size: 0.82rem; color: var(--color-text-muted); }
.inline-legend .legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* ---------- Dashboard: recent list (icon rows) ---------- */
.txn-list { list-style: none; margin: 0; padding: 0; }
.txn-list li {
  display: flex; align-items: center; gap: 12px; padding: 11px 0;
  border-bottom: 1px solid var(--color-border);
}
.txn-list li:last-child { border-bottom: none; }
.txn-icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.txn-icon-income { background: var(--color-income-light); color: var(--color-income); }
.txn-icon-expense { background: var(--color-expense-light); color: var(--color-expense); }
.txn-info { flex: 1; min-width: 0; }
.txn-info strong { display: block; font-size: 0.9rem; }
.txn-info span { display: block; font-size: 0.76rem; color: var(--color-text-muted); }
.txn-amount { font-weight: 700; font-size: 0.92rem; white-space: nowrap; }

/* ---------- Dashboard: breakdown donut + legend ---------- */
.breakdown-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.breakdown-head h2 { margin: 0; font-size: 1.05rem; }
.breakdown-body { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.donut-wrap { position: relative; width: 170px; height: 170px; flex-shrink: 0; }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; pointer-events: none; padding: 0 10px;
}
.donut-center span { font-size: 0.72rem; color: var(--color-text-muted); }
.donut-center strong { font-size: 1.05rem; line-height: 1.2; }
.breakdown-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 180px; font-size: 0.85rem; }
.breakdown-legend li { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; }
.breakdown-legend .swatch { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.breakdown-legend .legend-name { display: flex; align-items: center; color: var(--color-text-muted); }
.breakdown-legend .legend-val { font-weight: 600; }
select.select-sm {
  width: auto; padding: 6px 10px; font-size: 0.82rem; border-radius: 999px;
}

/* ---------- Modal (Add Income / Add Expense) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55);
  display: none; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--color-card); border-radius: var(--radius); width: 100%; max-width: 460px;
  padding: 24px; box-shadow: 0 25px 50px rgba(0,0,0,0.25);
  max-height: 92vh; overflow-y: auto;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h2 { margin: 0; font-size: 1.15rem; }
.modal-close {
  background: none; border: none; font-size: 1.5rem; line-height: 1;
  color: var(--color-text-muted); cursor: pointer; padding: 0 4px;
}
.modal-close:hover { color: var(--color-text); }

/* ---------- Reports: 4-col summary grid ---------- */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 960px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid-4 { grid-template-columns: 1fr; } }

/* ---------- Reports: quick-filter chips ---------- */
.quick-filter-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn {
  display: inline-block; padding: 6px 14px; border-radius: 999px; font-size: 0.82rem;
  font-weight: 600; background: #f1f5f9; color: var(--color-text-muted); border: 1px solid transparent;
}
.chip-btn:hover { background: var(--color-primary-light); color: var(--color-primary-dark); text-decoration: none; }
.chip-btn.active { background: var(--color-primary); color: #fff; }

/* ---------- Reports: professional filter row (quick chips | divider | custom range) ---------- */
.filter-panel-row { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.filter-divider { width: 1px; align-self: stretch; min-height: 38px; background: var(--color-border); flex-shrink: 0; }
@media (max-width: 760px) {
  .filter-divider { display: none; }
  .filter-panel-row { gap: 14px; }
}
.custom-range-form { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0; }
.custom-range-form .date-range-field { flex-wrap: wrap; }
.date-range-label { font-size: 0.78rem; font-weight: 600; color: var(--color-text-muted); flex-shrink: 0; }

/* ---------- Reports: insights ---------- */
.insights-card h2 { margin: 0 0 14px; font-size: 1.05rem; }
.insights-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 860px) { .insights-grid { grid-template-columns: 1fr; } }
.insight-item {
  display: flex; align-items: flex-start; gap: 12px; background: #f8fafc;
  border: 1px solid var(--color-border); border-radius: var(--radius); padding: 14px 16px;
}
.insight-item .insight-icon { font-size: 1.3rem; line-height: 1; flex-shrink: 0; }
.insight-item strong { display: block; font-size: 0.85rem; margin-bottom: 4px; }
.insight-item span { font-size: 0.85rem; color: var(--color-text-muted); line-height: 1.4; }

/* ---------- Reports: chart sizing ---------- */
.chart-card .chart-wrap { position: relative; height: 260px; margin-top: 4px; }

/* ---------- Reports: category progress bars ---------- */
.section-title { font-size: 1.05rem; margin: 0 0 14px; }
.progress-list { list-style: none; margin: 0; padding: 0; }
.progress-list li { margin-bottom: 14px; }
.progress-list li:last-child { margin-bottom: 0; }
.progress-row-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.85rem; margin-bottom: 6px;
}
.progress-row-head span:first-child { font-weight: 600; }
.progress-row-head span:last-child { color: var(--color-text-muted); }
.progress-track { background: #eef2f6; border-radius: 999px; height: 8px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; }
.progress-fill-expense { background: var(--color-expense); }
.progress-fill-income { background: var(--color-income); }

/* ---------- Reports: transactions table toolbar + pagination ---------- */
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 12px; margin-bottom: 16px;
}
.table-toolbar .section-title { flex-shrink: 0; }
.table-toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; justify-content: flex-end; }
.table-search {
  padding: 8px 12px; border: 1px solid var(--color-border); border-radius: 8px;
  font-size: 0.85rem; flex: 1 1 260px; min-width: 0; max-width: 380px;
  background: var(--color-card); color: var(--color-text);
}
.table-search:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(249,115,22,0.15); }
.table-pagination {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 10px; margin-top: 14px; font-size: 0.82rem; color: var(--color-text-muted);
}
.pagination-controls { display: flex; align-items: center; gap: 10px; }
.pagination-page { font-weight: 600; color: var(--color-text); }

/* ---------- Print (PDF export via browser print) ---------- */
.print-only { display: none; }
.print-report-header {
  border-bottom: 2px solid var(--color-text); padding-bottom: 10px; margin-bottom: 18px;
}
.print-report-header div { font-size: 0.85rem; color: var(--color-text-muted); }
.print-report-header div:first-child { font-size: 1rem; color: var(--color-text); margin-bottom: 4px; }

@media print {
  .no-print,
  .sidebar, .sidebar-toggle, .sidebar-overlay, .topbar-mini,
  .quick-filter-row, .filter-bar, .table-toolbar-actions, .table-pagination .pagination-controls,
  .site-footer, .toast, .btn, a.chip-btn { display: none !important; }
  .print-only { display: block; }
  .app-shell { display: block; }
  .main-content { width: 100%; }
  .container { max-width: 100%; padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; page-break-inside: avoid; }
  .grid-4, .grid-2, .grid-3 { break-inside: avoid; }
  .chart-card .chart-wrap, .donut-wrap { break-inside: avoid; }
  table { font-size: 0.8rem; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
}

/* =========================================================================
   Mobile phone fixes (<=640px): Dashboard / Transactions / Reports
   Additive only — stacks the control bars full-width so nothing overflows
   the viewport, and turns wide data tables into stacked "card" rows so
   they're readable without pinch-zooming or side-scrolling.
   ========================================================================= */
@media screen and (max-width: 640px) {
  /* Dashboard header controls: date range, filter, add-transaction button —
     stack each full width so nothing has to share a row with a narrow
     sibling (that narrowness is what pushed the filter dropdown off-screen). */
  .dash-controls { width: 100%; }
  .dash-controls > * { flex: 1 1 100%; width: 100%; }
  .date-range-field input[type=date] { flex: 1 1 auto; width: auto; min-width: 0; }

  /* Filter dropdown: an absolutely-positioned, edge-anchored popover has no
     reliable anchor once its trigger button is full-width and can end up
     mostly off-screen — render it inline instead, directly under the button. */
  .filter-panel-wrap { position: static; }
  .filter-panel {
    position: static;
    display: none;
    width: 100%;
    margin-top: 8px;
    box-shadow: none;
  }
  .filter-panel.open { display: block; }

  /* Transactions filter form: one field per row instead of a cramped grid */
  .filter-bar .form-group { flex: 1 1 100%; min-width: 0; }

  /* Reports: search + export buttons take their own full-width row */
  .table-toolbar { flex-direction: column; align-items: stretch; }
  .table-toolbar-actions { justify-content: flex-start; }
  .table-search { flex: 1 1 100%; max-width: none; }

  /* Reports: quick-filter chips as a tidy 2-column grid instead of a
     ragged wrap (3 on one row, 1 orphaned alone on the next) */
  .filter-panel-row { flex-direction: column; align-items: stretch; gap: 18px; }
  .quick-filter-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .chip-btn { text-align: center; padding: 8px 10px; }

  /* Reports: From / To as clean stacked labeled fields, not an inline row
     that wraps mid-way through a date */
  .custom-range-form {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--color-border);
  }
  .custom-range-form .date-range-field {
    flex-wrap: wrap;
    width: 100%;
    gap: 6px 10px;
    padding: 10px 12px;
  }
  .custom-range-form .date-range-label,
  .custom-range-form .date-range-field input[type=date] {
    flex: 1 1 100%;
    width: 100%;
  }
  .custom-range-form .date-range-label { margin-top: 4px; }
  .custom-range-form .date-range-label[for="start_date"] { margin-top: 0; }
  .custom-range-form .date-range-field .sep { display: none; }
  .custom-range-form .btn { width: 100%; }

  /* Breakdown donut + legend: center the donut when it wraps to its own row */
  .breakdown-body { justify-content: center; }
  .donut-wrap { margin: 0 auto; }
}

/* ---------- Responsive "card" tables (Transactions list, Reports detail table) ---------- */
@media screen and (max-width: 700px) {
  table.responsive-table thead { display: none; }
  table.responsive-table,
  table.responsive-table tbody,
  table.responsive-table tr,
  table.responsive-table td {
    display: block;
    width: 100%;
  }
  table.responsive-table tr {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 4px 12px;
  }
  table.responsive-table tr:hover td { background: transparent; }
  table.responsive-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--color-border);
    white-space: normal;
    text-align: right;
  }
  table.responsive-table td:last-child { border-bottom: none; }
  table.responsive-table td::before {
    content: attr(data-label);
    flex-shrink: 0;
    text-align: left;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-muted);
  }
  table.responsive-table td.actions-cell { justify-content: flex-end; }
  table.responsive-table td.actions-cell::before { content: none; }
}

/* ---------- Toast notifications ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: #1e293b; color: #fff;
  padding: 12px 18px; border-radius: 8px; box-shadow: var(--shadow);
  font-size: 0.9rem; z-index: 300; opacity: 0; transform: translateY(10px);
  transition: opacity .25s ease, transform .25s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-success { background: var(--color-income); }
.toast.toast-error { background: var(--color-expense); }

/* ---------- Auth extras: Google button, divider, OTP input, badges ---------- */
.auth-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 18px 0; color: var(--color-text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--color-border);
}

.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-google .icon { color: var(--color-primary); }

.otp-input {
  letter-spacing: 0.5em;
  font-size: 1.4rem;
  text-align: center;
  font-weight: 700;
}

.badge-google {
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 6px; padding: 2px 10px 2px 8px;
  background: #e8f0fe; color: #1a73e8;
}
.badge-google .icon { color: #1a73e8; }

/* =========================================================================
   Auth split-screen (login.php / register.php)
   New, additive classes only — nothing above this block is modified, so
   forgot_password.php / verify_otp.php / reset_password.php / complete_profile.php
   (which still use .auth-wrapper) keep their existing look untouched.
   ========================================================================= */

.auth-page {
  position: relative;
  left: 50%;
  width: 100vw;
  margin-left: -50vw;
  margin-top: -24px;
  margin-bottom: -60px;
  min-height: 100vh;
  display: flex;
  background: var(--color-card);
}
@media (max-width: 640px) {
  .auth-page { margin-top: -20px; }
}

/* ---- Left: branding panel ---- */
.auth-brand {
  flex: 1 1 44%;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
  padding: 48px 56px;
  overflow: hidden;
  background: linear-gradient(160deg, #fff8f1 0%, #ffe6c9 55%, #ffcf9e 100%);
  color: var(--color-text);
}
.auth-brand::before,
.auth-brand::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, rgba(249,115,22,0.30), rgba(249,115,22,0) 70%);
}
.auth-brand::before { width: 420px; height: 420px; top: -160px; right: -140px; }
.auth-brand::after  { width: 320px; height: 320px; bottom: -120px; left: -90px; }

.auth-brand-logo { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; }
.auth-brand-logo .logo-box {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  background: var(--color-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 18px rgba(249,115,22,0.35);
}
.auth-brand-logo strong { display: block; font-size: 1.05rem; color: var(--color-text); }
.auth-brand-logo span {
  display: block; font-size: 0.72rem; color: var(--color-primary-dark);
  font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; margin-top: 1px;
}

.auth-brand-hero { position: relative; z-index: 1; max-width: 420px; }
.auth-brand-hero h2 { margin: 0 0 12px; font-size: 2.1rem; line-height: 1.2; font-weight: 800; color: var(--color-text); }
.auth-brand-hero h2 span { color: var(--color-primary); }
.auth-brand-hero p { margin: 0; font-size: 0.98rem; color: var(--color-text-muted); }

.auth-features { position: relative; z-index: 1; list-style: none; margin: 26px 0 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.auth-features li { display: flex; align-items: flex-start; gap: 12px; }
.auth-features .feature-icon {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  background: rgba(249,115,22,0.16); color: var(--color-primary-dark);
  display: flex; align-items: center; justify-content: center;
}
.auth-features strong { display: block; font-size: 0.92rem; color: var(--color-text); }
.auth-features span { display: block; font-size: 0.8rem; color: var(--color-text-muted); margin-top: 1px; }

.auth-brand-bottom { position: relative; z-index: 1; font-size: 0.85rem; font-weight: 600; color: var(--color-primary-dark); }
.auth-brand-bottom em { display: block; margin-top: 8px; width: 46px; height: 3px; background: var(--color-primary); border-radius: 3px; font-style: normal; }

/* ---- Right: form panel ---- */
.auth-form-panel {
  flex: 1 1 56%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: var(--color-bg);
}

.auth-card-logo { display: none; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-card-logo .logo-box {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: var(--color-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.auth-card-logo strong { font-size: 0.98rem; color: var(--color-text); }

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--color-card);
  border-radius: 18px;
  box-shadow: 0 24px 48px rgba(15,23,42,0.10), 0 2px 8px rgba(15,23,42,0.06);
  padding: 40px 36px;
}
.auth-card h1 { margin: 0 0 6px; font-size: 1.55rem; font-weight: 800; color: var(--color-text); }
.auth-card .auth-subtitle { margin: 0 0 26px; font-size: 0.92rem; color: var(--color-text-muted); }
.auth-card .alert { margin-bottom: 18px; }

.auth-field { margin-bottom: 18px; }
.auth-field label { display: block; margin-bottom: 6px; font-size: 0.86rem; font-weight: 600; color: var(--color-text); }

.auth-input-wrap { position: relative; display: flex; align-items: center; }
.auth-input-wrap .field-icon {
  position: absolute; left: 13px; display: flex; color: var(--color-text-muted); pointer-events: none;
}
.auth-input-wrap input {
  width: 100%;
  padding: 11px 14px 11px 40px;
  border: 1.5px solid var(--color-border);
  border-radius: 10px;
  font-size: 0.96rem;
  background: var(--color-card);
  color: var(--color-text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.auth-input-wrap input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(249,115,22,0.14);
}
.auth-input-wrap.has-toggle input { padding-right: 42px; }
.auth-input-wrap .toggle-visibility {
  position: absolute; right: 10px;
  background: none; border: none; padding: 6px; margin: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted); cursor: pointer; border-radius: 6px;
  transition: color .15s ease, background .15s ease;
}
.auth-input-wrap .toggle-visibility:hover { color: var(--color-primary); background: var(--color-primary-light); }
.auth-input-wrap .toggle-visibility .icon-off { display: none; }
.auth-input-wrap .toggle-visibility.is-visible .icon-on { display: none; }
.auth-input-wrap .toggle-visibility.is-visible .icon-off { display: inline-block; }

.auth-field.field-invalid .auth-input-wrap input { border-color: var(--color-expense); }
.auth-field.field-invalid .auth-input-wrap input:focus { box-shadow: 0 0 0 4px rgba(220,38,38,0.12); }
.auth-field .field-error { display: none; margin-top: 5px; font-size: 0.8rem; color: var(--color-expense); }
.auth-field.field-invalid .field-error { display: block; }

.auth-row-between { display: flex; align-items: center; justify-content: flex-end; margin: -6px 0 18px; font-size: 0.85rem; }

.auth-submit .btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 10px 20px rgba(249,115,22,0.28);
  transition: background .15s ease, box-shadow .15s ease, transform .1s ease;
}
.auth-submit .btn:hover { transform: translateY(-1px); box-shadow: 0 12px 24px rgba(249,115,22,0.35); }
.auth-submit .btn:active { transform: translateY(0); }
.auth-submit .btn[disabled] { opacity: 0.75; cursor: not-allowed; transform: none; }
.btn-spinner {
  display: none; width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff;
  animation: auth-btn-spin 0.7s linear infinite;
}
.auth-submit .btn.is-loading .btn-spinner { display: inline-block; }
.auth-submit .btn.is-loading .btn-label { opacity: 0.85; }
@keyframes auth-btn-spin { to { transform: rotate(360deg); } }

.auth-card .auth-divider { margin: 22px 0; }
.auth-card .btn-google { transition: background .15s ease, border-color .15s ease, box-shadow .15s ease; }
.auth-card .btn-google:hover { box-shadow: 0 4px 12px rgba(15,23,42,0.08); border-color: #cbd5e1; }
.auth-card .auth-switch { margin-top: 22px; }

@media (max-width: 900px) {
  .auth-brand { display: none; }
  .auth-card-logo { display: flex; }
  .auth-form-panel { flex: 1 1 100%; padding: 32px 18px; }
}
@media (max-width: 640px) {
  .auth-card { padding: 28px 20px; border-radius: 14px; }
  .auth-card h1 { font-size: 1.35rem; }
}