:root {
  color-scheme: light;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #111827;
  --muted: #64748b;
  --line: #dbe3ee;
  --accent: #0d9488;
  --accent-dark: #0f766e;
  --danger: #b91c1c;
  --graphite: #0f172a;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-shell { min-height: 100%; }
.auth-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
  box-shadow: 0 18px 60px rgba(15, 23, 42, .12);
}
.brand-mark, .empty-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--graphite);
  color: #5eead4;
  font-weight: 800;
  font-size: 24px;
}
h1, h2, p { margin: 0; }
h1 { margin-top: 14px; font-size: 28px; letter-spacing: 0; }
h2 { font-size: 18px; letter-spacing: 0; }
.muted { color: var(--muted); font-size: 13px; }
.stack { display: grid; gap: 12px; margin-top: 18px; }
label { display: grid; gap: 6px; color: #334155; font-size: 13px; font-weight: 650; }
input, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}
textarea { resize: none; line-height: 1.35; max-height: 132px; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(13, 148, 136, .12); }
button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f1f5f9;
  color: var(--graphite);
  padding: 10px 13px;
  font-weight: 750;
}
button.primary, .primary, .send-button {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
button.primary:hover, .send-button:hover { background: var(--accent-dark); }
.divider {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.advanced-auth {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.advanced-auth summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}
.error { color: var(--danger); min-height: 20px; margin-top: 10px; font-size: 13px; }

.chat-layout {
  height: 100%;
  display: grid;
  grid-template-columns: 372px minmax(0, 1fr);
  background: var(--surface);
}
.sidebar {
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
}
.side-header, .thread-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.side-header {
  justify-content: space-between;
  background: var(--graphite);
  color: white;
}
.side-header .muted { color: #cbd5e1; }
.app-title { font-size: 17px; font-weight: 850; }
.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
}
.side-header .icon-button {
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.14);
  color: #ccfbf1;
}
.side-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}
.search-box { padding: 10px; border-bottom: 1px solid var(--line); }
.conversation-list { overflow: auto; }
.conversation-row {
  width: 100%;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 0;
  border-bottom: 1px solid #edf2f7;
  border-radius: 0;
  background: var(--surface);
  padding: 11px 12px;
  text-align: left;
}
.conversation-row:hover, .conversation-row.active { background: #ecfeff; }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--graphite);
  color: white;
  font-weight: 850;
}
.conversation-title, .thread-title { font-weight: 850; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.conversation-meta { text-align: right; color: var(--muted); font-size: 11px; }
.badge {
  margin-top: 6px;
  margin-left: auto;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: #ef4444;
  color: white;
  font-size: 11px;
  font-weight: 850;
}

.main-pane { min-width: 0; background: #e8edf4; }
.empty-pane {
  height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
}
.thread-pane {
  height: 100%;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    linear-gradient(135deg, rgba(255,255,255,.55), rgba(255,255,255,0)),
    #e8edf4;
}
.thread-header { background: var(--surface); }
.thread-title-wrap { min-width: 0; }
.message-list {
  overflow: auto;
  padding: 18px 18px 16px;
}
.day-note, .state-note {
  width: fit-content;
  max-width: 100%;
  margin: 10px auto;
  background: rgba(255,255,255,.78);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
}
.message-row {
  display: flex;
  margin: 6px 0;
}
.message-row.mine { justify-content: flex-end; }
.bubble {
  max-width: min(620px, 74%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px 6px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
}
.mine .bubble {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.bubble-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.38; font-size: 15px; }
.bubble-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.mine .bubble-meta { color: rgba(255,255,255,.78); }
.reaction-bar { margin-top: 6px; display: flex; gap: 5px; flex-wrap: wrap; }
.reaction-pill {
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(15, 23, 42, .08);
  font-size: 12px;
}
.mine .reaction-pill { background: rgba(255,255,255,.2); }
.reaction-actions {
  margin-top: 6px;
  display: none;
  gap: 4px;
}
.bubble:hover .reaction-actions { display: flex; }
.reaction-actions button {
  width: 30px;
  height: 28px;
  padding: 0;
  background: rgba(255,255,255,.9);
}
.voice-box {
  display: flex;
  align-items: center;
  gap: 8px;
}
.voice-box audio { max-width: 250px; height: 34px; }
.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.send-button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
}

dialog {
  border: 0;
  padding: 0;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .24);
}
dialog::backdrop { background: rgba(15, 23, 42, .36); }
.dialog-card {
  width: min(460px, calc(100vw - 28px));
  padding: 16px;
  display: grid;
  gap: 12px;
  background: var(--surface);
}
.dialog-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.dialog-list { display: grid; gap: 8px; max-height: 52vh; overflow: auto; }
.request-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 8px;
}
.request-actions { display: flex; gap: 8px; }
.mobile-only { display: none; }

@media (max-width: 760px) {
  .chat-layout { grid-template-columns: 1fr; }
  .sidebar { display: grid; }
  .main-pane { display: none; }
  .chat-layout.thread-open .sidebar { display: none; }
  .chat-layout.thread-open .main-pane { display: block; height: 100%; }
  .mobile-only { display: grid; }
  .bubble { max-width: 88%; }
  .message-list { padding: 12px 10px; }
}
