:root {
  --bg: #08090b;
  --panel: #0f1114;
  --panel-2: #14171b;
  --line: #22262c;
  --line-2: #2e333a;
  --text: #e8eaed;
  --muted: #8b919a;
  --faint: #5c626b;
  --silver: #c7ccd3;
  --ok: #7fc8a9;
  --warn: #d9b26f;
  --bad: #d98080;
  --radius: 10px;
  --sans: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2, h3 { font-weight: 500; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 15px; color: var(--silver); }
button, input, select, textarea { font: inherit; color: inherit; }

.eyebrow { font: 11px/1 var(--mono); letter-spacing: 0.22em; color: var(--muted); margin: 0 0 8px; text-transform: uppercase; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }

/* ---------- buttons & inputs ---------- */
.btn { border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 8px; padding: 8px 14px; cursor: pointer; transition: border-color .15s, background .15s; }
.btn:hover { border-color: var(--silver); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.btn.primary:hover { background: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
input, select, textarea { background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 11px; outline: none; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--silver); }
label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.form-error { color: var(--bad); min-height: 20px; margin: 0; font-size: 13px; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1a1d22 0%, var(--bg) 60%); }
.login-card { width: min(380px, 100%); display: grid; gap: 16px; padding: 36px 32px; background: rgba(15,17,20,.85);
  border: 1px solid var(--line); border-radius: 14px; backdrop-filter: blur(8px); }
.login-logo { width: 44px; margin-bottom: 4px; }
.login-card h1 { margin-bottom: 8px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.sidebar { border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; background: var(--bg); }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px; }
.brand img { width: 30px; }
.brand strong { display: block; font: 600 13px/1.1 var(--sans); letter-spacing: .24em; }
.brand span { font-size: 12px; color: var(--muted); }
#nav { display: grid; gap: 2px; }
#nav a { text-decoration: none; padding: 9px 10px; border-radius: 8px; color: var(--muted); }
#nav a:hover { color: var(--text); background: var(--panel); }
#nav a.active { color: var(--text); background: var(--panel-2); box-shadow: inset 2px 0 0 var(--silver); }
.whoami { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 8px; font-size: 12px; color: var(--muted); }

.view { padding: 28px 32px 48px; max-width: 1280px; width: 100%; outline: none; }
.view-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 22px; }
.view-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- cards & grids ---------- */
.grid { display: grid; gap: 14px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card h2 { margin-bottom: 12px; }
.kpi .label { font: 11px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.kpi .value { font-size: 28px; font-weight: 500; margin-top: 10px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.meter { height: 4px; background: var(--line); border-radius: 4px; margin-top: 12px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--silver); border-radius: 4px; }
.meter.warn > i { background: var(--warn); }
.meter.bad > i { background: var(--bad); }

/* ---------- neural map ---------- */
.map { position: relative; height: 300px; padding: 0; overflow: hidden; margin-bottom: 14px;
  background: radial-gradient(800px 300px at 50% 0%, #15181d 0%, var(--panel) 70%); }
.map canvas { width: 100%; height: 100%; display: block; }
.map .legend { position: absolute; left: 18px; bottom: 14px; display: flex; gap: 16px; font-size: 12px; color: var(--muted); pointer-events: none; }
.map .legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.map .title { position: absolute; left: 18px; top: 14px; pointer-events: none; }
.map .tip { position: absolute; pointer-events: none; background: var(--panel-2); border: 1px solid var(--line-2); padding: 4px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -140%); }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font: 11px/1.2 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 400; position: sticky; top: 0; background: var(--panel); }
tr:last-child td { border-bottom: 0; }
td.clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 9px; border-radius: 99px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.pill.ok { color: var(--ok); } .pill.ok::before { background: var(--ok); }
.pill.warn { color: var(--warn); } .pill.warn::before { background: var(--warn); }
.pill.bad { color: var(--bad); } .pill.bad::before { background: var(--bad); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.empty { color: var(--muted); padding: 18px 0; }
.notice { border: 1px dashed var(--line-2); border-radius: var(--radius); padding: 14px 16px; color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input { width: 240px; }
.toolbar select { width: auto; }

/* ---------- chat ---------- */
.chat { display: grid; grid-template-columns: 240px 1fr; gap: 14px; height: calc(100vh - 150px); min-height: 420px; }
.chat-list { overflow: auto; padding: 10px; }
.chat-list button.conv { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; color: var(--muted); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list button.conv:hover { background: var(--panel-2); color: var(--text); }
.chat-list button.conv.active { background: var(--panel-2); color: var(--text); }
.chat-main { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-head select { width: auto; }
.messages { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 78ch; white-space: pre-wrap; word-wrap: break-word; padding: 10px 14px; border-radius: 10px; }
.msg.user { align-self: flex-end; background: var(--panel-2); border: 1px solid var(--line-2); }
.msg.assistant { align-self: flex-start; }
.msg .meta { display: block; font: 11px var(--mono); color: var(--faint); margin-bottom: 4px; }
.msg.pending { color: var(--muted); }
.composer { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--line); }
.composer textarea { resize: none; height: 46px; max-height: 200px; }

/* ---------- misc ---------- */
.toast { position: fixed; right: 18px; bottom: 18px; background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 14px; border-radius: 8px; max-width: 420px; z-index: 10; }
.toast.bad { border-color: var(--bad); }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line-2); border-top-color: var(--silver); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  #nav { grid-auto-flow: column; overflow-x: auto; flex: 1 1 100%; order: 3; }
  #nav a { white-space: nowrap; }
  .whoami { margin: 0 0 0 auto; }
  .view { padding: 20px 14px 40px; }
  .chat { grid-template-columns: 1fr; height: auto; }
  .chat-list { max-height: 140px; }
  .chat-main { height: 70vh; }
  .grid.two { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* =========================================================
   AI Console v2: TEQNIKAL Intelligence
   ========================================================= */
.view:has(.cx) { padding: 16px; max-width: none; }
.cx { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 0; height: calc(100vh - 32px); min-height: 520px;
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--panel); }
.cx-history { border-right: 1px solid var(--line); padding: 14px 10px; overflow: auto; background: #0b0c0f; }
.cx-new { width: 100%; text-align: left; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 12px; cursor: pointer; }
.cx-new:hover { border-color: var(--silver); }
.cx-item { display: flex; align-items: center; border-radius: 7px; }
.cx-item:hover, .cx-item.active { background: var(--panel-2); }
.cx-item-title { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 8px 10px; color: var(--muted); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-item.active .cx-item-title, .cx-item:hover .cx-item-title { color: var(--text); }
.cx-item-del { background: none; border: 0; color: var(--faint); cursor: pointer; padding: 4px 8px; opacity: 0; font-size: 16px; }
.cx-item:hover .cx-item-del { opacity: 1; }
.cx-item-del:hover { color: var(--bad); }

.cx-stage { position: relative; display: flex; flex-direction: column; min-width: 0;
  background: radial-gradient(900px 520px at 50% 38%, #15181d 0%, var(--panel) 62%, #0a0b0d 100%); }
.cx-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,.04); position: relative; z-index: 2; }
.cx-seg { display: inline-flex; background: rgba(0,0,0,.35); border: 1px solid var(--line); border-radius: 99px; padding: 3px; }
.cx-seg-btn { background: none; border: 0; color: var(--muted); padding: 5px 14px; border-radius: 99px; cursor: pointer; font-size: 13px; }
.cx-seg-btn.on { background: var(--text); color: var(--bg); font-weight: 600; }
.cx-seg-btn:disabled { opacity: .35; cursor: default; }
.cx-toggle { display: inline-flex; align-items: center; gap: 8px; background: none; border: 1px solid var(--line-2); color: var(--muted); padding: 5px 12px 5px 6px; border-radius: 99px; cursor: pointer; font-size: 12px; }
.cx-toggle i { width: 26px; height: 14px; border-radius: 99px; background: var(--line-2); position: relative; transition: background .2s; }
.cx-toggle i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); transition: transform .2s, background .2s; }
.cx-toggle.on { color: var(--text); border-color: var(--silver); }
.cx-toggle.on i { background: #3a4048; }
.cx-toggle.on i::after { transform: translateX(12px); background: var(--text); }

.cx-center { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.cx-core { position: absolute; left: 50%; top: 22%; width: 300px; height: 300px; transform: translate(-50%, -50%);
  transition: all .7s cubic-bezier(.2,.8,.2,1); pointer-events: none; z-index: 1; }
.cx-core-canvas { width: 100%; height: 100%; display: block; }
.cx-core-label { position: absolute; left: 50%; top: calc(22% + 128px); transform: translateX(-50%); font: 11px var(--mono); letter-spacing: .18em; text-transform: uppercase; color: var(--muted); transition: opacity .3s; z-index: 1; }
.cx-hero { position: absolute; left: 50%; top: calc(22% + 170px); transform: translateX(-50%); width: min(680px, 92%); text-align: center; transition: opacity .4s; z-index: 2; }
.cx-hero h1 { font-size: 30px; font-weight: 400; letter-spacing: -.02em; margin-bottom: 8px; }
.cx-hero .muted { margin: 0 0 22px; }
.cx-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.cx-chip { background: rgba(20,23,27,.7); border: 1px solid var(--line-2); color: var(--silver); border-radius: 99px; padding: 8px 15px; cursor: pointer; font-size: 13px; backdrop-filter: blur(4px); transition: border-color .15s, color .15s, transform .15s; }
.cx-chip:hover { border-color: var(--text); color: var(--text); transform: translateY(-1px); }

/* conversation mode: core shrinks to a small live indicator at top-left */
.cx-stage:not(.empty) .cx-core { top: 34px; left: 40px; width: 64px; height: 64px; }
.cx-stage:not(.empty) .cx-core-label { top: 26px; left: 80px; transform: none; }
.cx-stage:not(.empty) .cx-hero { opacity: 0; pointer-events: none; }
.cx-stage.empty .cx-thread { opacity: 0; pointer-events: none; }

.cx-thread { flex: 1; overflow: auto; padding: 70px max(24px, calc(50% - 400px)) 24px; display: flex; flex-direction: column; gap: 22px; transition: opacity .4s; scroll-behavior: smooth; }
.cx-msg.user { align-self: flex-end; max-width: 80%; }
.cx-bubble { background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 15px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; word-wrap: break-word; }
.cx-msg.ai { max-width: 100%; padding-left: 16px; border-left: 1px solid var(--line-2); }
.cx-msg.ai.live { border-left-color: var(--silver); }
.cx-meta { font: 11px var(--mono); color: var(--faint); margin-bottom: 6px; letter-spacing: .02em; }
.cx-err { color: var(--bad); margin: 0; }

.md { line-height: 1.65; color: #dfe2e6; word-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 10px; }
.md h3, .md h4, .md h5, .md h6 { color: var(--text); font-weight: 600; margin: 16px 0 6px; font-size: 14px; letter-spacing: .01em; }
.md h3 { font-size: 15px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 20px; }
.md li { margin: 3px 0; }
.md li::marker { color: var(--faint); }
.md strong { color: var(--text); font-weight: 600; }
.md code { font: 12px var(--mono); background: rgba(255,255,255,.06); padding: 1px 5px; border-radius: 4px; }
.md pre { background: #08090b; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; overflow: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 2px solid var(--line-2); color: var(--muted); }
.md a { color: var(--silver); text-underline-offset: 3px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md-table { overflow: auto; margin: 0 0 12px; border: 1px solid var(--line); border-radius: 8px; }
.md-table table { font-size: 13px; }
.md-table th { position: static; }
.cx-caret { display: inline-block; width: 7px; height: 15px; margin-left: 2px; vertical-align: -2px; background: var(--silver); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cx-thinking { display: inline-flex; gap: 5px; padding: 6px 0; }
.cx-thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--silver); animation: dot 1.2s ease-in-out infinite; }
.cx-thinking i:nth-child(2) { animation-delay: .15s; } .cx-thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 80%, 100% { opacity: .2; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.cx-composer { position: relative; z-index: 2; margin: 0 auto 18px; width: min(820px, calc(100% - 32px)); display: flex; gap: 8px; align-items: flex-end;
  background: rgba(13,15,18,.85); border: 1px solid var(--line-2); border-radius: 16px; padding: 8px 8px 8px 16px; backdrop-filter: blur(8px); box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.cx-composer:focus-within { border-color: var(--silver); }
.cx-composer textarea { border: 0; background: none; padding: 9px 0; resize: none; max-height: 220px; line-height: 1.5; }
.cx-send { flex: none; width: 38px; height: 38px; border-radius: 11px; border: 0; background: var(--text); color: var(--bg); font-size: 17px; font-weight: 700; cursor: pointer; }
.cx-send:disabled { opacity: .3; cursor: default; }
.cx-send.stop { background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2); font-size: 12px; }

.cx-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 20; padding: 20px; }
.cx-modal-card { width: min(760px, 100%); max-height: 80vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; padding: 18px; }
.cx-snap { flex: 1; overflow: auto; margin: 0; font: 12px/1.55 var(--mono); color: var(--silver); background: #08090b; border: 1px solid var(--line); border-radius: 8px; padding: 12px; white-space: pre-wrap; }

@media (max-width: 860px) {
  .view:has(.cx) { padding: 10px; }
  .cx { grid-template-columns: minmax(0, 1fr); height: calc(100dvh - 130px); }
  .cx-bar .toolbar .btn.ghost:first-of-type { display: none; }
  .cx-history { display: none; }
  .cx-core { width: 220px; height: 220px; top: 20%; }
  .cx-core-label { top: calc(20% + 92px); }
  .cx-hero { top: calc(20% + 120px); }
  .cx-hero h1 { font-size: 24px; }
  .cx-bar { flex-wrap: wrap; }
  .cx-thread { padding: 76px 14px 16px; }
}
