/* Shared layout and components. Each app sets its brand tokens in app.css. */
:root {
  --bg: #f7f5f0; --surface: #ffffff; --surface-2: #efece4; --ink: #1d1d1b; --muted: #5b5a55;
  --line: rgba(0,0,0,.12); --brand: #205b3b; --brand-ink: #ffffff; --accent: #c9952b;
  --danger: #b3261e; --ok: #1f7a46; --focus: #2563eb;
  --radius: 14px; --radius-sm: 8px; --shadow: 0 10px 30px rgba(0,0,0,.08);
  --heading: Georgia, 'Times New Roman', serif; --body: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121311; --surface: #1b1c1a; --surface-2: #242522; --ink: #f2f0ea; --muted: #b6b3aa;
    --line: rgba(255,255,255,.14); --shadow: 0 10px 30px rgba(0,0,0,.4); --focus: #8ab4ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121311; --surface: #1b1c1a; --surface-2: #242522; --ink: #f2f0ea; --muted: #b6b3aa;
  --line: rgba(255,255,255,.14); --shadow: 0 10px 30px rgba(0,0,0,.4); --focus: #8ab4ff;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--body); min-height: 100vh; display: flex; flex-direction: column; }
h1, h2, h3 { font-family: var(--heading); line-height: 1.15; margin: 0 0 .4em; }
p { margin: 0 0 .7em; }
a { color: inherit; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 8px; }

/* Header */
.site-header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--brand); color: var(--brand-ink); }
.site-header .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--heading); font-size: 1.05rem; font-weight: 700; min-width: 0; }
.site-header .brand img { height: 34px; width: auto; }
.site-header .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-header .spacer { flex: 1; }
.site-header .back { color: inherit; font-size: .9rem; text-decoration: none; white-space: nowrap; }
.site-header .back:hover { text-decoration: underline; }
.icon-button { background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 999px; width: 36px; height: 36px; cursor: pointer; flex: none; }

/* Layout */
.tabs { display: none; }
.layout { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; align-items: start; }
.pane { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.stage { padding: 20px; }
.chat { position: sticky; top: 16px; display: flex; flex-direction: column; height: calc(100vh - 110px); min-height: 480px; }
.chat-head { padding: 14px 16px 8px; border-bottom: 1px solid var(--line); }
.chat-head h2 { font-size: 1.1rem; margin: 0; }
.chat-head p { font-size: .85rem; color: var(--muted); margin: 2px 0 0; }
@media (max-width: 900px) {
  .tabs { display: flex; gap: 6px; padding: 10px 16px 0; position: sticky; top: 0; z-index: 3; background: var(--bg); }
  .tabs button { flex: 1; padding: 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; position: relative; font-weight: 600; }
  .tabs button[aria-selected="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
  .tabs button.has-update::after { content: ''; position: absolute; top: 6px; right: 12px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
  .layout { grid-template-columns: 1fr; padding: 12px 16px 16px; }
  .layout > [data-active="false"] { display: none; }
  .chat { position: static; height: calc(100dvh - 140px); min-height: 420px; }
  .stage { padding: 16px; }
}

/* Chat */
.chat-log { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 92%; padding: 10px 13px; border-radius: 14px; background: var(--surface-2); overflow-wrap: anywhere; }
.bubble p:last-child, .bubble ul:last-child { margin-bottom: 0; }
.bubble ul { margin: 0 0 .6em; padding-left: 1.2em; }
.bubble.user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; border-bottom-left-radius: 4px; }
.typing { display: flex; gap: 4px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: .88rem; cursor: pointer; text-align: left; }
.chip:hover { border-color: var(--brand); }
.chat-status { font-size: .82rem; color: var(--muted); margin: 6px 16px 0; min-height: 1.2em; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-input { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface); min-height: 44px; max-height: 140px; }
.chat-note { font-size: .78rem; color: var(--muted); padding: 0 16px 10px; margin: 0; }

/* Controls */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; }
.button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.button:disabled { opacity: .5; cursor: not-allowed; }
.button.small { min-height: 34px; padding: 6px 12px; font-size: .88rem; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.field select, .field input { min-height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: var(--surface); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.notice { border-left: 4px solid var(--accent); background: var(--surface-2); padding: 10px 14px; border-radius: 8px; font-size: .9rem; }
.notice.error { border-left-color: var(--danger); }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); font-size: .8rem; margin: 0 4px 4px 0; }

.site-footer { padding: 18px 16px 24px; text-align: center; font-size: .84rem; color: var(--muted); }
.site-footer a { color: inherit; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
