/* ============================================================================
   FileItRover — Workshop design system (Story 2.1). Tokens + base + the
   9-component library + mascot animation. Distilled from DESIGN.md /
   EXPERIENCE.md; those spines win on conflict.
   ============================================================================ */

/* ---------- Design tokens (DESIGN.md frontmatter) ---------- */
:root {
  --bg: #FFF7ED;
  --surface: #FFFFFF;
  --surface-sunken: #FBEFE0;
  --ink: #2A211C;
  --ink-soft: #6B5D54;
  --brand: #E4572E;
  --brand-deep: #C63D1B;
  --bone: #F5B72E;
  --success: #3E9B6D;
  --trust: #12293F;
  --danger: #B23A48;
  --border: #EFE1D2;

  --r-sm: 8px;
  --r-md: 16px;
  --r-lg: 24px;
  --r-pill: 999px;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s6: 24px; --s8: 32px; --s12: 48px;

  --font-display: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --font-body: system-ui, "Segoe UI", Roboto, sans-serif;

  --shadow-card: 0 10px 24px rgba(198, 61, 27, 0.10);
  --shadow-soft: 0 6px 16px rgba(198, 61, 27, 0.08);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}
h1, h2, h3, .wordmark { font-family: var(--font-display); color: var(--brand-deep); letter-spacing: -0.01em; }
h1 { font-size: 2rem; margin: 0 0 var(--s3); }
h2 { font-size: 1.5rem; margin: 0 0 var(--s4); color: var(--ink); }
h3 { font-size: 1.25rem; margin: 0 0 var(--s3); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-deep); text-decoration: underline; }
p { margin: 0 0 var(--s4); }
.lede { color: var(--ink-soft); font-size: 1.05rem; max-width: 60ch; }
code { font-family: "Consolas", ui-monospace, monospace; font-size: 0.9em; background: var(--surface-sunken); padding: 1px 5px; border-radius: var(--r-sm); }

/* ---------- Accessibility ---------- */
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: var(--r-sm); }
.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; }

/* ---------- App shell / chrome ---------- */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.app-header {
  display: flex; align-items: center; gap: var(--s6);
  padding: var(--s3) var(--s6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: inline-flex; align-items: center; gap: var(--s3); text-decoration: none; }
.brand:hover { text-decoration: none; }
.wordmark { font-size: 1.3rem; font-weight: 700; }
.beta-badge {
  background: var(--bone); color: var(--ink);
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 3px 9px; border-radius: var(--r-pill);
}
.app-nav { display: flex; gap: var(--s4); margin-left: auto; }
.app-nav a { color: var(--ink-soft); font-weight: 600; padding: var(--s2) var(--s2); border-radius: var(--r-sm); }
.app-nav a:hover { color: var(--brand-deep); text-decoration: none; background: var(--surface-sunken); }
.app-main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: var(--s8) var(--s6); }
.app-footer {
  display: flex; flex-wrap: wrap; gap: var(--s3); justify-content: space-between;
  padding: var(--s4) var(--s6);
  background: var(--trust); color: #D7E0EA; font-size: 0.85rem;
}
.app-footer a { color: #F3C58A; }
.footer-beta { opacity: 0.85; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s6);
  font-family: var(--font-body); font-size: 0.95rem; font-weight: 700;
  border-radius: var(--r-pill); border: 2px solid transparent; cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-deep); color: #fff; text-decoration: none; }
.btn-outline { background: var(--surface); color: var(--brand); border-color: var(--brand); }
.btn-outline:hover { background: var(--surface-sunken); color: var(--brand-deep); text-decoration: none; }
.btn-sm { min-height: 36px; padding: 0 var(--s4); font-size: 0.85rem; }

/* ---------- Chips (quick-reply-chip) ---------- */
.chip {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s4);
  background: var(--surface); color: var(--brand);
  border: 2px solid var(--brand); border-radius: var(--r-pill);
  font-family: var(--font-body); font-size: 0.9rem; font-weight: 700; cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.chip:hover { background: var(--surface-sunken); }
.chip-pressed, .chip-pressed:hover { background: var(--brand); color: #fff; }
.chip-sm { min-height: 30px; padding: 0 var(--s3); font-size: 0.8rem; font-weight: 600; }

/* ---------- Rover avatar + mascot ---------- */
.rover-mascot { display: block; width: 100%; height: auto; }
.rover-avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  background: var(--surface); border-radius: var(--r-pill);
  box-shadow: inset 0 0 0 2px var(--border); overflow: hidden;
}
.rover-avatar .rover-mascot { width: 100%; height: 100%; }

/* ---------- Chat bubbles ---------- */
.chat-row { display: flex; align-items: flex-end; gap: var(--s2); margin-bottom: var(--s3); }
.chat-rover { justify-content: flex-start; }
.chat-user { justify-content: flex-end; }
.chat-bubble {
  max-width: 78%; padding: var(--s3) var(--s4); border-radius: var(--r-md);
  box-shadow: var(--shadow-soft); font-size: 0.95rem;
}
.chat-bubble-rover { background: var(--surface); border-bottom-left-radius: var(--r-sm); }
.chat-bubble-user { background: var(--surface-sunken); border-bottom-right-radius: var(--r-sm); }

/* ---------- Confirm card (Confirm Gate) ---------- */
.confirm-card {
  background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-card);
  padding: var(--s6); max-width: 420px; border: 1px solid var(--border);
}
.confirm-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s4); }
.confirm-title { font-family: var(--font-display); font-size: 1.15rem; color: var(--ink); }
.confirm-fields { margin: 0 0 var(--s4); display: grid; gap: var(--s2); }
.confirm-field { display: flex; justify-content: space-between; gap: var(--s4); padding: var(--s2) 0; border-bottom: 1px solid var(--border); }
.confirm-field:last-child { border-bottom: 0; }
.confirm-field dt { color: var(--ink-soft); font-size: 0.85rem; margin: 0; }
.confirm-field dd { margin: 0; font-weight: 600; text-align: right; }
.confirm-actions { display: flex; gap: var(--s3); }

/* ---------- Status toast ---------- */
.toast {
  display: inline-flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4); border-radius: var(--r-md); font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-soft);
}
.toast-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: var(--r-pill); color: #fff; font-weight: 800; font-size: 0.85rem;
}
.toast-success .toast-icon { background: var(--success); }
.toast-success { color: #2C6B4C; }
.toast-failure .toast-icon { background: var(--danger); }
.toast-failure { color: #8C2B37; }

/* ---------- Triage row ---------- */
.triage-row {
  display: flex; align-items: center; gap: var(--s4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s3) var(--s4); box-shadow: var(--shadow-soft);
}
.triage-thumb { font-size: 1.5rem; flex: 0 0 auto; }
.triage-main { flex: 1; min-width: 0; }
.triage-vendor { font-weight: 700; }
.triage-guess { color: var(--ink-soft); font-size: 0.85rem; }
.triage-actions { display: flex; align-items: center; gap: var(--s2); flex: 0 0 auto; }

/* ---------- Transaction table (Statement Triage) ---------- */
.txn-scroll { overflow-x: auto; }
.txn-table { width: 100%; border-collapse: collapse; background: var(--surface); }
.txn-table thead th {
  text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--trust); padding: var(--s2) var(--s3); border-bottom: 2px solid var(--border); white-space: nowrap;
}
.txn-table td { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.txn-amount { text-align: right; }
.txn-ignored { opacity: 0.5; }
.txn-ignored .txn-vendor, .txn-ignored .money { text-decoration: line-through; }
.ignore-toggle { display: inline-flex; align-items: center; gap: var(--s2); font-size: 0.85rem; color: var(--ink-soft); cursor: pointer; }
.txn-footer { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s3); font-weight: 600; color: var(--trust); }

/* ---------- Account card ---------- */
.account-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s4); min-width: 190px; flex: 1 1 190px;
}
.account-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: var(--s2); }
.account-name { font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; }
.account-count { color: var(--ink-soft); font-size: 0.8rem; }
.account-status { color: var(--trust); font-size: 0.85rem; display: flex; align-items: center; gap: var(--s2); }
.account-status-dot { width: 9px; height: 9px; border-radius: var(--r-pill); background: var(--success); flex: 0 0 auto; }

/* ---------- Money figure ---------- */
.money { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; color: var(--ink); font-weight: 600; }
.money-neg { color: var(--danger); }

/* ---------- Home ---------- */
.home-hero { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s12); }
.home-hero .rover-mascot { flex: 0 0 auto; }
.home-copy { flex: 1 1 320px; }
.home-cta { display: flex; flex-wrap: wrap; gap: var(--s3); margin: var(--s6) 0; }
.home-beta { color: var(--ink-soft); font-size: 0.9rem; }

/* ---------- Workshop (Accounts + Ledger + Item) ---------- */
.workshop-totals { display: flex; flex-wrap: wrap; gap: var(--s4); margin-bottom: var(--s6); }
.workshop-total { display: flex; flex-direction: column; gap: 2px; background: var(--trust); color: #fff; border-radius: var(--r-md); padding: var(--s6); min-width: 220px; }
.workshop-total-deductible { background: var(--success); }
.badge-deductible { display: inline-block; background: var(--success); color: #fff; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 8px; border-radius: var(--r-pill); }
.item-detail { margin: 0 0 var(--s6); max-width: 460px; }
.item-captured { background: var(--surface-sunken); border-radius: var(--r-sm); padding: var(--s3) var(--s4); }
.item-raw { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--s3) var(--s4); white-space: pre-wrap; overflow-x: auto; font-size: 0.85rem; color: var(--ink-soft); }
.workshop-total-label { font-size: 0.78rem; letter-spacing: 0.05em; text-transform: uppercase; opacity: 0.85; }
.workshop-total-value { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.workshop-total-value .money { color: #fff; }
.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--s4); }
.account-tile { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s4); box-shadow: var(--shadow-soft); text-decoration: none; color: var(--ink); transition: transform 0.12s ease, box-shadow 0.12s ease; }
.account-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-card); text-decoration: none; }
.account-tile-name { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--brand-deep); margin-bottom: var(--s2); }
.account-tile-meta { color: var(--ink-soft); font-size: 0.9rem; }
.signin-prompt { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s6); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s8); box-shadow: var(--shadow-soft); }
.signin-prompt .rover-mascot { flex: 0 0 auto; }
.crumb { margin-bottom: var(--s2); }
.crumb a { font-weight: 600; }

/* ---------- Signup + channels ---------- */
.signup { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s12); }
.signup .rover-mascot { flex: 0 0 auto; }
.signup-form { flex: 1 1 320px; }
.stack-form { display: flex; flex-direction: column; gap: var(--s4); max-width: 360px; margin: var(--s6) 0; }
.stack-form label { display: flex; flex-direction: column; gap: var(--s2); font-weight: 600; color: var(--ink-soft); font-size: 0.9rem; }
.stack-form input { padding: var(--s3) var(--s4); border: 1px solid var(--border); border-radius: var(--r-sm); font-size: 1rem; font-family: var(--font-body); background: var(--surface); color: var(--ink); }
.channel-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--s4); }
.channel-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s4); box-shadow: var(--shadow-soft); }
.channel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--s2); }
.channel-name { font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; }
.channel-status { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 8px; border-radius: var(--r-pill); background: var(--surface-sunken); color: var(--ink-soft); }
.channel-status-active { background: var(--success); color: #fff; }
.channel-status-testing { background: var(--bone); color: var(--ink); }
.channel-detail { color: var(--ink-soft); font-size: 0.88rem; margin-bottom: var(--s3); }
.channel-value { font-weight: 600; margin-bottom: var(--s3); }
.channel-actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.channel-inline { display: flex; gap: var(--s2); flex: 1 1 100%; }
.channel-inline input { flex: 1; padding: var(--s2) var(--s3); border: 1px solid var(--border); border-radius: var(--r-sm); font-size: 0.9rem; }

/* ---------- Foundation gallery ---------- */
.fnd-section { margin: var(--s12) 0; }
.fnd-note { color: var(--ink-soft); }
.swatch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s3); }
.swatch { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3); }
.swatch-chip { height: 40px; border-radius: var(--r-sm); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08); margin-bottom: var(--s2); }
.swatch-name { font-weight: 700; font-size: 0.9rem; }
.swatch-hex { font-family: "Consolas", monospace; font-size: 0.8rem; color: var(--ink-soft); }
.swatch-use { font-size: 0.78rem; color: var(--ink-soft); }
.token-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s4); margin-bottom: var(--s4); }
.round-demo { width: 78px; height: 78px; background: var(--surface); border: 2px solid var(--brand); display: flex; align-items: center; justify-content: center; font-size: 0.8rem; color: var(--brand-deep); font-weight: 700; }
.space-demo { display: flex; align-items: center; gap: var(--s2); font-size: 0.8rem; color: var(--ink-soft); }
.space-bar { height: 16px; background: var(--brand); border-radius: 3px; display: inline-block; }
.mascot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s4); }
.mascot-cell { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3); text-align: center; box-shadow: var(--shadow-soft); }
.mascot-cell figcaption { margin-top: var(--s2); font-family: "Consolas", monospace; font-size: 0.8rem; color: var(--brand-deep); font-weight: 700; }
.comp-demo { margin: var(--s6) 0; padding-top: var(--s4); border-top: 1px solid var(--border); }
.comp-tag { font-family: var(--font-body); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: #fff; background: var(--trust); padding: 2px 8px; border-radius: var(--r-pill); vertical-align: middle; }
.comp-row { display: flex; align-items: center; gap: var(--s4); }
.comp-wrap { flex-wrap: wrap; }
.comp-col { display: flex; flex-direction: column; gap: var(--s3); align-items: flex-start; }
.comp-chat { max-width: 460px; }
.fnd-a11y { color: var(--ink-soft); padding-left: var(--s6); }
.fnd-a11y li { margin-bottom: var(--s2); }

/* ---------- Mascot animations (scoped) — freeze under reduced motion ---------- */
.rover-mascot .wag { transform-box: fill-box; transform-origin: 50% 100%; animation: rv-wag 0.55s ease-in-out infinite; }
@keyframes rv-wag { 0%, 100% { transform: rotate(-20deg); } 50% { transform: rotate(20deg); } }
.rover-mascot .zoom { transform-box: fill-box; transform-origin: 50% 100%; animation: rv-bounce 0.9s ease-in-out infinite; }
@keyframes rv-bounce { 0%, 100% { transform: translateY(4px); } 45% { transform: translateY(-12px); } }
.rover-mascot .breathe { transform-box: fill-box; transform-origin: 50% 90%; animation: rv-breathe 3.4s ease-in-out infinite; }
@keyframes rv-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.035); } }
.rover-mascot .zz { opacity: 0; transform-box: fill-box; transform-origin: 50% 100%; }
.rover-mascot .zz1 { animation: rv-floatz 3s ease-in-out infinite; }
.rover-mascot .zz2 { animation: rv-floatz 3s ease-in-out 0.8s infinite; }
.rover-mascot .zz3 { animation: rv-floatz 3s ease-in-out 1.6s infinite; }
@keyframes rv-floatz { 0% { opacity: 0; transform: translate(0, 0) scale(0.6); } 18% { opacity: 1; } 70% { opacity: 0.85; } 100% { opacity: 0; transform: translate(16px, -34px) scale(1.15); } }
.rover-mascot .dot { animation: rv-blink 1.4s ease-in-out infinite; }
.rover-mascot .dot2 { animation-delay: 0.22s; }
.rover-mascot .dot3 { animation-delay: 0.44s; }
@keyframes rv-blink { 0%, 100% { opacity: 0.25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-2px); } }
.rover-mascot .flap { transform-box: fill-box; transform-origin: 50% 0%; animation: rv-flap 0.9s ease-in-out infinite; }
@keyframes rv-flap { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(6deg); } }
.rover-mascot .qbob { transform-box: fill-box; transform-origin: 50% 100%; animation: rv-qbob 2.2s ease-in-out infinite; }
@keyframes rv-qbob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-3px) rotate(4deg); } }
.rover-mascot .sparkle { animation: rv-twinkle 1.8s ease-in-out infinite; }
@keyframes rv-twinkle { 0%, 100% { opacity: 0.35; transform: scale(0.85); } 50% { opacity: 1; transform: scale(1.1); } }

@media (prefers-reduced-motion: reduce) {
  .rover-mascot .wag, .rover-mascot .zoom, .rover-mascot .breathe,
  .rover-mascot .zz1, .rover-mascot .zz2, .rover-mascot .zz3,
  .rover-mascot .dot, .rover-mascot .flap, .rover-mascot .qbob, .rover-mascot .sparkle {
    animation: none;
  }
  .rover-mascot .zz { opacity: 0.9; }
  * { scroll-behavior: auto; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .app-header { gap: var(--s3); padding: var(--s3) var(--s4); }
  .app-main { padding: var(--s6) var(--s4); }
  .app-nav { gap: var(--s2); }
  h1 { font-size: 1.6rem; }
  .chat-bubble { max-width: 85%; }
}
