/* ============================================================
   Design tokens
   ============================================================ */
:root {
  --paper: #EDEAE2;
  --paper-raised: #F5F3EC;
  --ink: #211F1A;
  --ink-soft: #55503F;
  --line: #C9C2B2;
  --line-soft: #DAD5C6;
  --brass: #B8862E;
  --brass-dark: #96701F;
  --teal: #1E5C4F;
  --teal-soft: #E4EDE9;
  --brick: #96392C;
  --brick-soft: #F3E4E0;
  --focus-ring: #1E5C4F;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "IBM Plex Mono", "SF Mono", Consolas, monospace;

  --radius-sm: 3px;
  --radius-md: 5px;
  --max-width: 1100px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1A1815;
    --paper-raised: #221F1A;
    --ink: #EDEAE2;
    --ink-soft: #B8B2A0;
    --line: #3A362C;
    --line-soft: #2C2921;
    --teal-soft: #16241F;
    --brick-soft: #2C1815;
  }
}
:root[data-theme="dark"] {
  --paper: #1A1815;
  --paper-raised: #221F1A;
  --ink: #EDEAE2;
  --ink-soft: #B8B2A0;
  --line: #3A362C;
  --line-soft: #2C2921;
  --teal-soft: #16241F;
  --brick-soft: #2C1815;
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; }

html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  margin: 0;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  margin: 0 0 0.5em;
  letter-spacing: -0.01em;
}

h1 { font-size: clamp(2.1rem, 4vw, 3.4rem); }
h2 { font-size: clamp(1.5rem, 2.6vw, 2rem); }
h3 { font-size: 1.15rem; }

p { margin: 0 0 1em; max-width: 62ch; }

a { color: var(--brass-dark); }
a:hover { color: var(--brass); }

/* Always-visible keyboard focus, never suppressed */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

/* ============================================================
   Nav
   ============================================================ */
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  max-width: var(--max-width);
  margin: 0 auto;
}

.site-nav__brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--ink);
  text-decoration: none;
}

.site-nav__links {
  display: flex;
  gap: 28px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav__links a {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.95rem;
}
.site-nav__links a:hover { color: var(--ink); }

/* ============================================================
   Buttons - deliberately square-cornered, not pill-shaped
   ============================================================ */
.btn {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}

.btn-primary {
  background: var(--brass);
  color: #1A1408;
  border-color: var(--brass);
}
.btn-primary:hover { background: var(--brass-dark); border-color: var(--brass-dark); }

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn-secondary:hover { border-color: var(--ink-soft); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   Forms - keyboard-friendly, clearly labelled
   ============================================================ */
.field { margin-bottom: 18px; }

.field label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-raised);
  color: var(--ink);
}

.field-hint {
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-top: 4px;
}

.field-error {
  font-size: 0.85rem;
  color: var(--brick);
  margin-top: 6px;
}

.form-error-banner {
  background: var(--brick-soft);
  border: 1px solid var(--brick);
  color: var(--brick);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 0.92rem;
}

/* ============================================================
   Hero
   ============================================================ */
.hero {
  padding: 72px 0 56px;
  border-bottom: 1px solid var(--line);
}

.hero__grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 56px;
  align-items: center;
}

@media (max-width: 800px) {
  .hero__grid { grid-template-columns: 1fr; }
}

.hero__eyebrow {
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin-bottom: 14px;
}

.hero__actions {
  display: flex;
  gap: 12px;
  margin-top: 28px;
  flex-wrap: wrap;
}

/* Example deal card in the hero - the "show, don't tell" moment */
.deal-example {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 22px;
}

.deal-example__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 0.92rem;
}
.deal-example__row:last-child { border-bottom: none; }

.deal-example__label { color: var(--ink-soft); }
.deal-example__value { font-family: var(--font-mono); }

.deal-example__markup {
  font-family: var(--font-mono);
  color: var(--teal);
  font-weight: 600;
}

/* ============================================================
   Deals table (dashboard)
   ============================================================ */
.deals-table {
  width: 100%;
  border-collapse: collapse;
}

.deals-table th {
  text-align: left;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.deals-table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 0.92rem;
  vertical-align: middle;
}

.deals-table tr:hover td { background: var(--paper-raised); }

.deals-table .num { font-family: var(--font-mono); text-align: right; white-space: nowrap; }

.markup-pill {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--teal);
  background: var(--teal-soft);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.deal-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--paper-raised);
  display: block;
}

/* ============================================================
   Filter bar
   ============================================================ */
.filter-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: end;
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}

.filter-bar .field { margin-bottom: 0; min-width: 140px; }

/* ============================================================
   Empty / error states
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--ink-soft);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: auto;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  z-index: 100;
}
.skip-link:focus {
  left: 12px;
  top: 12px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ============================================================
   Portfolio - stat cards, add-entry form, upgrade prompt
   ============================================================ */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin: 24px 0 8px;
}

.stat-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-card--highlight {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.stat-card__label {
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.stat-card__value {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 600;
}

.add-entry-form {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: end;
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}

.add-entry-form .field { margin-bottom: 0; min-width: 160px; flex: 1; }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
  margin-right: 6px;
}

.portfolio-table .muted {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.portfolio-table .actions-cell { white-space: nowrap; }

.profit-positive { color: var(--teal); font-weight: 600; }
.profit-negative { color: var(--brick); font-weight: 600; }

.sell-form-row td { padding: 14px 12px; background: var(--paper-raised); }

.inline-sell-form {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}
.inline-sell-form .field { margin-bottom: 0; }
.inline-sell-form input { width: 140px; }

.upgrade-banner {
  background: var(--paper-raised);
  border: 1px solid var(--brass);
  border-radius: var(--radius-md);
  padding: 28px;
  margin-top: 24px;
}
.upgrade-banner h2 { margin-bottom: 10px; }

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 32px 0;
  margin-top: 64px;
}

.site-footer__links {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  font-size: 0.88rem;
}
.site-footer__links a { color: var(--ink-soft); text-decoration: none; }
.site-footer__links a:hover { color: var(--ink); }

.site-footer__note {
  font-size: 0.82rem;
  color: var(--ink-soft);
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ============================================================
   Cookie consent banner
   ============================================================ */
.cookie-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  max-width: 560px;
  background: var(--ink);
  color: var(--paper);
  padding: 18px 20px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
  z-index: 50;
}

.cookie-banner p { color: var(--paper); font-size: 0.9rem; margin-bottom: 14px; }

.cookie-banner__actions { display: flex; gap: 10px; }

.cookie-banner .btn-primary {
  background: var(--brass);
  color: #1A1408;
}
.cookie-banner .btn-secondary {
  background: transparent;
  color: var(--paper);
  border-color: #4A4638;
}
