:root {
  --bg: #06182e;
  --surface: #0a2545;
  --surface-2: #10365f;
  --surface-glass: rgba(10, 37, 69, .94);
  --sidebar-bg: rgba(6, 24, 46, .94);
  --input-bg: #071d37;
  --border: #1f4e7a;
  --text: #f5f9ff;
  --muted: #91abc7;
  --label: #d5e5f7;
  --accent: #0087ff;
  --accent-strong: #0072d8;
  --accent-soft: rgba(0, 135, 255, .12);
  --accent-subtle: rgba(0, 135, 255, .08);
  --accent-dark: #074f91;
  --accent-contrast: #ffffff;
  --switch-bg: #06182e;
  --switch-knob: #6f91b2;
  --danger: #ff7c87;
  --danger-soft: rgba(255, 124, 135, .1);
  --danger-border: rgba(255, 124, 135, .28);
  --warning: #f0c77d;
  --warning-soft: rgba(240, 199, 125, .1);
  --warning-border: rgba(240, 199, 125, .24);
  --error: #ffabb2;
  --shadow: rgba(0, 8, 20, .38);
  --page-glow: rgba(0, 135, 255, .18);
  --red: #ff6868;
  --amber: #f0c77d;
  --radius: 15px;
}

:root[data-theme="light"] {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #edf4fb;
  --surface-glass: rgba(255, 255, 255, .96);
  --sidebar-bg: rgba(255, 255, 255, .94);
  --input-bg: #ffffff;
  --border: #d5e1ed;
  --text: #102a43;
  --muted: #627d98;
  --label: #334e68;
  --accent: #006fcf;
  --accent-strong: #005eaf;
  --accent-soft: rgba(0, 135, 255, .12);
  --accent-subtle: rgba(0, 135, 255, .07);
  --accent-dark: #d8ecff;
  --accent-contrast: #ffffff;
  --switch-bg: #dce7f1;
  --switch-knob: #829ab1;
  --danger: #c83f4c;
  --danger-soft: #fff0f1;
  --danger-border: #f2c3c8;
  --warning: #8b5d0a;
  --warning-soft: #fff8e8;
  --warning-border: #f1d89b;
  --error: #b42332;
  --shadow: rgba(31, 61, 90, .14);
  --page-glow: rgba(0, 135, 255, .1);
  --red: #d94754;
  --amber: #d49722;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 90% 0%, var(--page-glow), transparent 32rem), var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  transition: background-color .2s ease, color .2s ease;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.green, h1 span { color: var(--accent); }
.muted { color: var(--muted); line-height: 1.55; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font: 700 10px/1.2 "SFMono-Regular", Consolas, monospace; letter-spacing: .16em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(27px, 4vw, 40px); letter-spacing: -.045em; }
h2 { margin-bottom: 0; font-size: 28px; letter-spacing: -.035em; }
h3 { margin-bottom: 8px; font-size: 18px; }
code { color: var(--accent); }

.login-body { display: grid; place-items: center; padding: 24px; }
.login-shell { width: min(420px, 100%); }
.login-theme { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.login-card { padding: 38px; border: 1px solid var(--border); border-radius: 22px; background: var(--surface-glass); box-shadow: 0 28px 80px var(--shadow); }
.logo-mark { display: grid; place-items: center; width: 50px; height: 50px; margin-bottom: 25px; border-radius: 13px; background: var(--accent); color: var(--accent-contrast); font-size: 22px; font-weight: 900; }
.logo-mark.small { width: 34px; height: 34px; margin: 0; border-radius: 9px; font-size: 15px; }

label { display: block; margin: 17px 0 7px; color: var(--label); font-size: 12px; font-weight: 700; }
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: 0;
  background: var(--input-bg);
  color: var(--text);
}
input { height: 45px; padding: 0 13px; }
textarea { padding: 12px 13px; resize: vertical; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.form-error { margin: 14px 0 0; color: var(--error); font-size: 13px; }
.warning { margin-top: 18px; padding: 11px 13px; border: 1px solid var(--warning-border); border-radius: 10px; background: var(--warning-soft); color: var(--warning); font-size: 12px; line-height: 1.5; }

.button { min-height: 40px; padding: 0 16px; border: 1px solid transparent; border-radius: 9px; font-size: 12px; font-weight: 800; transition: transform .15s ease, opacity .15s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .42; }
.button.primary { background: var(--accent-strong); color: var(--accent-contrast); }
.button.primary:hover:not(:disabled) { background: var(--accent-strong); }
.button.secondary { border-color: var(--border); background: var(--surface-2); color: var(--text); }
.button.danger { border-color: var(--danger-border); background: var(--danger-soft); color: var(--danger); }
.button.ghost { border-color: var(--border); background: transparent; color: var(--muted); }
.button.full { width: 100%; margin-top: 22px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.theme-switcher { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.theme-option { min-height: 32px; padding: 0 10px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 800; }
.theme-option:hover { color: var(--text); }
.theme-option.active { background: var(--accent-strong); color: var(--accent-contrast); box-shadow: 0 4px 14px var(--shadow); }
.theme-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; display: flex; width: 235px; flex-direction: column; padding: 22px 17px; border-right: 1px solid var(--border); background: var(--sidebar-bg); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 7px 26px; color: var(--text); font-weight: 900; text-decoration: none; }
nav { display: grid; gap: 5px; }
.nav-link { padding: 11px 13px; border-radius: 9px; color: var(--muted); font-size: 13px; font-weight: 700; text-decoration: none; }
.nav-link:hover, .nav-link.active { background: var(--accent-subtle); color: var(--text); }
.sidebar-bottom { margin-top: auto; }
.connection-mini { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 12px currentColor; }
.dot.connected { background: var(--accent); }
.dot.stopped, .dot.error, .dot.logged_out { background: var(--red); }

.main { width: min(1280px, calc(100% - 235px)); margin-left: 235px; padding: 32px clamp(22px, 4vw, 54px) 80px; }
.topbar, .section-head, .form-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar { margin-bottom: 52px; }
.section { margin-bottom: 68px; scroll-margin-top: 25px; }
.section-head { margin-bottom: 20px; }
.section-note { max-width: 420px; margin: 0; font-size: 12px; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 13px; margin-bottom: 13px; }
.metric, .panel, .toggle-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-glass); }
.metric { display: flex; min-height: 145px; flex-direction: column; padding: 20px; }
.accent-card { background: linear-gradient(145deg, var(--accent-soft), transparent 64%), var(--surface); }
.metric span { color: var(--muted); font-size: 11px; font-weight: 700; }
.metric strong { margin: auto 0 7px; font-size: 24px; text-transform: capitalize; }
.metric small { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.panel { padding: 22px; }
.button-row { display: flex; gap: 9px; }
.bottom-actions { margin-top: 30px; }
.form-footer { margin-top: 15px; }

.toggle-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.toggle-card { display: flex; min-height: 102px; justify-content: space-between; gap: 16px; padding: 17px; }
.toggle-card h3 { margin-bottom: 6px; font: 800 14px/1.2 "SFMono-Regular", Consolas, monospace; }
.toggle-card p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.switch { position: relative; flex: 0 0 auto; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch span { position: relative; display: block; width: 42px; height: 24px; border: 1px solid var(--border); border-radius: 99px; background: var(--switch-bg); }
.switch span::after { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--switch-knob); content: ""; transition: transform .15s ease; }
.switch input:checked + span { background: var(--accent-dark); }
.switch input:checked + span::after { transform: translateX(18px); background: var(--accent); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.chat-layout { display: grid; grid-template-columns: 320px minmax(0,1fr); min-height: 520px; padding: 0; overflow: hidden; }
.chat-list { max-height: 620px; overflow-y: auto; border-right: 1px solid var(--border); }
.chat-item { width: 100%; padding: 15px 17px; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--text); text-align: left; }
.chat-item:hover, .chat-item.active { background: var(--accent-subtle); }
.chat-name { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; font-size: 13px; font-weight: 800; }
.chat-time { color: var(--muted); font: 400 9px/1.2 monospace; }
.chat-preview { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.conversation { display: flex; min-width: 0; flex-direction: column; }
.conversation-header { padding: 17px 20px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 800; }
.message-list { display: flex; min-height: 400px; max-height: 510px; flex: 1; flex-direction: column; gap: 9px; overflow-y: auto; padding: 20px; }
.bubble { max-width: 78%; padding: 9px 12px; border-radius: 12px 12px 12px 3px; background: var(--surface-2); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; }
.bubble.mine { align-self: flex-end; border-radius: 12px 12px 3px 12px; background: var(--accent-dark); }
.bubble-meta { display: block; margin-top: 5px; color: var(--muted); font: 400 9px/1.2 monospace; }
.chat-compose { display: grid; grid-template-columns: 1fr auto; gap: 9px; padding: 14px; border-top: 1px solid var(--border); }
.empty { margin: auto; color: var(--muted); font-size: 12px; text-align: center; }

.log-panel { padding: 0; overflow: hidden; }
#logList { max-height: 520px; overflow-y: auto; }
.log-row { display: grid; grid-template-columns: 145px 145px 1fr; gap: 15px; padding: 14px 18px; border-bottom: 1px solid var(--border); font: 400 10px/1.45 "SFMono-Regular", Consolas, monospace; }
.log-row:last-child { border-bottom: 0; }
.log-time, .log-detail { color: var(--muted); }
.log-type { color: var(--accent); font-weight: 700; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: 360px; padding: 12px 15px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); box-shadow: 0 20px 60px var(--shadow); font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(10px); transition: .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { color: var(--error); border-color: var(--danger-border); }

@media (max-width: 950px) {
  .sidebar { position: static; width: 100%; flex-direction: row; align-items: center; }
  .sidebar nav, .sidebar-bottom { display: none; }
  .brand { padding: 0; }
  .main { width: 100%; margin: 0; }
  .metrics, .toggle-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-two { grid-template-columns: 1fr; }
}
@media (max-width: 650px) {
  .main { padding: 24px 14px 60px; }
  .topbar, .section-head { align-items: flex-start; flex-direction: column; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .metrics, .toggle-grid { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; }
  .chat-list { max-height: 270px; border-right: 0; border-bottom: 1px solid var(--border); }
  .log-row { grid-template-columns: 1fr; gap: 4px; }
  .login-card { padding: 28px 22px; }
}
