/* ui-kit/shell.css — next-generation design tokens + layout (sovereign-first).
   Dark, high-contrast, reduced-motion-safe. No external fonts/CDN (C5). */
:root {
  --bg: #0b0e14; --bg-1: #11161f; --bg-2: #161d29; --line: #243044;
  --fg: #e6edf3; --fg-dim: #9aa7b8; --fg-mute: #6b7787;
  --accent: #5ee0c8; --accent-2: #7aa2ff; --warn: #ffcf6b; --bad: #ff7b7b; --ok: #4ade80;
  --radius: 12px; --gap: 12px; --rail: 200px; --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font); }
body { display: grid; grid-template-columns: var(--rail) 1fr; }

/* ── left rail ── */
.cx-rail { background: var(--bg-1); border-right: 1px solid var(--line); padding: var(--gap); display: flex; flex-direction: column; gap: 6px; }
.cx-rail h1 { font-size: 15px; letter-spacing: .5px; margin: 0 0 10px; color: var(--accent); font-weight: 700; }
.cx-rail button { background: transparent; border: 1px solid transparent; color: var(--fg-dim); text-align: left; padding: 9px 12px; border-radius: 9px; cursor: pointer; font-size: 13px; transition: background .15s, color .15s; }
.cx-rail button:hover, .cx-rail button.active { background: var(--bg-2); color: var(--fg); border-color: var(--line); }
.cx-rail .cx-foot { margin-top: auto; font-size: 11px; color: var(--fg-mute); }

/* ── main column ── */
.cx-main { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.cx-main > section { display: none; }
.cx-main > section:not([hidden]) { display: flex; flex-direction: column; height: 100%; min-height: 0; }
/* ── composer: floating glass bar with periodic moving light edge ── */
.cx-compose {
  position: fixed; z-index: 30;
  left: 50%; transform: translateX(-50%);
  bottom: 72px;
  width: min(900px, calc(100vw - 24px));
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 14px;
  /* Liquid glass: moderately transparent — content beneath stays visible but legible */
  background: color-mix(in srgb, var(--bg-1) 78%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
  border-radius: 18px;
  box-shadow: 0 8px 36px rgba(0,0,0,.40), inset 0 1px 0 rgba(255,255,255,.14);
  overflow: hidden;
}
/* Moving light sweep around the edge — moderately visible + moderately fast (4.5s) */
.cx-compose::before {
  content: ''; position: absolute; inset: -1px; border-radius: inherit; padding: 1.5px;
  background: conic-gradient(from var(--ang, 0deg), transparent 0deg, var(--accent-2) 45deg, var(--accent) 80deg, transparent 135deg, transparent 360deg);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  animation: cx-edge 4.5s linear infinite; pointer-events: none; opacity: .9;
}
@property --ang { syntax: '<angle>'; initial-value: 0deg; inherits: false; }
@keyframes cx-edge { to { --ang: 360deg; } }
.cx-compose.floating { left: auto; right: auto; transform: none; bottom: auto; }
.cx-compose.dragging { opacity: .96; box-shadow: 0 0 0 2px var(--accent) inset, 0 8px 40px rgba(0,0,0,.35); cursor: grabbing; }
.cx-compose-handle { align-self: stretch; display: flex; align-items: center; justify-content: center; width: 18px; cursor: grab; color: var(--fg-mute); font-size: 16px; user-select: none; touch-action: none; border-right: 1px solid var(--line); margin-right: 2px; }
.cx-compose-handle:hover { color: var(--accent); }
.cx-compose.dragging .cx-compose-handle { cursor: grabbing; }
.cx-attach { display: flex; gap: 6px; align-items: center; }
.cx-attach-btn { width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.cx-attach-btn.rec { color: var(--bad); border-color: var(--bad); animation: cx-pulse 1.2s ease-in-out infinite; }
.cx-attach-btn.cx-auto.on { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
@keyframes cx-pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.cx-tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; max-width: 100%; }
.cx-tool { background: color-mix(in srgb, var(--bg) 55%, transparent); color: var(--text); border: 1px solid color-mix(in srgb, var(--line) 80%, transparent); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; white-space: nowrap; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.cx-tool svg { width: 16px; height: 16px; vertical-align: -3px; margin-right: 5px; }
.cx-compose-handle svg { width: 16px; height: 16px; display: block; }
.cx-tool:hover { border-color: var(--accent); color: var(--accent); }
.cx-tool:active { transform: translateY(1px); }
/* input: prefers horizontal growth (wider), only modest vertical growth */
.cx-compose textarea#cx-input {
  flex: 1 1 auto; width: 100%; min-width: 0;
  max-width: 100%;
  min-height: 22px; height: 22px;
  max-height: 96px;            /* short vertical extent */
  resize: none; overflow-y: auto;
  background: color-mix(in srgb, var(--bg) 45%, transparent);
  color: var(--fg); border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 12px; padding: 8px 12px; font: inherit; font-size: 14px; line-height: 1.4;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.cx-compose .cx-send { flex: 0 0 auto; }
.cx-title { font-weight: 700; font-size: 15px; }
.cx-model { font-family: var(--mono); font-size: 12px; color: var(--accent-2); margin-left: auto; }
.cx-ico { background: var(--bg-2); border: 1px solid var(--line); color: var(--fg-dim); border-radius: 8px; padding: 5px 10px; cursor: pointer; transition: color .15s, border-color .15s; }
.cx-ico:hover { color: var(--fg); border-color: var(--accent-2); }

.cx-log { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: var(--gap); display: flex; flex-direction: column; gap: 16px; scroll-behavior: smooth; }
.cx-msg { display: flex; flex-direction: column; gap: 5px; max-width: 860px; width: 100%; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.cx-msg.user { align-self: flex-end; align-items: flex-end; max-width: 720px; }
.cx-msg.agent { align-self: flex-start; }
.cx-role { font-size: 11px; color: var(--fg-mute); text-transform: uppercase; letter-spacing: .6px; font-weight: 600; }
.cx-body { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; line-height: 1.6; font-size: 14.5px; box-shadow: var(--shadow); }
.cx-msg.user .cx-body { background: linear-gradient(180deg, #15324a, #122a40); border-color: #1f4a6b; }
.cx-msg.agent .cx-body { background: var(--bg-2); }

/* markdown content */
.cx-body p { margin: 0 0 10px; } .cx-body p:last-child { margin-bottom: 0; }
.cx-body h1, .cx-body h2, .cx-body h3, .cx-body h4 { margin: 14px 0 8px; line-height: 1.3; }
.cx-body h1 { font-size: 20px; } .cx-body h2 { font-size: 17px; } .cx-body h3 { font-size: 15px; } .cx-body h4 { font-size: 14px; }
.cx-body ul, .cx-body ol { margin: 8px 0; padding-left: 22px; }
.cx-body li { margin: 4px 0; }
.cx-body blockquote { margin: 10px 0; padding: 8px 14px; border-left: 3px solid var(--accent-2); background: rgba(122,162,255,.07); border-radius: 0 8px 8px 0; color: var(--fg-dim); }
.cx-body hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.cx-body a { color: var(--accent-2); text-decoration: none; } .cx-body a:hover { text-decoration: underline; }
.cx-body code { font-family: var(--mono); background: #0d121b; padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
.cx-body pre.code { background: #0d121b; border: 1px solid var(--line); border-radius: 10px; padding: 0; overflow: auto; position: relative; font-family: var(--mono); font-size: 12.5px; margin: 10px 0; }
.cx-body pre.code .code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); background: #0a0e16; border-radius: 10px 10px 0 0; }
.cx-body pre.code .code-lang { color: var(--fg-mute); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.cx-body pre.code .copy { background: var(--bg-2); border: 1px solid var(--line); color: var(--fg-dim); border-radius: 6px; padding: 2px 8px; cursor: pointer; font-size: 11px; }
.cx-body pre.code .copy:hover { color: var(--fg); border-color: var(--accent-2); }
.cx-body pre.code code { display: block; padding: 12px; background: transparent; font-size: 12.5px; line-height: 1.5; }
.cx-body table.md-table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13px; }
.cx-body .md-table th, .cx-body .md-table td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.cx-body .md-table th { background: var(--bg-1); color: var(--fg-dim); }

/* message meta + actions */
.cx-meta { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--fg-mute); font-family: var(--mono); flex-wrap: wrap; }
.cx-meta .cx-sig { color: var(--fg-mute); }
.cx-meta .ok { color: var(--ok); } .cx-meta .no { color: var(--bad); }
.cx-meta .cx-locus { color: var(--accent-2); }
.cx-meta .cx-verify { background: transparent; border: 1px solid var(--line); color: var(--fg-dim); border-radius: 6px; padding: 1px 7px; cursor: pointer; font-family: var(--mono); font-size: 11px; }
.cx-meta .cx-verify:hover { color: var(--fg); border-color: var(--accent-2); }
.cx-acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; opacity: 0; transition: opacity .15s; }
.cx-msg:hover .cx-acts, .cx-acts:focus-within { opacity: 1; }
.cx-act { background: var(--bg-2); border: 1px solid var(--line); color: var(--fg-dim); border-radius: 6px; padding: 3px 9px; font-size: 11px; cursor: pointer; transition: color .15s, border-color .15s; }
.cx-act:hover { color: var(--fg); border-color: var(--accent-2); }
.cx-act.abort { color: var(--bad); }

/* composer */
.cx-compose { align-items: flex-end; }
.cx-compose textarea:focus { outline: none; border-color: var(--accent-2); }
.cx-send { background: var(--accent); color: #042; border: none; border-radius: var(--radius); padding: 0 18px; font-size: 18px; cursor: pointer; font-weight: 700; transition: filter .15s; }
.cx-send:hover { filter: brightness(1.08); }
.cx-send:disabled { opacity: .5; cursor: default; }
.cx-edit { width: 100%; background: #15324a; color: var(--fg); border: 1px solid #1f4a6b; border-radius: 8px; padding: 8px; font-family: var(--font); font-size: 14px; }

/* ── palette ── */
.cx-palette-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(2px); display: flex; align-items: flex-start; justify-content: center; padding-top: 14vh; z-index: 50; }
.cx-palette-overlay[hidden] { display: none; }
.cx-palette { background: var(--bg-1); border: 1px solid var(--line); border-radius: 14px; width: min(540px, 92vw); overflow: hidden; box-shadow: var(--shadow); }
.cx-palette-input { width: 100%; background: transparent; border: none; border-bottom: 1px solid var(--line); color: var(--fg); padding: 15px; font-size: 15px; outline: none; }
.cx-palette-list { max-height: 340px; overflow-y: auto; padding: 6px; }
.cx-palette-item { padding: 11px 13px; border-radius: 9px; cursor: pointer; font-size: 14px; transition: background .12s; }
.cx-palette-item:hover, .cx-palette-item:focus, .cx-palette-item.active { background: var(--bg-2); outline: none; color: var(--accent); }
.cx-palette-empty { padding: 14px; color: var(--fg-mute); font-size: 13px; }

/* ── badges / misc ── */
.badge { font-size: 11px; color: var(--fg-dim); border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; font-family: var(--mono); }
.badge.ok { color: var(--ok); border-color: var(--ok); } .badge.pending { color: var(--warn); border-color: var(--warn); }
.status-bar { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px var(--gap); border-bottom: 1px solid var(--line); background: var(--bg-1); }
.cx-empty { color: var(--fg-mute); font-size: 13px; padding: 20px; }
.cx-btn { background: var(--bg-2); border: 1px solid var(--line); color: var(--fg); border-radius: 8px; padding: 8px 12px; cursor: pointer; transition: border-color .15s, color .15s; }
.cx-btn:hover { border-color: var(--accent-2); color: var(--fg); }
.cx-proof-body { background: #0d121b; border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-family: var(--mono); font-size: 12px; max-height: 50vh; overflow: auto; white-space: pre-wrap; }
.cx-proof-title { font-weight: 600; margin-bottom: 8px; } .cx-proof .cx-btn { margin-right: 8px; }
/* ── workspace file editor / terminal ── */
.ws-tree { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.ws-leaf { display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); cursor: pointer; font-size: 13px; }
.ws-leaf:hover, .ws-leaf.active { border-color: var(--accent-2); }
.ws-leaf.ws-empty { color: var(--fg-mute); cursor: default; border-style: dashed; }
.ws-name { font-family: var(--mono); }
.ws-meta { color: var(--fg-mute); font-size: 11px; }
.ws-editor { width: 100%; min-height: 160px; max-height: 40vh; resize: vertical; background: var(--bg-2); border: 1px solid var(--line); color: var(--fg); border-radius: 8px; padding: 10px; font-family: var(--mono); font-size: 13px; line-height: 1.5; }
.ws-log { background: #0d121b; border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-family: var(--mono); font-size: 12px; max-height: 30vh; overflow: auto; white-space: pre-wrap; }
.cx-ws h3, .cx-mesh h3, .cx-models h3 { margin: 0 0 12px; font-size: 15px; }
.cx-ws-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cx-ws-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.cx-ws-table td:first-child { color: var(--fg-dim); width: 42%; font-family: var(--mono); }
/* ── models (locus selector) ── */
.cx-model-row { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; cursor: pointer; background: var(--bg-2); transition: border-color .15s; }
.cx-model-row:hover { border-color: var(--fg-dim); }
.cx-model-row.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cx-model-title { font-weight: 600; font-size: 14px; }
.cx-model-title .cx-on { font-size: 11px; color: var(--ok); border: 1px solid var(--ok); border-radius: 999px; padding: 1px 7px; margin-left: 6px; font-family: var(--mono); }
.cx-model-desc { color: var(--fg-mute); font-size: 12px; margin-top: 4px; }
.cx-model-row.loading { opacity: .6; pointer-events: none; }
/* ── mesh / history shared ── */
.cx-mesh ul { margin: 0; padding-left: 18px; } .cx-mesh li { padding: 3px 0; }
.cx-note { color: var(--fg-mute); font-size: 12px; margin-top: 12px; line-height: 1.5; }
.cx-history-out { margin-top: 10px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.cx-h-item { border-left: 2px solid var(--line); padding: 9px 13px; margin-bottom: 8px; background: var(--bg-2); border-radius: 0 8px 8px 0; }
.cx-h-item.user { border-left-color: var(--accent); }
.cx-h-item.agent { border-left-color: var(--ok); }
.cx-h-item.amend { border-left-color: var(--warn); }
.cx-h-meta { font-size: 11px; color: var(--fg-dim); font-family: var(--mono); margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.cx-h-meta .ok { color: var(--ok); } .cx-h-meta .no { color: var(--bad); }
.cx-h-jump { background: var(--bg-1); border: 1px solid var(--line); color: var(--fg-dim); border-radius: 6px; padding: 2px 8px; cursor: pointer; font-size: 11px; margin-top: 6px; }
.cx-h-jump:hover { color: var(--fg); border-color: var(--accent-2); }
.cx-h-text { font-size: 13px; white-space: pre-wrap; line-height: 1.5; }

/* ── settings ── */
.cx-settings h3 { margin: 0 0 12px; font-size: 15px; }
.cx-fld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; font-size: 13px; }
.cx-fld > span { color: var(--fg-dim); font-family: var(--mono); font-size: 12px; }
.cx-fld select { background: var(--bg-2); border: 1px solid var(--line); color: var(--fg); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.cx-fld.cx-row { flex-direction: row; align-items: center; justify-content: space-between; }
.cx-fld.cx-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.cx-set-actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }

/* loading shimmer (streaming placeholder) */
.cx-shimmer { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 4px; animation: blink 1s infinite; }
.cx-shimmer:nth-child(2) { animation-delay: .2s; } .cx-shimmer:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,100% { opacity: .2; } 50% { opacity: 1; } }

/* light theme (Settings-controlled) */
:root[data-theme="light"] { --bg: #f4f6fa; --bg-1: #ffffff; --bg-2: #eef1f6; --line: #d4dbe6; --fg: #16202c; --fg-dim: #4a5564; --fg-mute: #7a8494; --accent: #0aa98e; --accent-2: #3a6df0; --shadow: 0 8px 30px rgba(0,0,0,.12); }
:root[data-density="compact"] { --gap: 8px; --radius: 9px; }
:root[data-density="compact"] .cx-msg { gap: 3px; }
:root[data-density="compact"] .cx-body { padding: 8px 12px; font-size: 13.5px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 720px) {
  body { grid-template-columns: 1fr; }
  .cx-rail { position: fixed; bottom: 0; left: 0; right: 0; flex-direction: row; overflow-x: auto; z-index: 40; border-top: 1px solid var(--line); border-right: none; height: 56px; align-items: stretch; padding: 6px; }
  .cx-rail h1, .cx-rail .cx-foot { display: none; }
  .cx-rail button { white-space: nowrap; }
  .cx-main { height: 100vh; }
  .cx-compose { bottom: calc(64px + env(safe-area-inset-bottom)); width: calc(100vw - 16px); left: 50%; transform: translateX(-50%); }
  .cx-compose.floating { left: auto; transform: none; }
  .cx-log { padding-bottom: 160px; } /* clear the floating composer + rail */
  .cx-msg { max-width: 100%; }
  .cx-compose-handle { display: none; } /* touch drag via bar area; handle optional on mobile */
}
