:root {
  --ink: #24221f;
  --muted: #77716a;
  --paper: #f7f3ec;
  --card: #fffdf9;
  --line: #e8e0d5;
  --terracotta: #c96f52;
  --terracotta-dark: #a94e35;
  --sage: #8da28c;
  --sage-light: #e8eee6;
  --yellow: #f3c85b;
  --red: #d94f4f;
  --shadow: 0 16px 48px rgba(71, 50, 35, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 85% 0, #f0dfd1 0, transparent 30rem), var(--paper); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 .35rem; color: var(--terracotta-dark); font-size: .72rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.muted { color: var(--muted); line-height: 1.5; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; margin: 0; }
h1 { font-size: 2rem; }
h2 { font-size: clamp(2rem, 8vw, 3.2rem); line-height: 1; }
h3 { font-size: 1.35rem; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: min(100%, 420px); background: rgba(255, 253, 249, .94); border: 1px solid rgba(255,255,255,.8); border-radius: 32px; padding: 2.25rem; box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.brand-mark { width: 58px; height: 58px; margin-bottom: 1.75rem; border-radius: 18px; background: var(--terracotta); position: relative; transform: rotate(4deg); }
.brand-mark span { position: absolute; width: 18px; height: 25px; background: var(--card); border-radius: 50% 50% 45% 45%; top: 17px; }
.brand-mark span:first-child { left: 12px; transform: rotate(-25deg); }
.brand-mark span:last-child { right: 12px; transform: rotate(25deg); }
.stack { display: grid; gap: 1rem; margin-top: 1.6rem; }

label { display: grid; gap: .45rem; color: #514d48; font-size: .86rem; font-weight: 700; }
label span, label small { color: var(--muted); font-weight: 500; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: .9rem 1rem; color: var(--ink); background: #fff; outline: none; transition: border .2s, box-shadow .2s; }
input:focus, textarea:focus { border-color: var(--terracotta); box-shadow: 0 0 0 3px rgba(201,111,82,.13); }
textarea { resize: vertical; }
.primary, .secondary { border: 0; border-radius: 15px; padding: 1rem 1.25rem; font-weight: 800; }
.primary { color: white; background: var(--terracotta); box-shadow: 0 8px 20px rgba(169,78,53,.2); }
.primary:hover { background: var(--terracotta-dark); }
.secondary { color: var(--terracotta-dark); background: #f7e4dc; }
.form-error { color: var(--red); min-height: 1.2em; margin: 0; font-size: .85rem; }
.form-status { color: var(--muted); min-height: 1.2em; margin: 0; font-size: .85rem; }

.app-shell { max-width: 760px; min-height: 100vh; margin: 0 auto; padding: 0 1rem 7rem; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 1.35rem .35rem 1.1rem; }
.topbar h1 { font-size: 1.55rem; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: rgba(255,255,255,.65); color: var(--muted); font-size: 1.2rem; }
.panel { display: none; animation: rise .3s ease; }
.panel.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.hero-card { position: relative; overflow: hidden; border-radius: 28px; padding: 2rem 1.35rem 1.35rem; color: #fff; background: linear-gradient(135deg, #b55a40, #d88261 70%, #e9aa85); box-shadow: var(--shadow); }
.hero-card::after { content: ""; position: absolute; width: 180px; height: 180px; border: 35px solid rgba(255,255,255,.08); border-radius: 50%; right: -90px; top: -80px; }
.hero-card .eyebrow { color: #ffe9df; }
.hero-card p:not(.eyebrow) { max-width: 32rem; color: #fff0e9; line-height: 1.45; }
.voice-button { position: relative; z-index: 1; width: 100%; display: flex; align-items: center; justify-content: center; gap: .7rem; border: 0; border-radius: 17px; padding: 1.05rem; background: #fff; color: var(--terracotta-dark); font-weight: 850; }
.mic-dot { width: 15px; height: 15px; border-radius: 50%; background: var(--terracotta); box-shadow: 0 0 0 5px #f7ded6; }
.voice-button.recording .mic-dot { animation: pulse 1s infinite; background: var(--red); }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(255,255,255,.25); } }
.voice-status { min-height: 1.2em; margin: .7rem 0 0 !important; font-size: .8rem; text-align: center; }

.card { margin-top: 1rem; padding: 1.2rem; border: 1px solid rgba(232,224,213,.9); border-radius: 24px; background: rgba(255,253,249,.92); box-shadow: 0 9px 30px rgba(71,50,35,.045); }
.event-form { display: grid; gap: 1rem; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.badge { border-radius: 999px; padding: .4rem .7rem; background: var(--sage-light); color: #556854; font-size: .72rem; font-weight: 800; }
.type-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: .45rem; }
.type-picker label { display: block; }
.type-picker input { position: absolute; opacity: 0; pointer-events: none; }
.type-picker span { display: block; padding: .7rem .25rem; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); text-align: center; font-size: .76rem; font-weight: 750; }
.type-picker input:checked + span { border-color: var(--terracotta); color: var(--terracotta-dark); background: #f9e9e2; }
.field-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .65rem; }
.warning-box { padding: .8rem; border-radius: 12px; color: #6e5315; background: #fff3cf; font-size: .82rem; }

.page-heading { padding: 1.3rem .3rem .8rem; }
.page-heading p:last-child { color: var(--muted); line-height: 1.5; }
.timeline-list { display: grid; gap: .75rem; }
.timeline-item { display: grid; grid-template-columns: 54px 1fr auto; gap: .8rem; padding: 1rem; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.timeline-time { color: var(--terracotta-dark); font-weight: 850; }
.timeline-item h3 { font-family: inherit; font-size: .95rem; font-weight: 850; }
.timeline-item p { margin: .25rem 0 0; color: var(--muted); font-size: .82rem; line-height: 1.4; }
.delete-button { align-self: start; border: 0; background: transparent; color: #aaa19a; font-size: 1rem; }
.empty-state { padding: 2rem 1rem; color: var(--muted); text-align: center; }

.upload-card { text-align: center; }
.upload-card p { color: var(--muted); font-size: .88rem; }
.upload-card input { margin: .5rem 0 .8rem; background: var(--paper); }
.upload-icon { width: 54px; height: 54px; display: grid; place-items: center; margin: 0 auto .8rem; border-radius: 16px; color: #566856; background: var(--sage-light); font-size: .72rem; font-weight: 900; }
.chart-card input[type=date] { width: auto; max-width: 155px; padding: .55rem .65rem; font-size: .78rem; }
.glucose-chart { overflow-x: auto; margin-top: 1rem; }
.glucose-chart svg { display: block; width: 100%; min-width: 560px; height: 240px; }
.chart-grid { stroke: #ebe4da; stroke-width: 1; }
.chart-target { fill: rgba(141,162,140,.12); }
.chart-line { fill: none; stroke: var(--sage); stroke-width: 2.2; }
.chart-label { fill: #918a82; font-size: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: .75rem; color: var(--muted); font-size: .72rem; }
.legend span { display: flex; align-items: center; gap: .35rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--sage); }
.dot.out { background: white; border: 2px solid #24221f; }
.square { width: 9px; height: 9px; display: inline-block; background: var(--red); }
.import-list { display: grid; gap: .65rem; margin-top: 1rem; }
.import-item { padding: .9rem 1rem; border-left: 4px solid var(--sage); border-radius: 10px 16px 16px 10px; background: var(--card); }
.import-item strong { display: block; font-size: .85rem; overflow-wrap: anywhere; }
.import-item span { color: var(--muted); font-size: .75rem; }

.bottom-nav { position: fixed; z-index: 10; left: 50%; bottom: max(.75rem, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(calc(100% - 2rem), 600px); display: grid; grid-template-columns: repeat(3, 1fr); padding: .45rem; border: 1px solid rgba(232,224,213,.9); border-radius: 22px; background: rgba(255,253,249,.92); box-shadow: 0 10px 35px rgba(71,50,35,.13); backdrop-filter: blur(15px); }
.bottom-nav button { display: grid; justify-items: center; gap: .15rem; border: 0; border-radius: 17px; padding: .55rem; color: var(--muted); background: transparent; font-size: .72rem; font-weight: 750; }
.bottom-nav button span { font-size: 1.25rem; line-height: 1; }
.bottom-nav button.active { color: var(--terracotta-dark); background: #f8e7df; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 7rem; transform: translate(-50%, 20px); max-width: calc(100% - 2rem); padding: .8rem 1rem; border-radius: 14px; color: white; background: #292621; opacity: 0; pointer-events: none; transition: .25s; font-size: .85rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .field-grid { grid-template-columns: 1fr 1fr; }
  .field-grid label:first-child { grid-column: span 2; }
  .type-picker { grid-template-columns: 1fr 1fr; }
  .section-heading { align-items: flex-start; }
}

@media (min-width: 760px) {
  .app-shell { padding-left: 0; padding-right: 0; }
  .hero-card, .card { padding: 1.65rem; }
}

