:root {
  --bg: #0f172a;
  --bg-elev: #111c33;
  --panel: #1a2540;
  --panel-2: #1e293b;
  --border: #2a3a5a;
  --divider: #3a4d75;
  --fg: #e2e8f0;
  --fg-dim: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #22d3ee;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem;
}

.topbar {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 1rem;
  padding-bottom: 1rem;
}
.topbar h1 { color: var(--accent); margin: 0; font-size: 1.4rem; }
.subtitle { color: var(--fg-dim); font-size: 0.9rem; }

.topbar-nav {
  display: flex;
  gap: 0.4rem;
  margin-left: 0.5rem;
}
.nav-link {
  color: var(--fg-dim);
  text-decoration: none;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
}
.nav-link:hover { color: var(--fg); background: rgba(56, 189, 248, 0.06); }
.nav-link.active {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
}

.day-tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin: 0 0 1rem 0;
  overflow-x: auto;
}
.day-tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  color: var(--fg-dim);
  font: inherit;
  font-weight: 500;
  font-size: 0.85rem;
  white-space: nowrap;
  margin-bottom: -1px;
}
.day-tab:hover { color: var(--fg); }
.day-tab.active {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--accent);
}

/* Meal picker */
.meal-picker-search {
  width: 100%;
  margin-bottom: 0.5rem;
}
.meal-picker-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 50vh;
  overflow-y: auto;
}
.picker-row label {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.5rem 0.6rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.picker-row label:hover { border-color: var(--accent); }
.picker-info { display: flex; flex-direction: column; }
.picker-name { font-weight: 600; }

/* Meals catalog page */
.meals-search {
  width: 100%;
  margin: 0.25rem 0 0.75rem 0;
}
.meals-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.meals-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.25rem;
  align-items: start;
}
.meals-sidebar { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
.meals-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Sidebar link (desktop) — rectangular card, no pill chrome. */
.meals-sidebar-link {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--fg-dim);
  text-decoration: none;
  transition: color 120ms ease, background 120ms ease, border-color 120ms ease;
}
.meals-sidebar-link:hover {
  color: var(--fg);
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.06);
}
.meals-sidebar-link.is-active {
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.6);
  background: rgba(56, 189, 248, 0.12);
}
.meals-sidebar-link-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.meals-sidebar-link-label { font-weight: 600; font-size: 0.92rem; }
.meals-sidebar-link-count {
  font-size: 0.78rem;
  color: var(--fg-dim);
  opacity: 0.85;
}
.meals-sidebar-link.is-active .meals-sidebar-link-count { color: var(--accent); opacity: 1; }
.meals-sidebar-link-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  color: var(--fg-dim);
  font-size: 0.78rem;
}
.meals-sidebar-link-info { white-space: nowrap; }
.meals-sidebar-link-tag {
  padding: 0 0.35rem;
  border-radius: 4px;
  background: rgba(250, 204, 21, 0.16);
  color: #facc15;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Horizontal typebar (mobile only) — pill chips. */
.meals-typebar {
  display: none;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 0.5rem 0.25rem;
  margin: 0 -0.25rem 0.75rem -0.25rem;
  background: linear-gradient(180deg, var(--panel) 85%, rgba(0, 0, 0, 0));
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}
.meals-typebar.hidden { display: none; }

@media (max-width: 860px) {
  .meals-layout { grid-template-columns: 1fr; }
  .meals-sidebar { display: none; }
  .meals-typebar {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 5;
  }
  .meals-typebar.hidden { display: none; }
}
.meals-typebar-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--fg-dim);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: color 120ms ease, background 120ms ease, border-color 120ms ease;
}
.meals-typebar-link:hover {
  color: var(--fg);
  background: rgba(56, 189, 248, 0.08);
  border-color: rgba(56, 189, 248, 0.35);
}
.meals-typebar-link.is-active {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.55);
}
.meals-typebar-count {
  font-size: 0.72rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  opacity: 0.85;
}

.meal-group { scroll-margin-top: 64px; }
.meal-group-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
}
.meal-group-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-left: auto;
}
.meal-group-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg-dim);
  font-size: 0.75rem;
  white-space: nowrap;
}
.badge-snack {
  background: rgba(250, 204, 21, 0.16);
  color: #facc15;
}

/* Read-only state */
.meal-card.readonly .meal-card-actions { gap: 0.25rem; }
.ingredient-row.readonly { padding: 0.3rem 0.55rem; }

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}
.panel-header,
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.panel-header h2,
.section-header h3 { margin: 0; font-size: 1.05rem; }

.panel-header-actions,
.section-header-actions { display: flex; gap: 0.4rem; }

.or-divider {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--fg-dim);
  font-size: 0.75rem;
  margin: 0.25rem 0;
}
.or-divider::before,
.or-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.import-panel textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
}

/* Import page (separate from main app) */
.topbar-back { margin-left: auto; }

.import-page {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.import-page form textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  tab-size: 4;
  white-space: pre;
}

.csv-input-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
}
.csv-input-label {
  display: block;
}
.csv-input-block textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 12rem;
  resize: vertical;
}

.textarea-toolbar {
  display: flex;
  gap: 0.4rem;
}

.file-input-row {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem;
}
.file-input-row input[type="file"] {
  flex: 1;
  min-width: 0;
}
.import-page form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.preview-scroll {
  overflow-x: auto;
  margin: 0.5rem 0;
}
.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.preview-table th,
.preview-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.3rem 0.4rem;
  text-align: left;
  vertical-align: top;
}
.preview-table th {
  background: var(--panel-2);
  color: var(--fg-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
}
.preview-table input,
.preview-table select {
  width: 100%;
  min-width: 4rem;
  padding: 0.3rem 0.4rem;
  font-size: 0.82rem;
}
.preview-table tr:hover td { background: rgba(56, 189, 248, 0.04); }

.plan-card {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 1rem;
}
.plan-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.plan-fields { margin-bottom: 0.75rem; }
.plan-meals { display: flex; flex-direction: column; gap: 0.4rem; }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.modal-body {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  width: 92%;
  max-width: 520px;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.modal-body-wide { max-width: 880px; }

/* Two-column modal: form (modal-main) + AI side panel (modal-side).
   The meal modal has a fixed height (80vh) so opening/closing the side
   panel just slides it in/out instead of resizing the whole dialog. */
.modal-body.modal-with-side {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  height: 80vh;
  max-height: 80vh;
  transition: max-width 240ms ease;
}
.modal-body.modal-with-side .modal-main {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
  padding: 1rem 1.1rem;
}
.modal-body.modal-with-side.is-side-open {
  max-width: min(95vw, 1240px);
}
/* The side panel is always in the DOM; we animate it in/out so screen
   readers and focus management work cleanly. Closed state: zero width,
   off-screen, transparent, not interactive. */
.modal-side {
  flex: 0 0 0;
  width: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateX(40px);
  pointer-events: none;
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  border-left: 0 solid var(--divider);
  box-shadow: none;
  transition:
    flex-basis 260ms cubic-bezier(0.22, 1, 0.36, 1),
    width 260ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 220ms ease,
    transform 260ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 220ms ease,
    border-left-width 0ms 260ms linear;
}
.modal-body.is-side-open .modal-side {
  flex: 0 0 380px;
  width: 380px;
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
  border-left-width: 2px;
  box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.04);
  transition:
    flex-basis 260ms cubic-bezier(0.22, 1, 0.36, 1),
    width 260ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 200ms ease 60ms,
    transform 260ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 220ms ease 60ms,
    border-left-width 0ms linear;
}
@media (prefers-reduced-motion: reduce) {
  .modal-body.modal-with-side,
  .modal-side,
  .modal-body.is-side-open .modal-side {
    transition: none;
  }
}
.modal-side-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.modal-side-header h4 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--accent);
}
.modal-side-body {
  flex: 1 1 auto;
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.modal-side-composer {
  border-top: 1px solid var(--border);
  padding: 0.75rem 0.9rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--panel-2);
}
.modal-side-composer textarea {
  width: 100%;
  resize: vertical;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-family: inherit;
  font-size: 0.9rem;
}

.turn-history {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.turn-history.is-empty {
  align-items: stretch;
  justify-content: flex-start;
}
.turn-history-empty {
  margin: 0;
  padding: 0.5rem 0;
}
.turn-history-title {
  margin: 0 0 0.2rem 0;
  font-size: 0.72rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.turn-history-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.turn-pair {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.turn-pair.is-pending .turn-bubble { box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.25); }
.turn-bubble {
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.turn-bubble.turn-user {
  align-self: flex-end;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  max-width: 88%;
}
.turn-bubble.turn-assistant {
  align-self: flex-start;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  max-width: 92%;
}
.turn-meta {
  display: flex;
  gap: 0.4rem;
  align-items: baseline;
  font-size: 0.7rem;
  color: var(--fg-dim);
  text-transform: none;
}
.turn-role { font-weight: 600; color: var(--fg); }
.turn-flag {
  padding: 0.05rem 0.4rem;
  background: rgba(56, 189, 248, 0.18);
  color: var(--accent);
  border-radius: 999px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.turn-text {
  margin: 0;
  color: var(--fg);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.turn-name { font-size: 0.9rem; }
.turn-ings { font-size: 0.75rem; }
.turn-warnings {
  margin: 0.25rem 0 0 1rem;
  padding: 0;
  color: var(--warning);
  font-size: 0.75rem;
}
.turn-tag {
  padding: 0.05rem 0.4rem;
  background: rgba(148, 163, 184, 0.18);
  color: var(--fg-dim);
  border-radius: 999px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.turn-bubble.turn-intro {
  background: rgba(56, 189, 248, 0.06);
  border: 1px dashed rgba(56, 189, 248, 0.35);
}
.turn-bubble.turn-loading {
  background: var(--bg-elev);
  border: 1px solid rgba(56, 189, 248, 0.45);
}
.turn-loader {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.turn-loader-dots {
  display: inline-flex;
  gap: 0.22rem;
}
.turn-loader-dots span {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--accent);
  animation: turn-dot-pulse 1.1s infinite ease-in-out both;
}
.turn-loader-dots span:nth-child(2) { animation-delay: 160ms; }
.turn-loader-dots span:nth-child(3) { animation-delay: 320ms; }
@keyframes turn-dot-pulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.7); }
  40% { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .turn-loader-dots span { animation: none; opacity: 0.8; }
  .btn-loader-dots span { animation: none; opacity: 0.8; }
}

.btn.is-loading {
  cursor: progress;
  opacity: 0.92;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.btn-loader-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.18rem;
  margin-right: 0.1rem;
}
.btn-loader-dots span {
  width: 0.34rem;
  height: 0.34rem;
  border-radius: 50%;
  background: currentColor;
  animation: turn-dot-pulse 1.1s infinite ease-in-out both;
}
.btn-loader-dots span:nth-child(2) { animation-delay: 160ms; }
.btn-loader-dots span:nth-child(3) { animation-delay: 320ms; }

.modal-side-composer textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

@media (max-width: 820px) {
  .modal-body.modal-with-side {
    flex-direction: column;
  }
  .modal-body.modal-with-side .modal-main { min-height: 0; }
  .modal-side {
    flex: 0 0 0;
    width: 100%;
    max-width: 100%;
    transform: translateY(20px);
    border-left: none;
    border-top: 0 solid var(--divider);
    transition:
      flex-basis 260ms cubic-bezier(0.22, 1, 0.36, 1),
      opacity 220ms ease,
      transform 260ms cubic-bezier(0.22, 1, 0.36, 1),
      border-top-width 0ms 260ms linear;
  }
  .modal-body.is-side-open .modal-main { max-height: 50vh; }
  .modal-body.is-side-open .modal-side {
    flex: 1 1 auto;
    width: 100%;
    transform: translateY(0);
    border-top-width: 2px;
    border-left-width: 0;
    transition:
      flex-basis 260ms cubic-bezier(0.22, 1, 0.36, 1),
      opacity 200ms ease 60ms,
      transform 260ms cubic-bezier(0.22, 1, 0.36, 1),
      border-top-width 0ms linear;
  }
}
.modal-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0.9rem 0 0.4rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.modal-section-header h4 {
  margin: 0;
  font-size: 0.9rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#meal-ings-table input[type="text"] { min-width: 8rem; }
#meal-ings-table input[type="number"] { min-width: 4rem; }
/* Labels dentro de modales: layout columna para alinear inputs. */
.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--fg-dim);
}
/* Labels en el flujo vertical del form llevan margen entre sí.
   Las que están dentro de .grid-2 no — el gap del grid se encarga. */
.modal-body > form > label,
.modal-body > label {
  margin: 0.6rem 0;
}
.modal-body .grid-2 > label {
  margin: 0;
}
/* Inputs del meal form: 100% del ancho disponible para que las dos columnas
   queden perfectamente alineadas. */
#meal-form input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
#meal-form select,
#meal-form textarea {
  width: 100%;
  box-sizing: border-box;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.modal-header h3 { margin: 0; font-size: 1.05rem; color: var(--fg); }
.modal-close {
  background: none;
  border: none;
  color: var(--fg-dim);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0.25rem;
}
.modal-close:hover { color: var(--fg); }

/* Types manager
   9-column grid: name | order | kcal min | kcal max | kcal target |
                  start | end | snack | actions.
   The header, each row in the list, and the "add new" form all share
   the same columns so things line up vertically. */
:root {
  --types-grid: minmax(10rem, 1.6fr) 4.5rem 4.5rem 4.5rem 5rem 5.5rem 5.5rem 4rem minmax(7rem, auto);
}
.types-grid-header {
  display: grid;
  grid-template-columns: var(--types-grid);
  gap: 0.5rem;
  align-items: center;
  padding: 0.4rem 0.5rem;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-dim);
  border-bottom: 1px solid var(--border);
}
.types-list {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0.75rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.type-row,
.add-type-form {
  display: grid;
  grid-template-columns: var(--types-grid);
  gap: 0.5rem;
  align-items: end;
  padding: 0.5rem 0.5rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.add-type-form {
  background: var(--bg-elev);
  border-style: dashed;
}
.types-add-title {
  margin: 1rem 0 0.5rem 0;
  font-size: 0.95rem;
}

/* Each cell is a label that stacks the column name above the input.
   On wide viewports the column-name labels are hidden (the header row
   handles that); on narrow viewports they reappear when rows wrap into
   stacked cards. */
.types-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}
.types-field-label {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-dim);
}
.types-field input[type="text"],
.types-field input[type="number"],
.types-field input[type="time"] {
  width: 100%;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}
.types-field-check {
  align-items: center;
  justify-content: center;
}
.types-field-check input[type="checkbox"] {
  width: auto;
  margin: 0.2rem 0 0 0;
  transform: scale(1.1);
}
.types-grid-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
  align-items: center;
}

/* Hide the per-cell labels when the header row is visible (wide layout). */
@media (min-width: 981px) {
  .type-row .types-field-label,
  .add-type-form .types-field-label {
    display: none;
  }
  .types-field-check {
    /* keep the "Snack" label visible because it acts as the checkbox caption */
  }
  .type-row .types-field-check .types-field-label,
  .add-type-form .types-field-check .types-field-label {
    display: inline;
    text-align: center;
  }
}

/* Below 980px the grid collapses to a stacked card layout. */
@media (max-width: 980px) {
  .types-grid-header { display: none; }
  .type-row,
  .add-type-form {
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
  }
  .types-grid-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

.import-panel {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  background: rgba(56, 189, 248, 0.04);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.import-panel a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
}
.import-panel a:hover { text-decoration: underline; }
.import-panel code {
  background: #0b1326;
  padding: 0 0.25rem;
  border-radius: 3px;
  font-size: 0.8rem;
}
.import-panel input[type="file"] {
  background: #0b1326;
  padding: 0.4rem;
  font-size: 0.8rem;
}
.import-result {
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
}
.import-result.success { border-color: var(--success); background: rgba(52, 211, 153, 0.08); }
.import-result.error { border-color: var(--danger); background: rgba(248, 113, 113, 0.08); }
.import-result ul { margin: 0.35rem 0 0 0; padding-left: 1.1rem; }

.plans-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 60vh;
  overflow-y: auto;
}
.plan-item {
  border: 1px solid var(--border);
  background: var(--panel-2);
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 120ms, background 120ms, transform 60ms;
}
.plan-item:hover { border-color: var(--accent); }
.plan-item.active {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}
.plan-item-name { font-weight: 600; }
.plan-item-meta { color: var(--fg-dim); font-size: 0.8rem; margin-top: 0.15rem; }

.plan-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}
.plan-header h2 { margin: 0 0 0.25rem 0; }
.plan-header-actions { display: flex; gap: 0.5rem; }

.totals {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 700px) {
  .totals { grid-template-columns: repeat(2, 1fr); }
}
.stat {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
}
.stat-label { font-size: 0.75rem; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { display: block; font-weight: 600; margin: 0.15rem 0 0.4rem; }
.bar { height: 6px; background: #0b1326; border-radius: 4px; overflow: hidden; }
.bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 200ms ease;
}

.meals-section { margin-top: 0.5rem; }
.meals-by-type {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.meal-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 0.75rem;
}
.meal-group-title {
  margin: 0;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.badge {
  background: rgba(56, 189, 248, 0.18);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.75rem;
}

.meal-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.meal-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
}
.meal-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}
.meal-name { font-weight: 600; }
.meal-macros {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.25rem;
}
.macro {
  background: #0b1326;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  font-size: 0.75rem;
  color: var(--fg-dim);
}
.macro.kcal { color: var(--accent); border-color: rgba(56, 189, 248, 0.4); }
.meal-notes { margin-top: 0.3rem; }
.meal-card-actions { display: flex; gap: 0.35rem; }

/* Ingredients */
.ingredients-section {
  margin-top: 0.4rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
}
.ingredients-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}
.ingredients-title {
  font-size: 0.8rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ingredient-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.ingredient-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
}
.ing-main { display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; }
.ing-name { font-weight: 600; }
.ing-qty {
  color: var(--fg-dim);
  font-size: 0.78rem;
  background: #0b1326;
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
}
.ing-macros { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.ing-macros .macro { font-size: 0.72rem; padding: 0.02rem 0.4rem; }
.ing-actions { display: flex; gap: 0.25rem; }
@media (max-width: 600px) {
  .ingredient-row { grid-template-columns: 1fr; }
}

/* Meal traffic-light + alert chips */
.traffic-dot {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: middle;
  border: 1px solid rgba(255, 255, 255, 0.18);
}
.traffic-dot.verde { background: var(--success); }
.traffic-dot.amarillo { background: var(--warning); }
.traffic-dot.rojo { background: var(--danger); }

.meal-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.3rem 0 0.1rem;
}
.chip {
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  line-height: 1.3;
  white-space: nowrap;
}
.chip-alert {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.35);
}
.chip-positive {
  background: rgba(52, 211, 153, 0.12);
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.35);
}

.form {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.form h3, .form h4 { margin: 0 0 0.25rem 0; }
.form label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: var(--fg-dim);
  gap: 0.2rem;
}
.modal-form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.modal-form label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: var(--fg-dim);
  gap: 0.25rem;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
@media (max-width: 520px) { .grid-2 { grid-template-columns: 1fr; } }

input, select, textarea, button {
  font: inherit;
}
input, select, textarea {
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0b1326;
  color: var(--fg);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(56, 189, 248, 0.35);
  border-color: var(--accent);
}
textarea { resize: vertical; }

.btn {
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.85rem;
  transition: filter 120ms, transform 60ms, background 120ms;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #0b1326; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost {
  background: transparent;
  color: var(--fg);
  border-color: var(--border);
}
.btn.ghost:hover { border-color: var(--accent); }
.btn.danger { background: var(--danger); color: #1a0808; border: none; }
.btn.danger:hover { filter: brightness(1.05); }
.btn.small { padding: 0.25rem 0.55rem; font-size: 0.75rem; }

.form-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.25rem;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--fg-dim);
}

.hidden { display: none !important; }
.muted { color: var(--fg-dim); }
.small { font-size: 0.8rem; }

.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--fg);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  z-index: 1000;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

/* ---------- Analyze nutrition image ---------- */
.analyze-advanced {
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(56, 189, 248, 0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.analyze-advanced summary {
  cursor: pointer;
  color: var(--fg-dim);
  font-size: 0.85rem;
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
.analyze-status {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}
.analyze-status.success { border-color: var(--success); }
.analyze-status.error { border-color: var(--danger); }

.generate-panel {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
/* When the panel is the side drawer, the .modal-side styles take over the
   chrome (border, background, scroll). Reset .generate-panel to a no-op. */
.modal-side.generate-panel {
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  gap: 0;
  display: flex;
}
.generate-label {
  font-size: 0.85rem;
  color: var(--fg-dim);
}
.generate-hint {
  margin: -0.25rem 0 0 0;
  font-size: 0.78rem;
  color: var(--fg-dim);
  line-height: 1.4;
}
.generate-panel textarea {
  width: 100%;
  resize: vertical;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-family: inherit;
  font-size: 0.9rem;
}
.generate-actions {
  display: flex;
  gap: 0.5rem;
}
.generate-summary {
  margin-top: 0.5rem;
  padding: 0.75rem 0.9rem;
  background: var(--bg-elev);
  border: 1px solid var(--accent);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.generate-summary-title {
  margin: 0;
  font-size: 0.85rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.generate-summary-meal {
  margin: 0;
  font-size: 0.95rem;
}
.generate-summary-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--fg);
  white-space: pre-wrap;
}
.generate-summary-warnings {
  margin: 0.25rem 0 0 1.1rem;
  padding: 0;
  font-size: 0.8rem;
  color: var(--warning);
}
.analyze-preview {
  margin-top: 1rem;
}
.analyze-preview-card {
  padding: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.analyze-preview-header h4 {
  margin: 0 0 0.25rem 0;
}
.analyze-warnings {
  margin: 0.5rem 0 0.25rem 1.1rem;
  color: var(--warning, #fbbf24);
  font-size: 0.8rem;
}
.analyze-ings {
  margin-top: 0.75rem;
}
.analyze-ings summary {
  cursor: pointer;
  color: var(--fg-dim);
  font-size: 0.85rem;
}

.ingredient-actions {
  display: inline-flex;
  gap: 0.5rem;
}

/* ---------- Dashboard ---------- */
.dashboard { display: grid; gap: 1rem; padding-top: 1rem; }

.dashboard-hero {
  padding: 1.25rem 1.5rem;
}
.dashboard-hero h2 { margin: 0; font-size: 1.6rem; }

/* Plan-activo card, sits directly below the welcome hero.
   Layout: info block (eyebrow + plan name) on the left, "Cambiar plan"
   button on the right. The button opens a modal picker. */
.dashboard-plan-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  flex-wrap: wrap;
}
.dashboard-plan-card-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.dashboard-plan-card-eyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-dim);
}
.dashboard-plan-card-name {
  font-size: 1.1rem;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
}
.dashboard-plan-card #dash-plan-empty { flex-basis: 100%; }

/* Plan picker modal list. */
.plan-picker-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 60vh;
  overflow-y: auto;
}
.plan-picker-row { margin: 0; }
.plan-picker-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.plan-picker-btn:hover { border-color: var(--accent); }
.plan-picker-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.plan-picker-row.is-current .plan-picker-btn {
  border-color: var(--accent);
  background: var(--bg-elev);
}
.plan-picker-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.plan-picker-tags { display: flex; gap: 0.3rem; flex: 0 0 auto; }

.bucket-carousel { padding: 1rem 1.5rem; }
.bucket-carousel-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.bucket-current-label {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.bucket-current-label > span:first-child {
  font-size: 1.15rem;
  font-weight: 600;
}

.meal-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.meal-card-compact {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.meal-card-compact:hover {
  border-color: var(--accent, #38bdf8);
  transform: translateY(-1px);
}
.meal-card-compact:focus-visible {
  outline: 2px solid var(--accent, #38bdf8);
  outline-offset: 2px;
}
.meal-card-compact header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.meal-card-compact h4 { margin: 0; font-size: 1rem; }
.meal-card-compact .macros {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--fg-dim);
}
/* Compact ingredient summary on the dashboard meal card:
   name on the left, quantity on the right, no per-ingredient macros. */
.meal-card-ing-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0.5rem 0 0;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.meal-card-ing-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--fg);
  line-height: 1.3;
}
.meal-card-ing-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meal-card-ing-qty {
  flex: 0 0 auto;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
}
.meal-card-ing-more {
  list-style: none;
  font-style: italic;
}
.status-dot.status-verde { color: var(--success, #22c55e); }
.status-dot.status-amarillo { color: #facc15; }
.status-dot.status-rojo { color: var(--danger, #ef4444); }

.snacks-section { padding: 1rem 1.5rem; }

.meal-detail-body h4 { margin: 0 0 0.25rem; }
.meal-detail-body .macros-large {
  font-size: 1rem;
  margin: 0.5rem 0;
}
.meal-detail-body ul.alerts,
.meal-detail-body ul.positives {
  margin: 0.25rem 0 0.5rem 1.1rem;
  font-size: 0.85rem;
}
.meal-detail-body ul.alerts { color: #fbbf24; }
.meal-detail-body ul.positives { color: var(--success, #22c55e); }

.inline-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--fg-dim);
}

/* ------- Form pages (NUT-4) -------
   Standalone pages that replace the old meal/plan/types modals.

   Shared vertical rhythm for all edit/create screens:
     [.form-page-top]    ← back button row
     [.form-page-header] ← title + description (+ optional actions on the right)
     [.panel ...]        ← one or more cards
*/
.form-page {
  display: block;
}
.form-page-top {
  display: flex;
  justify-content: flex-start;
  margin: 0 0 0.75rem 0;
}
.form-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin: 0 0 1rem 0;
}
.form-page-header-text { max-width: 720px; }
.form-page-header-text h2 { margin: 0 0 0.25rem 0; }
.form-page-header-text p { margin: 0; }
.form-page-header-actions { display: flex; gap: 0.4rem; align-items: center; }

/* Two-column layout: main form + aside (used by the meal form for the
   AI assistant). The aside collapses below the form on narrow viewports. */
.form-page.form-page-side {
  display: grid;
  grid-template-columns: 1fr 0;
  gap: 1.25rem;
  align-items: start;
  transition: grid-template-columns 260ms cubic-bezier(0.22, 1, 0.36, 1);
}
.form-page.form-page-side.is-side-open {
  grid-template-columns: 1fr 380px;
}
/* When inside the two-column grid, .form-page-top and .form-page-header
   span both columns so the back button and the title row stay above
   the panel + aside, aligned to the same left edge. */
.form-page.form-page-side > .form-page-top,
.form-page.form-page-side > .form-page-header {
  grid-column: 1 / -1;
}
.form-page-main { min-width: 0; }
.form-page-aside {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateX(20px);
  pointer-events: none;
  transition:
    opacity 220ms ease,
    transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
}
.form-page.form-page-side.is-side-open .form-page-aside {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
  /* Fixed minimum so the chat doesn't collapse when there are few turns,
     while still allowing growth up to the viewport-based max-height. */
  min-height: 560px;
}
/* Button toggling the assistant: mirror the ghost-hover styling while
   the panel is open so the state is obvious. */
.btn.ghost.is-active,
.btn.ghost[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
}
.form-page-aside-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.form-page-aside-header h4 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--accent);
}
.form-page-aside-body {
  flex: 1 1 auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.form-page-aside-composer {
  border-top: 1px solid var(--border);
  padding: 0.75rem 0.9rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--panel-2);
}
.form-page-aside-composer textarea {
  width: 100%;
  resize: vertical;
  background: var(--bg-elev);
}

.meal-ings-total-row td {
  font-weight: 600;
  border-top: 1px solid var(--border);
}

@media (max-width: 980px) {
  .form-page.form-page-side,
  .form-page.form-page-side.is-side-open {
    grid-template-columns: 1fr;
  }
  .form-page-aside {
    position: static;
    max-height: none;
  }
  /* Hide the aside entirely while closed on mobile so it doesn't keep
     vertical space below the form. */
  .form-page.form-page-side:not(.is-side-open) .form-page-aside {
    display: none;
  }
  /* Fixed height when open on mobile: enough room for intro + composer
     without making the user scroll the whole page to reach the textarea. */
  .form-page.form-page-side.is-side-open .form-page-aside {
    min-height: 0;
    height: 480px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .form-page.form-page-side,
  .form-page-aside {
    transition: none;
  }
}

/* --- Auth (NUT-5) --- */
.login-page {
  display: flex;
  justify-content: center;
  padding-top: 3rem;
}
.login-panel {
  width: min(420px, 100%);
  padding: 2rem;
}
.login-panel h2 {
  margin: 0 0 0.25rem 0;
}
.login-panel form label {
  display: block;
  margin: 0.85rem 0;
}
.login-panel form input {
  width: 100%;
  margin-top: 0.25rem;
}
.or-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 1.25rem 0;
  color: var(--muted, #94a3b8);
  font-size: 0.85rem;
}
.or-divider::before,
.or-divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--border);
}
.or-divider span {
  padding: 0 0.6rem;
}
.login-google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
}
.login-google-btn svg {
  flex: 0 0 18px;
}
.alert {
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}
.alert-error {
  background: rgba(248, 113, 113, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(248, 113, 113, 0.35);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
}
.topbar-right .topbar-back {
  margin-left: 0;
}
.topbar-user {
  font-size: 0.9rem;
  color: var(--muted, #94a3b8);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mobile drawer + hamburger toggle */
.nav-toggle {
  display: none;
  margin-left: auto;
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.nav-toggle:hover { background: rgba(56, 189, 248, 0.06); }
.nav-toggle-bar {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--fg);
  border-radius: 2px;
  transition: transform 160ms ease, opacity 160ms ease;
}
body.nav-open .nav-toggle-bar:nth-child(1) { transform: translateY(6px) rotate(45deg); }
body.nav-open .nav-toggle-bar:nth-child(2) { opacity: 0; }
body.nav-open .nav-toggle-bar:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.mobile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(80vw, 320px);
  background: var(--bg-elev, #0f172a);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.35);
  transform: translateX(100%);
  transition: transform 220ms ease;
  z-index: 60;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 0.75rem;
}
body.nav-open .mobile-drawer { transform: translateX(0); }
.mobile-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.mobile-drawer-title {
  font-weight: 600;
  color: var(--fg);
}
.mobile-drawer-close {
  background: transparent;
  border: none;
  color: var(--fg-dim);
  font-size: 1.6rem;
  line-height: 1;
  padding: 0 0.4rem;
  cursor: pointer;
  border-radius: 6px;
}
.mobile-drawer-close:hover { color: var(--fg); background: rgba(255, 255, 255, 0.05); }
.mobile-drawer-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.mobile-drawer-link {
  color: var(--fg-dim);
  text-decoration: none;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
}
.mobile-drawer-link:hover { color: var(--fg); background: rgba(56, 189, 248, 0.06); }
.mobile-drawer-link.active {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
}
.mobile-drawer-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.mobile-drawer-user {
  font-size: 0.9rem;
  color: var(--muted, #94a3b8);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 55;
  opacity: 0;
  transition: opacity 200ms ease;
}
body.nav-open .nav-overlay {
  opacity: 1;
}
body.nav-open { overflow: hidden; }

@media (max-width: 860px) {
  .topbar-nav,
  .topbar-right { display: none; }
  .nav-toggle { display: inline-flex; }
}
@media (min-width: 861px) {
  .mobile-drawer,
  .nav-overlay { display: none !important; }
}
