/* app/static/css/app.css
 * Thinking Budget brand — single source of truth for tokens, fonts, and
 * shared component styles. Light-first (warm paper); dark via html.dark.
 */

@import url('https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;1,6..72,400;1,6..72,500&family=Geist:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

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

/* ── Brand tokens: light (warm paper) is the default ── */
:root {
  --bg:      #F7F3EB;
  --surface: #FCFAF5;
  --border:  #D8CFC0;
  --text:    #1A1612;
  --muted:   #7A7166;
  --accent:  #B4441A;
  --green:   #2E4A37;
  --red:     #8A1F08;
  --yellow:  #9C7415;

  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans:  "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono:  "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;
}

/* ── Brand tokens: dark (deep paper) ── */
html.dark {
  --bg:      #16110A;
  --surface: #221A11;
  --border:  #2E2519;
  --text:    #F0E7D6;
  --muted:   #8A8073;
  --accent:  #E26A35;
  --green:   #5A8A6A;
  --red:     #E5604D;
  --yellow:  #C79A3A;
}

/* ── Base ── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Serif for headings only (Option 2). */
h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text);
}

/* ── Brand wordmark + 30% logo donut ── */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 19px;
  letter-spacing: -0.01em;
  color: var(--text);
}
/* Matches the marketing wordmark: "Thinking" set in italic burnt-orange. */
.brand em { font-style: italic; color: var(--accent); font-weight: 500; margin-right: -0.24em; }
.brand .logo-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
  background: conic-gradient(from -90deg, var(--accent) 0 30%, var(--border) 30% 100%);
}
.brand .logo-dot::after {
  content: "";
  position: absolute; inset: 5px;
  border-radius: 50%;
  background: var(--surface);
}

/* ── Theme toggle label (light default shows "Dark" to switch to) ── */
#theme-btn::after { content: 'Dark'; }
html.dark #theme-btn::after { content: 'Light'; }

/* ── Nav ── */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 52px;
}
nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
}
nav a:hover, nav a.active { color: var(--text); background: var(--border); }

main { max-width: 1400px; margin: 32px auto; padding: 0 24px; }

/* ── Components (rounded shapes retained — fidelity A) ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: var(--surface);
}
.btn:hover { filter: brightness(1.06); }
/* Outline/ghost variant: on-brand but lighter weight than a solid .btn, so a
   persistent affordance (e.g. the nav Feedback button) reads as inviting without
   competing with each page's solid-accent primary CTA. Override .btn's fill. */
.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
}
.btn-ghost:hover {
  background: var(--accent);
  color: var(--surface);
  filter: none;
}

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th {
  font-family: var(--mono);
  text-align: left;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
td { padding: 10px 8px; border-bottom: 1px solid var(--border); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--mono);
}

.htmx-indicator { opacity: 0; transition: opacity 200ms; }
.htmx-request .htmx-indicator { opacity: 1; }
.indicator-loading { display: none; }
.htmx-request .indicator-default { display: none; }
.htmx-request .indicator-loading { display: inline; }
button:disabled { opacity: 0.6; cursor: not-allowed; }

/* Inline animated loading spinner — a ring in the current text color, shown
   inside .indicator-loading while an htmx request is in flight. */
.spinner {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.12em;
  margin-right: 7px;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* The reset above zeroes padding on every element, so any control omitted from
   this selector renders with its text flush against the border. `textarea` was
   missing — that is why the feedback composer looked cramped — and so was
   `search`. Add new text-entry controls here.

   `input[type=date]` is deliberately NOT in this list. The two date inputs
   (partials/forecast_month_table.html, partials/forecast_row_edit.html) are
   pinned to an inline width:130px; with border-box, 12px of horizontal padding
   would drop their content box to 104px, which clips the native picker/clear
   icons in Firefox. Nobody has reported them as cramped, so adding them here
   would trade a real regression for a complaint no one made. If they ever do
   need padding, widen those two inline widths in the same change. */
input[type=text], input[type=number], input[type=url], input[type=email],
input[type=search], textarea, select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  width: 100%;
  font-family: var(--sans);
}

/* Browsers default textarea to a monospace font and allow horizontal resize,
   which breaks the card layouts these sit in. The font is covered by the rule
   above; this pins the resize axis. */
textarea { resize: vertical; }
[x-cloak] { display: none !important; }

/* ── Responsive layout helpers (unchanged from base.html) ── */
.stat-card-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; padding: 0; overflow: hidden; background: var(--border); }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.two-col { display: grid; gap: 24px; align-items: start; }
.two-col-sidebar  { grid-template-columns: 1fr 160px; }
.two-col-budget   { grid-template-columns: 200px 1fr; }
.two-col-forecast { grid-template-columns: 1fr 220px; }
.budget-row-grid  { display: grid; grid-template-columns: 140px 1fr 130px; gap: 12px; align-items: center; margin-bottom: 10px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 768px) {
  nav { overflow-x: auto; gap: 12px; padding: 0 12px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  nav::-webkit-scrollbar { display: none; }
  nav > * { flex-shrink: 0; }
  .nav-user-label { display: none; }
  main { padding: 0 12px; margin: 16px auto; }
  .stat-card-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-grid      { grid-template-columns: repeat(2, 1fr); }
  .two-col, .two-col-sidebar, .two-col-budget, .two-col-forecast { grid-template-columns: 1fr; }
  .budget-row-grid { grid-template-columns: 1fr; gap: 6px; }
  .forecast-sticky-panel { position: static; }
  #category-sidebar { position: static !important; max-height: none !important; overflow-y: visible !important; }
  .col-hide-mobile { display: none; }
}

/* ── Auth / pre-login pages (extend auth_base.html) ── */
body.auth { display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
}
.auth-card.center { text-align: center; }
.auth-card .brand { margin-bottom: 24px; }
.auth-card h1 { font-family: var(--serif); font-size: 22px; font-weight: 500; margin-bottom: 8px; }
.auth-card h1.error { color: var(--red); }
.auth-card p { color: var(--muted); font-size: 13px; line-height: 1.6; margin-bottom: 24px; }
.auth-card .email { color: var(--accent); }
.auth-card form button,
.auth-card > button {
  display: block; width: 100%; padding: 10px; border-radius: 6px;
  font-family: var(--sans); font-size: 14px; font-weight: 600; cursor: pointer;
  border: none; background: var(--accent); color: var(--surface); margin-bottom: 10px;
}
.auth-card input[type=email],
.auth-card input[type=text] {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 10px 14px; border-radius: 6px; font-size: 14px; width: 100%;
  margin-bottom: 12px; font-family: var(--sans);
}
.auth-card .recovery-link {
  display: block; width: 100%; text-align: center; margin-top: 4px;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 13px; text-decoration: underline; font-family: var(--sans);
}
.auth-card .status { font-size: 13px; color: var(--muted); margin-top: 8px; min-height: 18px; }
.auth-card a { color: var(--accent); font-size: 13px; }

/* ---- Course-correction card (Spec 2) ---- */
.btn-link { border: none; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 0; text-decoration: underline; }
.btn-link:hover { filter: brightness(1.1); }
.cc-chip { border: none; cursor: pointer; }
#cc-drawer:empty { display: none; }
.cc-panel { border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; margin-bottom: 16px; background: var(--surface); }
.cc-active { border-left: 4px solid var(--accent); }
.cc-ok { border-left: 4px solid var(--green); }
.cc-dismissed { border-left: 4px solid var(--muted); color: var(--muted); }
.cc-flag { display: flex; justify-content: space-between; align-items: center; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--accent); font-weight: 700; margin-bottom: 8px; }
.cc-h { font-size: 16px; font-weight: 700; margin: 0 0 10px; color: var(--text); }
.cc-x { border: none; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; }
.cc-move { font-size: 14px; margin: 4px 0 6px; }
.cc-moves { list-style: none; margin: 0 0 10px; padding: 8px 12px; background: var(--surface); border: 1px dashed var(--accent); border-radius: 10px; font-size: 14px; }
.cc-moves li { padding: 2px 0; }
.cc-moves-detail { font-size: 13px; color: var(--muted); margin: 4px 0 12px; }
.cc-preview { font-size: 14px; font-weight: 600; color: var(--green); margin: 0 0 6px; }
.cc-spare { font-size: 14px; color: var(--text); margin: 0 0 12px; }
.cc-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.cc-savings { font-size: 14px; color: var(--text); margin: 6px 0 10px; }
.cc-alt { margin: 6px 0; }
.cc-drawer-backdrop { position: fixed; inset: 0; background: rgba(20,15,10,.45); display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh; z-index: 50; }
.cc-drawer-panel { position: relative; max-width: 460px; width: 92%; }
.cc-drawer-close { position: absolute; top: -34px; right: 0; border: none; background: none; color: #fff; font-size: 26px; cursor: pointer; }

/* ---- Onboarding demo (Spec 3a) ---- */
.sample-banner { display:flex; justify-content:space-between; align-items:center; gap:12px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface)); border:1px solid var(--border);
  border-radius:10px; padding:8px 14px; margin-bottom:14px; font-size:13px; color:var(--text); }
#cc-coachmark .coach { background: var(--text); color: var(--surface); border-radius:12px;
  padding:12px 14px; margin-top:14px; margin-bottom:16px; font-size:13px; line-height:1.45; }
.coach-step { display:block; margin-top:6px; font-size:11px; color: var(--accent); font-weight:700; }
.coach-skip { color: var(--muted); text-decoration:underline; margin-left:8px; }
.coach-cta { display:inline-block; margin-top:8px; }

/* ---- Onboarding confirm screen (Spec 3b) ---- */
.confirm-card { max-width:520px; margin:24px auto; background:var(--surface); border:1px solid var(--border);
  border-radius:16px; padding:22px; }
.confirm-card .bar { height:30px; border-radius:8px; overflow:hidden; display:flex; font-size:11px; font-weight:700; color:#fff; }
.confirm-card .bar .fix { background:var(--muted); display:flex; align-items:center; justify-content:center; min-width:0; overflow:hidden; white-space:nowrap; }
.confirm-card .bar .flex { background:var(--accent); display:flex; align-items:center; justify-content:center; min-width:0; overflow:hidden; white-space:nowrap; }
.confirm-card .legend { display:flex; justify-content:space-between; font-size:12px; color:var(--muted); margin:6px 0 16px; }
.confirm-card .legend b { color:var(--text); }
.confirm-card .cols { display:flex; gap:12px; margin-bottom:18px; }
.confirm-card .col { flex:1; background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:10px; }
.confirm-card .col h4 { margin:0 0 8px; font-size:11px; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); }
.confirm-card .chip { display:flex; justify-content:space-between; align-items:center; background:var(--surface);
  border:1px solid var(--border); border-radius:7px; padding:6px 8px; margin-bottom:6px; font-size:12.5px; color:var(--text); }
.confirm-card .chip .amt { color:var(--muted); display:flex; align-items:center; gap:5px; }
.confirm-card .flip { border:none; background:none; color:var(--accent); font-size:15px; cursor:pointer; }
.confirm-card .confirm-form label { display:block; font-size:12px; color:var(--muted); font-weight:600; margin-bottom:10px; }
.confirm-card .confirm-form input { display:block; width:100%; margin-top:4px; padding:8px 10px; border:1px solid var(--border);
  border-radius:8px; background:var(--surface); color:var(--text); font:inherit; }
.confirm-card .hint { font-size:11px; color:var(--muted); margin:2px 0 12px; }

/* ---- In-app feedback sheet ---- */
.feedback-sheet { position:fixed; inset:auto 16px 16px auto; width:min(420px, calc(100vw - 32px));
  background:var(--bg); border:1px solid var(--border); border-radius:8px;
  box-shadow:0 8px 32px rgba(0,0,0,.18); padding:16px; z-index:1000; }
