/* The Porch Door (OW-492). Palette inherited from the walter door. */

:root {
  --bg: #0b0d10;
  --bg-panel: #12151a;
  --bg-elev: #1a1f26;
  --fg: #c9d3df;
  --fg-dim: #6b7683;
  --accent: #7fd88f;
  --accent-dim: #3f6b48;
  --border: #232a33;
  --danger: #e06c75;
  --warm: #e5c07b;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", monospace;
  --sidebar-w: 280px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  display: flex;
  overflow: hidden;
}

button {
  font: inherit;
  color: var(--fg);
  background: var(--accent-dim);
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
}
button:hover { background: var(--accent); color: var(--bg); }
button.ghost {
  background: none;
  color: var(--fg-dim);
  border: 1px solid var(--border);
}
button.ghost:hover { color: var(--accent); border-color: var(--accent-dim); background: none; }

/* --- login ------------------------------------------------------------- */

.login-body { align-items: center; justify-content: center; }

.login-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 40px 36px;
  width: min(360px, 90vw);
  text-align: center;
}
.login-logo { margin-bottom: 8px; }
.login-title { font-size: 24px; font-weight: 600; letter-spacing: 0.04em; }
.login-sub { color: var(--fg-dim); margin: 4px 0 24px; font-size: 14px; }
.login-card input {
  display: block;
  width: 100%;
  margin-bottom: 12px;
  padding: 12px 14px;
  font-size: 16px;
  color: var(--fg);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.login-card input:focus { outline: none; border-color: var(--accent-dim); }
.login-card button { width: 100%; padding: 12px; }
.login-error { color: var(--danger); font-size: 14px; margin-bottom: 12px; }

/* --- sidebar ----------------------------------------------------------- */

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  height: 100%;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 0 max(12px, env(safe-area-inset-bottom));
}

.side-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--border);
}
.side-brand { font-weight: 600; letter-spacing: 0.04em; }

.side-section { padding: 14px 8px 0; overflow-y: auto; }
.side-grow { flex: 1; min-height: 0; }
.side-section h2 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-dim);
  padding: 0 8px 8px;
}
.side-section ul { list-style: none; }
.side-section li button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  color: var(--fg);
  padding: 9px 10px;
  border-radius: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-section li button:hover { background: var(--bg-elev); color: var(--fg); }
.side-section li button.active { background: var(--bg-elev); color: var(--accent); }
.side-section li .meta {
  display: block;
  font-size: 12px;
  color: var(--fg-dim);
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-foot { padding: 12px 16px 0; border-top: 1px solid var(--border); }
.side-foot button { width: 100%; }

/* --- main pane --------------------------------------------------------- */

#main {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
#chat-title {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#menu-btn { display: none; padding: 8px 12px; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#empty-hint { color: var(--fg-dim); text-align: center; margin-top: 40vh; }

.bubble {
  max-width: min(640px, 86%);
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.bubble.user {
  align-self: flex-end;
  background: var(--accent-dim);
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--bg-elev);
  border-bottom-left-radius: 4px;
}
.bubble.failed { outline: 1px solid var(--danger); }
.bubble { cursor: default; }

.msg-actions {
  display: flex;
  gap: 8px;
  margin-top: -4px;
}
.msg-actions.user { align-self: flex-end; }
.msg-actions.assistant { align-self: flex-start; }
.msg-actions button {
  background: none;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  font-size: 13px;
  padding: 4px 10px;
}
.msg-actions button:hover { color: var(--danger); border-color: var(--danger); background: none; }
.msg-actions button.reroll:hover { color: var(--accent); border-color: var(--accent-dim); }

.side-section li button.quiet .meta { font-style: italic; }

#load-older {
  align-self: center;
  color: var(--fg-dim);
  font-size: 13px;
  padding: 6px 14px;
}

.retry-row { align-self: flex-end; }
.retry-row button { background: none; border: 1px solid var(--danger); color: var(--danger); padding: 6px 12px; font-size: 14px; }

.typing {
  align-self: flex-start;
  color: var(--fg-dim);
  padding: 10px 14px;
}
.typing::after {
  content: "...";
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

#composer[hidden] { display: none; }

#composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}
#input {
  flex: 1;
  resize: none;
  max-height: 160px;
  font: inherit;
  font-size: 16px;
  color: var(--fg);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
}
#input:focus { outline: none; border-color: var(--accent-dim); }
#send-btn { padding: 11px 16px; }
#send-btn:disabled { opacity: 0.5; cursor: default; }

#toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev);
  border: 1px solid var(--accent-dim);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 30;
}

/* --- mobile ------------------------------------------------------------ */

@media (max-width: 800px) {
  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: min(var(--sidebar-w), 84vw);
  }
  #sidebar.open { transform: translateX(0); }
  #menu-btn { display: block; }
  #overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10;
  }
}

/* --- character card panel (OW-497) ------------------------------------- */

#card-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
#card-panel[hidden] { display: none; }

.cp-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
#cp-title { font-weight: 600; flex: 1; }
.cp-tabs { display: flex; gap: 8px; }
.cp-tabs .active { color: var(--accent); border-color: var(--accent-dim); }

.cp-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px max(24px, env(safe-area-inset-bottom));
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}
.cp-badge { color: var(--fg-dim); font-size: 14px; margin-bottom: 14px; }
.cp-badge.human { color: var(--warm); }

.cp-field {
  display: block;
  color: var(--fg-dim);
  font-size: 13px;
  margin-bottom: 14px;
}
.cp-field input,
.cp-field textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  font: inherit;
  font-size: 15px;
  color: var(--fg);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  resize: vertical;
}
.cp-field input:focus,
.cp-field textarea:focus { outline: none; border-color: var(--accent-dim); }
#cp-save { margin-top: 4px; }

#cp-knows h3 {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin: 18px 0 8px;
}
#cp-knows ul { list-style: none; }
#cp-knows li {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
}
#cp-knows .fact-key {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent-dim);
}
.cp-note { color: var(--fg-dim); font-size: 13px; margin-top: 14px; }

/* --- the porch group thread (OW-498) ----------------------------------- */

.thread-group { margin-bottom: 6px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.thread-group button { font-weight: 600; }
.thread-group button .meta { color: var(--accent-dim); }

.bubble .speaker {
  display: block;
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 3px;
}
.bubble .speaker-body { display: block; white-space: pre-wrap; }

.quiet-line {
  align-self: center;
  color: var(--fg-dim);
  font-style: italic;
  font-size: 14px;
  padding: 6px 0;
}

/* --- side rooms -------------------------------------------------------- */
/* Amber, not green: the whole app repaints so there is no way to mistake a
   scratch room for the real thread and lose something you meant to keep. */

body.side-mode {
  --accent: #e5c07b;
  --accent-dim: #6b5433;
}
body.side-mode #messages { background: repeating-linear-gradient(
  135deg, transparent, transparent 22px,
  rgba(229, 192, 123, 0.03) 22px, rgba(229, 192, 123, 0.03) 44px); }
body.side-mode #topbar { border-bottom-color: var(--accent-dim); }

#side-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: rgba(229, 192, 123, 0.08);
  border-bottom: 1px solid var(--accent-dim);
  font-size: 13px;
  color: var(--warm);
}
#side-banner[hidden] { display: none; }
#side-banner-text { flex: 1; }
#side-banner button { padding: 6px 10px; font-size: 13px; white-space: nowrap; }

@media (max-width: 640px) {
  #side-banner { flex-wrap: wrap; }
  #side-banner-text { flex: 1 0 100%; }
}

/* --- smaller circles (group picker) ------------------------------------ */

#group-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
#group-panel[hidden] { display: none; }
#gp-members { list-style: none; margin-bottom: 16px; }
#gp-members li { padding: 4px 0; }
#gp-members label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--fg);
  font-size: 15px;
  cursor: pointer;
}
#gp-members input[type="checkbox"] { accent-color: var(--accent); width: 18px; height: 18px; }
.thread-new button { color: var(--fg-dim); font-size: 13px; }
.side-foot { display: flex; gap: 8px; }
.side-foot form { flex: 1; }
.side-foot > button { flex: 1; }

#listen-btn { padding: 11px 14px; font-size: 18px; line-height: 1; }
