:root {
  --paper: #f8f3ea;
  --card: #fffaf2;
  --ink: #251f19;
  --muted: #74685d;
  --line: #e5d8c7;
  --accent: #594636;
  --accent-2: #8b6f55;
  --soft: #efe4d4;
  --danger: #9b2c2c;
  --shadow: 0 18px 45px rgba(55, 43, 33, 0.12);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-weight: 700;
}

button.secondary {
  background: var(--soft);
  color: var(--ink);
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
}

button.danger {
  background: var(--danger);
}

button.small {
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
  padding: 0.85rem 0.9rem;
  color: var(--ink);
}

textarea { min-height: 92px; resize: vertical; }

label {
  display: grid;
  gap: 0.4rem;
  font-weight: 700;
  color: var(--accent);
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
}

.loading-card, .auth-card, .welcome-card {
  width: min(520px, 100%);
  margin: 10vh auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 1.4rem;
}

.auth-card h1, .welcome-card h1 { margin: 0 0 0.5rem; }
.auth-card p, .welcome-card p { color: var(--muted); margin-top: 0; line-height: 1.45; }

.stack { display: grid; gap: 1rem; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.inline-grid { display: grid; grid-template-columns: 1fr 0.75fr; gap: 0.75rem; }

.topbar {
  display: grid;
  gap: 1rem;
  margin-bottom: 1rem;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand h1 { margin: 0; font-size: clamp(1.5rem, 4vw, 2.2rem); }
.brand p { margin: 0.25rem 0 0; color: var(--muted); }

.actions {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.summary-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 1rem;
}

.summary-card span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
}

.summary-card strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.25rem;
}

.desktop-nav {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.5rem 0 0.75rem;
}

.week-strip {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding: 1rem;
  padding: 0.25rem 0 1rem;
  -webkit-overflow-scrolling: touch;
}

.week-card {
  flex: 0 0 calc(100vw - 2rem);
  scroll-snap-align: start;
  min-height: calc(100vh - 230px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 30px;
  box-shadow: var(--shadow);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.week-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.75rem;
}

.week-card h2 {
  margin: 0;
  font-size: 1.25rem;
}

.week-card .dates {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.2rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 800;
  padding: 0.35rem 0.6rem;
  white-space: nowrap;
}

.card-section {
  display: grid;
  gap: 0.55rem;
}

.card-section h3 {
  margin: 0;
  color: var(--accent);
  font-size: 0.95rem;
}

.entry-list {
  display: grid;
  gap: 0.5rem;
}

.entry-row {
  display: grid;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.55);
  border-radius: 18px;
  padding: 0.75rem;
}

.entry-main {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
}

.entry-main strong { font-size: 1rem; }
.entry-meta { color: var(--muted); font-size: 0.88rem; line-height: 1.35; }
.entry-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.empty { color: var(--muted); font-style: italic; }

.dose-day-prompt {
  background: rgba(239, 228, 212, 0.72);
  border-style: dashed;
}


.compact-message {
  margin: -0.35rem 0 0;
  min-height: 0;
  font-size: 0.9rem;
}

.settings-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 1rem;
  margin-top: 0.75rem;
}

.settings-box h2 { margin: 0 0 0.4rem; font-size: 1.1rem; }
.settings-box p { margin: 0.25rem 0 0.75rem; color: var(--muted); }

.message {
  color: var(--muted);
  min-height: 1.4rem;
}

.error {
  color: var(--danger);
  font-weight: 700;
}

.entry-dialog {
  border: 0;
  border-radius: 28px;
  padding: 0;
  width: min(560px, calc(100% - 2rem));
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.entry-dialog::backdrop {
  background: rgba(37, 31, 25, 0.35);
  backdrop-filter: blur(4px);
}

.dialog-inner {
  padding: 1.2rem;
}

.dialog-inner h2 { margin: 0 0 0.75rem; }
.dialog-actions { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1rem; }

@media (min-width: 760px) {
  .topbar { gap: 1.25rem; }
  .summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 980px) {
  .desktop-nav { display: flex; }
  .week-card { flex-basis: calc((100% - 2rem) / 3); min-height: 640px; }
}
