/* ============================================================
   GLOBAL THEME — Soft Light, Modern, Apple‑like
   ============================================================ */

:root {
  --bg: #F7F8FA;
  --card-bg: #FFFFFF;
  --border: #E2E4E8;
  --text: #1F2937;
  --text-muted: #6B7280;
  --accent: #3B82F6;
  --accent-hover: #2563EB;
  --hover: #F1F5F9;
  --radius: 12px;
  --shadow: 0 2px 6px rgba(0,0,0,0.06);
  --transition: 0.2s ease;
}

body[data-theme="dark"] {
  --bg: #0F172A;
  --card-bg: #111827;
  --border: #334155;
  --text: #E5E7EB;
  --text-muted: #94A3B8;
  --accent: #60A5FA;
  --accent-hover: #93C5FD;
  --hover: #1E293B;
  --shadow: 0 8px 22px rgba(0,0,0,0.35);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body[data-theme="dark"] .modal,
body[data-theme="dark"] .summary-card,
body[data-theme="dark"] .chart-card,
body[data-theme="dark"] .app-header,
body[data-theme="dark"] .tabs,
body[data-theme="dark"] .tab-content,
body[data-theme="dark"] .site-footer {
  background: var(--card-bg);
  color: var(--text);
  border-color: var(--border);
}

body[data-theme="dark"] .btn-secondary,
body[data-theme="dark"] .pill.pill-muted {
  background: #1F2937;
  color: var(--text);
  border-color: var(--border);
}

body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] textarea {
  background: #0B1220;
  color: var(--text);
  border-color: var(--border);
}

body[data-theme="dark"] .modal-backdrop {
  background: rgba(2, 6, 23, 0.72);
}

body[data-theme="dark"] .tabs {
  background: #0b1220;
  border: 1px solid #273449;
}

body[data-theme="dark"] .tab-button {
  color: #cbd5e1;
  background: transparent;
  border-color: transparent;
}

body[data-theme="dark"] .tab-button:hover {
  background: #1e293b;
  color: #f8fafc;
}

body[data-theme="dark"] .tab-button.active {
  background: #1d4ed8;
  color: #ffffff;
  border-color: #2563eb;
}

body[data-theme="dark"] .tabulator,
body[data-theme="dark"] .tabulator .tabulator-header,
body[data-theme="dark"] .tabulator .tabulator-tableholder,
body[data-theme="dark"] .tabulator .tabulator-footer {
  background: #0b1220;
  border-color: #334155;
  color: #e2e8f0;
}

body[data-theme="dark"] .tabulator .tabulator-col,
body[data-theme="dark"] .tabulator .tabulator-cell {
  border-color: #334155;
}

body[data-theme="dark"] .tabulator .tabulator-row {
  background: #0f172a;
  color: #e2e8f0;
}

body[data-theme="dark"] .tabulator .tabulator-row:nth-child(even) {
  background: #131d31;
}

body[data-theme="dark"] .tabulator .tabulator-row:hover,
body[data-theme="dark"] .tabulator .tabulator-row.tabulator-selected {
  background: #1e293b;
}

body[data-theme="dark"] .chart-card canvas,
body[data-theme="dark"] .debt-payoff-canvas-wrap canvas {
  background: #0b1220;
  border: 1px solid #273449;
  border-radius: 10px;
}

img,
canvas,
svg {
  max-width: 100%;
}

.navbar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  box-shadow: var(--shadow);
}

.navbar a {
  text-decoration: none;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--hover);
  white-space: nowrap;
}

.container {
  width: min(1100px, calc(100% - 32px));
  margin: 20px auto;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.basic-table,
.summary-table {
  width: 100%;
  border-collapse: collapse;
}

.basic-table {
  min-width: 560px;
}

.basic-table td,
.summary-table th,
.summary-table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
}

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

.auth-shell {
  width: 100%;
  max-width: 420px;
}

.auth-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.08);
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.auth-copy {
  margin: 0 0 18px;
  color: var(--text-muted);
  line-height: 1.5;
}

.auth-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #FEE2E2;
  color: #991B1B;
  font-size: 14px;
}

.auth-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-submit {
  width: 100%;
  margin-top: 8px;
}

.auth-divider {
  position: relative;
  margin: 18px 0;
  text-align: center;
}

.auth-divider::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 1px solid var(--border);
}

.auth-divider span {
  position: relative;
  padding: 0 10px;
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 13px;
}

.auth-google-btn {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  text-decoration: none;
  background: #111827;
}

.auth-google-btn:hover {
  background: #1F2937;
}

.auth-hint {
  margin: 16px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.auth-section-switcher {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.auth-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.auth-panel.hidden {
  display: none;
}

.auth-panel h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.auth-status {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #ECFDF5;
  border: 1px solid #A7F3D0;
  font-size: 13px;
  line-height: 1.4;
}

.auth-password-rules {
  margin-top: 8px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #F8FAFC;
}

.auth-password-rules-title {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 6px;
}

.auth-password-rules ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.auth-password-rules li {
  font-size: 12px;
  color: #92400E;
}

.auth-password-rules li::before {
  content: "○ ";
}

.auth-password-rules li.pass {
  color: #166534;
}

.auth-password-rules li.pass::before {
  content: "✓ ";
}

.auth-password-rules li.fail {
  color: #92400E;
}

.auth-password-rules li.fail::before {
  content: "○ ";
}

/* ============================================================
   HEADER
   ============================================================ */

.app-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}

.app-title {
  font-size: 20px;
  font-weight: 600;
}

.app-switcher {
  appearance: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 38px 10px 14px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.app-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.theme-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-switch-track {
  position: relative;
  width: 46px;
  height: 24px;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background var(--transition);
  flex-shrink: 0;
}

.theme-switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.24);
  transition: transform var(--transition);
}

.theme-switch input:checked + .theme-switch-track {
  background: linear-gradient(90deg, #2563eb 0%, #60a5fa 100%);
}

.theme-switch input:checked + .theme-switch-track::after {
  transform: translateX(22px);
}

.theme-switch-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}

.header-menu-toggle {
  display: none;
}

.current-user {
  font-size: 13px;
  color: var(--text-muted);
}

.logout-form {
  margin: 0;
}

.tracker-page {
  padding: 20px;
}

.tracker-upload-card,
.tracker-filters-card,
.tracker-summary-table-card,
.tracker-table-card {
  margin-bottom: 20px;
}

.tracker-upload-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.tracker-copy {
  margin: 6px 0 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.tracker-upload-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.tracker-feedback {
  margin-top: 14px;
  color: var(--text-muted);
  font-size: 14px;
}

.tracker-filter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 16px;
  align-items: end;
}

.tracker-filter-grid label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.tracker-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
}

.tracker-checkbox input {
  width: auto;
  margin: 0;
}

.tracker-summary-grid {
  grid-template-columns: repeat(4, 1fr);
}

.tracker-chart-row {
  align-items: stretch;
}

.tracker-chart-card {
  max-width: none !important;
  min-height: 420px;
}

.tracker-summary-table {
  width: 100%;
  border-collapse: collapse;
}

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

.tracker-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 10px;
  background: #E5E7EB;
  color: #374151;
  font-size: 12px;
  font-weight: 600;
}

.tracker-badge-duplicate {
  background: #FEF3C7;
  color: #92400E;
}

.profile-label {
  font-size: 13px;
  color: var(--text-muted);
}

.profile-select {
  min-width: 140px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
}

.save-status {
  font-size: 14px;
  color: var(--text-muted);
}

/* ============================================================
   BUTTONS / PILLS
   ============================================================ */

.pill {
  padding: 8px 14px;
  border-radius: 20px;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: var(--transition);
}

.pill:hover {
  background: var(--accent-hover);
}

.pill-muted {
  background: #E5E7EB;
  color: #374151;
}

.pill-danger {
  background: #DC2626;
  color: white;
}

.pill.active {
  background: #F97316;
  color: white;
  box-shadow: 0 0 0 2px #FED7AA;
}

.pill.active:hover {
  background: #EA580C;
}

.admin-inline-access-panel {
  margin-top: 10px;
  border: 1px solid #FED7AA;
  border-radius: 10px;
  background: #FFFFFF;
  padding: 12px;
}

.admin-inline-access-title {
  font-size: 12px;
  font-weight: 700;
  color: #1F2937;
  margin-bottom: 8px;
  text-align: left;
}

.admin-inline-access-section-label {
  font-size: 11px;
  color: #6B7280;
  margin: 8px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  text-align: left;
}

.admin-inline-access-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.admin-inline-access-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 7px 8px;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  background: #F9FAFB;
}

.admin-inline-access-label {
  font-size: 12px;
  color: #374151;
  text-align: left;
}

.admin-inline-toggle-btn {
  width: 28px;
  min-width: 28px;
  height: 24px;
  border: 1px solid #D1D5DB;
  border-radius: 7px;
  background: #FFFFFF;
  color: #B91C1C;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: 0.16s ease;
}

.admin-inline-toggle-btn.on {
  color: #166534;
  border-color: #86EFAC;
  background: #F0FDF4;
}

.admin-inline-toggle-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.admin-inline-toggle-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ============================================================
   PROFILE DROPDOWN
   ============================================================ */

.profile-dropdown {
  position: relative;
}

.profile-menu {
  position: absolute;
  top: 42px;
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 180px;
  padding: 6px 0;
  z-index: 20;
}

.profile-menu.hidden {
  display: none;
}

.profile-menu-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: var(--transition);
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
}

.profile-menu-item:hover {
  background: var(--hover);
}

.profile-menu-danger {
  color: #B91C1C;
}

.profile-menu-separator {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

/* ============================================================
   TOGGLE SWITCH
   ============================================================ */

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.toggle input {
  display: none;
}

.slider {
  width: 42px;
  height: 22px;
  background: #D1D5DB;
  border-radius: 22px;
  position: relative;
  transition: var(--transition);
}

.slider::before {
  content: "";
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: var(--transition);
  box-shadow: var(--shadow);
}

.toggle input:checked + .slider {
  background: var(--accent);
}

.toggle input:checked + .slider::before {
  transform: translateX(20px);
}

.toggle-label {
  font-size: 14px;
  color: var(--text-muted);
}

.expense-ai-mode-label {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.expense-ai-mode-help-trigger {
  border-bottom: 1px dotted #9CA3AF;
  line-height: 1.1;
}

.expense-ai-mode-help-tooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  width: min(360px, 80vw);
  background: #111827;
  color: #F9FAFB;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.45;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 25;
}

.expense-ai-mode-label:hover .expense-ai-mode-help-tooltip,
.expense-ai-mode-label:focus-within .expense-ai-mode-help-tooltip {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================================
   TABS
   ============================================================ */

.tabs {
  display: flex;
  gap: 10px;
  padding: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-button {
  display: inline-block;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: #E5E7EB;
  color: var(--text);
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: var(--transition);
  white-space: nowrap;
}

.tab-button.active {
  background: var(--accent);
  color: white;
}

.tab-content {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 0 20px 20px 20px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

/* ============================================================
   SUMMARY CARDS
   ============================================================ */

.summary-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 20px 0;
  box-shadow: var(--shadow);
}

.summary-card h3 {
  margin-top: 0;
  font-size: 16px;
  color: var(--text);
}

.expense-ai-summary {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 13px;
}

.expense-ai-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.expense-ai-dashboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.expense-ai-metric {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px;
  background: #fff;
}

.expense-ai-metric-label {
  font-size: 11px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.expense-ai-metric-value {
  margin-top: 5px;
  font-size: 15px;
  font-weight: 700;
  color: #111827;
}

.expense-ai-metric-value.tone-good {
  color: #065f46;
}

.expense-ai-metric-value.tone-medium {
  color: #92400e;
}

.expense-ai-metric-value.tone-high {
  color: #991b1b;
}

.expense-ai-metric-sub {
  margin-top: 4px;
  font-size: 12px;
  color: #4b5563;
}

.expense-ai-quick-list {
  margin-top: 6px;
  display: grid;
  gap: 6px;
}

.expense-ai-quick-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 6px;
  align-items: center;
  font-size: 12px;
}

.expense-ai-quick-rank {
  padding: 2px 6px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 10px;
}

.expense-ai-plan {
  margin-top: 10px;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 10px;
  background: #f8fbff;
}

.expense-ai-plan-step {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
}

.expense-ai-plan-index {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #3b82f6;
  color: #fff;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.expense-ai-plan-copy {
  margin-top: 2px;
  font-size: 12px;
  color: #4b5563;
}

.expense-ai-item {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px;
  background: #fff;
}

.expense-ai-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  flex-wrap: wrap;
}

.expense-ai-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.expense-ai-badge-high {
  background: #fef3c7;
  color: #92400e;
}

.expense-ai-badge-excessive {
  background: #fee2e2;
  color: #991b1b;
}

.expense-ai-save {
  color: #065f46;
  font-weight: 600;
  white-space: nowrap;
}

.expense-ai-line {
  margin-top: 4px;
  font-size: 12px;
  color: #4b5563;
}

.expense-ai-hint {
  margin-top: 4px;
  font-size: 12px;
  color: #1d4ed8;
  font-weight: 600;
}

.expense-ai-tip {
  margin-top: 5px;
  font-size: 12px;
  color: #111827;
}


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

.summary-item {
  background: var(--hover);
  padding: 10px;
  border-radius: var(--radius);
  text-align: center;
}

.summary-label {
  font-size: 13px;
  color: var(--text-muted);
}

.summary-value {
  font-size: 16px;
  font-weight: 600;
  margin-top: 4px;
}

.asset-mood {
  display: inline-block;
  margin-left: 8px;
  font-size: 18px;
  line-height: 1;
  vertical-align: middle;
  animation: assetMoodBob 1.9s ease-in-out infinite;
}

.asset-mood-text {
  display: inline-block;
  margin-left: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  vertical-align: middle;
}

@keyframes assetMoodBob {
  0% { transform: translateY(0); }
  50% { transform: translateY(-2px) rotate(-4deg); }
  100% { transform: translateY(0); }
}

/* ============================================================
   CATEGORY SUMMARY — FIXED + CLEAN
   ============================================================ */

.category-summary {
  margin-top: 25px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.category-summary table {
  width: 100%;
  border-collapse: collapse;
}

.category-summary th,
.category-summary td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.category-summary th {
  background: var(--hover);
  font-weight: 600;
  color: var(--text);
}

.category-summary tr:last-child td {
  border-bottom: none;
}

/* ============================================================
   UNIVERSAL PIE CHART STYLE — CENTERED + FADE‑IN
   ============================================================ */

.chart-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 25px auto;
  box-shadow: var(--shadow);

  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 420px;
  padding: 20px;
}

/* keep expense-specific charts narrower to avoid wasted width */
.chart-row .chart-card {
  flex: 1 1 calc(50% - 20px);
  max-width: 520px;
}

/* Expenses charts: keep side-by-side, but large enough to read */
#expensesTab .chart-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  align-items: stretch;
}

#expensesTab .chart-row .chart-card {
  width: 100%;
  max-width: none;
  min-height: 460px;
}

#assetsTab .chart-card,
#debtTab .chart-card,
#incomeTab .chart-card {
  flex: 1 1 100%;
  max-width: 620px;
}

#assetsTab .chart-row .chart-card {
  flex: 1 1 calc(50% - 20px);
  max-width: 520px;
}

.chart-card h3 {
  margin: 0 0 12px 0;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

/* Smooth fade + scale animation */
.chart-card canvas {
  width: 100% !important;
  max-width: 700px !important;
  height: auto !important;

  opacity: 0;
  transform: scale(0.96);
  animation: chartFadeIn 0.2s ease-out forwards;
  aspect-ratio: 1 / 1 !important;
  border-radius: 8px;
  background: #fff;
  box-shadow: inset 0 0 12px rgba(0,0,0,0.04);
}

#expensesTab .chart-card canvas {
  max-width: 620px !important;
}

#netCashflowSummary {
  margin-top: 14px;
}

#netCashflowSummary td:last-child,
#netCashflowSummary th:last-child {
  text-align: right;
}

@media (max-width: 1200px) {
  #expensesTab .chart-row {
    grid-template-columns: 1fr;
  }
}

@keyframes chartFadeIn {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================================
   TABULATOR — FIXED + CLEAN
   ============================================================ */

.tabulator {
  background: var(--card-bg) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.tabulator-header {
  background: #ECEFF3 !important;
  border-bottom: 2px solid #D0D4DA !important;
}

.tabulator-col {
  border-right: 1px solid #D5D8DE !important;
}

.tabulator-col-title {
  font-weight: 600;
  color: #374151;
}

.tabulator-row {
  border-bottom: 1px solid #E2E5EA !important;
}

.tabulator-row:nth-child(even) {
  background: #F8F9FB !important;
}

.tabulator-row:hover {
  background: #EEF2F7 !important;
}

.tabulator-cell {
  border-right: 1px solid #E2E5EA !important;
  padding: 10px !important;
  color: var(--text) !important;
  white-space: nowrap;
}

.tabulator-cell:last-child,
.tabulator-col:last-child {
  border-right: none !important;
}

/* Prevent iOS Safari auto-zoom on table cell inputs (font-size < 16px triggers zoom which destroys editor) */
.tabulator-row .tabulator-cell.tabulator-editing input,
.tabulator-row .tabulator-cell.tabulator-editing select,
.tabulator-edit-list {
  font-size: 16px !important;
  touch-action: manipulation;
}

/* ============================================================
   MODALS
   ============================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 9999;
}

.modal-backdrop.active {
  display: flex;
}

.modal-backdrop-front {
  z-index: 10001;
}

.modal {
  background: #ffffff;
  width: min(260px, 100%);
  max-width: 100%;
  padding: 16px 18px;
  border-radius: 14px;
  box-sizing: border-box;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
  animation: fadeIn 0.18s ease-out;
}

.modal-wide {
  width: min(760px, calc(100vw - 32px));
}

.modal h2 {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}

.delete-confirm-modal {
  width: min(420px, calc(100vw - 24px));
}

.strategy-sticky-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  font-size: 12px;
  color: #1e3a8a;
}

.strategy-progress-grid {
  display: grid;
  gap: 8px;
}

.strategy-progress-row {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 10px;
  align-items: center;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 10px;
  background: #f8fafc;
}

.strategy-progress-sub {
  margin-top: 3px;
  font-size: 12px;
  color: #6b7280;
}

.strategy-progress-input {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 7px 8px;
  touch-action: manipulation;
  appearance: none;
  -webkit-appearance: none;
}

.strategy-progress-mobile-value {
  margin-top: 6px;
  font-size: 12px;
  color: #6b7280;
  text-align: center;
}

.strategy-mobile-entry-pad {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10050;
  padding: 10px;
}

.strategy-mobile-entry-card {
  width: min(420px, calc(100vw - 16px));
  background: #fff;
  border-radius: 14px;
  padding: 12px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 18px 30px rgba(0,0,0,0.24);
}

.strategy-mobile-entry-title {
  font-size: 13px;
  color: #374151;
  margin-bottom: 8px;
  text-align: center;
}

.strategy-mobile-entry-display {
  font-size: 28px;
  font-weight: 700;
  color: #111827;
  text-align: center;
  margin-bottom: 10px;
}

.strategy-mobile-entry-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.strategy-mobile-entry-grid .pill {
  border-radius: 10px;
  min-height: 44px;
  font-size: 18px;
}

.strategy-progress-summary {
  margin-top: 6px;
}

.strategy-plan-content {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.strategy-sensitivity-table-wrap {
  overflow-x: auto;
}

.strategy-sensitivity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.strategy-sensitivity-table th,
.strategy-sensitivity-table td {
  border-bottom: 1px solid #e5e7eb;
  padding: 8px;
  text-align: left;
}

.modal-list {
  margin-top: 6px;
  max-height: 180px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.modal-list-item {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 8px;
  border-bottom: 1px solid #f2f2f2;
}

#hideAssetCategoriesList .modal-list-item,
#hideExpenseCategoriesList .modal-list-item {
  user-select: none;
}

#hideAssetCategoriesList .modal-list-item > div,
#hideExpenseCategoriesList .modal-list-item > div {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: auto;
  max-width: 260px;
}

#hideAssetCategoriesList .modal-list-item span,
#hideExpenseCategoriesList .modal-list-item span {
  flex: 1;
  text-align: left;
}

#hideAssetCategoriesList .modal-list-item input[type="checkbox"],
#hideExpenseCategoriesList .modal-list-item input[type="checkbox"] {
  pointer-events: auto;
  touch-action: manipulation;
  width: 16px;
  min-width: 16px;
  max-width: 16px;
  height: 16px;
  margin: 0 6px 0 0;
  margin-bottom: 0;
  padding: 0;
  border: 0;
  border-radius: 2px;
  box-shadow: none;
  flex: 0 0 16px;
  flex-shrink: 0;
}

.mobile-row-editor-modal {
  width: min(520px, calc(100vw - 20px));
}

.mobile-row-editor-form {
  display: grid;
  gap: 10px;
}

.mobile-row-editor-field {
  display: grid;
  gap: 6px;
}

.mobile-row-editor-field label {
  font-size: 13px;
  color: var(--text-muted);
}

.mobile-row-editor-field input,
.mobile-row-editor-field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  background: #fff;
}

.mobile-row-editor-field-checkbox {
  display: flex;
  align-items: center;
  justify-content: space-between;
  grid-template-columns: none;
}

.mobile-row-editor-field-checkbox input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

.desktop-hint-modal {
  width: min(420px, calc(100vw - 24px));
}

.desktop-hint-copy {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}

.desktop-hint-actions {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

.desktop-hint-checkbox {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.desktop-hint-checkbox input {
  width: 16px;
  height: 16px;
}

.mobile-quick-actions {
  display: none;
}

.mobile-quick-action-btn {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 999px;
}

.tab-date-editor {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid #93c5fd;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f8fafc);
  color: #0f172a;
  font-weight: 600;
  padding: 6px 8px;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

.tab-date-editor:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.tab-date-editor::-webkit-calendar-picker-indicator {
  background-color: #dbeafe;
  border-radius: 6px;
  padding: 3px;
  cursor: pointer;
}

.manual-payment-pair {
  display: flex;
  gap: 8px;
  width: 100%;
  align-items: center;
}

.manual-rollover-panel {
  padding: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f8fafc;
  margin-bottom: 8px;
}

.manual-rollover-title {
  font-size: 13px;
  color: #374151;
  margin-bottom: 6px;
}

.manual-rollover-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #374151;
  margin-bottom: 6px;
}

.manual-rollover-help {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 6px;
}

.manual-rollover-select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}

.manual-payment-row {
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
  font-size: 14px;
  overflow: hidden;
}

.manual-payment-heading {
  margin-bottom: 6px;
}

.manual-payment-note {
  color: #6b7280;
  margin-top: 2px;
  font-size: 12px;
}

.manual-custom-freq-row {
  gap: 8px;
  align-items: center;
  width: 100%;
  min-width: 0;
  margin-top: 8px;
}

.manual-payment-input,
.manual-freq-select,
.manual-custom-number,
.manual-custom-unit {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-sizing: border-box;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  background: #fff;
}

@media (max-width: 900px) {
  .tabulator {
    font-size: 13px;
  }

  .tabulator .tabulator-header {
    font-size: 12px;
  }

  .tabulator .tabulator-cell {
    white-space: normal;
    line-height: 1.35;
    padding: 8px !important;
  }

  .tabulator .tabulator-responsive-collapse {
    border-top: 1px dashed #d1d5db;
    padding: 8px 10px;
    background: #f8fafc;
  }

  .tabulator .tabulator-responsive-collapse table {
    width: 100%;
    border-collapse: collapse;
  }

  .tabulator .tabulator-responsive-collapse td {
    padding: 6px 0;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: top;
  }

  .tabulator .tabulator-responsive-collapse td:first-child {
    color: #6b7280;
    width: 46%;
    font-weight: 600;
    padding-right: 10px;
  }

  .tabulator .tabulator-responsive-collapse td:last-child {
    text-align: right;
  }
}

@media (max-width: 760px) {
  .mobile-quick-actions {
    display: flex;
    gap: 6px;
    margin: 0 0 8px;
    position: sticky;
    top: 6px;
    z-index: 8;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 0 6px;
    background: linear-gradient(to bottom, var(--bg) 75%, rgba(247, 248, 250, 0));
    backdrop-filter: saturate(1.1);
  }

  .mobile-quick-actions .mobile-quick-action-btn {
    white-space: nowrap;
    flex: 0 0 auto;
  }

  #expensesActionRow {
    position: sticky;
    top: 46px;
    z-index: 7;
    padding: 6px 0;
    margin-top: 2px !important;
    background: linear-gradient(to bottom, var(--bg) 70%, rgba(247, 248, 250, 0));
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #expensesActionRow .pill {
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .mobile-quick-actions .mobile-quick-action-btn[data-action-target^="export"] {
    display: none !important;
  }

  .tabulator.mobile-card-table {
    height: auto !important;
    min-height: 0 !important;
  }

  .tabulator.mobile-card-table .tabulator-header {
    display: none;
  }

  .tabulator.mobile-card-table .tabulator-tableholder {
    padding: 2px;
    background: #f3f6fb;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .tabulator.mobile-card-table .tabulator-table {
    height: auto !important;
  }

  .tabulator.mobile-card-table .tabulator-row {
    display: block !important;
    background: #fff !important;
    border: 1px solid #d9e1eb !important;
    border-radius: 7px;
    margin: 0 0 4px;
    overflow: visible;
    box-shadow: none;
    position: relative;
    min-height: 0 !important;
    height: auto !important;
    padding-bottom: 0 !important;
  }

  .tabulator.mobile-card-table .tabulator-row.has-card-title::before {
    content: attr(data-card-title);
    display: block;
    padding: 5px 72px 5px 7px;
    font-size: 11px;
    font-weight: 700;
    color: #0b3a78;
    background: #ffffff;
    border-bottom: 0;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-radius: 7px;
    margin-bottom: 0;
  }

  .tabulator.mobile-card-table .tabulator-row.has-card-meta::after {
    content: attr(data-card-meta);
    position: absolute;
    top: 6px;
    right: 7px;
    font-size: 8px;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1;
    max-width: 68px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tabulator.mobile-card-table .tabulator-cell {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    border-right: 0 !important;
    border-bottom: 1px solid #eef2f6 !important;
    white-space: nowrap;
    padding: 7px 10px !important;
  }

  .tabulator.mobile-card-table .tabulator-cell::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    max-width: 46%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tabulator.mobile-card-table .tabulator-cell .tabulator-cell-value,
  .tabulator.mobile-card-table .tabulator-cell > * {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 54%;
    text-align: right;
  }

  .tabulator.mobile-card-table .tabulator-cell[data-summary-visible="false"] {
    display: none !important;
  }

  .tabulator.mobile-card-table .tabulator-cell[data-label="Edit"] {
    display: inline-flex !important;
    position: absolute;
    top: 4px;
    right: 4px;
    width: auto;
    min-width: 48px;
    border: 0 !important;
    padding: 0 !important;
    background: transparent;
    z-index: 3;
  }

  .tabulator.mobile-card-table .tabulator-cell[data-label="Edit"]::before {
    content: "";
    display: none;
  }

  .tabulator.mobile-card-table .tabulator-cell[data-label="Edit"] > * {
    max-width: none;
    background: #dbeafe;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.4;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    min-width: 24px;
    text-align: center;
  }

  .tabulator.mobile-card-table .tabulator-cell[data-label="Edit"] .edit-pill {
    display: inline-block;
  }

  .tabulator.mobile-card-table .tabulator-cell:last-child {
    border-bottom: 0 !important;
  }

  .tabulator.mobile-card-table .tabulator-cell[data-label=""]::before {
    content: "";
  }

  .tabulator.mobile-card-table .tabulator-responsive-collapse {
    display: none !important;
  }

  .tabulator.mobile-card-table .tabulator-responsive-collapse-toggle {
    display: none !important;
  }
}

@media (max-width: 390px) {
  .tabulator.mobile-card-table .tabulator-row.has-card-title::before {
    font-size: 10px;
    line-height: 1.1;
    padding: 4px 64px 4px 6px;
  }

  .tabulator.mobile-card-table .tabulator-row.has-card-meta::after {
    font-size: 7px;
    top: 5px;
    right: 6px;
    max-width: 60px;
  }

  .tabulator.mobile-card-table .tabulator-tableholder {
    padding: 2px;
  }

  .tabulator.mobile-card-table .tabulator-row {
    margin: 0 0 3px;
  }
}

.modal-actions {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.site-footer-version {
  font-size: 12px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--card-bg);
}

.profile-ownership-hint {
  font-size: 11px;
  line-height: 1.2;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--card-bg);
  max-width: min(260px, 45vw);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body[data-theme="dark"] .profile-ownership-hint {
  background: #1F2937;
  border-color: var(--border);
  color: var(--text-muted);
}

body[data-theme="dark"] .theme-switch {
  background: #111827;
  border-color: #334155;
}

body[data-theme="dark"] .theme-switch-track {
  background: #334155;
}

.take-home-pay-copy {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

.take-home-pay-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px 16px;
}

.take-home-pay-grid label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.take-home-pay-grid input,
.take-home-pay-grid select {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 0;
}

.take-home-pay-toggle-row {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

.take-home-pay-result {
  margin-top: 18px;
}

.take-home-pay-frequency-row {
  margin-top: 14px;
}

.take-home-pay-frequency-title {
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.take-home-pay-summary-grid {
  grid-template-columns: repeat(4, minmax(120px, 1fr));
}

.take-home-pay-frequency-grid,
.take-home-pay-add-summary {
  grid-template-columns: repeat(4, minmax(120px, 1fr));
}

.take-home-pay-add-summary {
  display: grid;
  gap: 12px;
  margin: 14px 0;
}

.take-home-pay-add-grid {
  grid-template-columns: 1fr;
}

.take-home-pay-add-modal {
  width: min(560px, calc(100vw - 24px));
}

.take-home-pay-add-modal .take-home-pay-add-summary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.take-home-pay-add-modal .modal-actions {
  justify-content: flex-end;
}

#takeHomePayModalBackdrop .modal,
#takeHomePayAddModalBackdrop .modal {
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.btn-primary {
  background: #4F46E5;
  color: white;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  border: none;
  cursor: pointer;
}

.btn-secondary {
  background: #e5e7eb;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  border: none;
  cursor: pointer;
}

.debt-calc-card {
  margin-top: 24px;
}

.debt-calc-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.debt-calc-row {
  display: grid;
  gap: 24px;
}

.debt-calc-row-full {
  grid-template-columns: 1fr;
}

.debt-calc-row-four {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.debt-calc-row-two {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.debt-calc-grid label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.debt-calc-grid select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: #fff;
  color: var(--text);
}

.debt-calc-grid input,
.debt-calc-grid select {
  margin-bottom: 0;
}

.debt-calc-custom-group {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.debt-calc-custom-group input,
.debt-calc-custom-group select {
  margin-bottom: 0;
}

.debt-calc-actions {
  margin-top: 16px;
}

.debt-calc-results {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text);
}

.debt-calc-chart-card {
  margin-top: 24px;
  min-height: 0;
  width: 100%;
  max-width: none !important;
  align-items: stretch;
}

.debt-payoff-layout {
  display: flex;
  gap: 14px;
  align-items: stretch;
  min-height: 0;
}

.debt-payoff-canvas-wrap {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  height: clamp(320px, 46vh, 500px);
}

.debt-payoff-canvas-wrap canvas {
  width: 100% !important;
  max-width: none !important;
  height: 100% !important;
  aspect-ratio: auto !important;
  display: block;
}

.debt-payoff-summary {
  width: 260px;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}

.debt-additional-payment-summary {
  margin-top: 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: center;
}

.payoff-pill {
  border-radius: 10px;
  padding: 10px 12px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}

.payoff-pill-sub {
  margin-top: 3px;
  font-size: 11px;
  font-weight: 500;
  opacity: 0.92;
}

.payoff-pill-base {
  background: #EF4444;
}

.payoff-pill-extra {
  background: #10B981;
}

.payoff-pill-saved {
  background: #3B82F6;
}

.payoff-pill-interest {
  background: #8B5CF6;
}

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

.account-money-panel {
  min-height: 240px;
}

.account-money-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #f8fafc;
  margin-bottom: 8px;
}

.account-money-row-controls {
  display: grid;
  gap: 6px;
}

.account-money-drag-hint {
  font-size: 11px;
  color: #0369a1;
  font-weight: 600;
}

.account-money-row-draggable {
  cursor: grab;
  user-select: none;
}

.account-money-row-draggable.is-dragging {
  opacity: 0.55;
  transform: scale(0.99);
}

.account-money-row-title {
  font-size: 13px;
  font-weight: 600;
  color: #111827;
}

.account-money-row-sub {
  margin-top: 2px;
  font-size: 12px;
  color: #6b7280;
}

.account-money-route-chip {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 9px;
  border: 1px solid #d1d5db;
  background: #ffffff;
}

.account-money-account-card {
  padding: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #ffffff;
  margin-bottom: 8px;
}

.account-money-drop-zone {
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.account-money-drop-zone.is-drop-target {
  border-color: #0ea5e9;
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.18);
}

.account-money-drop-hint {
  margin-top: 8px;
  font-size: 11px;
  color: #0c4a6e;
  font-weight: 600;
}

.account-money-account-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  opacity: 0.6;
}

.icon-btn:hover {
  opacity: 1;
}

/* ============================================================
   FORMS
   ============================================================ */

input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 12px;
  background: #FFFFFF;
  color: var(--text);
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.25);
}

/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 900px) {
  .chart-row {
    flex-direction: column;
  }
}

@media (max-width: 768px) {
  .navbar {
    overflow-x: auto;
    white-space: nowrap;
  }

  .container {
    width: calc(100% - 20px);
    margin: 12px auto;
  }

  .app-header {
    position: relative;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
  }

  .app-switcher {
    width: calc(100% - 90px);
    max-width: calc(100vw - 120px);
  }

  .header-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 78px;
  }

  .tabs {
    flex-wrap: nowrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .tab-button {
    flex: 0 0 auto;
    text-align: center;
  }

  .tab-content {
    padding: 14px;
    margin: 0 12px 12px 12px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .app-actions {
    display: none;
  }

  .app-header.menu-open .app-actions {
    display: flex !important;
    position: absolute;
    top: calc(100% + 6px);
    left: 12px;
    right: 12px;
    z-index: 30;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 8px !important;
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .app-header.menu-open .app-actions > * {
    width: 100%;
  }

  .app-header.menu-open .current-user,
  .app-header.menu-open .save-status {
    white-space: normal;
    word-break: break-word;
  }

  .profile-select {
    min-width: 0;
  }

  .profile-ownership-hint {
    max-width: 100%;
    width: 100%;
    text-align: center;
  }

  .tracker-upload-actions {
    width: 100%;
  }

  .chart-card {
    min-width: 0 !important;
    min-height: 320px;
  }

  .chart-card canvas {
    height: auto !important;
    aspect-ratio: 1 / 1;
  }

  .take-home-pay-summary-grid,
  .take-home-pay-frequency-grid,
  .take-home-pay-add-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tracker-filter-grid,
  .tracker-summary-grid {
    grid-template-columns: 1fr;
  }

  .debt-calc-row-four,
  .debt-calc-row-two {
    grid-template-columns: 1fr;
  }

  .debt-payoff-layout {
    flex-direction: column;
  }

  .debt-payoff-canvas-wrap {
    height: clamp(280px, 42vh, 420px);
  }

  .debt-payoff-summary {
    width: 100%;
    min-width: 0;
  }

  .strategy-sticky-summary {
    position: static;
    top: auto;
    z-index: auto;
    box-shadow: none;
  }

  .strategy-progress-row {
    grid-template-columns: 1fr;
  }

  .strategy-progress-input {
    min-height: 42px;
    font-size: 16px;
    pointer-events: auto;
    margin-bottom: 0;
  }

  .manual-payment-pair,
  .manual-custom-freq-row {
    flex-direction: row;
    align-items: center !important;
  }

  .manual-payment-input,
  .manual-freq-select,
  .manual-custom-number,
  .manual-custom-unit {
    flex: 1 1 50% !important;
    width: 100% !important;
    min-width: 0 !important;
    font-size: 14px !important;
  }

  .modal {
    max-height: calc(100vh - 12px);
    width: min(760px, calc(100vw - 12px));
    padding: 12px;
    overflow-y: auto;
  }

  .account-money-layout {
    grid-template-columns: 1fr;
  }

  .account-money-row {
    grid-template-columns: 1fr;
  }

  .manual-rollover-select {
    min-height: 40px;
    font-size: 13px;
  }
}

@media (max-width: 560px) {
  .manual-payment-pair,
  .manual-custom-freq-row {
    flex-direction: column;
    align-items: stretch !important;
  }

  .manual-payment-input,
  .manual-freq-select,
  .manual-custom-number,
  .manual-custom-unit {
    flex: 1 1 100% !important;
  }

  .account-money-row-draggable {
    cursor: default;
  }

  .modal-backdrop {
    align-items: flex-start;
    padding: 8px 6px;
    overflow-y: hidden;
  }
}

@media (max-width: 520px) {
  .app-actions > * {
    width: 100%;
  }

  .logout-form button,
  .profile-select,
  #statementFiles {
    width: 100%;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .expense-ai-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .expense-ai-dashboard {
    grid-template-columns: 1fr;
  }

  .expense-ai-quick-item {
    grid-template-columns: 1fr;
  }

  .take-home-pay-grid,
  .take-home-pay-summary-grid,
  .take-home-pay-frequency-grid,
  .take-home-pay-add-summary {
    grid-template-columns: 1fr;
  }

  .take-home-pay-add-modal .modal-actions {
    justify-content: stretch;
  }

  .take-home-pay-add-modal .modal-actions button {
    width: 100%;
  }

  #takeHomePayModalBackdrop .modal-actions,
  #takeHomePayAddModalBackdrop .modal-actions {
    position: sticky;
    bottom: -12px;
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, rgba(247,248,250,0) 0%, var(--card-bg) 28%);
    z-index: 2;
  }
}

/* ============================================================
   MOBILE TABLE SCROLL + WRAP
   ============================================================ */

.tabulator {
  width: 100% !important;
  overflow-x: auto;
}

.tabulator .tabulator-tableHolder {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
}

.tabulator .tabulator-table {
  min-width: 100% !important;
}

.summary-item.threshold-exceeded {
  background: #FEF3C7;
  animation: pulse-highlight 0.5s ease-out;
}

@keyframes pulse-highlight {
  from {
    background: #FBBF24;
  }
  to {
    background: #FEF3C7;
  }
}

@media (max-width: 768px) {
  .tabulator .tabulator-cell {
    white-space: normal !important;
    word-break: break-word !important;
    text-overflow: clip !important;
    overflow: visible !important;
  }

  .tabulator .tabulator-row .tabulator-cell {
    padding: 8px !important;
  }

  /* Mobile header optimization */
  .app-header {
    align-items: center;
    padding: 8px 12px;
  }

  .app-actions {
    flex-direction: column;
    width: 100%;
    gap: 6px !important;
  }

  .mobile-hide-export {
    display: none !important;
  }

  .profile-select,
  .app-switcher {
    font-size: 14px;
    padding: 6px 8px;
  }

  /* Mobile tabs */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 8px;
  }

  .tab-button {
    padding: 8px 12px;
    font-size: 12px;
    flex-shrink: 0;
  }

  /* Mobile tab content */
  .tab-content {
    padding: 8px;
  }

  /* Mobile charts */
  .chart-row {
    flex-direction: column;
    gap: 12px;
  }

  .chart-card {
    min-width: 100%;
    min-height: 250px;
  }

  /* Mobile summary grid */
  .summary-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  /* Mobile buttons */
  .pill {
    padding: 8px 12px;
    font-size: 12px;
  }


body[data-theme="dark"] .summary-table,
body[data-theme="dark"] .tracker-summary-table {
  background: #0b1220;
  color: #e5edf8;
  border-color: #334155;
}

body[data-theme="dark"] .summary-table th,
body[data-theme="dark"] .summary-table td,
body[data-theme="dark"] .tracker-summary-table th,
body[data-theme="dark"] .tracker-summary-table td {
  border-color: #334155;
  color: #e5edf8;
}

body[data-theme="dark"] .tabulator {
  background: #0b1220 !important;
  border-color: #334155 !important;
}

body[data-theme="dark"] .tabulator-header {
  background: #162032 !important;
  border-bottom: 1px solid #334155 !important;
}

body[data-theme="dark"] .tabulator-col,
body[data-theme="dark"] .tabulator-cell {
  border-color: #334155 !important;
}

body[data-theme="dark"] .tabulator-col-title,
body[data-theme="dark"] .tabulator-header .tabulator-col,
body[data-theme="dark"] .tabulator-header .tabulator-col-content,
body[data-theme="dark"] .tabulator-header .tabulator-col-content .tabulator-col-title {
  color: #f8fafc !important;
}

body[data-theme="dark"] .tabulator-row {
  background: #0f172a !important;
  border-bottom: 1px solid #243244 !important;
  color: #e5edf8 !important;
}

body[data-theme="dark"] .tabulator-row:nth-child(even) {
  background: #111c2f !important;
}

body[data-theme="dark"] .tabulator-row:hover,
body[data-theme="dark"] .tabulator-row.tabulator-selected {
  background: #1a2940 !important;
}

body[data-theme="dark"] .tabulator-row .tabulator-cell,
body[data-theme="dark"] .tabulator-row .tabulator-cell *,
body[data-theme="dark"] .tabulator-row .tabulator-cell a {
  color: #e5edf8 !important;
}

body[data-theme="dark"] .tabulator-row .tabulator-cell.tabulator-editing,
body[data-theme="dark"] .tabulator-row .tabulator-cell.tabulator-editing input,
body[data-theme="dark"] .tabulator-row .tabulator-cell.tabulator-editing select,
body[data-theme="dark"] .tabulator-edit-list {
  background: #0b1220 !important;
  color: #f8fafc !important;
  border-color: #3b82f6 !important;
}
  /* Mobile modals */
  .modal {
    width: min(90vw, 100%) !important;
    padding: 12px 14px !important;
  }

  .modal-wide {
    width: min(95vw, 100%) !important;
  }

  /* Mobile inputs */
  input,
  select,
  textarea {
    font-size: 16px !important; /* Prevents zoom on iOS */
    padding: 8px !important;
  }

  /* Mobile tables */
  .summary-card {
    padding: 12px !important;
    margin-bottom: 8px !important;
  }

  .summary-card h3 {
    font-size: 14px;
  }

  /* Mobile debt chart */
  .debt-payoff-canvas-wrap {
    height: clamp(200px, 80vh, 350px) !important;
  }

  /* Mobile flexbox layouts */
  [style*="display:flex"] {
    flex-direction: column !important;
    gap: 6px !important;
  }

  .chart-row > * {
    flex: 1 1 100%;
    max-width: 100%;
  }

  /* Reduce line heights for mobile */
  .summary-label {
    font-size: 11px;
  }

  .summary-value {
    font-size: 13px;
  }

  /* Mobile asset mood */
  .asset-mood {
    font-size: 18px;
  }

  .asset-mood-text {
    font-size: 10px;
  }

  /* Expense row highlighting */
  .expense-row-high {
    background: #fee2e2 !important;
  }

  .expense-row-low {
    background: #f0fdf4 !important;
  }

  .expense-row-normal {
    background: #ffffff !important;
  }

  /* Goal progress bar */
  .goal-progress-bar {
    width: 100%;
    height: 8px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
    margin: 8px 0;
  }

  .goal-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    transition: width 0.3s ease;
  }
}

/* ============================================================
   TOGGLE SWITCH
   ============================================================ */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-switch .toggle-slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s ease;
}
.toggle-switch .toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--accent, #3B82F6);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

body[data-theme="dark"] .tabulator.mobile-card-table .tabulator-tableholder {
  background: #0b1220 !important;
}

body[data-theme="dark"] .tabulator.mobile-card-table .tabulator-row {
  background: #0f172a !important;
  border-color: #243244 !important;
  color: #e5edf8 !important;
}

body[data-theme="dark"] .tabulator.mobile-card-table .tabulator-row:nth-child(even) {
  background: #111c2f !important;
}

body[data-theme="dark"] .tabulator.mobile-card-table .tabulator-row.has-card-title::before {
  background: transparent !important;
  color: #bfdbfe !important;
}

body[data-theme="dark"] .tabulator.mobile-card-table .tabulator-row.has-card-meta::after {
  color: #94a3b8 !important;
}

body[data-theme="dark"] .tabulator.mobile-card-table .tabulator-cell {
  background: transparent !important;
  border-bottom-color: #243244 !important;
  color: #e5edf8 !important;
}

body[data-theme="dark"] .tabulator.mobile-card-table .tabulator-cell::before {
  color: #94a3b8 !important;
}

body[data-theme="dark"] .tabulator.mobile-card-table .tabulator-cell .tabulator-cell-value,
body[data-theme="dark"] .tabulator.mobile-card-table .tabulator-cell > * {
  color: #f8fafc !important;
}

body[data-theme="dark"] .tabulator.mobile-card-table .tabulator-cell[data-label="Edit"] > * {
  background: #1e3a8a !important;
  color: #dbeafe !important;
  border-color: #3b82f6 !important;
}

body[data-theme="dark"] .tabulator .tabulator-responsive-collapse {
  background: #0f172a !important;
  border-top-color: #243244 !important;
}

body[data-theme="dark"] .tabulator .tabulator-responsive-collapse td {
  border-bottom-color: #243244 !important;
  color: #e5edf8 !important;
}

body[data-theme="dark"] .tabulator .tabulator-responsive-collapse td:first-child {
  color: #94a3b8 !important;
}
