:root {
  --cocoa: #9d592b;
  --cocoa-dark: #6b3a1f;
  --milk: #c4894a;
  --cream: #f6ede3;
  --cream-2: #efe2d3;
  --paper: #fffaf4;
  --ink: #3b2416;
  --muted: #7a5a45;
  --line: #e4d3c3;
  --ok: #2f7d4a;
  --ok-bg: #e7f6ec;
  --warn: #b45309;
  --warn-bg: #fff4e5;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --shadow: 0 10px 28px rgba(75, 38, 20, 0.1);
  --radius: 16px;
  --font: 'Source Sans 3', 'Segoe UI', sans-serif;
  --display: 'Nunito', 'Segoe UI', sans-serif;
  --nav-h: calc(64px + env(safe-area-inset-bottom));
  --tap: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--cream);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button, input, select, textarea { font: inherit; font-size: 16px; }
a { color: inherit; }
#app { min-height: 100dvh; }

.wordmark { font-family: var(--display); font-weight: 800; letter-spacing: -0.04em; line-height: 0.95; }
.wordmark .choco { color: var(--cocoa-dark); }
.wordmark .dani { color: var(--cocoa); }
.since { font-size: 0.72rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--muted); font-weight: 700; }

.login-shell { min-height: 100dvh; display: flex; flex-direction: column; padding: env(safe-area-inset-top) 16px 24px; }
.brand-pane { padding: 28px 8px 8px; }
.brand-pane h1 { font-size: clamp(2.6rem, 12vw, 3.6rem); margin: 10px 0 8px; }
.tagline { font-size: 1.15rem; color: var(--cocoa-dark); font-weight: 700; margin: 12px 0 0; }
.system-kicker { font-weight: 800; color: var(--cocoa); letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.75rem; }
.login-pane {
  background: var(--paper);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 22px 18px 24px;
  margin-top: 12px;
}
.login-pane h2 { margin: 0 0 6px; font-family: var(--display); }
.lead { color: var(--muted); margin: 0 0 16px; line-height: 1.45; }
.privacy-login {
  color: var(--muted); background: var(--cream); border-radius: 12px;
  padding: 10px 12px; font-size: 0.88rem; line-height: 1.4;
}

label { display: block; font-weight: 700; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
input:focus, select:focus { border-color: var(--cocoa); box-shadow: 0 0 0 3px rgba(157, 89, 43, 0.16); }
.help { color: var(--muted); font-size: 0.86rem; margin-top: 6px; line-height: 1.4; }
.unit { display: inline-block; margin-left: 6px; color: var(--muted); font-weight: 600; font-size: 0.85rem; }

.btn {
  appearance: none; border: 0; background: var(--cocoa); color: #fff;
  font-weight: 700; border-radius: 999px; min-height: var(--tap);
  padding: 12px 18px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { background: var(--cocoa-dark); }
.btn.secondary { background: var(--cream-2); color: var(--cocoa-dark); }
.btn.ghost { background: transparent; color: var(--cocoa-dark); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); }
.btn:disabled { opacity: 0.55; }
.btn-block { width: 100%; }
a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(157, 89, 43, 0.42);
  outline-offset: 3px;
}

.app-shell { min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; padding-bottom: var(--nav-h); }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(255,250,244,0.94);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 8;
}
.topbar .wordmark { font-size: 1.25rem; text-decoration: none; }
.desktop-nav, .user-chip { display: none; }
.more-btn { min-width: var(--tap); min-height: var(--tap); border-radius: 12px; }

.page { padding: 16px 14px 28px; width: 100%; max-width: 720px; margin: 0 auto; }
.page h1 { font-family: var(--display); margin: 0 0 6px; font-size: 1.55rem; }
.page-head { margin-bottom: 14px; }
.page-head .btn { width: 100%; margin-top: 10px; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding: 6px 4px env(safe-area-inset-bottom);
}
.bottom-nav a {
  text-decoration: none; text-align: center; color: var(--muted);
  font-size: 0.7rem; font-weight: 700; padding: 6px 2px; border-radius: 12px;
}
.bottom-nav a span { display: block; font-size: 1.2rem; line-height: 1.2; }
.bottom-nav a.active { color: var(--cocoa-dark); background: var(--cream-2); }

.cards { display: grid; gap: 12px; }
.card {
  background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; text-decoration: none; color: inherit;
  display: flex; gap: 14px; align-items: center;
}
.card.disabled { opacity: 0.5; pointer-events: none; }
.icon-bubble {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  background: var(--cocoa); color: #fff; display: grid; place-items: center; font-size: 1.25rem;
}
.card h3 { margin: 0 0 2px; font-family: var(--display); }
.card p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.home-welcome {
  position: relative;
  overflow: hidden;
  margin: -2px 0 14px;
  padding: 22px 20px 18px;
  border-radius: 24px;
  color: #fff;
  background: linear-gradient(135deg, #7f3155 0%, #b74970 62%, #d86b82 100%);
  box-shadow: 0 14px 34px rgba(105, 39, 71, 0.2);
}
.home-welcome.complete { background: linear-gradient(135deg, #32664a 0%, #438863 58%, #70ad75 100%); }
.home-welcome h1 { position: relative; margin: 4px 0 8px; max-width: 430px; font-size: clamp(1.9rem, 9vw, 2.65rem); line-height: 1.04; }
.home-welcome > p:not(.home-eyebrow) { position: relative; max-width: 480px; margin: 0; color: rgba(255, 255, 255, 0.9); line-height: 1.45; }
.home-eyebrow {
  position: relative; margin: 0; color: #ffe6aa; font-size: 0.75rem;
  font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase;
}
.home-sprinkle { position: absolute; display: block; border-radius: 999px; transform: rotate(-28deg); }
.sprinkle-one { width: 74px; height: 22px; right: -14px; top: 22px; background: rgba(255, 225, 138, 0.8); }
.sprinkle-two { width: 42px; height: 14px; right: 34px; bottom: 45px; background: rgba(255, 255, 255, 0.22); transform: rotate(36deg); }
.home-progress-copy {
  position: relative; display: flex; justify-content: space-between; gap: 12px;
  margin-top: 22px; font-size: 0.82rem; color: rgba(255, 255, 255, 0.78);
}
.home-progress-copy strong { color: #fff; }
.home-progress {
  position: relative; height: 8px; margin-top: 7px; overflow: hidden;
  border-radius: 999px; background: rgba(255, 255, 255, 0.22);
}
.home-progress span { display: block; height: 100%; border-radius: inherit; background: #ffe08a; transition: width 500ms ease; }

.next-step-card {
  position: relative; overflow: hidden; margin-bottom: 12px; padding: 16px;
  border: 1px solid #edcf72; border-radius: 22px; background: #fff5ce;
  box-shadow: 0 10px 24px rgba(120, 79, 18, 0.1);
}
.next-step-card::after {
  content: ''; position: absolute; width: 130px; height: 130px; right: -70px; top: 34px;
  border-radius: 50%; background: rgba(236, 166, 63, 0.15);
}
.next-step-topline {
  position: relative; z-index: 1; display: flex; justify-content: space-between; gap: 12px;
  color: #75521d; font-size: 0.76rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
}
.next-step-number {
  position: relative; z-index: 1; width: 52px; height: 52px; margin: 18px 0 12px;
  display: grid; place-items: center; border-radius: 17px; background: #e8863f; color: #fff;
  font-family: var(--display); font-size: 1.45rem; font-weight: 800; transform: rotate(-3deg);
}
.next-step-content { position: relative; z-index: 1; }
.next-step-content h2 { margin: 0 0 6px; color: #542f1d; font-family: var(--display); font-size: 1.45rem; line-height: 1.15; }
.next-step-content > p { margin: 0 0 14px; color: #765542; line-height: 1.45; }
.step-benefit {
  display: grid; grid-template-columns: 24px 1fr; gap: 8px; align-items: start;
  margin-bottom: 16px; padding: 11px; border-radius: 13px; background: rgba(255, 255, 255, 0.58);
  color: #62442f; font-size: 0.88rem; line-height: 1.35;
}
.step-benefit > span:first-child {
  width: 22px; height: 22px; display: grid; place-items: center;
  border-radius: 50%; background: #dff3e5; color: #286c43; font-weight: 800;
}
.next-step-action { width: 100%; border-radius: 14px; background: #8a345c; text-decoration: none; }
.next-step-action:hover { background: #6e2848; }

.home-actions { display: grid; gap: 10px; margin-bottom: 12px; }
.home-action {
  display: grid; grid-template-columns: 46px 1fr auto; gap: 12px; align-items: center;
  min-height: 82px; padding: 14px; border-radius: 18px; text-decoration: none;
  border: 1px solid transparent; transition: transform 160ms ease, box-shadow 160ms ease;
}
.home-action.primary { background: #fde2ec; border-color: #f4bfd1; color: #682b47; }
.home-action.secondary { background: #dff3e8; border-color: #b9dfca; color: #245d40; }
.home-action-icon {
  width: 46px; height: 46px; display: grid; place-items: center; border-radius: 15px;
  background: rgba(255, 255, 255, 0.7); font-family: var(--display); font-weight: 800; font-size: 1.1rem;
}
.home-action strong, .home-action small { display: block; }
.home-action strong { font-family: var(--display); font-size: 1.05rem; }
.home-action small { margin-top: 2px; opacity: 0.78; font-size: 0.82rem; }
.home-action-arrow { font-size: 1.25rem; font-weight: 800; }
.home-action:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.home-journey {
  margin-bottom: 12px; padding: 0 14px; border: 1px solid var(--line);
  border-radius: 18px; background: var(--paper);
}
.home-journey > summary {
  min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  color: var(--cocoa-dark); cursor: pointer; font-weight: 800; list-style: none;
}
.home-journey > summary::-webkit-details-marker { display: none; }
.home-journey > summary::after { content: '⌄'; margin-left: 2px; font-size: 1.2rem; transition: transform 160ms ease; }
.home-journey[open] > summary::after { transform: rotate(180deg); }
.journey-count {
  margin-left: auto; padding: 3px 9px; border-radius: 999px;
  background: var(--cream-2); color: var(--muted); font-size: 0.76rem;
}
.journey-list { margin: 0; padding: 0 0 12px; list-style: none; }
.journey-step {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center;
  min-height: 56px; padding: 8px; border-top: 1px solid var(--line);
}
.journey-step.current { margin: 0 -4px; border-radius: 12px; background: #fff2d5; }
.journey-marker {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%;
  background: var(--cream-2); color: var(--muted); font-weight: 800; font-size: 0.82rem;
}
.journey-step.done .journey-marker { background: #dff3e8; color: #286c43; }
.journey-step strong, .journey-step small { display: block; }
.journey-step strong { font-size: 0.9rem; line-height: 1.2; }
.journey-step small { margin-top: 2px; color: var(--muted); }
.journey-step a { color: #803251; font-size: 0.82rem; font-weight: 800; }
.home-privacy {
  display: grid; grid-template-columns: 24px 1fr; gap: 8px; align-items: start;
  padding: 10px 4px; color: var(--muted); font-size: 0.79rem; line-height: 1.35;
}
.home-privacy > span:first-child {
  width: 21px; height: 21px; display: grid; place-items: center;
  border-radius: 50%; background: var(--ok-bg); color: var(--ok); font-weight: 800;
}
.flow-tabs {
  display: flex; overflow-x: auto; gap: 6px; margin-bottom: 12px;
}
.flow-tabs span {
  flex: 1 0 auto; padding: 9px 12px; text-align: center; border-radius: 999px;
  background: var(--cream-2); color: var(--muted); font-size: 0.82rem; font-weight: 700;
}
.flow-tabs .active { background: var(--cocoa); color: #fff; }
.result-cta { margin: 12px 0; text-decoration: none; }
.section-title { font-family: var(--display); color: var(--cocoa-dark); margin: 18px 0 4px; }
.calculation-details { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 8px; }
.calculation-details summary { cursor: pointer; color: var(--cocoa-dark); font-weight: 700; padding: 6px 0; }
.search-field { position: sticky; top: 68px; z-index: 6; background: var(--cream); padding: 4px 0; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
.tab {
  flex: none; text-decoration: none; border: 0; background: var(--cream-2); color: var(--cocoa-dark);
  padding: 10px 14px; border-radius: 999px; font-weight: 700; min-height: 40px;
}
.tab.active { background: var(--cocoa); color: #fff; }

.panel { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.group { margin-bottom: 14px; }
.group h3, .panel h3 { margin: 0 0 12px; color: var(--cocoa-dark); font-size: 1.05rem; }

.grid-2, .grid-3 { display: grid; grid-template-columns: 1fr; gap: 4px; }

.kpi { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpi div { background: var(--paper); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.kpi small { color: var(--muted); display: block; }
.kpi strong { font-size: 1.1rem; }

.badge { display: inline-flex; padding: 4px 10px; border-radius: 999px; font-weight: 700; font-size: 0.78rem; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.muted { background: var(--cream-2); color: var(--muted); }

.flash { padding: 10px 12px; border-radius: 12px; margin-bottom: 12px; }
.flash.error { background: var(--bad-bg); color: var(--bad); }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions .btn { flex: 1; }

.item-card, .result-card, .line-card, .list-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; margin-bottom: 10px;
}
.list-card-attention { box-shadow: 0 0 0 2px rgba(180, 83, 9, 0.18); }
.list-card-expiring {
  border-color: var(--warn);
  background: linear-gradient(180deg, var(--warn-bg), var(--paper) 48%);
}
.list-card-expired {
  border-color: var(--bad);
  background: linear-gradient(180deg, var(--bad-bg), var(--paper) 48%);
}
.attention-banner {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--warn);
  font-weight: 700;
  font-size: 0.86rem;
}
.list-card-expired .attention-banner { color: var(--bad); }
.practiced-edit {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.practiced-edit .field { margin: 0; }
.practiced-edit .btn { width: 100%; }
.price-practiced-box {
  border: 1px solid #c9b8a2;
  background: #fffaf3 !important;
}
.price-practiced-box strong { color: var(--cocoa-dark); }
.result-card .pair { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; font-size: 0.92rem; }
.result-card .pair span { color: var(--muted); }
.result-big { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.result-big div { background: var(--cream-2); border-radius: 12px; padding: 10px; }
.result-big small { color: var(--muted); display: block; }
.result-big strong { font-size: 1.05rem; }
.result-big em { display: block; margin-top: 4px; color: var(--muted); font-style: normal; font-size: 0.75rem; line-height: 1.3; }
.price-suggested { background: #fff1d8 !important; border: 1px solid #efd08a; }
.price-suggested strong { color: var(--cocoa-dark); font-size: 1.2rem; }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.price-loading { color: var(--muted); }

.toast-host {
  position: fixed;
  z-index: 50;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: grid;
  gap: 8px;
  pointer-events: none;
  max-width: 420px;
  margin: 0 auto;
}
.toast {
  pointer-events: auto;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 180ms ease, transform 180ms ease;
  padding: 12px 14px;
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(59, 36, 22, 0.18);
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.35;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #b7dfc4; }
.toast-error { background: var(--bad-bg); color: var(--bad); border: 1px solid #f0b7b1; }
.toast-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f0d2a4; }

details.accordion { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; padding: 4px 14px 10px; }
details.accordion > summary {
  list-style: none; cursor: pointer; font-weight: 800; color: var(--cocoa-dark);
  min-height: var(--tap); display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
details.accordion > summary::-webkit-details-marker { display: none; }

.sticky-save {
  position: sticky; bottom: calc(var(--nav-h) + 8px); z-index: 7;
  padding-top: 8px;
}
.sticky-save .btn { width: 100%; box-shadow: var(--shadow); }

.modal-bg {
  position: fixed; inset: 0; background: rgba(59, 36, 22, 0.5);
  display: grid; place-items: end center; z-index: 30; padding: 12px;
}
.modal {
  background: var(--paper); border-radius: 20px 20px 12px 12px;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  width: min(480px, 100%);
}
.modal h3 { margin: 0 0 12px; font-family: var(--display); }

.sheet {
  position: fixed; inset: 0; background: rgba(59, 36, 22, 0.45); z-index: 25;
  display: none; align-items: flex-end;
}
.sheet.open { display: flex; }
.sheet-body {
  background: var(--paper); width: 100%; border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-body a, .sheet-body button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 14px 4px; font-weight: 700; color: var(--ink); text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.pwa-notice {
  position: fixed;
  z-index: 40;
  left: 12px;
  right: 12px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 620px;
  margin: 0 auto;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 8px 30px rgba(59, 36, 22, 0.2);
  font-size: 0.9rem;
}
.pwa-notice[hidden] { display: none; }
.pwa-notice span { flex: 1; line-height: 1.3; }
.pwa-notice.warning { background: var(--warn-bg); color: var(--ink); border-color: var(--warn); }
.pwa-notice-action, .pwa-notice-close {
  flex: none;
  min-height: 36px;
  border: 0;
  border-radius: 10px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.pwa-notice-action { padding: 7px 11px; background: var(--cocoa); color: #fff; }
.pwa-notice-close { width: 36px; background: transparent; color: currentColor; font-size: 1.3rem; }

@media (min-width: 900px) {
  .login-shell { display: grid; grid-template-columns: 1.05fr 0.95fr; padding: 0; }
  .brand-pane { padding: 48px 56px 32px; display: flex; flex-direction: column; justify-content: space-between; }
  .login-pane { margin: 24px; display: flex; flex-direction: column; justify-content: center; }
  .app-shell { padding-bottom: 0; max-width: 1100px; margin: 0 auto; }
  .page { max-width: 1100px; padding: 24px 22px 48px; }
  .page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
  .page-head .btn { width: auto; margin-top: 0; }
  .bottom-nav { display: none; }
  .desktop-nav, .user-chip { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .more-btn { display: none; }
  .nav-link {
    text-decoration: none; padding: 8px 12px; border-radius: 999px; font-weight: 700; color: var(--muted);
  }
  .nav-link.active, .nav-link:hover { background: var(--cream-2); color: var(--cocoa-dark); }
  .nav-link.disabled { opacity: 0.4; }
  .grid-2 { grid-template-columns: 1fr 1fr; gap: 12px; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
  .kpi { grid-template-columns: repeat(4, 1fr); }
  .cards.home { grid-template-columns: 1fr 1fr; }
  .sticky-save { position: static; }
  .modal-bg { place-items: center; }
  .modal { border-radius: 20px; }
  .user-chip { font-size: 0.9rem; color: var(--muted); }
  .pwa-notice { bottom: 16px; }
  .home-welcome { padding: 30px 32px 24px; }
  .home-actions { grid-template-columns: 1fr 1fr; }
  .next-step-card { display: grid; grid-template-columns: 76px 1fr; column-gap: 20px; padding: 20px 22px; }
  .next-step-topline { grid-column: 1 / -1; }
  .next-step-number { grid-column: 1; margin-top: 22px; }
  .next-step-content { grid-column: 2; margin-top: 20px; }
  .next-step-action { width: auto; min-width: 250px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
