/* ===================== Tokens ===================== */
:root {
  --bg: #0b0f14;
  --surface: #121a23;
  --surface-raised: #18222e;
  --border: #243140;
  --text: #e6edf3;
  --text-muted: #93a1b0;
  --accent: #06b6d4;
  --accent-hover: #22d3ee;
  --accent-ink: #04222a;
  --added: #22c55e;
  --changed: #f59e0b;
  --removed: #f87171;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

/* ===================== Base ===================== */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

/* ===================== Buttons & inputs ===================== */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.6rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.button:hover { border-color: var(--accent); color: var(--text); }
.button:disabled { opacity: 0.55; cursor: not-allowed; }

.button-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.button-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }

input,
textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus,
textarea:focus { border-color: var(--accent); outline: none; }

/* ===================== Login ===================== */
.login {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.wordmark {
  margin: 0 0 2rem;
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.wordmark::after {
  content: ".";
  color: var(--accent);
}

.login-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.login-form label { font-size: 0.9rem; color: var(--text-muted); }
.login-form input { margin-bottom: 0.6rem; }
.login-form .button { margin-top: 0.4rem; }

.form-error {
  margin: 0 0 0.4rem;
  color: var(--removed);
  font-size: 0.95rem;
}

.muted { color: var(--text-muted); }

/* ===================== Portal layout ===================== */
.portal-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.portal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.portal-identity {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-width: 0;
}

.wordmark-small {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.wordmark-small::after { content: "."; color: var(--accent); }

.portal-who {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.portal-client { font-weight: 600; }
.portal-site {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.portal-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

.button-small {
  min-height: 36px;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

.portal-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ===================== Current menu panel ===================== */
.menu-panel {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.menu-toggle {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.menu-toggle-icon { transition: transform 0.2s ease; }
.menu-panel.is-open .menu-toggle-icon { transform: rotate(180deg); }

.menu-panel-body {
  display: none;
  max-height: 45dvh;
  overflow-y: auto;
  padding: 0 1rem 1rem;
}
.menu-panel.is-open .menu-panel-body { display: block; }

.menu-section + .menu-section { margin-top: 1.1rem; }
.menu-section-title {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.menu-note {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: pre-line;
}
.menu-items { list-style: none; margin: 0; padding: 0; }
.menu-item {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}
.menu-item:last-child { border-bottom: 0; }
.menu-item-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}
.menu-item-name { font-weight: 500; }
.menu-item-price { flex-shrink: 0; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.menu-item-description {
  margin: 0.1rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.menu-item.is-sold-out .menu-item-name,
.menu-item.is-sold-out .menu-item-price { text-decoration: line-through; opacity: 0.6; }
.menu-item-tags { display: flex; gap: 0.3rem; margin-top: 0.25rem; }

.tag {
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}
.tag-sold-out { border-color: var(--changed); color: var(--changed); }

/* ===================== Chat ===================== */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.bubble {
  max-width: min(85%, 640px);
  padding: 0.65rem 0.9rem;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble-assistant {
  align-self: flex-start;
  background: var(--surface-raised);
  border-bottom-left-radius: 4px;
}
.bubble-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-ink);
  border-bottom-right-radius: 4px;
}
.bubble-error {
  align-self: flex-start;
  border: 1px solid var(--removed);
  color: var(--removed);
  background: transparent;
}

.typing { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; min-height: 2.4rem; }
.typing-hint { flex-basis: 100%; margin-top: 0.3rem; font-size: 0.85rem; color: var(--text-muted); }
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-form textarea {
  resize: none;
  max-height: 160px;
  line-height: 1.4;
  overflow-y: hidden;
}

/* ===================== Preview card ===================== */
.preview-card {
  align-self: stretch;
  max-width: 640px;
  padding: 1rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
}
.preview-card.is-retired { border-color: var(--border); opacity: 0.75; }
.preview-card.is-published { border-color: var(--added); opacity: 1; }

.preview-heading {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.preview-summary { margin: 0 0 0.75rem; font-weight: 600; }

.diff-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.diff {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.45rem 0.6rem;
  border-left: 3px solid;
  border-radius: 6px;
  background: var(--surface-raised);
}
.diff-label {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.diff-text { overflow-wrap: anywhere; }
.diff-added { border-color: var(--added); }
.diff-added .diff-label { color: var(--added); }
.diff-changed { border-color: var(--changed); }
.diff-changed .diff-label { color: var(--changed); }
.diff-removed { border-color: var(--removed); }
.diff-removed .diff-label { color: var(--removed); }

.preview-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.button-large { flex: 1 1 140px; min-height: 52px; font-size: 1.05rem; }
.preview-status { margin: 0.6rem 0 0; font-size: 0.9rem; color: var(--text-muted); }

/* ===================== Narrow screens ===================== */
@media (max-width: 479px) {
  /* Client and site name matter more than our own brand here. */
  .portal-identity .wordmark-small { display: none; }
}

/* ===================== Wider screens ===================== */
@media (min-width: 900px) {
  .portal-layout { flex-direction: row; }

  .menu-panel {
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-bottom: 0;
    border-right: 1px solid var(--border);
  }
  .menu-toggle { cursor: default; pointer-events: none; }
  .menu-toggle-icon { display: none; }
  .menu-panel-body { display: block; flex: 1; max-height: none; }

  .chat-thread { padding: 1.5rem; }
}
