/* ──────────────────────────────────────────────────────────────
   Hammerstein — chat surface (hai-009c)
   Inherits the shadcn-flavored token system from /wargamer/.
   Two-column layout: sidebar conversation list + main pane stream.
   ────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
[hidden] { display: none !important; }

.chat-page {
  --background:       45 35% 95%;
  --foreground:       222 40% 12%;
  --card:             45 50% 99%;
  --card-foreground:  222 40% 12%;
  --primary:          14 70% 44%;
  --primary-foreground: 45 35% 98%;
  --secondary:        222 30% 22%;
  --secondary-foreground: 45 35% 96%;
  --accent:           38 78% 48%;
  --accent-foreground: 222 40% 12%;
  --muted:            45 18% 88%;
  --muted-foreground: 222 15% 38%;
  --border:           222 15% 80%;
  --border-strong:    222 18% 68%;
  --input:            222 15% 80%;
  --ring:             14 70% 44%;
  --destructive:      0 70% 48%;
  --destructive-foreground: 45 35% 98%;
  --rule:             222 18% 75%;
  --wg-radius: 6px;

  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font: 13px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.chat-page.dark {
  --background:       222 30% 9%;
  --foreground:       45 30% 90%;
  --card:             222 28% 12%;
  --card-foreground:  45 30% 90%;
  --primary:          14 70% 56%;
  --primary-foreground: 222 40% 8%;
  --secondary:        45 30% 88%;
  --secondary-foreground: 222 30% 9%;
  --accent:           38 78% 58%;
  --accent-foreground: 222 30% 9%;
  --muted:            222 22% 16%;
  --muted-foreground: 45 12% 62%;
  --border:           222 18% 22%;
  --border-strong:    222 18% 32%;
  --input:            222 18% 22%;
  --ring:             14 70% 56%;
  --destructive:      0 70% 56%;
  --destructive-foreground: 45 30% 96%;
  --rule:             222 18% 26%;
}

.chat-page a { color: hsl(var(--primary)); text-decoration: none; }
.chat-page a:hover { text-decoration: underline; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── primitives (mirrors .wg-* shape) ─────────────────── */

.chat-page .wg-icon {
  width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor;
  fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
  display: inline-block; vertical-align: middle;
}
.chat-page .wg-icon-sm { width: 14px; height: 14px; }

.chat-page .wg-btn {
  appearance: none; border: 1px solid hsl(var(--border-strong));
  background: hsl(var(--card)); color: hsl(var(--foreground));
  font: inherit; font-size: 13.5px; font-weight: 500;
  padding: 7px 11px; border-radius: var(--wg-radius); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s, border-color .12s;
}
.chat-page .wg-btn:hover:not(:disabled) { background: hsl(var(--muted)); }
.chat-page .wg-btn:disabled { opacity: .5; cursor: not-allowed; }
.chat-page .wg-btn-primary {
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  border-color: hsl(var(--primary));
}
.chat-page .wg-btn-primary:hover:not(:disabled) { background: hsl(var(--primary) / .9); }
.chat-page .wg-btn-ghost { border-color: transparent; background: transparent; }
.chat-page .wg-btn-ghost:hover { background: hsl(var(--muted)); }
.chat-page .wg-btn-sm { padding: 4px 8px; font-size: 12px; }
.chat-page .wg-btn-destructive {
  color: hsl(var(--destructive));
  border-color: hsl(var(--destructive) / .55);
  background: hsl(var(--destructive) / .06);
}
.chat-page .wg-btn-destructive:hover:not(:disabled) {
  background: hsl(var(--destructive) / .12);
}

.chat-page .wg-input,
.chat-page .wg-textarea {
  width: 100%; appearance: none; border: 1px solid hsl(var(--input));
  background: hsl(var(--card)); color: hsl(var(--foreground));
  font: inherit; padding: 7px 10px; border-radius: var(--wg-radius);
  outline: none;
}
.chat-page .wg-input:focus,
.chat-page .wg-textarea:focus { border-color: hsl(var(--ring)); box-shadow: 0 0 0 3px hsl(var(--ring) / .15); }
.chat-page .wg-textarea { resize: none; line-height: 1.55; font-family: inherit; }
.chat-page .wg-input::placeholder,
.chat-page .wg-textarea::placeholder { color: hsl(var(--muted-foreground) / .65); }

.chat-page .wg-icon-btn {
  appearance: none; border: 1px solid transparent; background: transparent;
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; cursor: pointer; color: hsl(var(--muted-foreground));
}
.chat-page .wg-icon-btn:hover { background: hsl(var(--muted)); color: hsl(var(--foreground)); }

/* ── topbar ───────────────────────────────────────────── */
.chat-page .wg-app { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-page .wg-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  flex-shrink: 0;
}
.chat-page .wg-topbar-l, .chat-page .wg-topbar-r { display: flex; align-items: center; gap: 12px; }

.chat-page .wg-brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 600; letter-spacing: -.005em;
  color: hsl(var(--foreground));
  text-decoration: none;
}
.chat-page .wg-brand:hover { text-decoration: none; }
.chat-page .wg-brand-mark {
  width: 26px; height: 26px; border-radius: 4px;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  display: inline-flex; align-items: center; justify-content: center;
  font-family: ui-monospace, Menlo, monospace; font-weight: 700; font-size: 11px;
  letter-spacing: .03em;
  border: 1px solid hsl(var(--secondary) / .8);
  position: relative;
}
.chat-page .wg-brand-mark::after {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(135deg, transparent 48%, hsl(var(--accent) / .55) 49%, hsl(var(--accent) / .55) 51%, transparent 52%);
  border-radius: 3px;
}
.chat-page .wg-brand-name { font-size: 14px; }
.chat-page .wg-brand-sub { color: hsl(var(--muted-foreground)); font-weight: 400; font-size: 13px; margin-left: 2px; }

.chat-page .wg-nav-tabs { display: flex; align-items: center; gap: 2px; margin-left: 18px; }
.chat-page .wg-nav-tab {
  padding: 6px 10px; font-size: 12.5px; font-weight: 500;
  color: hsl(var(--muted-foreground)); border-radius: 4px; cursor: pointer;
  border: 0; background: transparent;
  text-decoration: none;
}
.chat-page .wg-nav-tab.active { color: hsl(var(--foreground)); background: hsl(var(--muted)); }
.chat-page .wg-nav-tab:hover:not(.active) { color: hsl(var(--foreground)); text-decoration: none; }

.chat-page .wg-subscriber-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  max-width: 220px;
  padding: 4px 10px;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: hsl(var(--muted-foreground));
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-page .wg-subscriber-btn:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

/* ── two-column workspace ─────────────────────────────── */
.chat-page .ch-workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── sidebar ──────────────────────────────────────────── */
.chat-page .ch-sidebar {
  width: 280px;
  border-right: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  min-height: 0;
}
.chat-page .ch-sidebar-hd {
  padding: 12px;
  border-bottom: 1px solid hsl(var(--border));
  flex-shrink: 0;
}
.chat-page .ch-new-conv-btn {
  width: 100%;
  justify-content: center;
}
.chat-page .ch-conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}
.chat-page .ch-conv-row {
  display: block;
  width: 100%;
  text-align: left;
  appearance: none;
  border: 0;
  background: transparent;
  padding: 9px 14px;
  cursor: pointer;
  color: hsl(var(--foreground));
  font: inherit;
  border-left: 2px solid transparent;
  transition: background .1s;
}
.chat-page .ch-conv-row:hover { background: hsl(var(--muted) / .55); }
.chat-page .ch-conv-row.active {
  background: hsl(var(--muted));
  border-left-color: hsl(var(--primary));
}
.chat-page .ch-conv-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-page .ch-conv-date {
  font-size: 11px;
  color: hsl(var(--muted-foreground));
  margin-top: 2px;
}
.chat-page .ch-conv-empty {
  padding: 22px 14px;
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  text-align: center;
  line-height: 1.5;
}

/* ── main pane ────────────────────────────────────────── */
.chat-page .ch-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: hsl(var(--background));
}

.chat-page .ch-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
  color: hsl(var(--muted-foreground));
}
.chat-page .ch-empty h2 {
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 600;
  color: hsl(var(--foreground));
  margin: 0 0 8px;
  letter-spacing: -.005em;
}
.chat-page .ch-empty p {
  margin: 0 0 6px;
  font-size: 13px;
  max-width: 460px;
  line-height: 1.55;
}
.chat-page .ch-empty .ch-empty-hint {
  font-size: 12px;
  margin-top: 14px;
  opacity: .85;
}

/* ── conversation pane ────────────────────────────────── */
.chat-page .ch-conv {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-page .ch-conv-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  flex-shrink: 0;
}
.chat-page .ch-conv-hd-title {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.chat-page .ch-cost-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}
.chat-page .ch-cost-pill b { color: hsl(var(--foreground)); font-weight: 600; }
.chat-page .ch-cost-pill.warn {
  border-color: hsl(var(--accent) / .55);
  background: hsl(var(--accent) / .12);
  color: hsl(var(--accent));
}
.chat-page .ch-cost-pill.warn b { color: hsl(var(--accent)); }
.chat-page .ch-cost-pill.cap {
  border-color: hsl(var(--destructive) / .55);
  background: hsl(var(--destructive) / .12);
  color: hsl(var(--destructive));
}
.chat-page .ch-cost-pill.cap b { color: hsl(var(--destructive)); }

/* ── message stream ───────────────────────────────────── */
.chat-page .ch-stream {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 28px;
}
.chat-page .ch-stream-inner {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.chat-page .ch-turn {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-page .ch-turn-role {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
}
.chat-page .ch-turn.user .ch-turn-role { color: hsl(var(--primary)); }
.chat-page .ch-turn.assistant .ch-turn-role { color: hsl(var(--secondary)); }
.chat-page.dark .ch-turn.assistant .ch-turn-role { color: hsl(var(--foreground)); }

.chat-page .ch-turn-body {
  font-size: 14px;
  line-height: 1.65;
  color: hsl(var(--foreground));
  word-wrap: break-word;
}
.chat-page .ch-turn-body p { margin: 0 0 .7em; }
.chat-page .ch-turn-body p:last-child { margin-bottom: 0; }
.chat-page .ch-turn-body h3 {
  font-family: ui-serif, Georgia, serif;
  font-size: 15.5px;
  font-weight: 600;
  margin: 1em 0 .4em;
  letter-spacing: -.005em;
}
.chat-page .ch-turn-body h4 {
  font-size: 13.5px;
  font-weight: 600;
  margin: .9em 0 .3em;
  letter-spacing: .005em;
}
.chat-page .ch-turn-body ul,
.chat-page .ch-turn-body ol {
  margin: 0 0 .7em;
  padding-left: 1.4em;
}
.chat-page .ch-turn-body li { margin-bottom: .25em; }
.chat-page .ch-turn-body code {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: hsl(var(--muted));
  padding: 1px 4px;
  border-radius: 3px;
}
.chat-page .ch-turn-body pre {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: hsl(var(--muted));
  padding: 10px 12px;
  border-radius: var(--wg-radius);
  border: 1px solid hsl(var(--border));
  overflow-x: auto;
  margin: 0 0 .7em;
  white-space: pre;
  line-height: 1.5;
}
.chat-page .ch-turn-body pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}
.chat-page .ch-turn-body blockquote {
  margin: 0 0 .7em;
  padding-left: 12px;
  border-left: 3px solid hsl(var(--border-strong));
  color: hsl(var(--muted-foreground));
  font-style: italic;
}
.chat-page .ch-turn-body strong { font-weight: 700; }

.chat-page .ch-cursor {
  display: inline-block;
  width: 7px;
  height: 1em;
  background: hsl(var(--foreground));
  vertical-align: text-bottom;
  margin-left: 2px;
  opacity: .65;
  animation: ch-blink 1.05s infinite;
}
@keyframes ch-blink {
  0%, 60% { opacity: .65; }
  61%, 100% { opacity: 0; }
}

/* ── composer ─────────────────────────────────────────── */
.chat-page .ch-composer {
  border-top: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  padding: 12px 20px 14px;
  flex-shrink: 0;
}
.chat-page .ch-composer-inner {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.chat-page .ch-composer-ta {
  flex: 1;
  min-height: 56px;
  max-height: 220px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.55;
  padding: 10px 12px;
  resize: none;
}
.chat-page .ch-send-btn {
  height: 38px;
  padding: 0 16px;
  flex-shrink: 0;
}
.chat-page .ch-composer-hint {
  max-width: 760px;
  margin: 6px auto 0;
  font-size: 11px;
  color: hsl(var(--muted-foreground));
  text-align: center;
  line-height: 1.5;
}
.chat-page .ch-composer-hint kbd {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10.5px;
  padding: 1px 5px;
  border: 1px solid hsl(var(--border));
  border-bottom-width: 2px;
  border-radius: 3px;
  background: hsl(var(--muted) / .5);
}

/* ── banners (errors, notices) ────────────────────────── */
.chat-page .ch-banner {
  margin: 0 auto 0;
  max-width: 760px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--wg-radius);
  font-size: 12.5px;
  background: hsl(var(--card));
  color: hsl(var(--foreground));
}
.chat-page .ch-banner-wrap {
  padding: 10px 20px 0;
  flex-shrink: 0;
}
.chat-page .ch-banner.error {
  border-color: hsl(var(--destructive) / .55);
  background: hsl(var(--destructive) / .08);
}
.chat-page .ch-banner.warn {
  border-color: hsl(var(--accent) / .55);
  background: hsl(var(--accent) / .1);
}
.chat-page .ch-banner-text {
  flex: 1;
  line-height: 1.5;
}
.chat-page .ch-banner-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.chat-page .ch-banner-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: .65;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
}
.chat-page .ch-banner-close:hover { opacity: 1; }

/* ── subscriber dialog (mirrors wargamer's pattern) ───── */
.wg-subscriber-dialog {
  z-index: 100;
  max-width: min(540px, calc(100vw - 32px));
  width: 100%;
  padding: 0;
  border: 1px solid hsl(var(--border));
  border-radius: var(--wg-radius);
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  box-shadow: 0 12px 40px hsl(0 0% 0% / .18);
}
.wg-subscriber-dialog::backdrop {
  background: hsl(0 0% 0% / .45);
}
.wg-subscriber-dialog-inner {
  padding: 18px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.wg-subscriber-dialog-hd {
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: .02em;
  margin: 0;
  color: hsl(var(--foreground));
}
.wg-subscriber-dialog-intro {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: hsl(var(--muted-foreground));
}
.chat-page .wg-subscriber-token-ta {
  width: 100%;
  box-sizing: border-box;
  min-height: 72px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  line-height: 1.45;
  padding: 8px 10px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--wg-radius);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  resize: vertical;
  word-break: break-all;
}
.chat-page .wg-subscriber-token-err {
  font-size: 12px;
  color: hsl(var(--destructive));
  margin: 0;
}
.wg-subscriber-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.chat-page .wg-subscriber-signed {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--wg-radius);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--secondary) / .06);
  font-size: 12.5px;
}
.chat-page .wg-subscriber-signed strong {
  font-weight: 600;
  color: hsl(var(--foreground));
  word-break: break-all;
}

/* ── delete-confirm dialog ────────────────────────────── */
.ch-confirm-dialog {
  z-index: 100;
  max-width: min(420px, calc(100vw - 32px));
  width: 100%;
  padding: 0;
  border: 1px solid hsl(var(--border));
  border-radius: var(--wg-radius);
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  box-shadow: 0 12px 40px hsl(0 0% 0% / .18);
}
.ch-confirm-dialog::backdrop {
  background: hsl(0 0% 0% / .45);
}
.chat-page .ch-confirm-inner {
  padding: 18px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-page .ch-confirm-hd {
  font-family: ui-serif, Georgia, serif;
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}
.chat-page .ch-confirm-body {
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  margin: 0;
  line-height: 1.55;
}
.chat-page .ch-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── mobile ───────────────────────────────────────────── */
@media (max-width: 720px) {
  .chat-page .wg-nav-tabs {
    margin-left: 8px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .chat-page .wg-nav-tabs::-webkit-scrollbar { display: none; }
  .chat-page .wg-topbar { padding: 8px 12px; gap: 8px; }
  .chat-page .wg-brand-sub { display: none; }
  .chat-page .wg-topbar-r > .wg-btn-sm,
  .chat-page .wg-topbar-r > .wg-subscriber-btn {
    display: none;
  }

  .chat-page .ch-sidebar {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    z-index: 20;
    width: 84vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform .18s ease-out;
    box-shadow: 0 0 24px hsl(0 0% 0% / .25);
  }
  .chat-page .ch-sidebar.open { transform: translateX(0); }

  .chat-page .ch-workspace { position: relative; }

  .chat-page .ch-sidebar-toggle {
    display: inline-flex !important;
  }

  .chat-page .ch-stream { padding: 16px 14px 20px; }
  .chat-page .ch-composer { padding: 10px 14px 12px; }
  .chat-page .ch-conv-hd { padding: 9px 14px; }
}
.chat-page .ch-sidebar-toggle { display: none; }
