:root {
  --pine: #1F5C45;
  --moss: #3D8B6E;
  --clay: #D4784A;
  --ink: #14221C;
  --muted: #5C6B63;
  --sand: #F3EDE3;
  --paper: #F6F7F9;
  --line: rgba(15, 23, 42, 0.1);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 16px 40px rgba(15, 23, 42, 0.06);
  --radius: 16px;
  --font-serif: "Literata", Georgia, serif;
  --font-sans: "Outfit", "Segoe UI", sans-serif;
  --chrome: color-mix(in srgb, var(--pine) 84%, #04110c);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  color: var(--ink);
  background:
    radial-gradient(880px 360px at 0% -8%, color-mix(in srgb, var(--pine) 16%, transparent), transparent 60%),
    var(--paper);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--pine); text-decoration: none; }
button, a, .icon-btn { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; }
.wrap { width: min(1120px, calc(100% - 40px)); margin: 0 auto; }
.eyebrow {
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--clay);
  font-weight: 600;
  margin: 0 0 8px;
}
h1, h2, h3 { font-family: var(--font-serif); font-weight: 650; letter-spacing: -0.045em; line-height: 1.12; }
h1 { font-size: clamp(2rem, 4vw, 3.4rem); margin: 0 0 16px; }
.app-shell h1, .admin-shell h1 { font-size: 1.85rem; margin: 0; }
h2 { font-size: 1.6rem; margin: 0 0 12px; }
h3 { font-size: 1.15rem; margin: 0 0 8px; }
.lede { font-size: 1.15rem; color: var(--muted); max-width: 42rem; }

.site-header, .site-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.site-header { padding: 22px 0; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; font-weight: 700; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--pine); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 1rem; flex-shrink: 0;
}
.sidebar .brand-mark, .mobile-bar .brand-mark { background: #fff; color: var(--pine); }
.brand-logo { height: 32px; width: auto; max-width: 148px; object-fit: contain; display: block; }
.nav { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.nav a { color: var(--ink); opacity: 0.8; display: inline-flex; align-items: center; gap: 8px; }
.nav a:hover { opacity: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 11px 16px; cursor: pointer;
  font-weight: 650; letter-spacing: -0.01em;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--pine); color: #fff; box-shadow: 0 8px 20px color-mix(in srgb, var(--pine) 28%, transparent); }
.btn-accent { background: var(--clay); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-danger { background: #8b2e2e; color: #fff; }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; min-height: 38px; }
.hero { padding: 32px 0 80px; }
.hero-grid { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 48px; align-items: center; }
.hero-actions { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
.hero-card, .card, .panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero-card { padding: 28px; }
.card, .panel { padding: 22px; }
.feature-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.feature-list li { padding: 14px 0; border-bottom: 1px solid var(--line); }
.page-simple { padding: 40px 0 80px; }
.prose { max-width: 720px; }
.site-footer { padding: 40px 0 60px; color: var(--muted); font-size: 0.9rem; }

.auth-shell { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-visual {
  background: linear-gradient(160deg, var(--pine), #0e2b20 70%);
  color: #f7f3eb; padding: 64px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-visual h1 { color: #fff; max-width: 11ch; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: min(420px, 100%); }
.form { display: grid; gap: 14px; }
label { font-size: 0.82rem; font-weight: 600; }
.field { display: grid; gap: 6px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="color"], input[type="url"],
input[type="file"], select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 12px 14px; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--pine) 50%, white);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--pine) 16%, transparent);
}
input[type="color"] { height: 48px; padding: 6px; cursor: pointer; }
textarea { min-height: 120px; resize: vertical; }
.honeypot { position: absolute; left: -9999px; opacity: 0; height: 0; }

.flash { padding: 12px 14px; border-radius: 14px; margin-bottom: 16px; }
.flash-success { background: #e5f4ec; color: #145c3a; }
.flash-error { background: #fde8e4; color: #8b2e2e; }
.field-error { color: #8b2e2e; font-size: 0.8rem; }

.app-shell, .admin-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--chrome); color: #f3f7f4; padding: 22px 14px; display: flex; flex-direction: column; gap: 18px;
}
.sidebar a, .sidebar button { color: inherit; }
.side-nav { display: grid; gap: 4px; }
.side-nav a { border-radius: 12px; opacity: 0.82; }
.side-nav a:hover, .side-nav a.is-active { background: rgba(255,255,255,0.1); opacity: 1; }
.main { padding: 28px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stat { padding: 20px; }
.stat b { display: block; font-family: var(--font-serif); font-size: 1.8rem; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
.muted { color: var(--muted); }
.progress { height: 8px; background: var(--sand); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--pine); }
.progress.warn > span { background: var(--clay); }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.cal-cell {
  width: 100%; min-height: 92px; background: color-mix(in srgb, var(--paper) 55%, white); border: 1px solid var(--line); border-radius: 14px;
  padding: 8px; font: inherit; font-size: 0.8rem; text-align: left; cursor: pointer; color: inherit;
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
}
.cal-cell strong { font-size: 0.95rem; }
.cal-cell.is-today strong {
  background: var(--pine); color: #fff; border-radius: 99px; min-width: 1.6rem; text-align: center; padding: 1px 6px;
}
.cal-cell.is-selected { border-color: var(--pine); box-shadow: 0 0 0 2px var(--pine); }
.cal-count {
  align-self: flex-end; margin-top: -1.4rem; background: var(--clay); color: #fff;
  border-radius: 99px; min-width: 1.2rem; text-align: center; font-size: 0.68rem; font-weight: 700; padding: 0 5px;
}
.cal-pad { min-height: 92px; }
.day-sheet { margin-top: 18px; }
.day-sheet[hidden], .day-detail[hidden], #event-form[hidden] { display: none !important; }
.day-events { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 12px; }
.day-events li { display: flex; gap: 12px; align-items: flex-start; }
.day-events li .chip { margin-top: 4px; }
.cal-head { font-size: 0.75rem; font-weight: 700; text-align: center; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 99px; color: #fff; margin: 2px 0; }
.secret { font-family: ui-monospace, monospace; letter-spacing: 0.12em; background: var(--sand); padding: 12px; border-radius: 12px; }
.logo-preview { max-height: 48px; }
.media-row { display: flex; align-items: center; gap: 12px; }
.media-row input[type="file"] { width: auto; flex: 1; min-width: 0; }
.media-preview {
  width: 64px; height: 64px; flex-shrink: 0; border-radius: 14px;
  border: 1px solid var(--line); background: var(--paper);
  display: grid; place-items: center; overflow: hidden;
}
.media-preview img { max-width: 48px; max-height: 48px; object-fit: contain; }
.media-preview-icon { width: 48px; height: 48px; border-radius: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.theme-preview {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin: 8px 0 18px; padding: 16px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--line); border-radius: 16px;
}
.theme-preview .brand-mark { background: var(--pine); color: #fff; }
.theme-preview .muted { color: var(--muted); margin: 2px 0 0; }
.theme-preview strong { font-family: var(--font-serif); font-size: 1.15rem; }
.stack { display: grid; gap: 16px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.inline { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
code, .mono { font-family: ui-monospace, SFMono-Regular, monospace; }
.warn-banner { background: #fff4e5; border: 1px solid #f0c48a; padding: 12px 14px; border-radius: 14px; margin-bottom: 16px; }

.stat { position: relative; overflow: hidden; }
.stat-icon {
  width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center;
  background: var(--sand); color: var(--pine); margin-bottom: 10px;
}
.stat-icon .nav-icon { width: 22px; height: 22px; }
.stat small { display: block; margin-top: 6px; }
.stat-income b { color: var(--pine); }
.stat-expense b { color: var(--clay); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.people { display: grid; gap: 10px; }
.person {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.person:last-child { border-bottom: 0; }
.avatar {
  width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center;
  background: var(--pine); color: #fff; font-weight: 700; flex-shrink: 0;
}
.bars { display: flex; align-items: flex-end; gap: 10px; min-height: 150px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bar-pair { display: flex; align-items: flex-end; gap: 4px; height: 128px; }
.bar { width: 12px; border-radius: 8px 8px 3px 3px; display: block; }
.bar-in { background: var(--pine); }
.bar-out { background: var(--clay); }
.legend { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 0.85rem; }
.dot { width: 10px; height: 10px; border-radius: 99px; display: inline-block; }
.dot-in { background: var(--pine); }
.dot-out { background: var(--clay); }
.donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut { width: 140px; height: 140px; transform: rotate(-90deg); }
.donut-track { fill: none; stroke: var(--sand); stroke-width: 14; }
.legend-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; flex: 1; }
.legend-list li { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.legend-list i { width: 10px; height: 10px; border-radius: 99px; display: inline-block; }
.legend-list span { margin-left: auto; color: var(--muted); }
.amt-in { color: var(--pine); font-weight: 700; }
.amt-out { color: var(--clay); font-weight: 700; }
.filters { display: grid; gap: 14px; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; cursor: pointer;
  background: #fff; font-weight: 600; font-size: 0.9rem;
}
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill:has(input:checked), .pill.is-on { background: var(--pine); color: #fff; border-color: var(--pine); }
.preview-type { font-family: var(--font-serif); font-size: 1.8rem; margin: 8px 0 0; }

.nav-icon {
  width: 22px; height: 22px; flex-shrink: 0; display: block;
}
.nav-icon-sm { width: 18px; height: 18px; }
.nav-icon-wrap {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: rgba(255,255,255,0.08);
  color: #e7f3ec;
}
.side-nav a.is-active .nav-icon-wrap {
  background: #fff;
  color: var(--pine);
}
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 14px;
  background: rgba(255,255,255,0.1); color: inherit;
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.icon-btn .nav-icon { width: 22px; height: 22px; }
.mobile-bar, .bottom-nav, .sidebar-close, .nav-toggle, .nav-close { display: none; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nav-logout {
  display: inline-flex; align-items: center; gap: 8px; color: inherit;
}
.side-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; min-height: 48px;
}
.btn { min-height: 44px; }
.table { width: 100%; }
.card:has(table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.card:has(table) .table { min-width: 520px; }

@media (max-width: 900px) {
  .hero-grid, .auth-shell, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .auth-form { padding: 28px 18px calc(28px + env(safe-area-inset-bottom)); }
  .hero { padding: 16px 0 48px; }
  .hero-actions .btn { flex: 1 1 140px; }
  h1 { font-size: clamp(1.7rem, 8vw, 2.4rem); }
  .app-shell h1, .admin-shell h1 { font-size: 1.55rem; }
  .wrap { width: min(1120px, calc(100% - 24px)); }
  .site-header { padding: 12px 0; gap: 10px; }
  .site-footer { flex-direction: column; align-items: flex-start; padding: 24px 0 36px; }
  .nav-toggle { display: grid; background: var(--sand); color: var(--ink); }
  .nav-close { display: grid; align-self: flex-end; background: rgba(255,255,255,0.12); color: #fff; }
  .nav {
    position: fixed; top: 0; right: 0; bottom: 0; left: auto; width: min(86%, 340px);
    background: var(--chrome); color: #f3f7f4; z-index: 50;
    flex-direction: column; align-items: stretch; gap: 6px;
    padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
    transform: translateX(110%); transition: transform .22s ease;
    box-shadow: -20px 0 60px rgba(0,0,0,.25);
  }
  .nav a { color: inherit; padding: 12px 10px; border-radius: 12px; min-height: 48px; display: flex; align-items: center; gap: 10px; }
  body.menu-open .nav { transform: translateX(0); }
  body.menu-open .sidebar-backdrop { display: block; }
  .sidebar-backdrop[hidden] { display: none; }

  .app-shell, .admin-shell {
    display: block;
    min-height: 100vh;
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }
  .mobile-bar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 20;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    background: var(--chrome); color: #e8efe9;
  }
  .mobile-bar .brand span:last-child { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(86%, 320px); z-index: 40;
    transform: translateX(-110%); transition: transform .22s ease;
    padding: calc(14px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
    overflow-y: auto;
  }
  .sidebar-close { display: grid; }
  body.menu-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(10, 16, 14, 0.45); z-index: 30; border: 0;
  }
  .main { padding: 16px 14px 24px; }
  .topbar { margin-bottom: 14px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    background: var(--chrome); color: #d5e4dc;
    padding: 6px 4px calc(8px + env(safe-area-inset-bottom));
    box-shadow: 0 -12px 30px rgba(20, 34, 28, 0.18);
  }
  .bottom-nav a, .bottom-more {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; min-height: 52px; border: 0; background: transparent; color: inherit;
    font-size: 0.62rem; font-weight: 600; letter-spacing: 0.01em; padding: 4px 2px;
    opacity: 0.7; cursor: pointer;
  }
  .bottom-nav a.is-active, .bottom-more.is-open {
    opacity: 1; color: #fff;
  }
  .bottom-nav a.is-active .nav-icon, .bottom-more.is-open .nav-icon { color: var(--clay); }
  .bottom-nav .nav-icon { width: 22px; height: 22px; }
  .calendar { grid-template-columns: repeat(7, 1fr); gap: 4px; }
  .cal-cell { min-height: 58px; padding: 4px; border-radius: 10px; font-size: 0.7rem; }
  .chip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .form .btn-primary, .form .btn-accent { width: 100%; }
  .inline { flex-direction: column; align-items: stretch; }
  .row-actions .btn { min-height: 40px; }
  input[type="color"] { min-height: 44px; }
}

.tpl-editor { display: grid; grid-template-columns: minmax(280px, 440px) 1fr; gap: 18px; align-items: start; }
.tpl-controls, .tpl-preview-wrap { display: grid; gap: 14px; align-content: start; }
.tpl-preview-wrap { position: sticky; top: 16px; }
.tpl-preview {
  background: var(--paper); border: 1px solid var(--line); border-radius: 16px;
  min-height: 480px; overflow: auto; box-shadow: var(--shadow);
}
.tpl-add, .tpl-block-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.tpl-blocks { display: grid; gap: 10px; }
.tpl-block {
  border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 8px; background: #fff;
}
.tpl-block h3 { margin: 0; font-family: var(--font-sans); font-size: 0.95rem; letter-spacing: 0; }
.tpl-advanced summary { cursor: pointer; font-weight: 650; margin-bottom: 8px; }
.tpl-code { min-height: 140px; font-family: ui-monospace, monospace; font-size: 0.82rem; }
@media (max-width: 900px) {
  .tpl-editor { grid-template-columns: 1fr; }
  .tpl-preview-wrap { position: static; order: -1; }
}

@media (min-width: 901px) {
  .sidebar-backdrop { display: none !important; }
}
