:root {
  --cream: #f6efe4;
  --cream-deep: #ebe1d1;
  --ink: #2b241c;
  --ink-soft: #5a4d40;
  --orange: #c45c26;
  --orange-deep: #a4481a;
  --apricot: #f0b27a;
  --sage: #7d9b78;
  --card: rgba(255, 251, 245, 0.92);
  --shadow: 0 12px 30px rgba(64, 36, 16, 0.12);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 76px;
  font-family: "Nunito", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at 12% 8%, rgba(240, 178, 122, 0.45), transparent 42%),
    radial-gradient(circle at 88% 0%, rgba(196, 92, 38, 0.18), transparent 36%),
    linear-gradient(180deg, #fbf6ee 0%, #f1e6d6 55%, #e8d9c4 100%);
}

button,
textarea {
  font: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app-shell {
  width: min(520px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 16px 16px 8px;
}

.topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.user-badge {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
}

.btn-compact {
  min-height: 40px;
  padding: 0.35rem 0.8rem;
  font-size: 0.95rem;
}

.login-panel {
  margin-top: 12px;
}

.login-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.form-error {
  color: #8a1f11;
  font-weight: 700;
  min-height: 1.4em;
  margin: 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  border: 3px solid #fff;
  box-shadow: var(--shadow);
}

.brand-kicker {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.brand-title {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.55rem;
  line-height: 1.1;
}

.badge {
  margin: 0;
  padding: 10px 12px;
  border-radius: 999px;
  background: var(--cream-deep);
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  max-width: 42%;
}

.badge.ok {
  background: rgba(125, 155, 120, 0.25);
  color: #2f4f2c;
}

.badge.warn {
  background: rgba(196, 92, 38, 0.16);
  color: var(--orange-deep);
}

.views {
  padding: 8px 16px 20px;
}

.view {
  display: none;
  animation: fadeIn 220ms ease;
}

.view.is-active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero-card,
.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.hero-image {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  object-position: center top;
  border-radius: 18px;
  display: block;
}

.hero-copy {
  margin-top: 14px;
}

.hero-copy h2,
.panel h2,
.panel h3 {
  font-family: "Fraunces", Georgia, serif;
  margin: 0 0 8px;
}

.hero-copy p,
.panel p,
.hint,
.step-text {
  margin: 0 0 14px;
  font-size: 1.1rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

.panel-muted {
  background: rgba(255, 251, 245, 0.7);
}

.planned-banner {
  display: inline-block;
  margin-bottom: 10px !important;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(196, 92, 38, 0.14);
  color: var(--orange-deep);
  font-weight: 800;
  font-size: 0.95rem;
}

.status-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.status-list li {
  padding: 12px 14px;
  border-radius: 16px;
  background: #fffaf3;
  border: 1px solid rgba(90, 77, 64, 0.1);
  font-size: 1.05rem;
  line-height: 1.35;
}

.status-list .tag {
  display: inline-block;
  margin-right: 8px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.tag.op { color: var(--sage); }
.tag.pl { color: var(--orange); }

.btn,
.nav-btn {
  min-height: 52px;
  min-width: 52px;
  border: 0;
  border-radius: 16px;
  padding: 12px 18px;
  font-weight: 800;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #d56a31, var(--orange));
  color: #fff8f2;
  box-shadow: 0 8px 18px rgba(196, 92, 38, 0.28);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #de7340, var(--orange-deep));
}

.btn-secondary {
  background: #fff7ee;
  color: var(--ink);
  border: 2px solid rgba(90, 77, 64, 0.15);
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-row .btn-primary {
  grid-column: 1 / -1;
}

.chat-log {
  height: calc(100dvh - 280px);
  min-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 2px 16px;
}

.bubble {
  max-width: 92%;
  padding: 14px 16px;
  border-radius: 18px;
  font-size: 1.125rem; /* 18px */
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: var(--orange);
  color: #fff8f2;
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid rgba(90, 77, 64, 0.1);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
  color: var(--ink);
  user-select: text;
  -webkit-user-select: text;
}

.bubble.system {
  align-self: center;
  max-width: 95%;
  background: rgba(196, 92, 38, 0.1);
  color: var(--orange-deep);
  font-size: 1rem;
  text-align: center;
  white-space: pre-wrap;
}

.bubble.assistant .md {
  margin: 0;
}

.bubble.assistant .md > *:first-child {
  margin-top: 0;
}

.bubble.assistant .md > *:last-child {
  margin-bottom: 0;
}

.bubble.assistant .md p {
  margin: 0 0 0.85em;
  font-size: 1.125rem;
  line-height: 1.55;
  color: var(--ink);
}

.bubble.assistant .md h1,
.bubble.assistant .md h2,
.bubble.assistant .md h3,
.bubble.assistant .md h4 {
  font-family: "Fraunces", Georgia, serif;
  color: var(--ink);
  line-height: 1.25;
  margin: 0.9em 0 0.45em;
  font-weight: 700;
}

.bubble.assistant .md h1 { font-size: 1.45rem; }
.bubble.assistant .md h2 { font-size: 1.3rem; color: var(--orange-deep); }
.bubble.assistant .md h3 { font-size: 1.18rem; }
.bubble.assistant .md h4 { font-size: 1.12rem; }

.bubble.assistant .md strong,
.bubble.assistant .md b {
  font-weight: 800;
  color: var(--ink);
}

.bubble.assistant .md em,
.bubble.assistant .md i {
  font-style: italic;
}

.bubble.assistant .md ul,
.bubble.assistant .md ol {
  margin: 0.4em 0 1em;
  padding-left: 1.35em;
}

.bubble.assistant .md li {
  margin: 0.45em 0;
  padding-left: 0.15em;
  font-size: 1.125rem;
  line-height: 1.55;
}

.bubble.assistant .md ol {
  list-style: decimal;
}

.bubble.assistant .md ul {
  list-style: disc;
}

.bubble.assistant .md ol > li::marker {
  font-weight: 800;
  color: var(--orange-deep);
}

.bubble.assistant .md ul > li::marker {
  color: var(--orange);
}

.bubble.assistant .md blockquote {
  margin: 0.75em 0;
  padding: 0.65em 0.9em;
  border-left: 4px solid var(--apricot);
  background: rgba(240, 178, 122, 0.18);
  border-radius: 0 12px 12px 0;
  color: var(--ink-soft);
}

.bubble.assistant .md hr {
  border: 0;
  border-top: 2px solid rgba(90, 77, 64, 0.15);
  margin: 1em 0;
}

.bubble.assistant .md code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.95em;
  background: rgba(90, 77, 64, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 6px;
}

.bubble.assistant .md pre {
  margin: 0.75em 0;
  padding: 12px;
  overflow-x: auto;
  max-width: 100%;
  background: rgba(90, 77, 64, 0.08);
  border-radius: 12px;
}

.bubble.assistant .md pre code {
  padding: 0;
  background: transparent;
}

.bubble.assistant .md a {
  color: var(--orange-deep);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
  min-height: 48px;
  display: inline;
  padding: 0.15em 0;
}

.bubble.assistant .md .table-wrap,
.bubble.assistant .md table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.bubble.assistant .md table {
  border-collapse: collapse;
  margin: 0.75em 0 1em;
  font-size: 1.05rem;
}

.bubble.assistant .md th,
.bubble.assistant .md td {
  border: 1px solid rgba(90, 77, 64, 0.2);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  min-width: 4.5rem;
}

.bubble.assistant .md th {
  background: rgba(196, 92, 38, 0.12);
  color: var(--ink);
  font-weight: 800;
}

.bubble.assistant .md td {
  background: #fffaf3;
}

/* Scheda ricettario dedicata */
.bubble.assistant {
  max-width: 96%;
  padding: 12px;
}

.recipe-card {
  background: linear-gradient(180deg, #fffaf3 0%, #f7eee2 100%);
  border: 1px solid rgba(90, 77, 64, 0.12);
  border-radius: 18px;
  padding: 16px 14px 12px;
  user-select: text;
  -webkit-user-select: text;
}

.recipe-title {
  margin: 0 0 8px;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.45rem;
  line-height: 1.25;
  color: var(--orange-deep);
}

.recipe-meta {
  margin: 0 0 14px;
  display: inline-block;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(196, 92, 38, 0.12);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 800;
}

.recipe-section {
  margin: 0 0 16px;
}

.recipe-section-title {
  margin: 0 0 10px;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.2rem;
  color: var(--ink);
}

.recipe-ingredients {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.recipe-ingredient {
  display: grid;
  grid-template-columns: minmax(4.5rem, auto) 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px 12px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid rgba(90, 77, 64, 0.1);
  font-size: 1.125rem;
  line-height: 1.45;
}

.recipe-qty {
  font-weight: 800;
  color: var(--orange-deep);
  white-space: nowrap;
}

.recipe-ing-name {
  color: var(--ink);
}

.recipe-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
  counter-reset: none;
}

.recipe-step {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px 12px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid rgba(90, 77, 64, 0.1);
}

.recipe-step-num {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--orange);
  color: #fff8f2;
  font-weight: 800;
  font-size: 1.15rem;
}

.recipe-step-text {
  font-size: 1.125rem;
  line-height: 1.55;
  color: var(--ink);
  padding-top: 8px;
}

.recipe-format-note {
  margin: 4px 0 0;
  font-size: 0.92rem;
  color: var(--ink-soft);
  line-height: 1.4;
}

@media (max-width: 380px) {
  .recipe-ingredient {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

.hidden { display: none !important; }

.stack {
  display: grid;
  gap: 12px;
}

.field-label {
  display: block;
  margin: 10px 0 6px;
  font-weight: 800;
}

.field-input {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  border: 2px solid rgba(90, 77, 64, 0.16);
  background: #fffaf3;
  padding: 12px 14px;
  font: inherit;
  font-size: 1.1rem;
  color: var(--ink);
  margin-bottom: 10px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 10px;
}

.menu-slot {
  margin: 12px 0;
  padding: 12px;
  border-radius: 14px;
  background: #fffaf3;
  border: 1px solid rgba(90, 77, 64, 0.1);
}

.menu-meal-label {
  margin: 0 0 8px;
  font-weight: 800;
  color: var(--orange-deep);
}

.shop-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 52px;
  font-size: 1.1rem;
  margin: 8px 0;
}

.shop-item input[type="checkbox"] {
  width: 24px;
  height: 24px;
}

.action-tag {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(125, 155, 120, 0.22);
  color: #2f4f2c;
  font-size: 0.95rem;
  font-weight: 800;
}

.recipe-list-card h3 {
  margin-top: 0;
  font-family: "Fraunces", Georgia, serif;
}

.recipe-context-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(196, 92, 38, 0.12);
  border: 1px solid rgba(196, 92, 38, 0.2);
}

.context-kicker {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.context-title {
  margin: 2px 0 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.2rem;
  color: var(--orange-deep);
}

.context-step {
  margin: 4px 0 0;
}

.recipe-step.is-current-step {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(196, 92, 38, 0.18);
}

.bubble.system {
  user-select: text;
}

.voice-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 8px;
}

.voice-toolbar .btn {
  min-height: 48px;
  flex: 1 1 140px;
  font-size: 1.05rem;
}

.voice-toolbar .btn[aria-pressed="true"] {
  background: rgba(196, 92, 38, 0.16);
  border-color: var(--orange);
  color: var(--ink);
}

#chat-voice-status.form-error {
  color: #8a2b12;
  font-weight: 700;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

#chat-input {
  width: 100%;
  resize: none;
  border-radius: 16px;
  border: 2px solid rgba(90, 77, 64, 0.16);
  background: #fffaf3;
  padding: 14px;
  font-size: 1.12rem;
  color: var(--ink);
}

#chat-input:focus {
  outline: 3px solid rgba(196, 92, 38, 0.28);
  border-color: var(--orange);
}

.hint {
  margin-top: 10px;
  font-size: 0.95rem;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(520px, 100%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: rgba(251, 246, 238, 0.96);
  border-top: 1px solid rgba(90, 77, 64, 0.12);
  backdrop-filter: blur(10px);
}

.nav-btn {
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.92rem;
  border-radius: 14px;
  padding: 8px 4px;
}

.nav-btn.is-active {
  background: rgba(196, 92, 38, 0.14);
  color: var(--orange-deep);
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 12px;
  }

  .hero-card {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    gap: 16px;
    align-items: center;
  }

  .hero-copy {
    margin-top: 0;
  }
}
