*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2d3148;
  --accent: #5b6af0;
  --accent-hover: #7080ff;
  --green: #22c55e;
  --orange: #f59e0b;
  --red: #ef4444;
  --gray: #4b5563;
  --text: #e2e8f0;
  --text-muted: #6b7280;
  --text-dim: #94a3b8;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  --radius: 10px;
  --sidebar-w: 260px;
  --panel-w: 280px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; overflow: hidden; }

/* ── LAYOUT ── */
#app { display: flex; height: 100vh; }

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  transition: transform .25s ease;
}
.sidebar-logo {
  padding: 18px 16px 14px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #5b6af0, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; color: #fff; flex-shrink: 0;
}
.sidebar-logo-text { font-size: 15px; font-weight: 700; color: var(--text); }
.sidebar-logo-sub { font-size: 11px; color: var(--text-muted); }

.sidebar-section { padding: 14px 16px 4px; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }

.sidebar-agents { padding: 4px 8px; flex-shrink: 0; }
.agent-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  transition: background .15s;
}
.agent-item:hover { background: var(--surface2); }
.agent-item.active { background: var(--surface2); }
.agent-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.agent-dot.green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.agent-dot.orange { background: var(--orange); }
.agent-dot.gray { background: var(--gray); }
.agent-name { font-size: 13px; font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-time { font-size: 11px; color: var(--text-muted); }

.sidebar-channels { padding: 4px 8px; flex: 1; overflow-y: auto; }
.channel-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 8px; cursor: pointer;
  transition: background .15s; color: var(--text-dim);
}
.channel-item:hover { background: var(--surface2); color: var(--text); }
.channel-item.active { background: var(--surface2); color: var(--text); }
.channel-item span { font-size: 15px; }

/* ── MAIN CHAT ── */
#main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg);
}
.topbar {
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg); flex-shrink: 0;
}
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-status { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.4;} }

#messages {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 2px;
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg-group { display: flex; gap: 12px; padding: 6px 0; }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; margin-top: 2px;
}
.msg-body { flex: 1; min-width: 0; }
.msg-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-author { font-size: 13px; font-weight: 600; }
.msg-time { font-size: 11px; color: var(--text-muted); }
.msg-content { font-size: 13.5px; color: var(--text-dim); line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.msg-content .mention { color: var(--accent); font-weight: 500; }

.day-divider { text-align: center; margin: 12px 0; }
.day-divider span { font-size: 11px; color: var(--text-muted); background: var(--bg); padding: 0 12px; position: relative; }
.day-divider::before { content:''; position:absolute; left:0;right:0; top:50%; height:1px; background: var(--border); z-index:-1; }

/* ── COMPOSER ── */
.composer {
  padding: 12px 20px 16px; border-top: 1px solid var(--border);
  background: var(--bg); flex-shrink: 0;
}
.composer-inner {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
  transition: border-color .2s;
}
.composer-inner:focus-within { border-color: var(--accent); }
#draft {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 14px; font-family: var(--font);
  resize: none; min-height: 22px; max-height: 120px; line-height: 1.5;
}
#draft::placeholder { color: var(--text-muted); }
#send-btn {
  background: var(--accent); border: none; border-radius: 8px;
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: background .15s;
  color: #fff;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { background: var(--surface2); cursor: not-allowed; color: var(--text-muted); }
.composer-hint { font-size: 11px; color: var(--text-muted); margin-top: 6px; text-align: center; }

/* ── CONTEXT PANEL ── */
#panel {
  width: var(--panel-w); min-width: var(--panel-w);
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel-header {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600;
}
.panel-tabs {
  display: flex; border-bottom: 1px solid var(--border);
}
.panel-tab {
  flex: 1; padding: 10px; text-align: center; font-size: 12px; font-weight: 500;
  color: var(--text-muted); cursor: pointer; border: none; background: none;
  border-bottom: 2px solid transparent; transition: all .15s;
}
.panel-tab:hover { color: var(--text); }
.panel-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel-content { flex: 1; overflow-y: auto; padding: 12px; }

/* Agent card */
.agent-card {
  background: var(--surface2); border-radius: 8px; padding: 12px;
  margin-bottom: 8px; border: 1px solid var(--border);
}
.agent-card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.agent-card-name { font-size: 13px; font-weight: 600; flex: 1; }
.agent-card-badge {
  font-size: 10px; padding: 2px 7px; border-radius: 999px; font-weight: 600;
}
.badge-ok { background: rgba(34,197,94,.15); color: var(--green); }
.badge-offline { background: rgba(75,85,99,.15); color: var(--gray); }
.agent-card-meta { font-size: 11px; color: var(--text-muted); display: flex; flex-direction: column; gap: 3px; }
.agent-card-note { font-size: 11px; color: var(--text-dim); margin-top: 6px; border-top: 1px solid var(--border); padding-top: 6px; }

/* Audit log */
.audit-row {
  background: var(--surface2); border-radius: 6px; padding: 8px 10px;
  margin-bottom: 6px; border-left: 2px solid var(--accent);
}
.audit-row-header { display: flex; justify-content: space-between; margin-bottom: 3px; }
.audit-actor { font-size: 12px; font-weight: 600; color: var(--accent); }
.audit-time { font-size: 10px; color: var(--text-muted); }
.audit-action { font-size: 12px; color: var(--text-dim); }

/* ── VIEWS ── */
.view { display: none; }
.view.active { display: flex; flex-direction: column; height: 100%; }

/* ── MOBILE ── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; --panel-w: 0px; }
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 100; transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  #panel { display: none; }
  .mob-menu { display: flex !important; }
}
.mob-menu { display: none; background: none; border: none; color: var(--text); cursor: pointer; padding: 4px; }

/* ── EMPTY STATE ── */
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--text-muted); }
.empty svg { opacity: .3; }

/* ── LOGIN ── */
#login-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.login-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 36px 32px; width: 340px;
  display: flex; flex-direction: column; gap: 20px;
}
.login-logo { display: flex; align-items: center; gap: 12px; }
.login-logo-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, #5b6af0, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; color: #fff;
}
.login-logo-name { font-size: 22px; font-weight: 800; }
.login-logo-sub { font-size: 12px; color: var(--text-muted); }
.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-field label { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.login-field input {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; color: var(--text);
  font-size: 14px; outline: none; transition: border-color .2s;
}
.login-field input:focus { border-color: var(--accent); }
.login-btn {
  background: var(--accent); border: none; border-radius: 8px;
  padding: 11px; color: #fff; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.login-btn:hover { background: var(--accent-hover); }
.login-error { font-size: 12px; color: var(--red); text-align: center; display: none; }

/* scrollbar global */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
