:root {
  --forest: #17211d;
  --forest-soft: #22312a;
  --sage: #9db7a7;
  --mint: #dce8df;
  --cream: #f2eee5;
  --paper: #fbf9f3;
  --ink: #1f2925;
  --muted: #6c756f;
  --line: #d8d6cd;
  --accent: #d6a95f;
  --danger: #9c4d45;
  --shadow: 0 20px 60px rgba(17, 27, 22, 0.12);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--cream); }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.home-page { background: var(--forest); color: var(--paper); overflow-x: hidden; }
.tv-shell { min-height: 100vh; padding: clamp(28px, 4vw, 76px); display: grid; grid-template-rows: auto 1fr auto; gap: clamp(30px, 4vh, 58px); }
.home-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 32px; }
.eyebrow { margin: 0 0 12px; color: var(--sage); font-size: clamp(0.72rem, 0.9vw, 1rem); font-weight: 800; letter-spacing: 0.2em; }
.eyebrow.dark { color: #537060; }
.home-header h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.4rem, 4vw, 5.2rem); font-weight: 400; line-height: 0.95; letter-spacing: -0.04em; }
.date-clock { text-align: right; }
.date-clock p { margin: 0 0 4px; color: var(--sage); font-size: clamp(1rem, 1.4vw, 1.55rem); text-transform: capitalize; }
.date-clock time { font-size: clamp(2.2rem, 4vw, 4.8rem); font-weight: 650; letter-spacing: -0.06em; }

.home-grid { display: grid; grid-template-columns: 0.88fr 1.12fr; border-top: 1px solid rgba(255,255,255,0.16); border-bottom: 1px solid rgba(255,255,255,0.16); }
.tv-dashboard { display: grid; grid-template-columns: minmax(300px, 0.72fr) minmax(600px, 1.28fr); border-top: 1px solid rgba(255,255,255,0.16); border-bottom: 1px solid rgba(255,255,255,0.16); }
.countdown-card { display: flex; flex-direction: column; justify-content: center; min-height: 52vh; padding: clamp(30px,4vw,70px) clamp(28px,4vw,64px) clamp(30px,4vw,70px) 0; border-right: 1px solid rgba(255,255,255,0.16); }
.money-dashboard { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); align-content: stretch; }
.money-card { display: flex; flex-direction: column; justify-content: center; padding: clamp(24px,3vw,52px); border-bottom: 1px solid rgba(255,255,255,0.16); }
.money-card:nth-child(odd) { border-right: 1px solid rgba(255,255,255,0.16); }
.money-card:nth-child(n+3) { border-bottom: 0; }
.money-card p { margin: 0 0 16px; color: var(--sage); font-size: clamp(0.88rem,1.1vw,1.2rem); font-weight: 700; letter-spacing: 0.04em; }
.money-card strong { display: block; color: var(--mint); font-size: clamp(2.8rem,5vw,6rem); line-height: .95; letter-spacing: -.06em; white-space: nowrap; }
.money-card small { display: block; margin-top: 14px; color: #cbd7d0; font-size: clamp(.78rem,.9vw,1rem); }
.money-card.primary strong { color: #fff; }
.money-card.projection { background: rgba(214,169,95,.08); }
.money-card.projection strong { color: #e8c98f; }
.money-card.projection.negative { background: rgba(209,116,105,.10); }
.money-card.projection.negative strong { color: #ef9f95; }
.owner-strip { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); border-top: 1px solid rgba(255,255,255,.16); background: rgba(0,0,0,.08); }
.owner-strip div { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; padding: 15px clamp(18px,2vw,34px); border-right: 1px solid rgba(255,255,255,.12); }
.owner-strip div:last-child { border-right: 0; }
.owner-strip span { color: var(--sage); font-size: clamp(.72rem,.85vw,.9rem); font-weight: 700; }
.owner-strip strong { color: var(--mint); font-size: clamp(1rem,1.45vw,1.55rem); white-space: nowrap; }
.owner-strip strong.negative { color: #ef9f95; }
.hero-panel { min-height: 48vh; display: flex; flex-direction: column; justify-content: center; padding: clamp(32px, 5vw, 90px); }
.hero-panel + .hero-panel { border-left: 1px solid rgba(255,255,255,0.16); }
.countdown-panel { padding-left: 0; }
.income-panel { padding-right: 0; }
.panel-kicker { margin: 0 0 clamp(20px, 3vh, 40px); color: var(--sage); font-size: clamp(1rem, 1.4vw, 1.5rem); font-weight: 650; letter-spacing: 0.04em; }
.countdown-value { font-family: Georgia, "Times New Roman", serif; font-size: clamp(8rem, 18vw, 20rem); line-height: 0.7; letter-spacing: -0.08em; }
.countdown-unit { margin: clamp(22px, 3vh, 36px) 0 0; font-size: clamp(1.6rem, 3vw, 3.5rem); }
.income-total { margin: 0; font-size: clamp(5rem, 10vw, 12rem); font-weight: 650; line-height: 0.9; letter-spacing: -0.07em; color: var(--mint); }
.panel-detail { margin: clamp(18px, 3vh, 30px) 0 0; color: #d1dbd4; font-size: clamp(1rem, 1.5vw, 1.6rem); text-transform: capitalize; }
.income-bar { width: 100%; height: 6px; margin-top: clamp(32px, 5vh, 56px); background: rgba(255,255,255,0.12); overflow: hidden; }
.income-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 450ms ease; }
.estimate-note { margin: 14px 0 0; color: var(--sage); font-size: clamp(0.85rem, 1vw, 1.1rem); }
.home-footer { display: flex; justify-content: space-between; align-items: center; gap: 28px; color: var(--sage); font-size: clamp(0.9rem, 1.1vw, 1.2rem); }
.home-footer p { margin: 0; }
.home-footer-actions { display: flex; align-items: center; gap: clamp(18px, 2.5vw, 36px); }
.sync-indicator { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.sync-indicator i { width: 8px; height: 8px; border-radius: 50%; background: #76bd8e; box-shadow: 0 0 0 4px rgba(118,189,142,0.12); }
.sync-indicator.syncing i { background: var(--accent); }
.sync-indicator.offline i { background: #d17469; }
.quiet-link { text-decoration: none; color: var(--paper); border-bottom: 1px solid rgba(255,255,255,0.3); padding-bottom: 4px; }
.quiet-link:hover, .quiet-link:focus-visible { border-color: var(--accent); outline: none; }

.app-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 clamp(20px, 5vw, 72px); border-bottom: 1px solid var(--line); background: rgba(251,249,243,0.92); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; font-weight: 800; letter-spacing: 0.08em; }
.brand span { display: grid; place-items: center; width: 36px; height: 36px; background: var(--forest); color: white; font-size: 0.72rem; }
.app-header nav { display: flex; gap: 8px; }
.app-header nav a { padding: 10px 16px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; }
.app-header nav a.active { color: var(--ink); border-color: var(--accent); }
.nav-button { border: 0; padding: 10px 12px; background: transparent; color: var(--muted); cursor: pointer; }
.nav-button:hover { color: var(--danger); }
.app-shell { width: min(1440px, calc(100% - 40px)); margin: 0 auto; padding: clamp(42px, 6vw, 88px) 0 90px; }
.page-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; margin-bottom: clamp(56px, 8vw, 110px); }
.page-intro h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(4rem, 9vw, 8rem); font-weight: 400; line-height: 0.85; letter-spacing: -0.07em; }
.page-intro p:not(.eyebrow) { margin: 22px 0 0; max-width: 620px; color: var(--muted); font-size: 1.08rem; }
.summary-chip { min-width: 220px; padding: 18px 0 18px 24px; border-left: 3px solid var(--accent); }
.summary-chip span { display: block; color: var(--muted); font-size: 0.86rem; }
.summary-chip strong { display: block; margin-top: 4px; font-size: 2rem; }
.settings-section, .income-section, .expense-section, .account-section, .data-section { padding: 42px 0 54px; border-top: 1px solid var(--line); }
.summary-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 1px; margin-bottom: 12px; background: var(--line); border: 1px solid var(--line); box-shadow: var(--shadow); }
.summary-grid article { min-height: 132px; padding: 24px; background: var(--paper); }
.summary-grid span, .summary-grid strong { display: block; }
.summary-grid span { color: var(--muted); font-size: .82rem; font-weight: 700; }
.summary-grid strong { margin-top: 10px; font-size: clamp(1.8rem,3vw,2.8rem); letter-spacing: -.04em; }
.summary-grid .accent-summary { background: var(--forest); color: white; }
.summary-grid .accent-summary span { color: var(--sage); }
.summary-grid .accent-summary strong { color: #e8c98f; }
.summary-grid .accent-summary.negative strong, .summary-chip.negative strong { color: var(--danger); }
.currency-note { margin: 0 0 clamp(52px,7vw,92px); color: var(--muted); font-size: .82rem; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 28px; margin-bottom: 30px; }
.section-heading > div { display: flex; align-items: baseline; gap: 18px; }
.section-number { margin: 0; color: #718078; font-size: 0.82rem; font-weight: 800; letter-spacing: 0.08em; }
.section-heading h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.8rem, 3vw, 2.7rem); font-weight: 400; letter-spacing: -0.03em; }
.section-heading > p { margin: 8px 0 0; max-width: 420px; color: var(--muted); text-align: right; }
.settings-row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.field, .switch-field { background: var(--paper); border: 1px solid var(--line); padding: 22px; }
.field > span { display: block; margin-bottom: 10px; font-size: 0.88rem; font-weight: 700; }
.field input { width: 100%; border: 0; border-bottom: 1px solid #a8ada8; padding: 7px 0; color: var(--ink); background: transparent; }
.switch-field { display: flex; align-items: center; justify-content: space-between; gap: 24px; cursor: pointer; }
.switch-field strong, .switch-field small { display: block; }
.switch-field small { margin-top: 5px; color: var(--muted); }
.switch-field input { width: 50px; height: 27px; accent-color: var(--forest-soft); }
.primary-button, .secondary-button { border: 0; cursor: pointer; transition: transform 150ms ease, background 150ms ease; }
.primary-button { padding: 12px 18px; background: var(--forest); color: white; font-weight: 700; }
.secondary-button { padding: 12px 18px; background: transparent; color: var(--ink); border: 1px solid #9fa59f; font-weight: 700; }
.primary-button:hover, .secondary-button:hover { transform: translateY(-1px); }
.primary-button:focus-visible, .secondary-button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(214,169,95,0.45); outline-offset: 2px; }
.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow); }
table { width: 100%; min-width: 1100px; border-collapse: collapse; }
.table-wrap.wide table { min-width: 1760px; }
th { padding: 15px 14px; background: #e8e5dc; color: #59635d; font-size: 0.72rem; text-align: left; text-transform: uppercase; letter-spacing: 0.09em; }
td { padding: 10px 8px; border-top: 1px solid #e3e0d8; vertical-align: middle; }
tr:first-child td { border-top: 0; }
.table-input { width: 100%; min-width: 110px; padding: 10px 8px; border: 1px solid transparent; background: transparent; color: var(--ink); }
.table-input:hover { border-color: #d5d2ca; }
.concept-input { min-width: 170px; }
.category-input, .type-input, .payment-account-input, .frequency-input { min-width: 130px; }
.name-input { min-width: 150px; }
.notes-input { min-width: 180px; }
.money-input { display: flex; align-items: center; min-width: 120px; }
.money-input span { color: var(--muted); }
.amount-input { min-width: 85px; }
.actions-cell { width: 1%; white-space: nowrap; }
.delete-button { border: 0; background: transparent; color: var(--danger); padding: 9px; cursor: pointer; font-size: 0.84rem; }
.delete-button:hover { text-decoration: underline; }
.empty-state { padding: 46px 24px; text-align: center; }
.empty-state strong, .empty-state span { display: block; }
.empty-state span { margin-top: 8px; color: var(--muted); }
.save-status { min-height: 20px; margin: 12px 0 0; color: var(--muted); font-size: 0.82rem; text-align: right; }
.save-status.save-error { color: var(--danger); font-weight: 700; }
.data-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.file-button { display: inline-flex; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.import-message { min-height: 22px; color: var(--muted); }

.auth-overlay { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 22px; background: rgba(23,33,29,0.96); color: var(--ink); }
.auth-card { width: min(100%, 460px); padding: clamp(28px, 5vw, 50px); background: var(--paper); box-shadow: 0 30px 100px rgba(0,0,0,0.3); }
.auth-card h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.7rem, 7vw, 4.4rem); font-weight: 400; line-height: 0.95; letter-spacing: -0.05em; }
.auth-card > p:not(.eyebrow):not(.auth-error):not(.auth-warning) { margin: 20px 0 28px; color: var(--muted); line-height: 1.55; }
.auth-field { display: block; margin-top: 12px; padding: 16px 18px; }
.auth-field input { font-size: 1.25rem; letter-spacing: 0.12em; }
.auth-submit { width: 100%; margin-top: 18px; padding: 15px 18px; }
.auth-submit:disabled { opacity: 0.62; cursor: wait; }
.auth-error { min-height: 22px; margin: 14px 0 0; color: var(--danger); font-weight: 700; }
.auth-warning { margin: 12px 0 0; color: var(--muted); font-size: 0.8rem; line-height: 1.45; }

@media (max-width: 820px) {
  .tv-shell { min-height: 100svh; padding: 24px; }
  .home-header { align-items: flex-end; }
  .home-header h1 { font-size: 2.8rem; }
  .date-clock p { display: none; }
  .date-clock time { font-size: 2.2rem; }
  .home-grid { grid-template-columns: 1fr; }
  .tv-dashboard { grid-template-columns: 1fr; }
  .countdown-card { min-height: auto; padding: 48px 0; border-right: 0; border-bottom: 1px solid rgba(255,255,255,.16); }
  .money-dashboard { min-height: 520px; }
  .hero-panel { min-height: auto; padding: 52px 0; }
  .hero-panel + .hero-panel { border-left: 0; border-top: 1px solid rgba(255,255,255,0.16); }
  .countdown-value { font-size: clamp(7rem, 38vw, 12rem); }
  .income-total { font-size: clamp(4rem, 19vw, 7rem); }
  .home-footer { align-items: flex-start; flex-direction: column; }
  .home-footer-actions { width: 100%; justify-content: space-between; }
  .page-intro { align-items: flex-start; flex-direction: column; }
  .summary-chip { padding-left: 18px; }
  .settings-row { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading > p { text-align: left; }
  .app-shell { width: min(100% - 28px, 1440px); }
}

@media (max-width: 620px) {
  .app-header { padding: 0 14px; }
  .brand { font-size: 0; }
  .brand span { font-size: 0.72rem; }
  .app-header nav a { padding: 10px 12px; }
  .page-intro h1 { font-size: 4.6rem; }
  .money-dashboard { grid-template-columns: 1fr; min-height: auto; }
  .money-card, .money-card:nth-child(odd), .money-card:nth-child(n+3) { min-height: 180px; border-right: 0; border-bottom: 1px solid rgba(255,255,255,.16); }
  .money-card:last-child { border-bottom: 0; }
  .owner-strip { grid-template-columns: 1fr; }
  .owner-strip div { border-right: 0; border-bottom: 1px solid rgba(255,255,255,.12); }
  .owner-strip div:last-child { border-bottom: 0; }
  .summary-grid { grid-template-columns: 1fr; }
  .table-wrap { overflow: visible; border: 0; background: transparent; box-shadow: none; }
  table, tbody { display: block; min-width: 0; }
  thead { display: none; }
  tr { display: grid; gap: 10px; padding: 18px; margin-bottom: 14px; background: var(--paper); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(17,27,22,0.07); }
  td { display: grid; grid-template-columns: 100px minmax(0,1fr); align-items: center; gap: 10px; padding: 0; border: 0; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
  .table-input, .concept-input, .notes-input { min-width: 0; border: 1px solid #d5d2ca; background: #fff; }
  .actions-cell { width: auto; display: block; text-align: right; }
  .actions-cell::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
