/* Tokens, reset, layout shell. One system in light and dark; the tenant's accent comes from /v1/me (brand.color). */
:root {
  --accent: #2563eb;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e4e5e9;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 12px;
  --rail: 280px;
  --panel: 320px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --text: #e7e9ee; --muted: #9aa1ad; --line: #2a2f3a;
  }
}
:root[data-theme="dark"] { --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --text: #e7e9ee; --muted: #9aa1ad; --line: #2a2f3a; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); font-size: 13px; }

.icon { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 8px; color: var(--muted); }
.icon:hover { background: var(--surface-2); color: var(--text); }
.icon svg { width: 18px; height: 18px; }
.primary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--accent); color: #fff; border-radius: 10px; padding: 9px 14px; font-weight: 600; }
.primary:hover { filter: brightness(1.08); }
.primary svg { width: 16px; height: 16px; }
.link { color: var(--accent); }

/* Gate */
.gate { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.gate-card { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; display: grid; gap: 12px; }
.gate-card h1 { margin: 0; font-size: 20px; }
.gate-card p { margin: 0; }
.gate-card input { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
.gate-logo { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); display: none; background-size: cover; }
.gate-logo.has { display: block; }

/* Shell */
.app { height: 100%; display: grid; grid-template-columns: var(--rail) 1fr; }
.app.with-panel { grid-template-columns: var(--rail) 1fr var(--panel); }
.rail { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.rail-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 8px; }
.brand-logo { width: 26px; height: 26px; border-radius: 7px; object-fit: cover; }
.brand-name { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rail-close { display: none; }
.new-chat { margin: 6px 14px 10px; }
.rail-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface); }
#rail-open { display: none; }
.title-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.chat-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel { background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }

@media (max-width: 860px) {
  .app, .app.with-panel { grid-template-columns: 1fr; }
  .rail { position: fixed; inset: 0 auto 0 0; width: min(var(--rail), 86vw); z-index: 20; transform: translateX(-100%); transition: transform .18s ease; box-shadow: 0 0 0 100vmax rgba(0,0,0,0); }
  .app.rail-open .rail { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  #rail-open, #rail-close { display: inline-flex; }
  .panel { position: fixed; inset: 0 0 0 auto; width: min(var(--panel), 92vw); z-index: 20; }
}
@media (prefers-reduced-motion: reduce) { .rail { transition: none; } }
#gate-clerk { display: grid; justify-items: center; }
#gate-clerk .cl-rootBox { width: 100%; }
