/* Hearth — "linen & moss" design system */

@font-face {
  font-family: 'Fraunces';
  font-style: normal;
  font-weight: 500 600;
  font-display: swap;
  src: url('/static/fonts/fraunces-var.woff2') format('woff2-variations'),
       url('/static/fonts/fraunces-var.woff2') format('woff2');
}
@font-face {
  font-family: 'Karla';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('/static/fonts/karla-var.woff2') format('woff2-variations'),
       url('/static/fonts/karla-var.woff2') format('woff2');
}

:root {
  --bg: #F6F1E7;
  --surface: #FFFDF8;
  --ink: #23281F;
  --muted: #6E7264;
  --sage: #5C6B4A;
  --clay: #C4643B;
  --amber: #D9A441;
  --madder: #A4482F;
  --hairline: #E4DCCB;
  --sage-ink: #FFFDF8;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(35, 40, 31, 0.06);
  --shadow-lg: 0 8px 24px rgba(35, 40, 31, 0.08);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 200ms;
  --tabbar-h: 64px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1C1F1A;
    --surface: #262A23;
    --ink: #EDE7DA;
    --muted: #9BA08D;
    --sage: #8A9B74;
    --clay: #D07B54;
    --amber: #D9A441;
    --madder: #E08265;
    --hairline: #363B31;
    --sage-ink: #1C1F1A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1C1F1A;
  --surface: #262A23;
  --ink: #EDE7DA;
  --muted: #9BA08D;
  --sage: #8A9B74;
  --clay: #D07B54;
  --amber: #D9A441;
  --madder: #E08265;
  --hairline: #363B31;
  --sage-ink: #1C1F1A;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Karla', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
}

h1, h2, h3, h4 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.4em;
  color: var(--ink);
}
h1 { font-size: 1.6rem; font-weight: 600; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1.05rem; font-weight: 500; }

a { color: var(--sage); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 16px 8px;
}

header.topbar {
  max-width: 680px;
  margin: 0 auto;
  padding: 22px 16px 4px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
header.topbar .greeting { color: var(--muted); font-size: 0.9rem; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 14px;
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.card + .card { margin-top: 0; }
.card-lg { box-shadow: var(--shadow-lg); }

/* Section headers */
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 22px 0 10px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.section-title:first-child { margin-top: 0; }

/* Pills / chips */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  white-space: nowrap;
}
.pill.active, .pill[aria-pressed="true"] {
  background: var(--sage);
  border-color: var(--sage);
  color: var(--sage-ink);
}
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill.danger.active { background: var(--madder); border-color: var(--madder); }
.pill.amber.active { background: var(--amber); border-color: var(--amber); color: #23281F; }

/* Buttons */
button, .btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  padding: 11px 16px;
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
button:active, .btn:active { transform: scale(0.97); }
.btn-primary { background: var(--sage); border-color: var(--sage); color: var(--sage-ink); }
.btn-clay { background: var(--clay); border-color: var(--clay); color: #FFFDF8; }
.btn-danger { background: transparent; border-color: var(--madder); color: var(--madder); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; }
.btn-icon { min-width: 44px; padding: 0; }
.btn-block { width: 100%; }

/* Forms */
label { display: block; font-size: 0.85rem; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
input[type="text"], input[type="search"], input[type="password"], input[type="date"],
input[type="number"], input[type="url"], textarea, select {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  min-height: 44px;
  transition: border-color var(--dur) var(--ease);
}
textarea { min-height: 88px; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--sage);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sage) 20%, transparent);
}
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 10px; align-items: flex-end; }
.field-row > .field { flex: 1; min-width: 0; }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; accent-color: var(--sage); }

/* Icons */
.icon { width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex-shrink: 0; }
.icon-lg { width: 2rem; height: 2rem; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.row-title { flex: 1 1 140px; min-width: 0; }
.row-title .name { font-weight: 600; }
.row-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.row.checked .name { text-decoration: line-through; color: var(--muted); opacity: 0.7; }
.row.overdue { border-color: var(--madder); background: color-mix(in srgb, var(--madder) 6%, var(--surface)); }
.row.overdue .row-title .name { color: var(--madder); font-weight: 700; }
.row.settling { animation: settle 260ms var(--ease); }
@keyframes settle { from { opacity: 0.4; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

.checkbox-btn {
  width: 26px; height: 26px; border-radius: 8px;
  border: 2px solid var(--hairline);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; cursor: pointer; color: transparent;
  transition: all var(--dur) var(--ease);
}
.checkbox-btn.done { background: var(--sage); border-color: var(--sage); color: var(--sage-ink); }
.checkbox-btn .icon { width: 16px; height: 16px; }

/* Attribution */
.attribution { font-size: 0.78rem; color: var(--muted); }
.avatar-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--hairline); color: var(--muted);
  font-size: 0.65rem; font-weight: 700;
}

/* Empty states */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .icon { width: 2.2rem; height: 2.2rem; color: var(--sage); opacity: 0.6; margin-bottom: 10px; }
.empty-state p { max-width: 32ch; margin: 0 auto; font-style: italic; }

/* Both-agreed flag */
.agreed { background: color-mix(in srgb, var(--sage) 14%, var(--surface)) !important; }

/* Bottom tab bar */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  display: flex;
  z-index: 40;
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.68rem;
  font-weight: 600;
  min-height: 44px;
}
.tabbar a.active { color: var(--sage); }
.tabbar a .icon { width: 1.4rem; height: 1.4rem; }

/* Utility */
.muted { color: var(--muted); }
.flex { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.mt-0 { margin-top: 0; }
.text-right { text-align: right; }
.divider { height: 1px; background: var(--hairline); margin: 16px 0; border: none; }

/* htmx swap fade */
.htmx-added { opacity: 0; }
.htmx-settling { opacity: 1; transition: opacity var(--dur) var(--ease); }
.htmx-swapping { opacity: 0; transition: opacity 120ms var(--ease); }

/* Theme toggle */
.theme-toggle {
  background: transparent; border: 1px solid var(--hairline); border-radius: 999px;
  width: 40px; height: 40px; padding: 0; min-height: unset;
}
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: inline; }
}

/* Login page */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card .leaf { color: var(--sage); width: 2.6rem; height: 2.6rem; margin-bottom: 6px; }

.error-banner {
  background: color-mix(in srgb, var(--madder) 12%, var(--surface));
  border: 1px solid var(--madder);
  color: var(--madder);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--hairline);
  color: var(--muted);
}
.badge-recur { background: color-mix(in srgb, var(--amber) 25%, var(--surface)); color: #6b4e0f; }
:root[data-theme="dark"] .badge-recur { color: var(--amber); }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--clay);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  z-index: 45;
}
.fab .icon { width: 1.6rem; height: 1.6rem; }

.thumb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.thumb-grid img, .thumb-grid .thumb {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--hairline);
  cursor: pointer;
}

.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

@media (min-width: 720px) {
  .tabbar { max-width: 680px; left: 50%; transform: translateX(-50%); border-radius: var(--radius) var(--radius) 0 0; border-left: 1px solid var(--hairline); border-right: 1px solid var(--hairline); }
}
