:root {
  color-scheme: dark;
  --bg: #090b0d;
  --surface: #101417;
  --surface-2: #151b1f;
  --line: #273238;
  --muted: #839098;
  --text: #ecf2f1;
  --cyan: #48d7dd;
  --lime: #b8e85d;
  --coral: #ff7868;
  --paper: #d9e2df;
  --radius: 6px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
  overflow-x: hidden;
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.is-hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  padding: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(9, 11, 13, .94);
}

.login-mark, .brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  aspect-ratio: 1;
  border: 1px solid var(--cyan);
  color: var(--cyan);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-weight: 800;
}

.eyebrow {
  margin: 22px 0 8px;
  color: var(--cyan);
  font: 700 11px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  text-transform: uppercase;
}

h1 { margin: 0 0 34px; font-size: 36px; line-height: 1; }
h2 { margin: 0; font-size: 13px; line-height: 1.2; text-transform: uppercase; }

label { display: block; margin: 0 0 8px; color: var(--muted); font-size: 12px; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
  background: #0b0f11;
  color: var(--text);
}

input, select { height: 44px; padding: 0 12px; }
textarea { padding: 12px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--cyan); }

.login-row { display: grid; grid-template-columns: 1fr 48px; gap: 8px; }
.login-row button, .send-button {
  border: 0;
  border-radius: 4px;
  background: var(--cyan);
  color: #061012;
  font-size: 22px;
  font-weight: 800;
}

.form-error { min-height: 18px; margin: 10px 0 0; color: var(--coral); font-size: 12px; }

.app-shell {
  height: 100vh;
  min-height: 100vh;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) 40px;
  overflow: hidden;
}

.topbar, .footerbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: #0c0f11;
}

.footerbar {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  color: var(--muted);
  font: 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.footerbar strong { color: var(--paper); }

.brand-block, .top-status { display: flex; align-items: center; gap: 12px; }
.brand-block div { display: grid; gap: 2px; }
.brand-block strong { font-size: 15px; }
.brand-block span:not(.brand-mark) { color: var(--muted); font: 9px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.top-status { color: var(--muted); font: 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.top-status time { color: var(--paper); min-width: 70px; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 12px rgba(184, 232, 93, .45); }
.status-dot.busy { background: var(--cyan); }
.status-dot.error { background: var(--coral); }

.icon-button, .text-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--paper);
}
.icon-button { width: 34px; height: 34px; border-radius: 4px; font-size: 18px; }
.icon-button.small { width: 26px; height: 26px; font-size: 15px; }
.text-button { border: 0; color: var(--muted); font-size: 11px; }
.icon-button:hover, .text-button:hover { color: var(--cyan); border-color: var(--cyan); }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(220px, 18vw) minmax(420px, 1fr) minmax(260px, 22vw);
}

.rail { min-height: 0; overflow: auto; background: #0c1012; }
.rail-left { border-right: 1px solid var(--line); }
.rail-right { border-left: 1px solid var(--line); }

.panel { padding: 18px; border-bottom: 1px solid var(--line); }
.panel-heading { min-height: 28px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-heading > span { color: var(--cyan); font: 9px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; }

.metric { margin-bottom: 13px; }
.metric div { display: flex; justify-content: space-between; margin-bottom: 7px; font: 10px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.metric span { color: var(--muted); }
.metric strong { color: var(--paper); }
progress { display: block; width: 100%; height: 4px; border: 0; border-radius: 0; background: #20272b; }
progress::-webkit-progress-bar { background: #20272b; }
progress::-webkit-progress-value { background: var(--cyan); }
progress::-moz-progress-bar { background: var(--cyan); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.stat-grid div { min-width: 0; padding: 9px; border: 1px solid var(--line); }
.stat-grid span, .stat-grid strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-grid span { margin-bottom: 5px; color: var(--muted); font-size: 9px; text-transform: uppercase; }
.stat-grid strong { font: 10px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; }

.skill-list { display: grid; gap: 5px; }
.skill-button {
  min-height: 42px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.skill-button:hover { border-color: var(--line); background: var(--surface); }
.skill-button b { color: var(--cyan); font: 12px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.skill-button span { display: grid; gap: 3px; min-width: 0; }
.skill-button strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.skill-button small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; }

.core { min-height: 0; display: grid; grid-template-rows: minmax(240px, .85fr) minmax(250px, 1fr); background: #090c0e; }
.core-visual { position: relative; min-height: 270px; overflow: hidden; border-bottom: 1px solid var(--line); }
#neuralCanvas { display: block; width: 100%; height: 100%; }
.core-label { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%); display: grid; justify-items: center; pointer-events: none; }
.core-label span, .core-label small { color: var(--muted); font: 9px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; }
.core-label strong { margin: 8px 0; font: 800 28px/1 ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--paper); }

.conversation { min-height: 0; display: grid; grid-template-rows: 34px minmax(0, 1fr) 58px; padding: 0 18px 14px; }
.conversation-head { display: flex; align-items: center; justify-content: space-between; color: var(--cyan); font: 9px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.conversation-actions { min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
#attachmentName { max-width: min(260px, 35vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--lime); }
.messages { min-height: 0; overflow-y: auto; padding: 8px 0 16px; }
.message { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 12px; padding: 9px 0; }
.message span { color: var(--muted); font: 9px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.message p { margin: 0; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.message.user p { color: var(--paper); }
.message.assistant p { color: var(--text); }

.command-line { display: grid; grid-template-columns: 22px 34px minmax(0, 1fr) 42px 42px; gap: 7px; align-items: center; padding: 7px; border: 1px solid var(--line); background: #0d1113; }
.command-line .prompt { color: var(--lime); font: 700 18px/1 ui-monospace, SFMono-Regular, Consolas, monospace; text-align: center; }
.command-line input { height: 42px; padding: 0; border: 0; background: transparent; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.send-button, .voice-button { width: 42px; height: 42px; border-radius: 4px; }
.attach-button { width: 34px; height: 34px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: transparent; color: var(--cyan); font-size: 20px; line-height: 1; }
.attach-button.has-file { border-color: var(--lime); color: var(--lime); }
.attach-button:hover { border-color: var(--cyan); }
.voice-button { border: 1px solid var(--line); background: transparent; color: var(--coral); font-size: 18px; }
.voice-button.recording { border-color: var(--coral); background: rgba(255, 120, 104, .13); box-shadow: 0 0 20px rgba(255, 120, 104, .2); }

.task-list, .note-list { display: grid; }
.task, .note-item { display: grid; align-items: center; gap: 10px; min-height: 45px; border-top: 1px solid #1c2529; }
.task { grid-template-columns: 42px minmax(0, 1fr) 24px; }
.task time { color: var(--cyan); font: 10px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.task span { font-size: 11px; line-height: 1.3; }
.task.done span { color: var(--muted); text-decoration: line-through; }
.task button { width: 22px; height: 22px; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--lime); }
.task.done button { border-color: var(--lime); }

.vault-tabs { display: flex; gap: 4px; margin: -4px 0 10px; overflow-x: auto; }
.vault-tabs button { padding: 5px 8px; border: 0; border-bottom: 1px solid transparent; background: transparent; color: var(--muted); font-size: 10px; }
.vault-tabs button.active { border-color: var(--cyan); color: var(--cyan); }
.note-item { grid-template-columns: minmax(0, 1fr) 18px; padding: 7px 0; border-left: 0; border-right: 0; border-bottom: 0; background: transparent; color: var(--text); text-align: left; }
.note-item > span:first-child { display: grid; gap: 4px; min-width: 0; }
.note-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.note-item small { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.note-item > b { color: var(--cyan); font-size: 12px; }

.activity-panel ol { list-style: none; margin: 0; padding: 0; }
.activity-panel li { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 8px; padding: 7px 0; border-top: 1px solid #1c2529; font-size: 10px; }
.activity-panel time { color: var(--lime); font: 9px/1.3 ui-monospace, SFMono-Regular, Consolas, monospace; }
.activity-panel span { color: var(--muted); }

.channel-list, .automation-list { display: grid; }
.channel-row, .automation-row { min-height: 42px; display: grid; align-items: center; gap: 9px; border-top: 1px solid #1c2529; }
.channel-row { grid-template-columns: 10px minmax(0, 1fr) auto; }
.channel-row i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.channel-row.active i { background: var(--lime); box-shadow: 0 0 8px rgba(184, 232, 93, .35); }
.channel-row strong, .automation-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.channel-row small, .automation-row small { display: block; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 9px; }
.channel-row > span:last-child { color: var(--muted); font: 9px/1 ui-monospace, SFMono-Regular, Consolas, monospace; text-transform: uppercase; }
.automation-row { grid-template-columns: minmax(0, 1fr) 24px; padding: 7px 0; }
.automation-row button { width: 22px; height: 22px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--muted); }
.automation-row button:hover { border-color: var(--coral); color: var(--coral); }
.automation-row.error small { color: var(--coral); }

.toggle { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle > span { position: relative; width: 28px; height: 15px; border: 1px solid var(--line); border-radius: 8px; }
.toggle > span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); transition: transform .2s ease; }
.toggle input:checked + span::after { transform: translateX(13px); background: var(--lime); }

dialog { width: min(560px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); }
#settingsDialog { width: min(760px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(3, 5, 6, .82); }
.dialog-shell { padding: 22px; }
.settings-shell { max-height: min(88vh, 840px); overflow-y: auto; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.dialog-heading .eyebrow { margin: 0 0 5px; }
.dialog-heading h2 { font-size: 18px; text-transform: none; }
.dialog-shell > label:not(:first-child) { margin-top: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.primary-button, .secondary-button { min-height: 40px; padding: 0 14px; border-radius: 4px; }
.primary-button { border: 1px solid var(--cyan); background: var(--cyan); color: #071113; font-weight: 700; }
.secondary-button { border: 1px solid var(--line); background: transparent; color: var(--text); }
.danger-button { min-height: 40px; padding: 0 14px; border: 1px solid var(--coral); border-radius: 4px; background: transparent; color: var(--coral); }
.reader-shell { max-height: min(80vh, 760px); overflow: auto; }
.reader-shell pre { margin: 0; white-space: pre-wrap; word-break: break-word; color: var(--paper); font: 12px/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; }
.reader-actions { display: flex; justify-content: flex-end; gap: 8px; margin: -12px 0 18px; }
#readerEditor { min-height: min(58vh, 540px); font: 12px/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; }

.settings-tabs { display: flex; gap: 4px; margin: -8px 0 24px; border-bottom: 1px solid var(--line); }
.settings-tabs button { min-width: 88px; padding: 10px 12px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); }
.settings-tabs button.active { border-color: var(--cyan); color: var(--text); }
.settings-section { display: none; }
.settings-section.active { display: block; }
.settings-section h3 { margin: 24px 0 12px; color: var(--cyan); font: 700 11px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; text-transform: uppercase; }
.settings-section > label:not(:first-child), .settings-section > input + label, .settings-section > textarea + label { margin-top: 16px; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 12px; }
.form-grid label { margin: 0; }
.form-grid .wide { grid-column: 1 / -1; }
.setting-switches { display: grid; gap: 10px; margin-bottom: 18px; }
.remember-toggle { margin-top: 16px !important; }
.check-line { min-height: 24px; display: flex; align-items: center; gap: 9px; margin: 0; color: var(--text); }
.check-line input { width: 16px; height: 16px; margin: 0; accent-color: var(--lime); }
.diagnostic-row { min-height: 40px; display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.diagnostic-row span { color: var(--muted); font-size: 11px; }
.webhook-list { display: grid; gap: 7px; margin-top: 10px; }
.webhook-list code { display: block; padding: 9px 10px; background: #0b0f11; color: var(--paper); font-size: 11px; overflow-wrap: anywhere; }

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 210px minmax(420px, 1fr); }
  .rail-right { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); border-left: 0; }
  .rail-right .panel { border-right: 1px solid var(--line); }
  .app-shell { min-height: 100vh; height: auto; overflow: visible; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-rows: 58px auto 42px; }
  .topbar { padding: 0 12px; }
  .brand-block span:not(.brand-mark), .top-status > span:not(.status-dot) { display: none; }
  .top-status { gap: 7px; }
  .workspace { display: block; }
  .rail-left, .rail-right { display: block; border: 0; }
  .rail-left { border-bottom: 1px solid var(--line); }
  .rail-left .vitals-panel { display: none; }
  .skills-panel { padding: 10px 12px; }
  .skill-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .skill-button { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .skill-button small { display: none; }
  .core { grid-template-rows: 300px minmax(380px, auto); }
  .conversation { min-height: 430px; padding: 0 12px 12px; }
  .rail-right .panel { border-right: 0; }
  .footerbar { padding: 0 12px; }
  .footerbar > span:first-child { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .settings-tabs button { min-width: 0; flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition-duration: 0s !important; }
}
