/* Hoofnote – base styles. Mobile first, light + dark. */
:root {
  --bg: #f6f2ea;
  --surface: #ffffff;
  --surface-2: #efe9dd;
  --ink: #1f2a24;
  --ink-2: #56625a;
  --line: #e0d8c8;
  --primary: #2f4a3a;
  --primary-ink: #ffffff;
  --accent: #b07a45;
  --good: #2e7d4f;
  --good-bg: #e3f2e8;
  --warn: #a8660b;
  --warn-bg: #fbefd9;
  --bad: #b3261e;
  --bad-bg: #fbe3e1;
  --info-bg: #e6eef5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141a17; --surface: #1c2420; --surface-2: #25302a; --ink: #eef2ee; --ink-2: #a7b4ab;
    --line: #2f3b34; --primary: #7fb894; --primary-ink: #0f1a14; --accent: #d9a46b;
    --good: #7fd19b; --good-bg: #1d3526; --warn: #f0b85a; --warn-bg: #3a2d14; --bad: #ff8a80; --bad-bg: #3d1d1b; --info-bg: #1d2a36;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141a17; --surface: #1c2420; --surface-2: #25302a; --ink: #eef2ee; --ink-2: #a7b4ab;
  --line: #2f3b34; --primary: #7fb894; --primary-ink: #0f1a14; --accent: #d9a46b;
  --good: #7fd19b; --good-bg: #1d3526; --warn: #f0b85a; --warn-bg: #3a2d14; --bad: #ff8a80; --bad-bg: #3d1d1b; --info-bg: #1d2a36;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
img { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--primary); color: var(--primary-ink);
}
.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand img { border-radius: 8px; background: #fff2; }
.badge-dev { font-size: .65rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; background: var(--accent); color: #fff; padding: 1px 6px; border-radius: 99px; }
.top-links { display: flex; gap: 14px; }
.top-links a { color: inherit; text-decoration: none; font-weight: 500; opacity: .92; }

main { max-width: 960px; margin: 0 auto; padding: 16px; outline: none; }

/* Bottom nav */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.bottomnav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .72rem; color: var(--ink-2); text-decoration: none; }
.bottomnav a span { font-size: 1.25rem; line-height: 1; }
.bottomnav a.active { color: var(--primary); font-weight: 700; }

/* Layout helpers */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: 1fr; }
@media (min-width: 700px) { .grid.two { grid-template-columns: 1fr 1fr; } }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.section { margin: 20px 0 8px; display: flex; justify-content: space-between; align-items: center; }
.section h2 { margin: 0; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card h3 { margin-bottom: 4px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; gap: 12px; align-items: flex-start; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .meta { color: var(--ink-2); font-size: .85rem; }
.item .actions { display: flex; gap: 4px; flex-shrink: 0; }
.item.clickable { cursor: pointer; }
.item.clickable:hover { border-color: var(--primary); }
.empty { text-align: center; color: var(--ink-2); padding: 24px 12px; border: 1px dashed var(--line); border-radius: var(--radius); }

.horse-card { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; }
.avatar { width: 64px; height: 64px; border-radius: 14px; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; font-size: 1.8rem; flex-shrink: 0; overflow: hidden; }
.avatar.lg { width: 96px; height: 96px; border-radius: 18px; font-size: 2.6rem; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat .label { font-size: .78rem; color: var(--ink-2); }
.stat .value { font-size: 1.3rem; font-weight: 700; }

/* Pills / badges */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--primary); }

.banner { padding: 10px 16px; font-size: .9rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.callout { border-radius: 12px; padding: 12px 14px; font-size: .9rem; background: var(--info-bg); }
.callout.good { background: var(--good-bg); }
.callout.warn { background: var(--warn-bg); }
.callout.bad { background: var(--bad-bg); }

/* Buttons */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 9px 14px; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  min-height: 42px;
}
button:hover, .btn:hover { border-color: var(--primary); }
.btn.primary, button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger, button.danger { color: var(--bad); }
.btn.sm, button.sm { padding: 5px 10px; min-height: 34px; font-size: .85rem; }
.btn.icon, button.icon { padding: 6px; min-width: 36px; min-height: 36px; border-color: transparent; background: transparent; }
.btn.block { width: 100%; }
button:disabled { opacity: .5; cursor: not-allowed; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 15;
  width: 56px; height: 56px; border-radius: 18px; font-size: 1.8rem; background: var(--accent); color: #fff; border: 0; box-shadow: 0 6px 18px rgba(0,0,0,.2);
}

/* Tabs / chips */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin: 12px -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex-shrink: 0; padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: .9rem; }
.tab.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

/* Forms */
.sheet { border: 0; border-radius: 18px 18px 0 0; padding: 0; width: 100%; max-width: 640px; max-height: 92vh; margin: auto auto 0; background: var(--surface); color: var(--ink); }
@media (min-width: 700px) { .sheet { border-radius: 18px; margin: auto; } }
.sheet::backdrop { background: rgba(0,0,0,.45); }
.sheet form, .sheet .sheet-body { padding: 16px; }
.sheet-head { position: sticky; top: 0; background: var(--surface); display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); z-index: 1; }
.sheet-head h2 { margin: 0; }
.sheet-foot { position: sticky; bottom: 0; background: var(--surface); display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label, .field .label { font-size: .85rem; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: .78rem; color: var(--ink-2); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type="checkbox"] { width: auto; min-height: auto; }
.checks { display: flex; gap: 12px; flex-wrap: wrap; }
.checks label { display: flex; align-items: center; gap: 6px; font-weight: 500; color: var(--ink); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 420px) { .form-grid { grid-template-columns: 1fr; } }
.photo-preview { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--ink-2); font-weight: 600; font-size: .8rem; }
td.num, th.num { text-align: right; }

/* Bars */
.bar-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 8px; align-items: center; font-size: .85rem; margin-bottom: 6px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* Timeline */
.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl-item { position: relative; margin-bottom: 12px; }
.tl-item::before { content: ""; position: absolute; left: -18px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.tl-date { font-size: .78rem; color: var(--ink-2); }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 12px; border-radius: 14px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--primary); color: var(--primary-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 8px; margin-top: 12px; }
.chat-input textarea { min-height: 48px; }

/* Blog */
.post-card { overflow: hidden; padding: 0; }
.post-card img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: var(--surface-2); }
.post-card .body { padding: 14px; }
.post-body { font-size: 1.02rem; }
.post-body img { border-radius: 12px; }
.video { position: relative; aspect-ratio: 16/9; border-radius: 12px; overflow: hidden; background: #000; margin: 12px 0; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; }

.spark { width: 100%; height: 48px; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark circle { fill: var(--accent); }

/* Print (passport + feed board) */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; font-size: 12px; }
  .topbar, .bottomnav, .fab, .no-print, #storage-banner, .toast { display: none !important; }
  .print-only { display: block; }
  main { max-width: none; padding: 0; }
  .card, .item, .stat { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  a { color: #000; text-decoration: none; }
}
.feedboard td, .feedboard th { border: 1px solid var(--line); padding: 8px; }
.feedboard th { background: var(--surface-2); }

/* Calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .68rem; font-weight: 700; color: var(--ink-2); padding-bottom: 2px; }
.cal-cell { aspect-ratio: 1 / 1; border: 1px solid var(--line); border-radius: 8px; padding: 4px; display: flex; flex-direction: column; background: var(--surface); }
.cal-cell.empty { border-color: transparent; background: transparent; }
.cal-cell.today { border-color: var(--primary); border-width: 2px; }
.cal-cell.clickable { cursor: pointer; }
.cal-cell.clickable:hover { border-color: var(--primary); }
.cal-daynum { font-size: .76rem; font-weight: 600; }
.cal-dots { display: flex; gap: 2px; flex-wrap: wrap; margin-top: auto; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* Feed order grid */
.feedorder td, .feedorder th { border: 1px solid var(--line); padding: 8px; white-space: nowrap; }
.feedorder th { background: var(--surface-2); }
.feedorder .total-row td, .feedorder .total-row th { background: var(--surface-2); font-weight: 600; }
.btn.ghost, button.ghost { background: transparent; border-style: dashed; color: var(--ink-2); }
.linklike { background: none; border: 0; padding: 0; min-height: auto; color: var(--primary); font-weight: 600; text-decoration: underline; display: inline; }

/* Welcome / splash screen: full-bleed hero photo + dark scrim + minimal type, like a premium
   app's landing screen. Placeholder photo (free-to-use stock) – swap public/index.html's
   .welcome-bg src for commissioned artwork or real photography later; nothing else changes. */
.welcome {
  position: fixed; inset: 0; z-index: 999; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end;
  background: #0a100c; transition: opacity .5s ease, visibility .5s ease;
}
.welcome.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.welcome-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 42%; }
.welcome-scrim {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(8, 14, 10, .1) 0%, rgba(8, 14, 10, .22) 38%, rgba(7, 12, 9, .82) 76%, #070c09 100%);
}
.welcome-logo {
  position: absolute; z-index: 2; top: calc(18px + env(safe-area-inset-top)); right: 18px;
  border-radius: 9px; background: rgba(255, 255, 255, .12); padding: 6px; backdrop-filter: blur(6px);
}
.welcome-content { position: relative; z-index: 2; padding: 0 24px calc(30px + env(safe-area-inset-bottom)); animation: welcome-rise .7s ease .1s both; }
.welcome-eyebrow { color: #e8c9a0; font-size: .72rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; margin-bottom: 10px; }
.welcome-content h1 { font-size: 2.3rem; line-height: 1.08; margin: 0 0 10px; color: #fff; font-weight: 800; letter-spacing: -.01em; }
.welcome-tag { color: #d7e0d9; font-size: .92rem; margin: 0 0 20px; max-width: 34ch; }
.welcome-content .primary.block { width: 100%; max-width: 420px; font-size: 1rem; padding: 14px; border-radius: 12px; }
@keyframes welcome-rise { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .welcome-content { animation: none !important; } }
