/* ═══════════════════════════════════════════════════════════════
   Budget App — Stylesheet
   Color palette: teal accent, slate neutrals, clean minimal
═══════════════════════════════════════════════════════════════ */

/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #0d9488;
  --primary-dark:  #0f766e;
  --primary-light: #ccfbf1;
  --bg:            #f1f5f9;
  --card:          #ffffff;
  --text:          #0f172a;
  --text-muted:    #64748b;
  --border:        #e2e8f0;
  --border-dark:   #cbd5e1;
  --success:       #059669;
  --success-bg:    #d1fae5;
  --error:         #dc2626;
  --error-bg:      #fee2e2;
  --warning:       #d97706;
  --warning-bg:    #fef3c7;
  --positive:      #059669;
  --negative:      #dc2626;
  --radius:        6px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:     0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
}

html { font-size: 14px; }

body, table, th, td, input, select, button, textarea {
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
}

body {
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Typography ───────────────────────────────────────────────── */
h1 { font-size: 1.5rem;  font-weight: 700; }
h2 { font-size: 1.125rem; font-weight: 600; }
h3 { font-size: 1rem;    font-weight: 600; }

.text-muted   { color: var(--text-muted); font-size: .875rem; }
.text-sm      { font-size: .8125rem; }
.text-right   { text-align: right; }
.font-mono    { font-family: 'SF Mono', 'Cascadia Mono', 'Consolas', monospace; }
.positive     { color: var(--positive); font-weight: 600; }
.negative     { color: var(--negative); font-weight: 600; }

/* ── Navbar ───────────────────────────────────────────────────── */
.navbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex; align-items: center; padding: 0 1.5rem;
  gap: 1.5rem;
}

.nav-brand {
  display: flex; align-items: center; gap: .5rem;
  font-size: 1rem; font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  flex-shrink: 0;
}
.nav-brand svg { width: 22px; height: 22px; }

.nav-links {
  display: flex; align-items: center; gap: .25rem;
  flex: 1;
}

.nav-link {
  padding: .375rem .75rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover       { background: var(--bg); color: var(--text); }
.nav-link.active      { background: var(--primary-light); color: var(--primary-dark); }

.nav-user {
  display: flex; align-items: center; gap: .75rem;
  flex-shrink: 0;
  margin-left: auto;
}
.nav-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700;
}

/* ── Layout ───────────────────────────────────────────────────── */
.main-content {
  padding-top: 56px;      /* clear fixed navbar */
  min-height: 100vh;
}

.container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
}

.container-sm {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ── Page header ─────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.25rem; }

.header-meta {
  display: flex; align-items: center; gap: .75rem;
  flex-shrink: 0;
}

.year-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: .125rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
}

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: .75rem;
  flex-wrap: wrap;
}
.card-header h2 { font-size: 1rem; }

.card-body  { padding: 0; }  /* tables flush to edges */
.card-body.padded { padding: 1rem; }

/* ── Tables ────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8125rem;
}

thead th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: .6875rem;
  letter-spacing: .04em;
  padding: .5rem .75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th.text-right { text-align: right; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

td {
  padding: .375rem .75rem;
  vertical-align: middle;
}

tfoot td {
  padding: .5rem .75rem;
  font-weight: 600;
  background: #f8fafc;
  border-top: 2px solid var(--border-dark);
}

/* ── Table inputs (spreadsheet feel) ─────────────────────────── */
.table-input {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  padding: .25rem .375rem;
  font-size: .8125rem;
  font-family: inherit;
  color: var(--text);
  text-align: right;
  transition: border-color .15s, background .15s;
  -moz-appearance: textfield;
  appearance: textfield;
}
.table-input::-webkit-inner-spin-button,
.table-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.table-input:hover  { border-color: var(--border-dark); }
.table-input:focus  {
  outline: none;
  border-color: var(--primary);
  background: #f0fdf9;
  box-shadow: 0 0 0 2px rgba(13,148,136,.12);
}

.table-input-label {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  padding: .25rem .375rem;
  font-size: .8125rem;
  font-family: inherit;
  color: var(--text);
  transition: border-color .15s, background .15s;
}
.table-input-label:hover { border-color: var(--border-dark); }
.table-input-label:focus {
  outline: none;
  border-color: var(--primary);
  background: #f0fdf9;
  box-shadow: 0 0 0 2px rgba(13,148,136,.12);
}

/* ── Amount display ───────────────────────────────────────────── */
.amount { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.amount.total { font-weight: 700; }

/* ── Summary bar ──────────────────────────────────────────────── */
.summary-bar {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin: 1.25rem 0;
}

.summary-card {
  flex: 1;
  min-width: 140px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .875rem 1rem;
  box-shadow: var(--shadow);
}
.summary-card .label {
  display: block;
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: .25rem;
}
.summary-card .value {
  display: block;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.summary-card .value.primary  { color: var(--primary-dark); }
.summary-card .value.positive { color: var(--positive); }
.summary-card .value.negative { color: var(--negative); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .375rem;
  padding: .5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline:hover:not(:disabled) { background: var(--primary-light); }

.btn-outline-sm {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-dark);
  padding: .3rem .7rem;
  font-size: .8125rem;
}
.btn-outline-sm:hover:not(:disabled) { color: var(--text); border-color: var(--text-muted); background: var(--bg); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

.btn-danger {
  background: transparent;
  color: var(--error);
  border-color: transparent;
  padding: .25rem .5rem;
  font-size: .75rem;
}
.btn-danger:hover:not(:disabled) { background: var(--error-bg); }

.btn-sm {
  padding: .3125rem .625rem;
  font-size: .8125rem;
}
.btn-full { width: 100%; justify-content: center; }

/* ── Forms ────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: .375rem;
  margin-bottom: 1rem;
}
.form-group label {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--text);
}
.form-group input {
  padding: .5625rem .75rem;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  font-size: .9375rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13,148,136,.15);
}

/* ── Alerts ───────────────────────────────────────────────────── */
.alert {
  padding: .625rem .875rem;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: .75rem;
  border: 1px solid;
}
.alert-error   { background: var(--error-bg);   color: #991b1b; border-color: #fca5a5; }
.alert-success { background: var(--success-bg); color: #065f46; border-color: #6ee7b7; }
.alert-warning { background: var(--warning-bg); color: #92400e; border-color: #fcd34d; }

/* ── Auth page ────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f0fdfa 0%, #e0f2fe 100%);
}

.auth-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: .625rem;
  margin-bottom: .375rem;
  color: var(--primary);
}
.auth-logo h1 { font-size: 1.375rem; }
.auth-logo svg { width: 32px; height: 32px; }

.forgot-link { text-align: center; font-size: .8125rem; margin-top: .75rem; }
.forgot-link a { color: var(--primary); text-decoration: none; }
.forgot-link a:hover { text-decoration: underline; }

.auth-subtitle {
  font-size: .875rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* ── Dashboard welcome ────────────────────────────────────────── */
.welcome-hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  color: #fff;
  margin-bottom: 1.25rem;
}
.welcome-hero h2 { font-size: 1.25rem; margin-bottom: .25rem; }
.welcome-hero p  { opacity: .85; font-size: .875rem; }

.quick-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.quick-nav-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1rem;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .15s;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.quick-nav-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.quick-nav-card .icon {
  width: 36px; height: 36px;
  background: var(--primary-light);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
}
.quick-nav-card h3 { font-size: .9375rem; }
.quick-nav-card p  { font-size: .8125rem; color: var(--text-muted); }

/* ── Savings progress ─────────────────────────────────────────── */
.savings-stats {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  font-size: .8125rem;
  color: var(--text-muted);
}
.savings-stats strong { color: var(--text); }

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: .25rem 0;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width .3s;
}
.progress-fill.over { background: var(--success); }
.progress-fill.under { background: var(--warning); }

/* ── Section label strip ──────────────────────────────────────── */
.section-label {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  padding: .375rem .75rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

/* ── Family budget specifics ──────────────────────────────────── */
.family-section {
  margin-bottom: 1.5rem;
}
.family-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: .625rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.family-section-title::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--primary-light);
  border-radius: 999px;
}

.contrib-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: .125rem .5rem;
  border-radius: 999px;
  font-size: .6875rem;
  font-weight: 600;
}

/* family table: month columns fixed-width */
.month-col { width: 68px; min-width: 68px; }
.total-col  { width: 80px; min-width: 80px; font-weight: 700; }
.label-col  { min-width: 180px; }
.total-col .table-input { font-weight: 700; }

/* ── Last saved indicator ─────────────────────────────────────── */
.last-saved {
  font-size: .75rem;
  color: var(--text-muted);
}
.last-saved.fresh { color: var(--success); }

/* ── Spinner ──────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utility ──────────────────────────────────────────────────── */
.hidden   { display: none !important; }
.mt-1     { margin-top: .5rem; }
.mt-2     { margin-top: 1rem; }
.mb-0     { margin-bottom: 0 !important; }
.gap-1    { gap: .5rem; }
.flex     { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* ── Hamburger nav toggle (hidden on desktop) ─────────────────── */
.nav-toggle {
  display: none;
  flex-direction: column; justify-content: center; align-items: center;
  gap: 5px; width: 44px; height: 44px;
  background: none; border: none; cursor: pointer; padding: 0;
  border-radius: var(--radius);
}
.nav-toggle span {
  display: block; width: 22px; height: 2px;
  background: currentColor; border-radius: 2px;
  transition: transform .2s, opacity .2s;
}
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Responsive ───────────────────────────────────────────────── */

/* Tablet (≤900px) */
@media (max-width: 900px) {
  .budget-panels { grid-template-columns: 1fr; }
  .mfc-panel { overflow-x: auto; }
}

/* Mobile (≤768px) */
@media (max-width: 768px) {
  .navbar { padding: 0 1rem; flex-wrap: wrap; height: auto; min-height: 56px; }
  .nav-toggle { display: flex; }
  .nav-links {
    display: none; flex-direction: column; width: 100%;
    order: 3; padding: .5rem 0 .75rem; gap: 2px;
  }
  .nav-links.open { display: flex; }
  .nav-link { padding: .6rem .5rem; font-size: .9375rem; }
  .nav-user { margin-left: auto; }

  .container { padding: 1rem 1rem 2rem; }
  .page-header { flex-direction: column; align-items: flex-start; gap: .5rem; }
  .header-meta { width: 100%; justify-content: flex-start; }

  .formula-bar-container { flex-wrap: wrap; gap: .25rem; }
  .formula-bar-input { min-width: 0; flex: 1 1 100%; }

  .summary-bar { gap: .5rem; flex-wrap: wrap; }
  .summary-card { min-width: calc(50% - .5rem); flex: 1 1 calc(50% - .5rem); }
  .summary-card .value { font-size: .9375rem; }

  .quick-nav { grid-template-columns: 1fr; }

  /* Ensure all inputs are ≥16px on mobile to prevent iOS zoom */
  input, select, textarea { font-size: 16px !important; }

  /* Touch-friendly tap targets */
  .btn, .nav-link, .sheet-tab, .tab-menu-btn, .sheet-tab-close { min-height: 44px; }
  .btn { padding: .6rem 1rem; }

  /* Table horizontal scroll on mobile */
  .table-wrapper, .card-body.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .family-table, .mfc-table, .annual-table { min-width: 600px; }
  .mfc-table { min-width: 700px; }
}

/* Small mobile (≤480px) */
@media (max-width: 480px) {
  html { font-size: 13px; }
  .summary-card { min-width: 100%; }
  .auth-card { padding: 1.5rem 1rem; }
  .page-header h1 { font-size: 1.25rem; }
  .sheet-tab { padding: 4px 8px; font-size: .75rem; }
  .nav-user .text-sm { display: none; }
}


/* ================================================================
   Extended styles: multi-sheet, formula bar, budget panels,
   planned/actual columns, family budget redesign
================================================================ */

/* -- Sheet tab bar (Excel-style) -------------------------------- */
.sheet-tab-bar {
  display: flex; align-items: flex-end; gap: 2px;
  background: #e2e8f0; padding: 6px 8px 0;
  border-top: 1px solid var(--border-dark);
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin;
}
.sheet-tab {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 12px 6px;
  background: #d1d5db; border: 1px solid #b0b8c4; border-bottom: none;
  border-radius: 4px 4px 0 0;
  font-size: .75rem; font-weight: 500; color: #4b5563;
  cursor: pointer; white-space: nowrap; user-select: none;
  position: relative; bottom: -1px; transition: background .1s;
}
.sheet-tab:hover { background: #e9ecef; }
.sheet-tab.active {
  background: #fff; color: var(--text);
  border-color: var(--border-dark); font-weight: 600; z-index: 1;
}
.sheet-tab .tab-menu-btn, .sheet-tab-close {
  background: none; border: none; cursor: pointer;
  color: #9ca3af; font-size: .7rem; padding: 0 2px; line-height: 1;
}
.sheet-tab .tab-menu-btn:hover, .sheet-tab-close:hover { color: var(--text); }
.sheet-tab-add {
  padding: 5px 10px 6px;
  background: transparent; border: 1px dashed #b0b8c4; border-bottom: none;
  border-radius: 4px 4px 0 0;
  font-size: .875rem; color: #6b7280; cursor: pointer;
  position: relative; bottom: -1px;
}
.sheet-tab-add:hover { background: #e9ecef; color: var(--text); }
.tab-rename-input {
  font-size: .75rem; font-weight: 600;
  border: none; border-bottom: 1px solid var(--primary);
  outline: none; background: transparent; width: 90px; color: var(--text);
}
.tab-context-menu {
  position: fixed; background: #fff;
  border: 1px solid var(--border-dark); border-radius: var(--radius);
  box-shadow: var(--shadow-md); z-index: 999;
  min-width: 140px; padding: 4px 0;
}
.tab-context-menu button {
  display: block; width: 100%; padding: 6px 14px;
  background: none; border: none; text-align: left;
  font-size: .8125rem; cursor: pointer; color: var(--text);
}
.tab-context-menu button:hover { background: var(--bg); }
.tab-context-menu .danger { color: var(--error); }

/* -- Formula bar ----------------------------------------------- */
.formula-bar-container {
  display: flex; align-items: center;
  background: #fff; border: 1px solid var(--border-dark);
  border-radius: var(--radius); margin-bottom: .625rem; overflow: hidden;
}
.formula-bar-ref {
  min-width: 56px; padding: 5px 8px; font-size: .75rem; font-weight: 600;
  font-family: monospace; color: var(--primary-dark);
  background: #f0fdf9; border-right: 1px solid var(--border);
  text-align: center; white-space: nowrap;
}
.formula-bar-fx {
  padding: 5px 8px; font-size: .75rem; font-style: italic;
  color: var(--text-muted); border-right: 1px solid var(--border);
  white-space: nowrap; user-select: none;
}
.formula-bar-input {
  flex: 1; border: none; padding: 5px 8px;
  font-size: .8125rem; font-family: monospace; color: var(--text);
  outline: none; background: transparent;
}
.formula-bar-input:focus { background: #fffbf0; }

/* -- Budget panels layout -------------------------------------- */
.budget-panels { display: grid; grid-template-columns: 290px 1fr; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .budget-panels { grid-template-columns: 1fr; } }
.budget-panel-left, .budget-panel-right { display: flex; flex-direction: column; gap: .625rem; }

/* -- Budget section headers ------------------------------------ */
.budget-section-header {
  background: #1e293b; color: #fff;
  font-size: .6875rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  padding: 5px 10px; border-radius: var(--radius) var(--radius) 0 0;
}

/* -- Planned / Actual cell colouring --------------------------- */
.planned-cell { background: #A8C4E0 !important; text-align: right; }
.actual-cell  { background: #C8DDF0 !important; text-align: right; }
.planned-cell:focus { background: #80aad0 !important; }
.actual-cell:focus  { background: #a8cce8 !important; }
thead .col-planned { background: #d0e4f5 !important; color: #1e3a5f !important; }
thead .col-actual  { background: #ddeef8 !important; color: #1e3a5f !important; }

/* -- Variance column ------------------------------------------- */
.col-variance { text-align: right; font-size: .75rem; font-weight: 600; }
.var-positive { color: #059669; }
.var-negative { color: #dc2626; }
.var-blank    { color: #94a3b8; }

/* -- Formula indicator ----------------------------------------- */
.formula-cell { position: relative; }
.formula-cell::after {
  content: ""; position: absolute; top: 2px; right: 2px;
  width: 0; height: 0; border-style: solid;
  border-width: 0 5px 5px 0;
  border-color: transparent #0d9488 transparent transparent;
  pointer-events: none;
}
.cell-error { color: #dc2626 !important; }
.cell-selected { outline: 2px solid #0d9488 !important; outline-offset: -1px; }

/* -- Savings progress section ---------------------------------- */
.savings-progress-section {
  background: #f8fafc; border: 1px solid var(--border); border-top: none;
  padding: .625rem .75rem; font-size: .8125rem;
}
.savings-progress-label {
  display: flex; justify-content: space-between;
  margin-bottom: .25rem; color: var(--text-muted);
}
.savings-target-row { margin-top: .5rem; color: var(--text-muted); }
.savings-target-row input {
  width: 100px; border: 1px solid var(--border-dark); border-radius: 4px;
  padding: 2px 6px; font-size: .8125rem; text-align: right; background: #A8C4E0;
}

/* -- Category badges ------------------------------------------- */
.cat-badge { display: inline-block; padding: 1px 6px; border-radius: 999px; font-size: .6875rem; font-weight: 600; }
.cat-essential  { background: #dbeafe; color: #1e40af; }
.cat-lifestyle  { background: #fce7f3; color: #9d174d; }
.cat-investment { background: #d1fae5; color: #065f46; }
.cat-family     { background: #fef3c7; color: #92400e; }
.cat-education  { background: #ede9fe; color: #5b21b6; }
.cat-other      { background: #f1f5f9; color: #475569; }
.cat-summary {
  display: flex; flex-wrap: wrap; gap: .375rem;
  padding: .5rem .75rem; background: #f8fafc; border-top: 1px solid var(--border); font-size: .75rem;
}

/* -- Budget summary panel -------------------------------------- */
.budget-summary-panel { background: #fff; border: 2px solid var(--border-dark); border-radius: var(--radius); overflow: hidden; }
.budget-summary-panel .sg { display: grid; grid-template-columns: 1fr 1fr; }
.budget-summary-panel .sc { padding: .5rem .75rem; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.budget-summary-panel .sc:nth-child(2n) { border-right: none; }
.budget-summary-panel .sc .label { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.budget-summary-panel .sc .value { font-size: .9375rem; font-weight: 700; margin-top: 2px; }
.accbal-box { grid-column: span 2; background: #1e293b; color: #fff; padding: .75rem 1rem; display: flex; justify-content: space-between; align-items: center; }
.accbal-box .label { font-size: .7rem; letter-spacing: .06em; opacity: .7; }
.accbal-box .value { font-size: 1.375rem; font-weight: 800; }

/* -- Custom sheet ----------------------------------------- */
.custom-sheet-wrap { overflow-x: auto; }
.custom-sheet-table th { background: #1e293b; color: #fff; }
.custom-sheet-table td .table-input { background: #f0f7ff; }
.sheet-content-area {
  background: #fff; border: 1px solid var(--border); border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: .875rem; min-height: 300px;
}

/* -- Family budget redesign ------------------------------------ */
.family-page-banner {
  background: #1e293b; color: #fff; text-align: center;
  padding: .75rem 1.25rem; border-radius: var(--radius);
  margin-bottom: .875rem; font-size: 1rem; font-weight: 700;
}
.readonly-banner {
  background: #fffbeb; border: 1px solid #fbbf24; color: #92400e;
  padding: .625rem 1rem; border-radius: var(--radius);
  font-size: .875rem; font-weight: 500; margin-bottom: .75rem;
}
.fb-section-header {
  background: #1e293b; color: #fff; font-size: .75rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; padding: 6px 12px;
}
.fb-contrib-row td { background: #A8C4E0 !important; }
.fb-total-row td   { background: #4a5e2a !important; color: #fff !important; font-weight: 700; }
.fb-expense-total td { background: #fde8e8 !important; color: #991b1b !important; font-weight: 700; }
.fb-balance-row.surplus td { background: #d1fae5 !important; color: #065f46 !important; font-weight: 700; }
.fb-balance-row.deficit td { background: #fee2e2 !important; color: #991b1b !important; font-weight: 700; }
.pct-col { color: var(--text-muted); font-size: .75rem; text-align: right; }
.month-input-cell { background: #dbeafe; }

/* -- MFC panel ------------------------------------------------- */
.mfc-panel { background: #f0fdf9; border: 1px solid #a7f3d0; border-radius: var(--radius); padding: .75rem; margin-bottom: .875rem; overflow-x: auto; }
.mfc-panel h3 { font-size: .8125rem; color: var(--primary-dark); margin-bottom: .5rem; }
.mfc-table { font-size: .8125rem; }
.mfc-table th { background: #0d9488; color: #fff; padding: 4px 8px; }
.mfc-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); }
.mfc-table tr:last-child td { font-weight: 700; background: #e6faf7; }
.mfc-salary-input { width: 90px; text-align: right; border: 1px solid var(--border); border-radius: 3px; padding: 2px 4px; background: transparent; font-size: .8125rem; }

/* -- Annual summary card --------------------------------------- */
.annual-summary-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-top: 1rem; box-shadow: var(--shadow); }
.annual-summary-card h3 { font-size: .875rem; font-weight: 700; color: #1e293b; margin-bottom: .75rem; border-bottom: 2px solid var(--primary-light); padding-bottom: .375rem; }
.annual-summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .625rem; }
.asc { background: #f8fafc; border: 1px solid var(--border); border-radius: 4px; padding: .5rem .625rem; }
.asc .label { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.asc .value { font-size: .9375rem; font-weight: 700; margin-top: 2px; }
.apply-all-btn {
  font-size: .6rem; padding: 1px 4px; border: 1px solid var(--border-dark);
  border-radius: 3px; background: #f8fafc; cursor: pointer; color: var(--text-muted); white-space: nowrap;
}
.apply-all-btn:hover { background: var(--primary-light); color: var(--primary-dark); }

/* ================================================================
   Personal budget: cells, sections, summary panel, custom sheet
================================================================ */

/* Generic editable cell input */
.cell-input {
  width: 100%; border: 1px solid transparent; border-radius: 3px;
  padding: 2px 5px; font-size: .8rem; background: transparent; color: var(--text);
  outline: none; text-align: right;
}
.cell-input:focus { border-color: var(--primary); background: #fff; }
.cell-input.planned-cell:focus { background: #80aad0 !important; }
.cell-input.actual-cell:focus  { background: #a8cce8 !important; }

/* Budget section wrapper */
.budget-section { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.budget-section .budget-section-header {
  display: flex; justify-content: space-between; align-items: center; padding: 5px 10px;
}

/* Budget table */
.budget-table { width: 100%; border-collapse: collapse; font-size: .8125rem; }
.budget-table th { background: #f1f5f9; color: #475569; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 5px 8px; border-bottom: 1px solid var(--border-dark); text-align: left; }
.budget-table th:not(:first-child) { text-align: right; }
.budget-table td { padding: 3px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.budget-table tfoot td { background: #f8fafc; font-size: .8rem; font-weight: 600; }
.budget-table .text-right { text-align: right; }

/* Row label input */
.label-input {
  width: 100%; border: none; outline: none; background: transparent;
  font-size: .8125rem; color: var(--text); padding: 1px 0;
}
.label-input:focus { border-bottom: 1px solid var(--primary); }

/* Category select */
.cat-select {
  font-size: .75rem; border: 1px solid var(--border); border-radius: 3px;
  padding: 1px 3px; background: #fff; color: var(--text); cursor: pointer;
}

/* Add row button in section header */
.add-row-btn {
  font-size: .7rem; padding: 2px 8px; border: 1px solid var(--border-dark);
  border-radius: 3px; background: #f8fafc; cursor: pointer; color: var(--primary-dark);
}
.add-row-btn:hover { background: var(--primary-light); }

/* Remove row button */
.btn-remove {
  background: none; border: none; cursor: pointer; color: #dc2626;
  font-size: .8rem; padding: 1px 4px; border-radius: 3px; line-height: 1;
}
.btn-remove:hover { background: #fee2e2; }

/* Budget summary panel internals */
.summary-title {
  background: #1e293b; color: #fff;
  font-size: .7rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  padding: 5px 10px;
}
.summary-table { width: 100%; border-collapse: collapse; font-size: .8125rem; }
.summary-table th { background: #f1f5f9; padding: 4px 8px; text-align: right; font-size: .7rem; font-weight: 700; text-transform: uppercase; color: #475569; }
.summary-table th:first-child { text-align: left; }
.summary-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); text-align: right; }
.summary-table td:first-child { text-align: left; color: var(--text-muted); font-size: .8rem; }
.summary-balance-row td { font-weight: 700; background: #f8fafc; }
.summary-val { font-weight: 600; }
.summary-val.positive { color: #059669; }
.summary-val.negative { color: #dc2626; }
.accbal-label { font-size: .7rem; letter-spacing: .06em; opacity: .7; text-transform: uppercase; }
.accbal-amount { font-size: 1.375rem; font-weight: 800; }
.accbal-amount.positive { color: #86efac; }
.accbal-amount.negative { color: #fca5a5; }

/* Savings target row */
.savings-target-row { display: flex; justify-content: space-between; align-items: center; padding: .5rem .75rem; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.savings-target-row label { font-size: .75rem; font-weight: 600; color: var(--text-muted); }
.target-input { width: 110px; text-align: right; border: 1px solid var(--border-dark) !important; border-radius: 3px !important; }

/* Progress bar header */
.progress-header { display: flex; justify-content: space-between; font-size: .75rem; font-weight: 600; color: var(--text-muted); margin-bottom: .25rem; }

/* Category summary strip */
.cat-summary-strip { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .375rem; padding: .5rem .75rem; background: #f8fafc; border-top: 1px solid var(--border); }
.cat-badge { display: inline-flex; align-items: center; justify-content: center; gap: .25rem; padding: 2px 8px; border-radius: 999px; font-size: .6875rem; font-weight: 600; flex: 1; text-align: center; }
.cat-badge .cat-label { font-weight: 700; }
.cat-badge .cat-vals  { opacity: .85; }

/* Tab label span */
.tab-label { pointer-events: none; }
.sheet-tab.active .tab-label { pointer-events: auto; }

/* Context menu items (div.ctx-item) */
.ctx-item {
  padding: 6px 14px; font-size: .8125rem; cursor: pointer; color: var(--text);
}
.ctx-item:hover { background: var(--bg); }
.ctx-item.danger { color: var(--error); }

/* Custom sheet toolbar and table */
.custom-toolbar { display: flex; gap: .5rem; margin-bottom: .5rem; }
.custom-table { border-collapse: collapse; font-size: .8125rem; min-width: 100%; }
.custom-table th { background: #1e293b; color: #fff; }
.custom-table th, .custom-table td { border: 1px solid var(--border); padding: 2px 4px; }
.col-header-input {
  background: transparent; border: none; outline: none;
  color: #fff; font-size: .75rem; font-weight: 600; min-width: 60px;
}
.col-del-btn {
  color: #fca5a5 !important; font-size: .65rem; padding: 0 2px;
  vertical-align: middle; margin-left: 3px;
}
.col-del-btn:hover { color: #fff !important; background: #dc2626 !important; }

/* Family budget: balance row as flex div */
.fb-balance-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: .5rem .875rem; border-radius: var(--radius); margin: .5rem 0;
  background: #f8fafc; border: 1px solid var(--border); font-size: .875rem;
}
.fb-balance-amount { font-weight: 700; font-size: .9375rem; }
.fb-balance-amount.positive { color: #059669; }
.fb-balance-amount.negative { color: #dc2626; }

/* Family budget: month input cell */
.fb-month-input {
  width: 68px; border: 1px solid transparent; border-radius: 3px;
  padding: 2px 4px; font-size: .75rem; text-align: right; background: transparent; color: var(--text); outline: none;
}
.fb-month-input:focus { border-color: var(--primary); background: #fff; }

/* Month-col, total-col, label-col in family table */
.family-table { border-collapse: collapse; font-size: .78rem; width: 100%; }
.family-table th, .family-table td { padding: 3px 5px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.family-table th { background: #f1f5f9; color: #475569; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.family-table tfoot td { background: #f0fdf9; font-weight: 700; }
.family-table .label-col { min-width: 180px; white-space: normal; }
.family-table .month-col { width: 68px; min-width: 68px; }
.family-table .total-col { width: 80px; min-width: 80px; }
.family-table .salary-hdr { width: 88px; }
.readonly-cell { font-weight: 500; color: var(--text); text-align: right; }

/* MFC panel title */
.mfc-title { font-size: .8125rem; font-weight: 700; color: var(--primary-dark); margin-bottom: .5rem; }

/* Undo toast */
.undo-toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(1rem);
  background: #1e293b; color: #fff; padding: .5rem 1.25rem; border-radius: 99px;
  font-size: .8125rem; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 9999;
}
.undo-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Annual summary table */
.annual-title { font-size: .875rem; font-weight: 700; color: #1e293b; margin-bottom: .75rem; border-bottom: 2px solid var(--primary-light); padding-bottom: .375rem; }
.annual-table { width: 100%; border-collapse: collapse; font-size: .8125rem; }
.annual-table th { background: #f1f5f9; padding: 4px 8px; font-size: .7rem; font-weight: 700; text-transform: uppercase; color: #475569; text-align: right; }
.annual-table th:first-child { text-align: left; }
.annual-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); text-align: right; }
.annual-table td:first-child { text-align: left; color: var(--text-muted); }
.annual-table .fb-total-row td { background: #f8fafc; font-weight: 700; color: var(--text) !important; }

/* ── Wealth section ───────────────────────────────────────────────── */
.wealth-saved-row td { background: #f0fdf4; font-weight: 600; }
.wealth-sub-header td { background: #f8fafc; color: #64748b; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 5px 5px 2px; }
.wealth-cash-row td { background: #eff6ff; font-weight: 700; font-size: .85rem; }

.bonus-row td { background: #fefce8; border-top: 2px solid #fde68a; }
