@font-face {
  font-family: 'Rajdhani';
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  src: url('/vendor/fonts/rajdhani-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Rajdhani';
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  src: url('/vendor/fonts/rajdhani-700.woff2') format('woff2');
}
@font-face {
  font-family: 'Share Tech Mono';
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url('/vendor/fonts/sharetechmono.woff2') format('woff2');
}

:root {
  --bg: #020617;
  --panel: rgba(8, 15, 35, .72);
  --line: #1e3a5f;
  --cyan: #22d3ee;
  --blue: #3b82f6;
  --violet: #8b5cf6;
  --ok: #34d399;
  --warn: #fbbf24;
  --crit: #f87171;
  --text: #e2f3ff;
  --dim: #7da2c1;
  --font-display: 'Rajdhani', 'Segoe UI', sans-serif;
  --font-mono: 'Share Tech Mono', ui-monospace, monospace;
  --glow-cyan: 0 0 12px rgba(34, 211, 238, .35);
  --panel-dark: rgba(2, 8, 23, .88);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 70% 50% at 50% 36%, rgba(34, 211, 238, .06), transparent 60%),
    radial-gradient(ellipse 80% 70% at 50% 50%, transparent 50%, rgba(0, 0, 0, .55) 100%),
    linear-gradient(rgba(30, 58, 95, .14) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(90deg, rgba(30, 58, 95, .14) 1px, transparent 1px) 0 0 / 44px 44px,
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.45;
  overflow-x: hidden;
}

h1, h2, h3, h4, button, kbd, .status-pill, .chip, .voice-state {
  font-family: var(--font-display);
}

a { color: var(--cyan); text-decoration: none; }
a:hover { text-shadow: var(--glow-cyan); }
button { cursor: pointer; color: inherit; background: none; border: none; font-size: inherit; }
input { font-family: var(--font-mono); color: var(--text); }
svg { flex-shrink: 0; }

::selection { background: rgba(34, 211, 238, .3); }

:focus-visible {
  outline: 1px solid var(--cyan);
  outline-offset: 2px;
  border-radius: 2px;
}

.scroll { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.scroll::-webkit-scrollbar { width: 5px; height: 5px; }
.scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.scroll::-webkit-scrollbar-thumb:hover { background: var(--cyan); }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* ---------- scanline global ---------- */
.scanline {
  position: fixed; inset: 0; z-index: 200; pointer-events: none;
  background: repeating-linear-gradient(0deg,
    transparent 0 2px, rgba(34, 211, 238, .022) 2px 3px);
}
.scanline::after {
  content: '';
  position: absolute; left: 0; right: 0; height: 90px;
  background: linear-gradient(180deg, transparent, rgba(34, 211, 238, .045), transparent);
  animation: scan-sweep 9s linear infinite;
}
@keyframes scan-sweep {
  from { top: -12%; }
  to { top: 112%; }
}

/* ---------- painéis + corner brackets ---------- */
.panel {
  position: relative;
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 0 24px rgba(0, 0, 0, .45), inset 0 0 42px rgba(34, 211, 238, .025);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
.panel::after {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(var(--cyan), var(--cyan)) top left    / 14px 1.5px,
    linear-gradient(var(--cyan), var(--cyan)) top left    / 1.5px 14px,
    linear-gradient(var(--cyan), var(--cyan)) top right   / 14px 1.5px,
    linear-gradient(var(--cyan), var(--cyan)) top right   / 1.5px 14px,
    linear-gradient(var(--cyan), var(--cyan)) bottom left / 14px 1.5px,
    linear-gradient(var(--cyan), var(--cyan)) bottom left / 1.5px 14px,
    linear-gradient(var(--cyan), var(--cyan)) bottom right/ 14px 1.5px,
    linear-gradient(var(--cyan), var(--cyan)) bottom right/ 1.5px 14px;
  background-repeat: no-repeat;
  opacity: .55;
  transition: opacity .25s;
}
.panel:hover::after { opacity: .95; }

.panel-title {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  font-size: 12px; font-weight: 700;
  letter-spacing: .22em; text-transform: uppercase;
  color: var(--cyan);
  border-bottom: 1px solid var(--line);
  text-shadow: 0 0 10px rgba(34, 211, 238, .4);
  flex-shrink: 0;
}
.panel-title svg { color: var(--cyan); opacity: .9; }
.panel-title .title-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.panel-sub {
  padding: 8px 12px 4px;
  font-size: 11px; font-weight: 700;
  letter-spacing: .2em; text-transform: uppercase;
  color: var(--dim);
  flex-shrink: 0;
}

.panel-body { padding: 10px 12px; min-height: 0; }

/* ---------- skeleton shimmer ---------- */
.sk-lines { padding: 12px; }
.sk-lines i {
  display: block; height: 10px; border-radius: 2px;
  margin-bottom: 12px;
  background: linear-gradient(90deg,
    rgba(125, 162, 193, .07) 25%, rgba(125, 162, 193, .2) 50%, rgba(125, 162, 193, .07) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}
.sk-lines i:nth-child(2) { width: 82%; }
.sk-lines i:nth-child(3) { width: 64%; }
@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ---------- login ---------- */
#login-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 26px; padding: 24px;
  background:
    radial-gradient(ellipse 60% 45% at 50% 42%, rgba(34, 211, 238, .08), transparent 60%),
    radial-gradient(ellipse 90% 80% at 50% 50%, transparent 40%, rgba(0, 0, 0, .7) 100%),
    var(--bg);
}

.reactor { position: relative; width: 190px; height: 190px; }
.reactor-ring { position: absolute; border-radius: 50%; }
.reactor-ring.r1 {
  inset: 0;
  border: 1px solid rgba(34, 211, 238, .22);
  border-top-color: var(--cyan);
  box-shadow: 0 0 30px rgba(34, 211, 238, .18), inset 0 0 30px rgba(34, 211, 238, .07);
  animation: spin 3.2s linear infinite;
}
.reactor-ring.r2 {
  inset: 18px;
  border: 1px dashed rgba(59, 130, 246, .45);
  animation: spin 9s linear infinite reverse;
}
.reactor-ring.r3 {
  inset: 38px;
  border: 2px solid transparent;
  border-left-color: var(--violet);
  border-right-color: rgba(34, 211, 238, .55);
  animation: spin 5.5s linear infinite;
}
.reactor-ticks {
  position: absolute; inset: 7px; border-radius: 50%;
  background: repeating-conic-gradient(rgba(34, 211, 238, .55) 0 1.2deg, transparent 1.2deg 12deg);
  -webkit-mask-image: radial-gradient(circle, transparent 61%, #000 62%, #000 67%, transparent 68%);
  mask-image: radial-gradient(circle, transparent 61%, #000 62%, #000 67%, transparent 68%);
  animation: spin 22s linear infinite;
}
.reactor-core {
  position: absolute; inset: 62px; border-radius: 50%;
  background: radial-gradient(circle at 50% 45%,
    rgba(226, 243, 255, .95), rgba(34, 211, 238, .8) 35%, rgba(59, 130, 246, .35) 70%, transparent 100%);
  box-shadow: 0 0 40px rgba(34, 211, 238, .55), 0 0 90px rgba(59, 130, 246, .3);
  animation: core-pulse 2.6s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes core-pulse {
  0%, 100% { transform: scale(1); opacity: .9; }
  50% { transform: scale(1.08); opacity: 1; }
}

.login-title {
  font-size: clamp(26px, 4vw, 40px);
  font-weight: 700; letter-spacing: .3em; text-transform: uppercase;
  color: var(--text); text-align: center;
  text-shadow: 0 0 24px rgba(34, 211, 238, .5);
}
.login-title span { color: var(--cyan); font-weight: 500; }
.login-sub {
  color: var(--dim); letter-spacing: .16em; text-transform: uppercase;
  font-size: 12px; text-align: center;
}

#login-form { display: flex; gap: 10px; align-items: stretch; }
#login-pass {
  width: min(280px, 60vw);
  background: var(--panel-dark);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 11px 14px;
  font-size: 14px; letter-spacing: .3em; text-align: center;
  transition: border-color .2s, box-shadow .2s;
}
#login-pass::placeholder { color: var(--dim); letter-spacing: .18em; font-size: 11px; }
#login-pass:focus { border-color: var(--cyan); box-shadow: var(--glow-cyan); outline: none; }
#login-form button {
  display: flex; align-items: center; gap: 8px;
  padding: 0 18px;
  background: rgba(34, 211, 238, .1);
  border: 1px solid var(--cyan);
  border-radius: 3px;
  color: var(--cyan);
  font-weight: 700; font-size: 12px; letter-spacing: .2em;
  transition: background .2s, box-shadow .2s;
}
#login-form button:hover { background: rgba(34, 211, 238, .22); box-shadow: var(--glow-cyan); }

#login-err {
  color: var(--crit); font-size: 12px; letter-spacing: .1em;
  text-shadow: 0 0 10px rgba(248, 113, 113, .5);
}
.login-foot {
  position: absolute; bottom: 26px;
  color: var(--dim); font-size: 10px; letter-spacing: .3em; text-transform: uppercase;
  opacity: .7;
}
#login-screen.authing .reactor-ring.r1 { animation-duration: .7s; }
#login-screen.authing .reactor-ring.r3 { animation-duration: 1s; }
#login-screen.authing .reactor-core { animation-duration: .8s; }

/* ---------- HUD grid ---------- */
#hud {
  display: grid;
  height: 100dvh;
  padding: 10px;
  gap: 10px;
  grid-template-columns: minmax(232px, 19fr) minmax(0, 44fr) minmax(304px, 22fr);
  grid-template-rows: auto minmax(0, 1fr) clamp(172px, 21vh, 244px) auto;
  grid-template-areas:
    'header header header'
    'left   center right'
    'bottom bottom bottom'
    'footer footer footer';
  animation: hud-boot .9s cubic-bezier(.2, .8, .3, 1) both;
}
@keyframes hud-boot {
  from { opacity: 0; transform: scale(.985); filter: brightness(2) saturate(1.6); }
  to { opacity: 1; transform: scale(1); filter: none; }
}

/* ---------- header ---------- */
.hud-header {
  grid-area: header;
  flex-direction: row;
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  align-items: center;
  gap: 18px;
  padding: 8px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { filter: drop-shadow(0 0 8px rgba(34, 211, 238, .5)); }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700; font-size: 15px; letter-spacing: .08em;
}

.clock-block {
  display: flex; flex-direction: column;
  padding-left: 18px; border-left: 1px solid var(--line);
}
#clock {
  font-size: 21px; letter-spacing: .1em; color: var(--text);
  text-shadow: 0 0 12px rgba(34, 211, 238, .35);
}
#clock-date { font-size: 10px; color: var(--dim); letter-spacing: .18em; text-transform: uppercase; }

.hud-title { text-align: center; min-width: 0; }
.hud-title h1 {
  font-size: clamp(17px, 1.9vw, 27px);
  font-weight: 700; letter-spacing: .32em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 0 20px rgba(34, 211, 238, .45);
}
.hud-title h1 span { color: var(--cyan); font-weight: 500; }
.hud-title p {
  font-size: 10px; color: var(--dim); letter-spacing: .22em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.hud-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 34px; height: 34px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 3px;
  background: rgba(8, 15, 35, .6);
  color: var(--dim);
  transition: color .2s, border-color .2s, box-shadow .2s;
}
.icon-btn:hover, .icon-btn.active {
  color: var(--cyan); border-color: var(--cyan); box-shadow: var(--glow-cyan);
}
.icon-btn kbd {
  font-size: 10px; font-weight: 700; letter-spacing: .05em;
  color: var(--dim); border: 1px solid var(--line); border-radius: 2px;
  padding: 1px 4px; line-height: 1.3;
}
.icon-btn:hover kbd { color: var(--cyan); border-color: var(--cyan); }

.status-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  border: 1px solid rgba(52, 211, 153, .5); border-radius: 3px;
  font-size: 11px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ok);
  background: rgba(52, 211, 153, .06);
}
.status-pill .lbl { color: var(--dim); font-weight: 500; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  animation: dot-pulse 2s ease-in-out infinite;
}
.dot.warn { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.dot.crit { background: var(--crit); box-shadow: 0 0 8px var(--crit); }
@keyframes dot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.8); }
}

/* ---------- colunas ---------- */
.col-left { grid-area: left; display: flex; min-height: 0; overflow: hidden; }
.col-left .panel { flex: 1; }
#agents-list { flex: 1; padding: 8px; min-height: 0; }

.col-center { grid-area: center; display: flex; min-height: 0; overflow: hidden; }
.col-right { grid-area: right; display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: hidden; }
#panel-infra { flex: 0 1 auto; min-height: 150px; max-height: 52%; }

/* ---------- cérebro ---------- */
.brain-panel { flex: 1; }
.brain-top {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0; flex-wrap: wrap;
}
.brain-top .panel-title { border-bottom: none; }

#brain-modes { display: flex; gap: 4px; padding: 6px 10px; flex-wrap: wrap; }
#brain-modes button {
  padding: 5px 12px;
  font-size: 10px; font-weight: 700; letter-spacing: .16em;
  color: var(--dim);
  border: 1px solid var(--line); border-radius: 2px;
  background: rgba(8, 15, 35, .5);
  transition: color .2s, border-color .2s, background .2s, box-shadow .2s;
}
#brain-modes button:hover { color: var(--text); border-color: var(--cyan); }
#brain-modes button.active,
#brain-modes button[aria-selected='true'] {
  color: var(--cyan); border-color: var(--cyan);
  background: rgba(34, 211, 238, .1);
  box-shadow: var(--glow-cyan);
}

.brain-body { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#brain-canvas { position: absolute; inset: 0; }
#brain-canvas canvas { outline: none; }

#brain-stats {
  position: absolute; left: 12px; bottom: 12px; z-index: 5;
  display: flex; gap: 6px; flex-wrap: wrap;
  pointer-events: none;
}
#brain-stats > * { pointer-events: auto; }
.chip, #brain-stats > span, #brain-stats > div {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  font-family: var(--font-display);
  font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--dim);
  background: var(--panel-dark);
  border: 1px solid var(--line); border-radius: 2px;
}
.chip strong, #brain-stats strong { color: var(--cyan); font-family: var(--font-mono); font-weight: 400; }

#brain-detail {
  position: absolute; top: 10px; right: 10px; bottom: 10px; z-index: 6;
  width: min(300px, 78%);
  background: var(--panel-dark);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--cyan);
  border-radius: 4px;
  box-shadow: 0 0 30px rgba(34, 211, 238, .18);
  padding: 14px;
  overflow-y: auto;
  animation: detail-in .28s cubic-bezier(.2, .8, .3, 1) both;
}
@keyframes detail-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

#global-sync {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.sync-lbl {
  font-family: var(--font-display);
  font-size: 10px; font-weight: 700; letter-spacing: .22em;
  color: var(--dim); white-space: nowrap;
}
.sync-bar {
  flex: 1; height: 5px;
  background: rgba(30, 58, 95, .5);
  border-radius: 3px; overflow: hidden;
}
.sync-fill {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--blue), var(--cyan));
  box-shadow: 0 0 10px rgba(34, 211, 238, .6);
  border-radius: 3px;
  transition: width .8s cubic-bezier(.2, .8, .3, 1);
}
.sync-val { color: var(--cyan); font-size: 13px; min-width: 42px; text-align: right; }

/* ---------- infra & modelos ---------- */
#panel-infra { flex: 1.15; }
#infra-metrics { padding: 10px 12px; flex-shrink: 0; }

#health-gauges {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.gauge { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.gauge svg { width: 56px; height: 56px; }
.gauge .g-track { stroke: rgba(30, 58, 95, .6); fill: none; }
.gauge .g-arc {
  stroke: var(--cyan); fill: none; stroke-linecap: round;
  filter: drop-shadow(0 0 4px rgba(34, 211, 238, .6));
  transform: rotate(-90deg); transform-origin: center;
  transition: stroke-dashoffset .8s cubic-bezier(.2, .8, .3, 1);
}
.gauge.warn .g-arc { stroke: var(--warn); filter: drop-shadow(0 0 4px rgba(251, 191, 36, .6)); }
.gauge.crit .g-arc { stroke: var(--crit); filter: drop-shadow(0 0 4px rgba(248, 113, 113, .6)); }
.gauge .g-val { font-family: var(--font-mono); font-size: 12px; fill: var(--text); text-anchor: middle; }
.gauge .g-lbl {
  font-family: var(--font-display);
  font-size: 9px; font-weight: 700; letter-spacing: .18em;
  color: var(--dim); text-transform: uppercase;
}

.metric-line, #infra-metrics .m-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 4px 0;
  border-bottom: 1px dashed rgba(30, 58, 95, .5);
  font-size: 12px;
}
.metric-line:last-child { border-bottom: none; }
.metric-line .m-lbl { color: var(--dim); letter-spacing: .08em; text-transform: uppercase; font-size: 10px; }
.metric-line .m-val { color: var(--text); }

#models-list { flex: 1; padding: 4px 12px 10px; min-height: 0; }
.model-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; margin-bottom: 4px;
  border: 1px solid rgba(30, 58, 95, .55); border-radius: 3px;
  background: rgba(8, 15, 35, .5);
  font-size: 12px;
  transition: border-color .2s;
}
.model-row:hover { border-color: var(--cyan); }
.model-row.active { border-color: var(--cyan); box-shadow: inset 0 0 14px rgba(34, 211, 238, .08); }
.model-row .m-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-row .m-tag {
  font-family: var(--font-display);
  font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ok);
}

/* ---------- voz / hermes ---------- */
#panel-infra { flex: 0 0 auto; }
#voice-panel { flex: 1 1 auto; min-height: 230px; }
.voice-top {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px 4px;
  flex-shrink: 0;
}
.voice-state {
  flex: 0 0 auto; max-width: 45%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 11px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase;
  color: var(--dim);
}
.voice-state[data-state='listening'] { color: var(--cyan); text-shadow: var(--glow-cyan); }
.voice-state[data-state='thinking'] { color: var(--violet); }
.voice-state[data-state='speaking'] { color: var(--ok); }
.voice-state[data-state='error'] { color: var(--crit); }

#btn-mic {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--cyan);
  background: radial-gradient(circle at 50% 40%, rgba(34, 211, 238, .18), rgba(8, 15, 35, .8));
  color: var(--cyan);
  box-shadow: 0 0 12px rgba(34, 211, 238, .25);
  transition: box-shadow .2s, transform .15s;
  flex-shrink: 0;
  align-self: flex-end;
}
#btn-mic:hover { box-shadow: 0 0 24px rgba(34, 211, 238, .5); transform: scale(1.05); }
#btn-mic.active, #btn-mic[aria-pressed='true'] {
  border-color: var(--ok); color: var(--ok);
  box-shadow: 0 0 26px rgba(52, 211, 153, .5);
  animation: mic-pulse 1.6s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 14px rgba(52, 211, 153, .35); }
  50% { box-shadow: 0 0 30px rgba(52, 211, 153, .65); }
}

#voice-viz {
  flex: 1 1 auto; min-width: 0; height: 30px;
  border: 1px solid rgba(30, 58, 95, .55); border-radius: 3px;
  background: var(--panel-dark);
}

#chat-log {
  flex: 1; min-height: 110px;
  padding: 4px 12px;
  display: flex; flex-direction: column; gap: 6px;
  overscroll-behavior: contain;
}
#chat-log .msg {
  max-width: 94%;
  padding: 7px 10px;
  border-radius: 3px;
  font-size: 12.5px;
  line-height: 1.45;
  border: 1px solid rgba(30, 58, 95, .55);
  background: rgba(8, 15, 35, .55);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
#chat-log .msg.user { align-self: flex-end; border-color: rgba(59, 130, 246, .5); color: var(--text); }
#chat-log .msg.hermes { align-self: flex-start; border-color: rgba(34, 211, 238, .4); color: var(--text); }
#chat-log .msg .who {
  display: block;
  font-family: var(--font-display);
  font-size: 9px; font-weight: 700; letter-spacing: .18em;
  color: var(--dim); text-transform: uppercase;
  margin-bottom: 2px;
}

#chat-form {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 12px 12px;
  flex-shrink: 0;
  border-top: 1px solid rgba(30, 58, 95, .45);
  background: rgba(4, 9, 24, .5);
}
#chat-input {
  flex: 1; min-width: 0;
  background: var(--panel-dark);
  border: 1px solid var(--line); border-radius: 3px;
  padding: 9px 11px;
  font-size: 12.5px;
  font-family: var(--font-mono, inherit);
  line-height: 1.4;
  color: var(--text);
  resize: none;
  max-height: 96px;
  transition: border-color .2s, box-shadow .2s;
}
#chat-input::placeholder { color: var(--dim); }
#chat-input:focus { border-color: var(--cyan); box-shadow: var(--glow-cyan); outline: none; }
#chat-form button[type='submit'] {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 3px;
  color: var(--dim);
  transition: color .2s, border-color .2s, box-shadow .2s;
  align-self: flex-end;
}
#chat-form button[type='submit']:hover { color: var(--cyan); border-color: var(--cyan); box-shadow: var(--glow-cyan); }

/* ---------- linha inferior ---------- */
.row-bottom {
  grid-area: bottom;
  display: grid;
  grid-template-columns: 1.05fr 1.3fr 1.3fr 1.3fr .42fr;
  gap: 10px;
  min-height: 0;
}
.row-bottom .panel > div:last-child { flex: 1; min-height: 0; }

#dev-panel, #timeline-list, #approvals-list { padding: 8px 10px; }

.dev-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 5px 8px; margin-bottom: 4px;
  border: 1px solid rgba(30, 58, 95, .5); border-radius: 3px;
  font-size: 11px;
}
.dev-row .d-tag {
  font-family: var(--font-display);
  font-size: 9px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ok);
}

.tl-item, #timeline-list > li, #timeline-list > div {
  position: relative;
  padding: 4px 6px 4px 16px;
  margin-bottom: 3px;
  font-size: 11px;
  border-left: 2px solid var(--line);
  list-style: none;
}
.tl-item::before, #timeline-list > li::before, #timeline-list > div::before {
  content: '';
  position: absolute; left: -5px; top: 9px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--dim);
}
.tl-item.ok { border-left-color: var(--ok); }
.tl-item.ok::before { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.tl-item.warn { border-left-color: var(--warn); }
.tl-item.warn::before { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.tl-item.crit { border-left-color: var(--crit); }
.tl-item.crit::before { background: var(--crit); box-shadow: 0 0 6px var(--crit); }
.tl-item .tl-ts { color: var(--dim); margin-right: 6px; font-size: 10px; }

#sync-panel { padding: 8px 10px 0; flex-shrink: 0; }
#sync-panel .sync-row {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 0; font-size: 11px;
}
#sync-panel .sync-row .s-lbl { color: var(--dim); min-width: 72px; text-transform: uppercase; font-size: 10px; letter-spacing: .1em; }

.appr-item {
  padding: 6px 8px; margin-bottom: 4px;
  border: 1px solid rgba(30, 58, 95, .5); border-left-width: 3px; border-radius: 3px;
  font-size: 11px;
}
.appr-item.r2 { border-left-color: var(--warn); }
.appr-item.r3 { border-left-color: var(--crit); }
.appr-item .risk {
  font-family: var(--font-display);
  font-size: 9px; font-weight: 700; letter-spacing: .1em;
  padding: 1px 5px; border-radius: 2px;
  border: 1px solid var(--line); color: var(--dim);
}

.term-panel .panel-title { color: #5eead4; text-shadow: 0 0 10px rgba(94, 234, 212, .35); }
#term-view {
  flex: 1; min-height: 0;
  margin: 8px; padding: 8px 10px;
  background: #010409;
  border: 1px solid rgba(30, 58, 95, .5); border-radius: 3px;
  font-size: 11px; line-height: 1.6;
  color: #5eead4;
  white-space: pre-wrap; word-break: break-word;
}
#term-view .t-dim { color: var(--dim); }
#term-view .t-warn { color: var(--warn); }
#term-view .t-crit { color: var(--crit); }

.apps-panel { overflow: hidden; }
#btn-apps {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: var(--dim);
  font-weight: 700; font-size: 12px; letter-spacing: .3em; text-transform: uppercase;
  transition: color .25s, background .25s;
}
#btn-apps:hover { color: var(--cyan); background: rgba(34, 211, 238, .06); }
#btn-apps svg { width: 30px; height: 30px; }
#btn-apps small { font-size: 9px; letter-spacing: .18em; color: var(--dim); font-weight: 500; }

/* ---------- footer ---------- */
.hud-footer {
  grid-area: footer;
  display: flex; align-items: center; gap: 26px;
  padding: 8px 16px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 4px;
  font-size: 11px;
  overflow-x: auto;
}
.foot-status {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-display);
  font-weight: 700; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ok); white-space: nowrap;
}
.foot-item {
  display: flex; align-items: baseline; gap: 8px;
  color: var(--dim);
  font-family: var(--font-display);
  font-size: 10px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase;
  white-space: nowrap;
}
.foot-item strong { font-family: var(--font-mono); font-weight: 400; font-size: 12px; color: var(--text); }
.foot-item:last-child { margin-left: auto; }
#f-status { color: var(--cyan); }

/* ---------- apps modal ---------- */
#apps-modal {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(2, 6, 23, .75);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.modal-panel {
  width: min(980px, 94vw);
  max-height: 86vh;
  animation: modal-in .25s cubic-bezier(.2, .8, .3, 1) both;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-right: 8px;
}
.modal-head .panel-title { border-bottom: none; }
#apps-grid {
  flex: 1; min-height: 120px;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  align-content: start;
}
#apps-grid .cat-title {
  grid-column: 1 / -1;
  font-family: var(--font-display);
  font-size: 10px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase;
  color: var(--dim);
  padding-top: 6px;
  border-bottom: 1px dashed rgba(30, 58, 95, .5);
}
.app-tile, #apps-grid a {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px;
  border: 1px solid rgba(30, 58, 95, .55); border-radius: 3px;
  background: rgba(8, 15, 35, .55);
  color: var(--text);
  font-size: 12px;
  transition: border-color .2s, box-shadow .2s, transform .15s;
}
.app-tile:hover, #apps-grid a:hover {
  border-color: var(--cyan); box-shadow: var(--glow-cyan);
  transform: translateY(-2px); text-shadow: none;
}
.app-tile small { color: var(--dim); font-size: 10px; }

/* ---------- palette ---------- */
#palette {
  position: fixed; inset: 0; z-index: 95;
  display: flex; justify-content: center; align-items: flex-start;
  padding-top: 16vh;
  background: rgba(2, 6, 23, .72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.palette-panel {
  width: min(580px, 92vw);
  max-height: 56vh;
  animation: modal-in .22s cubic-bezier(.2, .8, .3, 1) both;
}
.palette-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--cyan);
}
#palette-input {
  flex: 1; min-width: 0;
  background: none; border: none; outline: none;
  font-size: 15px; letter-spacing: .04em;
}
#palette-input::placeholder { color: var(--dim); }
#palette-results {
  list-style: none;
  overflow-y: auto;
  padding: 6px;
  min-height: 40px;
}
#palette-results li, #palette-results .pal-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 3px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
}
#palette-results li:hover, #palette-results li.active,
#palette-results .pal-item:hover, #palette-results .pal-item.active {
  background: rgba(34, 211, 238, .08);
  border-color: rgba(34, 211, 238, .4);
  color: var(--cyan);
}
#palette-results .pal-kind {
  margin-left: auto;
  font-family: var(--font-display);
  font-size: 9px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--dim);
}

/* ---------- modos focus / wall ---------- */
body.mode-focus #hud {
  grid-template-columns: minmax(0, 1fr) minmax(304px, 24fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    'header header'
    'center right'
    'footer footer';
}
body.mode-focus .col-left,
body.mode-focus .row-bottom,
body.mode-focus #panel-infra { display: none; }

body.mode-wall #hud {
  grid-template-columns: minmax(260px, 19fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    'header header'
    'left   center'
    'footer footer';
  font-size: 15px;
}
body.mode-wall .col-right,
body.mode-wall .row-bottom { display: none; }
body.mode-wall .hud-title h1 { font-size: clamp(22px, 2.6vw, 36px); }
body.mode-wall #clock { font-size: 26px; }
body.mode-wall .hud-actions .icon-btn kbd { display: none; }

#models-list { max-height: 132px; }
#sync-panel { flex-shrink: 0; }

#btn-missions {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 5px;
  background: none; border: 1px solid var(--line); border-radius: 3px;
  color: var(--cyan);
  font: 700 9.5px/1 var(--font-display); letter-spacing: .14em; text-transform: uppercase;
  padding: 4px 8px; cursor: pointer;
  transition: border-color .2s, box-shadow .2s;
}
#btn-missions:hover { border-color: var(--cyan); box-shadow: var(--glow-cyan); }
#missions-badge:not(:empty) {
  background: rgba(34, 211, 238, .18);
  border-radius: 8px; padding: 1px 6px; color: var(--cyan);
}

/* telas baixas: HUD cresce e a página rola em vez de esmagar painéis */
@media (max-height: 820px) {
  #hud {
    height: auto;
    min-height: 100dvh;
    grid-template-rows: auto minmax(480px, 62vh) minmax(200px, auto) auto;
  }
  html, body { overflow-y: auto; }
  #voice-panel { min-height: 260px; }
}

/* ---------- responsivo ---------- */
@media (max-width: 1280px) {
  .row-bottom { grid-template-columns: repeat(3, 1fr); }
  .apps-panel { grid-column: span 1; }
  #health-gauges { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1024px) {
  #hud {
    height: auto; min-height: 100dvh;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto minmax(440px, 56vh) auto auto auto;
    grid-template-areas:
      'header header'
      'center center'
      'left   right'
      'bottom bottom'
      'footer footer';
  }
  .col-left, .col-right { min-height: 320px; }
  .hud-header { grid-template-columns: auto 1fr auto; gap: 12px; }
  .clock-block, .status-pill .lbl { display: none; }
  .row-bottom { grid-template-columns: repeat(2, 1fr); }
  body.mode-focus #hud, body.mode-wall #hud {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(440px, 60vh) auto auto;
  }
  body.mode-focus #hud { grid-template-areas: 'header' 'center' 'right' 'footer'; }
  body.mode-wall #hud { grid-template-areas: 'header' 'center' 'left' 'footer'; }
}

@media (max-width: 768px) {
  body { font-size: 12px; }
  #hud {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(360px, 48vh) auto auto auto auto;
    grid-template-areas: 'header' 'center' 'left' 'right' 'bottom' 'footer';
    padding: 8px; gap: 8px;
  }
  .hud-header { display: flex; flex-wrap: wrap; justify-content: space-between; padding: 8px 10px; }
  .hud-title { order: -1; width: 100%; }
  .hud-title h1 { letter-spacing: .18em; white-space: normal; }
  .row-bottom { grid-template-columns: 1fr; }
  .row-bottom .panel { min-height: 150px; }
  #brain-detail { width: 88%; }
  .hud-footer { gap: 14px; }
  .foot-item:last-child { margin-left: 0; }
  #health-gauges { grid-template-columns: repeat(4, 1fr); }
  .reactor { width: 150px; height: 150px; }
  .reactor-core { inset: 48px; }
  .reactor-ring.r3 { inset: 30px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .scanline { display: none; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
