:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #16181d;
  --muted: #646b78;
  --border: #e1e4ea;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --user: #e8efff;
  --good: #16794b;
  --warn: #9a6700;
  --bad: #b42318;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-2: #1e222b;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --border: #2a2f3a;
    --accent: #5b8cff;
    --user: #1f2a44;
    --good: #4cc38a;
    --warn: #e5b454;
    --bad: #ff7a6e;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); min-height: 1.4em; }

.btn {
  border: 1px solid var(--border); background: var(--panel); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; font-weight: 550;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.icon-btn {
  border: 1px solid var(--border); background: var(--panel); border-radius: 10px;
  width: 40px; height: 40px; cursor: pointer; display: inline-grid; place-items: center; flex: none;
}
.logo {
  width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 26px; margin: 0 auto 8px;
}
.logo.small { width: 34px; height: 34px; border-radius: 10px; font-size: 16px; margin: 0; }

/* Sign in */
.signin { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.signin-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  padding: 32px 28px; width: min(380px, 100%); text-align: center;
}
.signin-card h1 { margin: 4px 0; font-size: 24px; }
.signin-card p { color: var(--muted); }

/* Layout */
.app { display: grid; grid-template-columns: 280px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column;
  gap: 12px; padding: 14px; min-height: 0;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand div { display: flex; flex-direction: column; line-height: 1.2; }
.brand .muted { font-size: 12px; }
.threads { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.thread {
  text-align: left; border: 0; background: none; border-radius: 10px; padding: 8px 10px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.thread:hover { background: var(--panel-2); }
.thread.active { background: var(--user); }
.thread strong { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); padding-top: 10px; font-size: 14px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--panel); min-width: 0;
}
.topbar #thread-title { margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tabs { display: flex; gap: 4px; background: var(--panel-2); border-radius: 10px; padding: 3px; }
.tab { border: 0; background: none; padding: 5px 14px; border-radius: 8px; cursor: pointer; font-weight: 550; color: var(--muted); }
.tab.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.only-mobile { display: none; }

.view { flex: 1; min-height: 0; }
.chat { display: flex; flex-direction: column; }
.messages { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: min(760px, 100%); width: fit-content; }
.msg.user { align-self: flex-end; background: var(--user); border-radius: 14px 14px 4px 14px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; padding: 10px 14px; overflow-wrap: anywhere; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 8px; padding-left: 22px; }
.msg.assistant pre { background: var(--panel-2); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 13px; }
.msg.assistant code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
.msg.assistant h3, .msg.assistant h4 { margin: 10px 0 6px; font-size: 15px; }
.msg.error { border-color: var(--bad); }
.typing { color: var(--muted); font-style: italic; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 460px; padding: 20px; }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.suggestions button { border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 12px 16px 6px; border-top: 1px solid var(--border); background: var(--panel); }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px; min-height: 40px; max-height: 220px;
  background: var(--bg); color: var(--text); font: inherit; min-width: 0;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.mic.recording { background: var(--bad); color: #fff; border-color: transparent; animation: pulse 1.2s infinite; }
.mic.busy { opacity: 0.6; }
@keyframes pulse { 50% { opacity: 0.7; } }
.hint { padding: 0 16px 10px; margin: 0; background: var(--panel); }

/* Activity */
.activity { overflow-y: auto; padding: 18px 16px 32px; }
.activity-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.activity-head h2 { margin: 0; font-size: 18px; }
.activity-head .btn { margin-left: auto; }
.activity-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; min-width: 0; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.count { background: var(--panel-2); border-radius: 999px; padding: 0 8px; font-size: 12px; color: var(--muted); }
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rows li { border-top: 1px solid var(--border); padding-top: 8px; min-width: 0; }
.rows li:first-child { border-top: 0; padding-top: 0; }
.row-title { font-weight: 560; overflow-wrap: anywhere; }
.row-sub { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); margin-right: 6px; font-weight: 600; }
.badge.good { color: var(--good); } .badge.warn { color: var(--warn); } .badge.bad { color: var(--bad); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
details.raw pre { font-size: 12px; overflow-x: auto; background: var(--panel-2); padding: 8px; border-radius: 8px; max-height: 300px; }

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 25% 0 0; z-index: 10; box-shadow: 0 0 40px rgba(0,0,0,.25); transform: translateX(-105%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .only-mobile { display: inline-grid; }
  .topbar #thread-title { display: none; }
  .messages { padding: 14px 12px; }
  .composer { padding: 10px 12px 6px; }
  .hint { display: none; }
}
