:root {
  --bg: #fafafa; --panel: #ffffff; --side: #f4f4f5; --line: #e4e4e7; --line2: #d4d4d8;
  --text: #18181b; --muted: #71717a; --faint: #a1a1aa;
  --accent: #18181b; --accent-text: #ffffff; --hover: #ececee;
  --agent: #eef2ff; --agent-line: #c7d2fe; --agent-ink: #3730a3;
  --warn-bg: #fffbeb; --warn-line: #fcd34d; --warn-ink: #92400e;
  --ok: #16a34a; --bad: #dc2626; --busy: #d97706;
  --code: #f4f4f5; --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0d; --panel: #131316; --side: #0f0f12; --line: #26262b; --line2: #34343a;
    --text: #f4f4f5; --muted: #a1a1aa; --faint: #71717a;
    --accent: #f4f4f5; --accent-text: #0b0b0d; --hover: #1c1c21;
    --agent: #161a2e; --agent-line: #2e3566; --agent-ink: #a5b4fc;
    --warn-bg: #241a06; --warn-line: #6b4f12; --warn-ink: #fcd34d;
    --code: #1c1c21; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0b0d; --panel: #131316; --side: #0f0f12; --line: #26262b; --line2: #34343a;
  --text: #f4f4f5; --muted: #a1a1aa; --faint: #71717a;
  --accent: #f4f4f5; --accent-text: #0b0b0d; --hover: #1c1c21;
  --agent: #161a2e; --agent-line: #2e3566; --agent-ink: #a5b4fc;
  --warn-bg: #241a06; --warn-line: #6b4f12; --warn-ink: #fcd34d;
  --code: #1c1c21; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

.btn { border: 1px solid var(--line2); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 550; font-size: 14px; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { opacity: .9; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--muted); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
input[type=text], input[type=email], input[type=number], select, textarea {
  border: 1px solid var(--line2); background: var(--panel); border-radius: 8px; padding: 8px 10px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--muted); }
label.field { display: block; margin: 0 0 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
label.field > small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 4px; }

/* Login */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; }
.card h1 { font-size: 20px; margin: 0 0 4px; }
.card p { margin: 0 0 18px; }
.brand { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* Layout */
.shell { display: grid; grid-template-columns: 260px 1fr; height: 100vh; height: 100dvh; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 16px 14px 8px; display: flex; align-items: center; justify-content: space-between; }
.rooms { flex: 1; overflow-y: auto; padding: 4px 8px; }
.room-link { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; text-decoration: none; cursor: pointer; }
.room-link:hover { background: var(--hover); }
.room-link.active { background: var(--panel); box-shadow: 0 0 0 1px var(--line); }
.room-link .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.on { background: var(--ok); }
.dot.busy { background: var(--busy); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.side-foot { border-top: 1px solid var(--line); padding: 10px 14px; font-size: 13px; display: grid; gap: 6px; }
.side-foot .row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); min-height: 56px; }
.top .title { flex: 1; min-width: 0; }
.top .title b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .title span { display: block; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line2); color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

.empty { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }

/* Messages */
.feed { flex: 1; overflow-y: auto; padding: 16px 16px 8px; }
.feed-inner { max-width: 820px; margin: 0 auto; }
.msg { display: grid; grid-template-columns: 34px 1fr; gap: 10px; padding: 6px 0; }
.av { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; font-size: 14px; background: var(--hover); color: var(--muted); }
.av.agent { background: var(--agent); color: var(--agent-ink); border: 1px solid var(--agent-line); }
.msg .who { font-size: 13.5px; font-weight: 650; }
.msg .who time { font-weight: 400; color: var(--faint); font-size: 12px; margin-left: 6px; }
.msg.cont { padding-top: 0; }
.msg.cont .av { visibility: hidden; height: 0; }
.msg.cont .who { display: none; }
.body { overflow-wrap: anywhere; min-width: 0; }
.body p { margin: 0 0 8px; }
.body p:last-child { margin-bottom: 0; }
.body pre { background: var(--code); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font: 13px/1.45 var(--mono); margin: 6px 0; }
.body code { background: var(--code); border-radius: 4px; padding: 1px 5px; font: 13px var(--mono); }
.body pre code { background: none; padding: 0; }
.body ul, .body ol { margin: 4px 0 8px; padding-left: 22px; }
.body h3, .body h4 { margin: 10px 0 4px; font-size: 15px; }
.body a { color: var(--agent-ink); }
.agent-bubble { background: var(--agent); border: 1px solid var(--agent-line); border-radius: var(--radius); padding: 9px 12px; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.thumbs img { max-width: 220px; max-height: 160px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.file-chip { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; padding: 5px 9px; border: 1px solid var(--line2); border-radius: 8px; text-decoration: none; }
.sys { text-align: center; color: var(--muted); font-size: 12.5px; padding: 8px 0; }
.acts { margin: 2px 0 4px 44px; font-size: 12.5px; color: var(--muted); }
.acts summary { cursor: pointer; list-style: none; display: inline-flex; gap: 6px; align-items: center; padding: 2px 6px; border-radius: 6px; max-width: 100%; }
.acts summary::-webkit-details-marker { display: none; }
.acts summary:hover { background: var(--hover); }
.acts summary .last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12px; }
.acts ol { margin: 4px 0 0; padding-left: 26px; font-family: var(--mono); font-size: 12px; }
.acts li { overflow-wrap: anywhere; }

.approval { margin: 8px 0 8px 44px; border: 1px solid var(--warn-line); background: var(--warn-bg); border-radius: var(--radius); padding: 12px 14px; }
.approval .head { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--warn-ink); }
.approval .sum { font: 13.5px/1.45 var(--mono); margin: 6px 0; overflow-wrap: anywhere; }
.approval .why { font-size: 13px; color: var(--muted); }
.approval details { margin-top: 6px; font-size: 13px; }
.approval details pre { max-height: 300px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: 12px/1.45 var(--mono); white-space: pre-wrap; }
.approval .acts-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.approval.done { opacity: .7; border-color: var(--line2); background: var(--panel); }
.approval.done .head { color: var(--muted); }

.statusbar { max-width: 820px; margin: 0 auto; width: 100%; padding: 0 16px; font-size: 12.5px; color: var(--muted); min-height: 22px; display: flex; align-items: center; gap: 8px; }

/* Composer */
.composer { padding: 8px 16px 14px; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
.composer-inner { max-width: 820px; margin: 0 auto; border: 1px solid var(--line2); background: var(--panel); border-radius: 12px; padding: 8px; }
.composer textarea { border: 0; padding: 6px 8px; resize: none; max-height: 220px; min-height: 40px; background: transparent; }
.composer .row { display: flex; align-items: center; gap: 6px; }
.composer .row .grow { flex: 1; font-size: 12px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-files { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 4px 6px; }
.pending-files .file-chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 0 0 2px; }
.drop-hint { outline: 2px dashed var(--muted); outline-offset: -6px; }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); background: var(--panel); border-left: 1px solid var(--line); z-index: 50; display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-body { overflow-y: auto; padding: 18px; flex: 1; }
.section { margin-bottom: 26px; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 10px; }
.modal { position: fixed; z-index: 50; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; }

.sessions { border: 1px solid var(--line); border-radius: 10px; max-height: 300px; overflow-y: auto; margin-top: 8px; }
.sess { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; gap: 1px; }
.sess:last-child { border-bottom: 0; }
.sess:hover { background: var(--hover); }
.sess.sel { background: var(--agent); box-shadow: inset 3px 0 0 var(--agent-ink); }
.sess b { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess span { font-size: 12px; color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 6px 12px; cursor: pointer; font-size: 13.5px; font-weight: 550; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.member { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.member .em { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.member select { width: auto; padding: 5px 8px; font-size: 13px; }
.level-help { font-size: 12.5px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 4px; }
.level-help b { color: var(--text); }
.level-help div + div { margin-top: 5px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--accent); color: var(--accent-text); padding: 9px 14px; border-radius: 10px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); }
.code-line { font: 12px var(--mono); background: var(--code); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; overflow-x: auto; white-space: nowrap; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 45; transform: translateX(-100%); transition: transform .18s; }
  .shell.nav-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .menu-btn { display: inline-grid; }
  .feed { padding: 12px 12px 6px; }
  .composer { padding: 6px 10px 10px; }
  .acts, .approval { margin-left: 0; }
  .thumbs img { max-width: 160px; }
  .top { padding: 8px 10px; }
  .top .hide-sm { display: none; }
}
