:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: #171716;
  color: #f3f1e8;
  --bg: #171716;
  --panel: #20201e;
  --panel-2: #292925;
  --line: #3a3934;
  --muted: #a5a299;
  --accent: #dbff64;
  --danger: #ff766c;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { overflow: hidden; background: radial-gradient(circle at 75% 10%, #2c3022 0, transparent 35%), var(--bg); }
button, input, textarea, select { font: inherit; }
button { color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(460px, 100%); padding: 34px; background: #20201ef2; border: 1px solid var(--line); border-radius: 28px; box-shadow: 0 30px 90px #0008; }
.brand-icon { width: 58px; height: 58px; }
.eyebrow { margin: 18px 0 8px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
h1, h2, p { margin-top: 0; }
.login-card h1 { margin-bottom: 10px; font-size: 32px; }
.login-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.6; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 650; }
.login-row { display: flex; gap: 10px; margin-top: 7px; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #11110f; color: #fff; padding: 12px 14px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: #9db849; box-shadow: 0 0 0 3px #a7c64a22; }
.primary, .danger { border: 0; border-radius: 12px; padding: 11px 18px; font-weight: 800; }
.primary { background: var(--accent); color: #171716; }
.danger { background: var(--danger); color: #1d0b09; }
.error { min-height: 18px; margin: 8px 0 0; color: #ff9188; }
.login-card small { color: #77756e; }

.shell { display: grid; grid-template-columns: 310px 1fr; height: 100%; height: 100dvh; min-height: 0; overflow: hidden; }
.sidebar { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: #1d1d1be8; border-right: 1px solid var(--line); backdrop-filter: blur(16px); }
.sidebar-head, .topbar { display: flex; align-items: center; gap: 12px; min-height: 68px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sidebar-head { justify-content: space-between; }
.wordmark { display: flex; align-items: center; gap: 10px; }
.wordmark img { width: 30px; height: 30px; }
.icon-button { border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); width: 38px; height: 38px; }
.search { position: relative; margin: 14px 14px 8px; }
.search span { position: absolute; left: 12px; top: 10px; color: var(--muted); }
.search input { padding-left: 34px; }
.list-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.list-head button, footer button { border: 0; background: transparent; color: var(--muted); }
.session-list { flex: 1; min-height: 0; overflow: auto; padding: 0 8px 12px; }
.session-item { display: grid; gap: 5px; width: 100%; padding: 12px; border: 1px solid transparent; border-radius: 12px; background: transparent; text-align: left; }
.session-item:hover { background: #ffffff08; }
.session-item.active { background: #b7d75214; border-color: #b7d75236; }
.session-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.session-item span { color: var(--muted); font-size: 11px; }
.list-empty { padding: 20px 12px; color: var(--muted); text-align: center; }
footer { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
footer button { margin-left: auto; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #69675f; }
.dot.online { background: var(--accent); box-shadow: 0 0 12px #d7ff5d88; }

.main { min-width: 0; min-height: 0; height: 100%; overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.topbar { background: #171716d9; backdrop-filter: blur(16px); }
.menu { display: none; }
.identity { min-width: 0; flex: 1; }
.identity h1 { margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.identity p { margin: 4px 0 0; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { border: 1px solid #b6d64e55; border-radius: 999px; padding: 5px 9px; color: var(--accent); font-size: 11px; }
.abort { width: 36px; height: 36px; border: 1px solid #ff766c55; border-radius: 10px; background: #ff766c12; color: var(--danger); }
.empty { place-self: center; padding: 28px; text-align: center; color: var(--muted); }
.empty img { width: 72px; height: 72px; filter: drop-shadow(0 12px 30px #d7ff5d33); }
.empty h2 { color: #fff; margin: 18px 0 8px; }
.conversation { min-height: 0; overflow: auto; padding: 24px max(20px, calc((100% - 820px) / 2)); }
.notice { margin-bottom: 16px; padding: 12px 14px; border: 1px solid #d5b84e55; border-radius: 12px; background: #d5b84e11; color: #ead98f; font-size: 12px; line-height: 1.5; }
.transcript { display: grid; gap: 18px; padding-bottom: 20px; }
.message { display: grid; gap: 7px; max-width: 88%; }
.message.user { justify-self: end; }
.message-label { color: var(--muted); font-size: 11px; font-weight: 800; }
.message.user .message-label { text-align: right; }
.message-body { padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.58; }
.message.user .message-body { background: #cdec6330; border-color: #cdec6340; }
.message details { color: var(--muted); font-size: 12px; }
.tool-card, .system-card { padding: 9px 12px; border-left: 2px solid #79776e; color: var(--muted); font-size: 12px; }
.tool-card.running { border-color: var(--accent); color: #d6e8a0; }
.error-card { border-color: var(--danger); color: #ff9b94; }
.composer { width: min(820px, calc(100% - 32px)); margin: 0 auto max(16px, env(safe-area-inset-bottom)); padding: 12px; border: 1px solid var(--line); border-radius: 18px; background: #22221ff2; box-shadow: 0 18px 50px #0007; }
.composer textarea { min-height: 48px; max-height: 180px; resize: vertical; border: 0; background: transparent; padding: 6px; box-shadow: none; }
.composer-row { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 11px; }
.send { width: 38px; height: 38px; border: 0; border-radius: 11px; background: var(--accent); color: #161614; font-size: 22px; font-weight: 900; }
.send:disabled { opacity: .35; cursor: not-allowed; }

dialog { width: min(520px, calc(100% - 28px)); border: 1px solid var(--line); border-radius: 20px; background: #22221f; color: #fff; padding: 22px; box-shadow: 0 30px 100px #000b; }
dialog::backdrop { background: #0009; backdrop-filter: blur(4px); }
dialog form { display: grid; gap: 14px; }
.dialog-head { display: flex; align-items: start; justify-content: space-between; }
.dialog-head h2, dialog h2 { margin: 0; }
.dialog-head .eyebrow, dialog > form > .eyebrow { margin-top: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.dialog-actions > button:not(.primary):not(.danger) { border: 1px solid var(--line); border-radius: 11px; background: transparent; padding: 10px 16px; }
#permission-detail { max-height: 300px; overflow: auto; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #11110f; color: #ece8d7; white-space: pre-wrap; word-break: break-word; }
#permission-summary { color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; max-width: calc(100% - 32px); padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: #30302d; box-shadow: 0 12px 30px #0008; }
.scrim { display: none; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; width: min(86vw, 320px); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 20px 0 60px #0009; }
  .sidebar.open { transform: translateX(0); }
  .scrim { position: fixed; inset: 0; z-index: 9; border: 0; background: #0008; }
  .scrim.open { display: block; }
  .menu { display: inline-grid; place-items: center; }
  .topbar { padding-top: max(12px, env(safe-area-inset-top)); }
  .conversation { padding: 18px 14px; }
  .message { max-width: 94%; }
  .composer { width: calc(100% - 20px); margin-bottom: max(10px, env(safe-area-inset-bottom)); }
}
