/* Claude-inspired clean layout: warm off-white, calm sans-serif, left thread
   sidebar, centered chat column. All element hooks from index.html/app.js are
   preserved; only the visual system changed. */
:root {
  color-scheme: light;
  --bg: #f4f3ee;
  --bg-sidebar: #ebe9e1;
  --panel: #ffffff;
  --ink: #2b2924;
  --muted: #73706a;
  --faint: #97938b;
  --border: rgba(40, 36, 30, 0.10);
  --border-soft: rgba(40, 36, 30, 0.06);
  --accent: #c45f3c;
  --accent-strong: #a84e30;
  --user: #ffffff;
  --assistant: transparent;
  --system: #efede6;
  --ok: #3f7d52;
  --off: #b14d2b;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 1px 2px rgba(40, 36, 30, 0.06), 0 8px 24px rgba(40, 36, 30, 0.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

.is-hidden { display: none !important; }

/* ---------- shell layout ---------- */
.layout {
  display: flex;
  min-height: 100vh;
}

.thread-sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.new-thread-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.new-thread-button:hover { background: #fff; border-color: var(--accent); color: var(--accent-strong); }

.thread-sidebar-title {
  margin: 8px 4px 2px;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}

.thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.thread-item {
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s, color 0.12s;
}
.thread-item:hover { background: rgba(40, 36, 30, 0.05); color: var(--ink); }
.thread-item.is-active {
  background: rgba(196, 95, 60, 0.12);
  color: var(--accent-strong);
  font-weight: 600;
}

/* ---------- main column ---------- */
.shell {
  flex: 1;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 28px 24px 40px;
  min-width: 0;
}

.hero { padding: 4px 2px 18px; }

.eyebrow,
.chat-label,
.status {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}

.hero h1 {
  margin: 6px 0 8px;
  font-family: var(--font);
  font-weight: 600;
  font-size: 1.5rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.lede {
  margin: 0;
  max-width: 60ch;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--muted);
}

/* ---------- chat card ---------- */
.chat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}

.chat-header h2 {
  margin: 2px 0 0;
  font-family: var(--font);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.runtime-status-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.runtime-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  align-items: center;
  padding: 12px 20px 0;
}

.runtime-summary-text {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.runtime-badge {
  margin: 0;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.runtime-badge-ready { background: rgba(63, 125, 82, 0.12); color: var(--ok); border: 1px solid rgba(63, 125, 82, 0.2); }
.runtime-badge-offline { background: rgba(177, 77, 43, 0.12); color: var(--off); border: 1px solid rgba(177, 77, 43, 0.2); }
.runtime-badge-pending { background: rgba(40, 36, 30, 0.06); color: var(--muted); border: 1px solid var(--border); }

/* ---------- messages ---------- */
.messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  min-height: 220px;
  max-height: 56vh;
  overflow-y: auto;
}

.message { max-width: 100%; }

.message-meta {
  margin-bottom: 4px;
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.message-body {
  margin: 0;
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.role-assistant .message-body {
  color: var(--ink);
}

.role-user {
  align-self: flex-end;
  max-width: 80%;
}
.role-user .message-meta { text-align: right; }
.role-user .message-body {
  background: var(--user);
  border: 1px solid var(--border);
  border-radius: 14px 14px 4px 14px;
  padding: 10px 14px;
}

.role-system .message-body {
  color: var(--muted);
  font-size: 0.85rem;
  background: var(--system);
  border-radius: 10px;
  padding: 8px 12px;
}

/* ---------- composer ---------- */
.composer {
  border-top: 1px solid var(--border-soft);
  padding: 14px 20px 18px;
}

.composer textarea,
.manual-bridge-panel textarea {
  width: 100%;
  resize: vertical;
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--ink);
  background: #fdfdfb;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.composer textarea:focus,
.manual-bridge-panel textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(196, 95, 60, 0.12);
}

.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.send-button {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.15s;
}
.send-button:hover { background: var(--accent-strong); }
.send-button:disabled { opacity: 0.5; cursor: not-allowed; }

.ghost-button {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ghost-button:hover { background: rgba(40, 36, 30, 0.05); color: var(--ink); border-color: var(--accent); }

/* ---------- manual bridge ---------- */
.manual-bridge-panel {
  border-top: 1px solid var(--border-soft);
  padding: 16px 20px;
  background: #fbfaf7;
}
.manual-bridge-header,
.manual-bridge-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.manual-bridge-header h3 {
  margin: 2px 0 0;
  font-family: var(--font);
  font-weight: 600;
  font-size: 1rem;
}
.manual-bridge-copy { margin: 12px 0 14px; color: var(--muted); font-size: 0.9rem; }
.manual-bridge-label {
  display: block;
  margin: 12px 0 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}
.manual-bridge-feedback {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.88rem;
}
.error-feedback { background: rgba(177, 77, 43, 0.1); color: var(--off); }
.success-feedback { background: rgba(63, 125, 82, 0.1); color: var(--ok); }

/* ---------- auth overlay ---------- */
.auth-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 36, 30, 0.45);
  backdrop-filter: blur(4px);
  z-index: 50;
  padding: 20px;
}
.auth-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.auth-card h2 { margin: 4px 0 0; font-weight: 600; font-size: 1.3rem; }
.auth-hint { margin: 2px 0 10px; color: var(--muted); font-size: 13px; }
.auth-label { color: var(--ink); font-size: 13px; font-weight: 600; margin-top: 10px; }
.auth-card input {
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fdfdfb;
  margin-top: 4px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(196, 95, 60, 0.12); }
.auth-card .send-button { margin-top: 16px; }
.auth-error { color: var(--off); font-size: 13px; margin: 8px 0 0; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .thread-sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
  }
  .new-thread-button { width: auto; flex-shrink: 0; }
  .thread-sidebar-title { display: none; }
  .thread-list { flex-direction: row; gap: 6px; }
  .thread-item { max-width: 160px; background: var(--panel); border: 1px solid var(--border-soft); }
  .shell { padding: 18px 16px 32px; }
  .chat-header { flex-direction: column; align-items: stretch; }
  .chat-header-actions { flex-wrap: wrap; }
  .messages { max-height: none; }
  .role-user { max-width: 92%; }
}
