:root {
  --bg: #141417;
  --panel: #1c1c20;
  --panel-2: #232329;
  --border: #2e2e35;
  --text: #e8e8ea;
  --muted: #9a9aa3;
  --gold: #c9a227;
  --gold-dim: #a8871d;
  --accent: #3a3a42;
  --danger: #d95555;
  --ok: #4fae6b;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 13px; margin: 6px 0; }
button { font: inherit; cursor: pointer; border: none; border-radius: 8px; }
button:disabled { opacity: .5; cursor: default; }

.primary { background: var(--gold); color: #1a1608; padding: 10px 16px; font-weight: 600; }
.primary:hover:not(:disabled) { background: #d6b333; }
.primary.small { padding: 6px 12px; font-size: 13px; }
.ghost { background: transparent; color: var(--muted); padding: 8px 12px; }
.ghost:hover { color: var(--text); background: var(--panel-2); }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.login-card {
  width: min(360px, 92vw); background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 14px;
}
.login-mark, .brand-mark { color: var(--gold); }
.login-mark { font-size: 34px; text-align: center; }
.login-card h1 { margin: 0; font-size: 22px; text-align: center; }
.login-card .muted { text-align: center; margin: -6px 0 6px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; outline: none; width: 100%;
}
input:focus, textarea:focus { border-color: var(--gold); }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 240px 280px 1fr;
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.brand { display: flex; align-items: center; gap: 8px; padding: 16px; font-weight: 700; font-size: 17px; }
.brand-mark { font-size: 22px; }
.sidebar-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 8px 16px 4px; }
.agent-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.agent-list li { padding: 11px 16px; cursor: pointer; display: flex; flex-direction: column; border-left: 3px solid transparent; }
.agent-list li:hover { background: var(--panel-2); }
.agent-list li.active { background: var(--panel-2); border-left-color: var(--gold); }
.agent-list .a-label { font-weight: 600; }
.agent-list .a-role { font-size: 12px; color: var(--muted); }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.user-label { font-size: 12px; color: var(--muted); text-align: center; padding-top: 4px; }

.sessions { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
.session-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; min-height: 0; }
.session-list li { padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.session-list li:hover { background: var(--panel-2); }
.session-list li.active { background: var(--accent); }
.session-list .s-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-list .s-meta { font-size: 11px; color: var(--muted); }
.session-empty { color: var(--muted); text-align: center; padding: 24px 12px; font-size: 13px; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg); }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; background: var(--panel); }
.activity { font-size: 12px; font-weight: 500; color: var(--gold); font-family: var(--mono); }

.messages { flex: 1; overflow-y: auto; min-height: 0; padding: 20px 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 74%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.msg .role-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 3px; }
.msg.streaming { border-left: 2px solid var(--gold); }

.composer { display: flex; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--panel); }
.composer textarea { resize: none; max-height: 160px; flex: 1; }
.composer button { align-self: flex-end; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 10; }
.modal-card {
  width: min(380px, 92vw); background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 12px;
}
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Mobile ---------- */
.menu-btn { display: none; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .menu-btn { display: block; }
  .sidebar, .sessions { position: fixed; inset: 0 auto 0 0; width: 82%; max-width: 300px; z-index: 5; transform: translateX(-100%); transition: transform .18s ease; }
  .sidebar.open, .sessions.open { transform: translateX(0); }
}
