:root {
  --bg: #0a1120;
  --bg-2: #0f1a2e;
  --panel: rgba(255,255,255,0.045);
  --panel-border: rgba(255,255,255,0.09);
  --panel-hover: rgba(255,255,255,0.07);
  --text: #e8edf6;
  --text-dim: #93a1bb;
  --text-faint: #5c6a87;
  --accent: #38c6f4;
  --accent-2: #7dd3fc;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 16px;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .live-portrait-wrap, .live-pulse-target { animation: none !important; }
  * { scroll-behavior: auto !important; }
}

html, body {
  margin: 0;
  background: linear-gradient(135deg, rgba(10,17,32,0.92), rgba(15,26,46,0.88)),
              url('assets/control-center-bg.jpg') center/cover no-repeat fixed;
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden; /* safety net on top of the real fixes above — never let the page itself scroll sideways */
}

.shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #0c1526, #081020);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 22px; }
.brand-spark { color: var(--accent-2); font-size: 22px; }
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: 0.5px; }
.brand-sub { font-size: 10px; letter-spacing: 2px; color: var(--text-dim); }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover:not(.disabled) { background: var(--panel-hover); color: var(--text); }
.nav-item.active { background: rgba(56,198,244,0.14); color: var(--accent-2); font-weight: 600; }
.nav-item.disabled { color: var(--text-faint); cursor: default; }
.nav-item.disabled::after { content: " · bald"; font-size: 10px; }

.sidebar-footer { padding-top: 16px; border-top: 1px solid var(--panel-border); }
.sidebar-tagline { font-size: 10px; letter-spacing: 2px; color: var(--text-faint); line-height: 1.8; }
.sidebar-version { font-size: 10px; color: var(--text-faint); margin-top: 12px; }

/* Content */
.content { flex: 1; padding: 26px 32px 60px; max-width: 1400px; }
.view { display: none; flex-direction: column; gap: 20px; }
.view.active { display: flex; }

.card {
  background: rgba(15,26,46,0.65);
  border: 1px solid rgba(125,211,252,0.2);
  border-radius: var(--radius);
  padding: 20px 22px;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { font-size: clamp(14px, 1.5vw, 15px); margin: 0; color: var(--text); font-weight: 600; }

.link-btn { background: none; border: none; color: var(--accent-2); font-size: 12px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* Hero */
.hero { display: flex; align-items: center; justify-content: space-between; }
.hero h1 { margin: 0 0 6px; font-size: clamp(19px, 3.2vw, 26px); }
.hero-sub { margin: 0; color: var(--text-dim); }
.hero-clock { text-align: right; }
.clock-time { font-size: clamp(19px, 3.2vw, 26px); font-weight: 700; color: var(--accent-2); }

/* Card subheads / section headers */
.card-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.team-panel .card-head, .brain-card .card-head, .live-card .card-head { align-items: flex-start; }
.team-head-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.team-online-summary { font-size: 12px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 6px; }
.team-online-summary::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px var(--green); display: inline-block; }
.team-online-summary.mixed::before { background: var(--amber); box-shadow: 0 0 6px var(--amber); }

/* Hero main: LUMI LIVE + LUMI BRAIN side by side */
.hero-main { align-items: stretch; }
.hero-main .card { display: flex; flex-direction: column; }

/* Agent strip */
.agent-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.agent-tile {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
  display: flex;
  flex-direction: column;
}
.agent-tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.agent-tile img { width: 100%; aspect-ratio: 1.1/1; object-fit: cover; display: block; }
.agent-tile .agent-icon-fallback {
  width: 100%; aspect-ratio: 1.1/1; display: flex; align-items: center; justify-content: center;
  font-size: 28px; background: linear-gradient(135deg, #142642, #0b1526);
}
.agent-tile-label { padding: 8px 10px; position: relative; }
.agent-tile-label .name { font-size: 12.5px; font-weight: 600; }
.agent-tile-label .role { font-size: 10.5px; color: var(--text-dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; position: absolute; top: 10px; right: 10px; }
.dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.concept { background: var(--amber); }
.dot.on_demand { background: var(--text-faint); }
.dot.offline { background: var(--red); }
.dot.configured { background: var(--accent); }
.dot.unknown { background: var(--text-faint); }

/* LUMI CORE 3D visual (Main-Dashboard agent-strip tile only) */
.lumi-core-slot { position: relative; width: 100%; aspect-ratio: 1.1/1; background: linear-gradient(135deg, #142642, #0b1526); }
.lumi-core-canvas-host { position: absolute; inset: 0; }
.lumi-core-canvas-host canvas { width: 100%; height: 100%; display: block; }
.lumi-core-label {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none; font-weight: 700; letter-spacing: 0.12em; font-size: clamp(11px, 2.4vw, 14px);
  color: var(--text); text-shadow: 0 0 14px rgba(56,198,244,0.65);
}
.lumi-core-label span { display: block; font-size: 0.75em; font-weight: 600; color: var(--accent-2); letter-spacing: 0.22em; margin-top: 1px; }

/* Real routing signal only (LUMI LIVE handed a task to this agent) — never decorative. */
.agent-tile.agent-active { border-color: var(--amber); box-shadow: 0 0 0 1px rgba(251,191,36,0.5), 0 0 26px 2px rgba(251,191,36,0.25); }

/* Grids */
/* minmax(0, 1fr), not bare 1fr — a bare 1fr track won't shrink below its content's min-content
   width, which silently forces the whole page wider than the viewport on phones the moment any
   descendant (a canvas, a long chat message, ...) has a wide intrinsic size. */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; min-height: 20px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,0.03);
  font-size: 13px; gap: 2px 10px;
}
.list-item > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.list-item .meta { color: var(--text-dim); font-size: 11.5px; flex-shrink: 0; }
.list-item.done { opacity: 0.5; text-decoration: line-through; }
.loading, .empty-state { color: var(--text-faint); font-size: 13px; padding: 10px 2px; }

.status-list { display: flex; flex-direction: column; gap: 7px; }
.status-row { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; }
.status-row .label { display: flex; align-items: center; gap: 8px; }
.status-row .state-badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.state-badge.online { color: var(--green); background: rgba(52,211,153,0.12); }
.state-badge.offline { color: var(--red); background: rgba(248,113,113,0.12); }
.state-badge.configured { color: var(--accent-2); background: rgba(56,198,244,0.12); }
.state-badge.unknown { color: var(--text-faint); background: rgba(255,255,255,0.06); }

/* Forms */
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.stack-form { display: flex; flex-direction: column; gap: 10px; }
input, textarea, button {
  font-family: inherit; font-size: 13px; border-radius: 10px;
  border: 1px solid var(--panel-border); background: rgba(255,255,255,0.04); color: var(--text);
  padding: 9px 12px;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
.inline-form input { flex: 1; }
button { cursor: pointer; background: rgba(56,198,244,0.16); border-color: rgba(56,198,244,0.35); color: var(--accent-2); font-weight: 600; }
button:hover:not(:disabled) { background: rgba(56,198,244,0.28); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.notice {
  font-size: 12px; color: var(--text-dim); background: rgba(56,198,244,0.07);
  border: 1px solid rgba(56,198,244,0.18); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px;
}

.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 10px; }
.qa-btn { padding: 14px; text-align: left; background: rgba(255,255,255,0.04); color: var(--text); font-weight: 500; }
.qa-btn.disabled { opacity: 0.35; cursor: not-allowed; }

/* Chat */
.chat-window { min-height: 220px; max-height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 10px 0; }
.chat-msg { max-width: 70%; padding: 10px 14px; border-radius: 14px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 480px) { .chat-msg { max-width: 88%; } }
.chat-msg.lumi { background: rgba(255,255,255,0.06); align-self: flex-start; }
.chat-msg.user { background: color-mix(in srgb, var(--accent) 25%, transparent); align-self: flex-end; }
.chat-msg.pending { opacity: 0.5; }
.chat-msg.setup-offer { max-width: 85%; }
.setup-offer-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.setup-offer-status { font-size: 12px; color: var(--text-dim); }

/* LUMI LIVE */
.live-stage { display: flex; flex-direction: column; gap: 16px; flex: 1; }

.live-top {
  display: flex;
  align-items: center;
  gap: 20px;
}
@media (max-width: 700px) {
  .live-top { flex-direction: column; }
}

.live-portrait-wrap {
  position: relative;
  width: 128px;
  height: 128px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, #142642, #0b1526);
  box-shadow: 0 0 0 1px var(--panel-border), 0 0 36px 0 rgba(56,198,244,0.10);
  transition: box-shadow .4s ease;
}
.live-portrait { width: 100%; height: 100%; object-fit: cover; display: block; }

.live-portrait-wrap.state-listening { box-shadow: 0 0 0 1px rgba(56,198,244,0.5), 0 0 46px 6px rgba(56,198,244,0.35); }
.live-portrait-wrap.state-understanding { box-shadow: 0 0 0 1px rgba(125,211,252,0.5), 0 0 40px 6px rgba(125,211,252,0.28); animation: live-pulse 1.6s ease-in-out infinite; }
.live-portrait-wrap.state-thinking { box-shadow: 0 0 0 1px rgba(251,191,36,0.45), 0 0 40px 6px rgba(251,191,36,0.22); animation: live-pulse 1.8s ease-in-out infinite; }
.live-portrait-wrap.state-olaf { box-shadow: 0 0 0 1px rgba(251,191,36,0.55), 0 0 46px 8px rgba(251,191,36,0.3); animation: live-pulse 1.2s ease-in-out infinite; }
.live-portrait-wrap.state-speaking { box-shadow: 0 0 0 1px rgba(52,211,153,0.5), 0 0 48px 8px rgba(52,211,153,0.3); animation: live-pulse 1.1s ease-in-out infinite; }
.live-portrait-wrap.state-error { box-shadow: 0 0 0 1px rgba(248,113,113,0.5), 0 0 40px 6px rgba(248,113,113,0.25); }

@keyframes live-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

/* LUMI ATOM: real-audio-reactive canvas (idle/thinking = decorative motion, listening/speaking = real signal) */
.live-atom {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 180px;
  border-radius: 14px;
}

.live-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.live-pill {
  font-size: 12px; font-weight: 600; letter-spacing: 0.3px; color: var(--text-faint);
  background: rgba(255,255,255,0.03); border: 1px solid var(--panel-border);
  border-radius: 999px; padding: 7px 14px; transition: all .25s ease;
}
.live-pill.active { color: var(--accent-2); background: rgba(56,198,244,0.14); border-color: rgba(56,198,244,0.4); }

.live-controls { display: flex; align-items: center; gap: 14px; }
.live-hint { font-size: 12px; color: var(--text-faint); }

.live-mic-btn {
  width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0;
  font-size: 22px; display: flex; align-items: center; justify-content: center;
  background: rgba(56,198,244,0.16); border: 1px solid rgba(56,198,244,0.35);
}
.live-mic-btn:hover:not(:disabled) { background: rgba(56,198,244,0.28); }
@media (max-width: 700px) { .live-mic-btn { width: 72px; height: 72px; font-size: 28px; } }

.live-transcript { min-height: 160px; max-height: 320px; }

.live-hint { font-size: 12px; color: var(--text-faint); text-align: center; min-height: 16px; }

.live-transcript-col { display: flex; flex-direction: column; }
.live-transcript { min-height: 320px; max-height: 60vh; }
@media (max-width: 900px) { .live-transcript { min-height: 220px; max-height: 40vh; } }

/* LUMI BRAIN dashboard panel */
.brain-mini-graph {
  width: 100%; height: 180px; border-radius: 12px;
  border: 1px solid var(--panel-border); background: rgba(255,255,255,0.02);
  overflow: hidden;
}
.brain-mini-graph canvas { width: 100%; height: 100%; display: block; }
.brain-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }

/* Team grid */
.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.team-card { background: rgba(255,255,255,0.03); border: 1px solid var(--panel-border); border-radius: 14px; padding: 14px; cursor: pointer; }
.team-card:hover { border-color: var(--accent); }
.team-card .thead { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.team-card img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
.team-card .tname { font-weight: 600; font-size: 13.5px; }
.team-card .trole { font-size: 11.5px; color: var(--text-dim); }
.team-card .tquote { font-size: 12px; color: var(--text-dim); font-style: italic; }

/* Knowledge */
.knowledge-group { margin-bottom: 4px; }
.knowledge-group-head { font-size: 12px; font-weight: 600; color: var(--text-dim); letter-spacing: 0.5px; text-transform: uppercase; margin: 14px 0 8px; }
.knowledge-group:first-child .knowledge-group-head { margin-top: 0; }
.file-preview {
  white-space: pre-wrap; word-break: break-word; font-size: 12.5px; color: var(--text-dim);
  background: rgba(255,255,255,0.03); border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 12px; max-height: 50vh; overflow-y: auto;
}

/* Knowledge Graph */
.kg-tabs { display: flex; gap: 6px; }
.kg-tab {
  background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border); color: var(--text-dim);
  font-family: inherit; font-size: 12px; padding: 6px 12px; border-radius: 999px; cursor: pointer;
}
.kg-tab.active { background: rgba(56,198,244,0.14); border-color: rgba(56,198,244,0.4); color: var(--accent-2); }
.kg-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 0 10px; flex-wrap: wrap; }
.kg-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.kg-chip {
  background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border); color: var(--text-dim);
  font-family: inherit; font-size: 11.5px; padding: 4px 10px; border-radius: 999px; cursor: pointer;
}
.kg-chip.active { background: rgba(255,255,255,0.09); color: var(--text); border-color: rgba(255,255,255,0.22); }
.kg-refresh-btn {
  background: none; border: 1px solid var(--panel-border); color: var(--text-dim); font-family: inherit;
  font-size: 12px; padding: 5px 10px; border-radius: 8px; cursor: pointer;
}
.kg-refresh-btn:hover { color: var(--text); }
.kg-canvas-wrap {
  position: relative; width: 100%; height: 480px; border: 1px solid var(--panel-border);
  border-radius: 12px; background: rgba(255,255,255,0.02); overflow: hidden;
}
.kg-canvas-wrap canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.kg-canvas-wrap canvas.dragging { cursor: grabbing; }
.net-canvas-wrap { height: 560px; }
@media (max-width: 480px) { .net-canvas-wrap, .kg-canvas-wrap { height: 420px; } }
.kg-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 11px; color: var(--text-dim); }
.kg-legend-item { display: flex; align-items: center; gap: 5px; }
.kg-legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.kg-meta { margin-top: 6px; font-size: 11px; color: var(--text-faint); }
.kg-node-detail dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; font-size: 12.5px; margin: 0 0 12px; }
.kg-node-detail dt { color: var(--text-faint); }
.kg-node-detail dd { margin: 0; color: var(--text-dim); overflow-wrap: anywhere; }
.kg-node-detail .kg-conn-list { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.kg-node-detail .kg-conn-list li { padding: 4px 0; border-bottom: 1px solid var(--panel-border); color: var(--text-dim); }
.kg-node-detail .kg-conn-list li:last-child { border-bottom: none; }
.kg-badge { display: inline-block; font-size: 10.5px; padding: 2px 8px; border-radius: 999px; margin-left: 6px; }
.kg-badge.protected { color: var(--red); background: rgba(248,113,113,0.12); }
.kg-badge.offen { color: var(--green); background: rgba(52,211,153,0.12); }
.kg-badge.intern { color: var(--accent-2); background: rgba(56,198,244,0.12); }
.kg-badge.unklar { color: var(--text-faint); background: rgba(255,255,255,0.06); }

/* Modal */
.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(4,8,16,0.7);
  align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-backdrop.active { display: flex; }
.modal {
  background: var(--bg-2); border: 1px solid var(--panel-border); border-radius: var(--radius);
  max-width: 480px; width: 100%; padding: 24px; max-height: 85vh; overflow-y: auto;
}
.modal img { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; margin-bottom: 12px; }
.modal h3 { margin: 0 0 2px; }
.modal .role { color: var(--text-dim); font-size: 13px; margin-bottom: 10px; }
.modal .quote { font-style: italic; color: var(--accent-2); margin-bottom: 14px; }
.modal ul { padding-left: 18px; margin: 0 0 14px; font-size: 13px; color: var(--text-dim); }
.modal .status-note { font-size: 12px; color: var(--text-faint); border-top: 1px solid var(--panel-border); padding-top: 10px; }
.modal-close { float: right; background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; }

/* Responsive: sidebar becomes a horizontal top bar on tablet/phone (spec: nav must fully
   adapt, not just reflow content) */
/* Notebook (1366×768-class displays): tighten padding, no layout change needed otherwise */
@media (max-width: 1300px) {
  .content { padding: 22px 20px 50px; }
  .card { padding: 16px 18px; }
}

/* Tablet / phone: sidebar becomes a horizontal top bar (nav must fully adapt, not just reflow) */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 40;
    flex-direction: row; align-items: center; padding: 10px 12px; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--panel-border);
    padding-top: max(10px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .brand { padding: 0 12px 0 2px; flex-shrink: 0; }
  .nav { flex-direction: row; flex: none; overflow-x: auto; overflow-y: visible; gap: 4px; }
  .nav-item { white-space: nowrap; }
  .nav-item.disabled::after { content: ""; }
  .sidebar-footer { display: none; }
  .content {
    padding: 16px 14px 48px; max-width: 100%;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    padding-bottom: max(48px, env(safe-area-inset-bottom));
  }
  .hero { flex-direction: column; align-items: flex-start; gap: 10px; }
  .hero-clock { text-align: left; }
  .card-head { flex-wrap: wrap; gap: 8px; }
  .team-head-right { width: 100%; justify-content: space-between; }
}

/* Phone: decluttered agent cards (portrait + name + status only, per spec), smaller atom */
@media (max-width: 480px) {
  .agent-strip { grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 8px; }
  .agent-tile-label .role { display: none; }
  .live-atom { height: 140px; }
  .live-pill { font-size: 11px; padding: 6px 10px; }
  .live-mic-btn { width: 64px; height: 64px; font-size: 24px; }
  .brain-mini-graph { height: 140px; }
  .modal { padding: 18px; }
}
