:root {
  color-scheme: dark;
  --bg: #07130f;
  --panel: #10251f;
  --panel-2: #16342b;
  --line: #285346;
  --text: #f2f7f4;
  --muted: #a9c1b8;
  --accent: #a8e43f;
  --accent-dark: #1d3b19;
  --gold: #e1bd5b;
  --danger: #ff968a;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-padding-bottom: 190px; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, color-mix(in srgb, var(--accent) 13%, transparent), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: color .2s, background-color .2s;
}
button, textarea, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

input, select {
  width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 11px;
  color: var(--text); background: var(--bg); outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card {
  width: min(540px, 100%); padding: clamp(24px, 5vw, 44px); border: 1px solid var(--line); border-radius: 24px;
  background: color-mix(in srgb, var(--panel) 96%, transparent); box-shadow: 0 28px 90px color-mix(in srgb, #000 48%, transparent);
}
.auth-logo { width: 62px; height: 62px; display: grid; place-items: center; margin-bottom: 18px; border-radius: 19px; color: var(--accent-dark); background: var(--accent); font-size: 1.25rem; font-weight: 950; }
.auth-card h1 { margin: 6px 0 12px; font-size: clamp(1.75rem, 5vw, 2.5rem); }
.auth-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.55; }
.stack-form { display: grid; gap: 15px; margin-top: 24px; }
.stack-form label, .agent-name-grid label, .create-user-form label { display: grid; gap: 7px; color: var(--muted); font-size: .78rem; font-weight: 750; }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 48px; }
.eye-button { position: absolute; top: 4px; right: 4px; width: 36px; height: 36px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; filter: grayscale(1); }
.eye-button:hover, .eye-button.revealed { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); filter: none; }
.form-error { margin: 0; color: var(--danger) !important; font-size: .82rem; }
.form-notice { padding: 11px 13px; border: 1px solid var(--accent); border-radius: 11px; color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.wide-button { min-height: 50px; }

.workspace {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.specialist-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 94%, var(--bg));
}
.sidebar-title { display: flex; gap: 11px; align-items: center; padding: 0 5px; }
.sidebar-logo {
  width: 44px; height: 44px; flex: 0 0 auto; display: grid; place-items: center;
  border-radius: 14px; color: var(--accent-dark); background: var(--accent); font-weight: 950;
}
.sidebar-title div { min-width: 0; display: grid; gap: 2px; }
.sidebar-title strong { font-size: 1.05rem; }
.sidebar-title small, .specialist-button small { color: var(--muted); }
.specialist-list { display: grid; gap: 8px; }
.specialist-divider { display: flex; align-items: center; gap: 8px; padding: 4px 8px 0; color: var(--muted); font-size: .65rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.specialist-divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }
.majordome-button { min-height: 82px; border-color: color-mix(in srgb, var(--gold) 38%, var(--line)); background: color-mix(in srgb, var(--gold) 5%, transparent); }
.specialist-button {
  width: 100%; display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 10px; align-items: center;
  min-height: 70px; padding: 10px; border: 1px solid transparent; border-radius: 15px;
  color: var(--text); background: transparent; text-align: left;
}
.specialist-button:hover { border-color: var(--line); background: color-mix(in srgb, var(--accent) 5%, transparent); }
.specialist-button.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, var(--panel)); }
.specialist-button > span:last-child { min-width: 0; display: grid; gap: 3px; }
.specialist-button strong { line-height: 1.2; }
.specialist-button small.connected { color: var(--accent); font-weight: 750; }
.specialist-icon {
  width: 46px; height: 46px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 13px;
  color: var(--accent); background: var(--bg); font-size: .76rem; font-weight: 900;
}
.specialist-button.active .specialist-icon { color: var(--accent-dark); background: var(--accent); border-color: var(--accent); }
.sidebar-note { margin: auto 5px 0; color: var(--muted); font-size: .72rem; line-height: 1.5; }
.sidebar-logout { min-height: 42px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: var(--bg); }
.sidebar-logout:hover { border-color: var(--accent); color: var(--accent); }

.app-shell {
  width: min(1000px, calc(100% - 36px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas:
    "topbar"
    "intro"
    "messages"
    "composer";
  gap: 18px;
  padding: 20px 0;
}
.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 18px; background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: 0 16px 50px color-mix(in srgb, var(--bg) 55%, transparent);
}
.brand-mark {
  min-width: 52px; height: 48px; padding: 0 8px; display: grid; place-items: center; border-radius: 15px;
  color: var(--accent-dark); background: var(--accent); font-size: .78rem; font-weight: 950;
}
.brand-copy { flex: 1; min-width: 0; }
.eyebrow { margin: 0; color: var(--accent); font-size: .68rem; font-weight: 850; letter-spacing: .12em; }
h1 { margin: 1px 0 0; font-size: clamp(1.2rem, 3vw, 1.6rem); }
.status {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; border: 1px solid var(--line);
  border-radius: 999px; color: var(--muted); font-size: .76rem; white-space: nowrap;
}
.status span { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }
.status-online span { background: var(--accent); box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 70%, transparent); }
.status-error span { background: var(--danger); }
.settings-button, .modal-close {
  flex: 0 0 auto; width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--line);
  border-radius: 13px; color: var(--text); background: var(--panel); font-size: 1.35rem;
}
.settings-button:hover, .modal-close:hover { border-color: var(--accent); color: var(--accent); }

.intro {
  grid-area: intro;
  padding: clamp(22px, 5vw, 42px); border: 1px solid var(--line); border-radius: 22px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 9%, var(--panel)), var(--panel));
}
.intro-kicker { margin: 0 0 8px; color: var(--gold); font-weight: 800; }
.intro h2 { margin: 0; font-size: clamp(1.75rem, 5vw, 3rem); letter-spacing: -.035em; }
.intro > p:not(.intro-kicker) { max-width: 740px; color: var(--muted); font-size: 1.02rem; line-height: 1.6; }
.safety-badge {
  display: inline-flex; margin-top: 4px; padding: 8px 11px; border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line));
  border-radius: 999px; color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); font-size: .75rem; font-weight: 750;
}
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.suggestions button {
  border: 1px solid var(--line); border-radius: 999px; padding: 10px 14px; color: var(--text); background: var(--bg);
}
.suggestions button:hover { border-color: var(--accent); color: var(--accent); }

.messages { grid-area: messages; display: flex; flex-direction: column; gap: 14px; padding: 2px 0 12px; }
.messages::after { content: ''; display: block; height: 4px; flex: 0 0 4px; }
.message { display: grid; gap: 5px; max-width: 88%; }
.message-user { align-self: flex-end; }
.message-assistant { align-self: flex-start; }
.message-label { padding: 0 5px; color: var(--muted); font-size: .72rem; font-weight: 700; }
.message-user .message-label { text-align: right; }
.message-bubble {
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 17px; background: var(--panel);
  line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere;
}
.message-user .message-bubble { color: var(--accent-dark); background: var(--accent); border-color: var(--accent); border-bottom-right-radius: 5px; }
.message-assistant .message-bubble { border-bottom-left-radius: 5px; }
.message-error .message-bubble { border-color: var(--danger); color: var(--danger); }
.thinking { color: var(--muted); }
.thinking::after { content: ""; animation: dots 1.2s infinite; }
@keyframes dots { 0%{content:""} 33%{content:"."} 66%{content:".."} 100%{content:"..."} }
.answer-meta { padding: 0 5px; color: var(--muted); opacity: .75; font-size: .68rem; }
.answer-sources { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 5px 0; color: var(--muted); font-size: .68rem; }
.answer-sources strong { width: 100%; }
.answer-sources span, .answer-sources a {
  padding: 4px 7px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
  color: var(--muted); text-decoration: none;
}
.answer-sources a:hover { border-color: var(--accent); color: var(--accent); }

.composer {
  grid-area: composer;
  align-self: end;
  position: sticky; bottom: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 19px;
  background: color-mix(in srgb, var(--panel) 96%, transparent); box-shadow: 0 18px 55px color-mix(in srgb, var(--bg) 65%, transparent);
  backdrop-filter: blur(14px);
}
.composer > label { display: block; margin: 0 0 8px 4px; color: var(--muted); font-size: .76rem; font-weight: 700; }
.composer-row { display: flex; gap: 10px; align-items: stretch; }
textarea {
  flex: 1; min-height: 62px; max-height: 220px; resize: vertical; border: 1px solid var(--line); border-radius: 13px;
  padding: 12px 14px; color: var(--text); background: var(--bg); outline: none;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.send-button, .primary-button {
  min-width: 112px; border: 0; border-radius: 13px; padding: 0 18px; color: var(--accent-dark); background: var(--accent); font-weight: 850;
}
.send-button:disabled { opacity: .45; cursor: wait; }
.voice-button {
  position: relative; display: grid; place-items: center; flex: 0 0 62px; min-width: 62px;
  border: 1px solid var(--line); border-radius: 13px; color: var(--accent); background: var(--bg);
  transition: transform .16s ease, border-color .16s ease, background .16s ease, box-shadow .16s ease;
}
.voice-button:hover { border-color: var(--accent); transform: translateY(-1px); }
.voice-button svg { width: 27px; height: 27px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.voice-button.active { color: var(--accent-dark); border-color: var(--accent); background: var(--accent); box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 14%, transparent); }
.voice-button.listening::after {
  content: ''; position: absolute; inset: -5px; border: 2px solid var(--accent); border-radius: 17px;
  animation: voice-pulse 1.45s ease-out infinite; pointer-events: none;
}
.voice-button.processing svg { animation: voice-breathe 1s ease-in-out infinite alternate; }
.voice-status { margin: 9px 4px 0; color: var(--accent); font-size: .74rem; font-weight: 750; }
.voice-status.error { color: #e88282; }
@keyframes voice-pulse { from { opacity: .7; transform: scale(.96); } to { opacity: 0; transform: scale(1.12); } }
@keyframes voice-breathe { from { opacity: .5; transform: scale(.9); } to { opacity: 1; transform: scale(1.08); } }
.composer-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 9px; color: var(--muted); font-size: .7rem; }
.composer-meta button { border: 0; padding: 0; color: var(--muted); background: transparent; text-decoration: underline; }
.memory-choice { display: flex; align-items: center; gap: 8px; }
.memory-choice select { width: auto; min-height: 30px; padding: 3px 28px 3px 8px; border-radius: 8px; font-size: .7rem; }

.modal-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px;
  background: color-mix(in srgb, #000 62%, transparent); backdrop-filter: blur(8px);
}
.settings-dialog {
  width: min(880px, 100%); max-height: min(880px, calc(100vh - 36px)); overflow: auto;
  border: 1px solid var(--line); border-radius: 22px; background: var(--panel); box-shadow: 0 28px 90px #0008;
}
.settings-header, .settings-footer { display: flex; justify-content: space-between; gap: 14px; align-items: center; padding: 18px 20px; }
.settings-header { position: sticky; top: 0; z-index: 2; border-bottom: 1px solid var(--line); background: var(--panel); }
.settings-header h2 { margin: 2px 0 0; }
.settings-tabs { position: sticky; top: 81px; z-index: 2; display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.settings-tabs button { min-height: 42px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: var(--bg); }
.settings-tabs button.selected { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--bg)); }
.settings-section { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.settings-section-title { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.settings-section-title h3 { margin: 0 0 14px; }
.settings-section-title span { color: var(--muted); font-size: .75rem; }
.theme-choices { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.theme-choices button {
  display: grid; gap: 7px; justify-items: center; padding: 9px 6px; border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); background: var(--bg);
}
.theme-choices button.selected, .font-choices button.selected { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent); }
.theme-choices button > span { width: 100%; height: 34px; border-radius: 8px; background: linear-gradient(135deg, var(--swatch-bg) 50%, var(--swatch) 50%); }
.theme-choices small { line-height: 1.15; }
.font-choices { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.font-choices button { min-height: 48px; padding: 8px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); background: var(--bg); }
.settings-footer { position: sticky; bottom: 0; background: var(--panel); }
.primary-button { min-height: 44px; }
.secondary-button { min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: var(--bg); }
.danger-button { min-height: 42px; padding: 0 13px; border: 1px solid color-mix(in srgb, var(--danger) 65%, var(--line)); border-radius: 11px; color: var(--danger); background: color-mix(in srgb, var(--danger) 6%, var(--bg)); }
.settings-help { margin: -5px 0 16px; color: var(--muted); line-height: 1.5; font-size: .83rem; }
.agent-name-grid, .create-user-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; align-items: end; }
.agent-name-grid button, .create-user-form button { min-height: 44px; }
.manual-memory-form { display: grid; grid-template-columns: minmax(0, 1fr) 170px 130px; gap: 9px; align-items: stretch; margin-bottom: 16px; }
.manual-memory-form textarea { min-height: 48px; }
.memory-list, .user-list { display: grid; gap: 10px; }
.memory-card, .user-card { padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.shared-memory { border-color: color-mix(in srgb, var(--gold) 45%, var(--line)); }
.memory-card-header, .user-card-title { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 9px; }
.memory-card-header small, .user-card-title small { color: var(--muted); }
.memory-card p { margin: 4px 0; white-space: pre-wrap; line-height: 1.5; }
.memory-controls, .user-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px; align-items: center; }
.memory-controls select, .user-controls select { width: auto; min-width: 145px; }
.user-card-title { display: grid; gap: 2px; }
.check-label { display: inline-flex; align-items: center; color: var(--muted); font-size: .78rem; }
.check-label input { width: 18px; min-height: 18px; box-shadow: none; }

@media (max-width: 1000px) {
  .workspace { grid-template-columns: 240px minmax(0, 1fr); }
  .theme-choices { grid-template-columns: repeat(4, 1fr); }
  .font-choices { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 820px) {
  .workspace { display: block; }
  .specialist-sidebar {
    position: sticky; top: 0; z-index: 20; width: 100%; height: auto; gap: 9px; padding: 9px;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .sidebar-title, .sidebar-note { display: none; }
  .specialist-list { display: grid; grid-template-columns: repeat(5, 118px); gap: 6px; overflow-x: auto; }
  .specialist-divider { display: none; }
  .specialist-button { grid-template-columns: 34px minmax(0, 1fr); min-height: 54px; padding: 6px; border-radius: 12px; }
  .majordome-button { min-height: 54px; }
  .specialist-icon { width: 34px; height: 34px; border-radius: 10px; font-size: .62rem; }
  .specialist-button strong { font-size: .72rem; }
  .specialist-button small { display: none; }
  .app-shell { width: min(100% - 18px, 1000px); min-height: calc(100vh - 74px); padding: 9px 0 14px; gap: 10px; }
  .topbar { padding: 10px; border-radius: 15px; }
  .status strong { display: none; }
  .intro { padding: 22px 17px; border-radius: 17px; }
  .suggestions { display: grid; }
  .suggestions button { text-align: left; border-radius: 12px; }
  .message { max-width: 95%; }
  .composer { bottom: 5px; padding: 10px; border-radius: 16px; }
  .composer-row { display: grid; grid-template-columns: 54px minmax(0, 1fr); }
  .composer-row textarea { grid-column: 1 / -1; }
  .voice-button { grid-column: 1; min-width: 54px; min-height: 46px; }
  .send-button { grid-column: 2; }
  .send-button { min-height: 46px; }
  .theme-choices { grid-template-columns: repeat(3, 1fr); }
  .sidebar-logout { display: none; }
  .manual-memory-form { grid-template-columns: 1fr; }
  .agent-name-grid, .create-user-form { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .specialist-list { grid-template-columns: repeat(5, 112px); }
  .brand-mark { display: none; }
  .settings-button { width: 40px; height: 40px; }
  .theme-choices { grid-template-columns: repeat(2, 1fr); }
  .font-choices { grid-template-columns: repeat(2, 1fr); }
  .settings-dialog { max-height: calc(100vh - 18px); border-radius: 16px; }
  .settings-header, .settings-footer, .settings-section { padding: 14px; }
  .settings-tabs { top: 73px; grid-template-columns: repeat(2, 1fr); padding: 8px 14px; }
  .settings-footer { flex-direction: column-reverse; align-items: stretch; }
  .settings-footer button { width: 100%; }
}
