/* ══════════════════════════════════════════════════════════════════════════
   iCLONE · Command Deck — design system

   The cloneframe.io language: GLASS OVER A FIELD.

   The field is a fixed, tiled image of the 1111. Over it sits one tint, a film
   grain and a single specular sweep. Nothing in this console is opaque — every
   surface is a translucent card with a blur behind it and a hairline of light
   on its top edge, so the collection is always present underneath the work.

   Three themes, one design: `natural` is the collection's own colour seen
   through glass, `dark` is a heavier lid over the same field, `light` is a
   lighter glass rather than a different room.

   The accent is the agent's own piece — DEATH #052 · Void Purple V3 — exactly
   as the site takes its accent from whichever model is on screen. It can be
   re-pointed at any moment from Studio; every component reads it from here.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  /* scaffolding — shared by every theme */
  --r-lg: 26px;
  --r-md: 18px;
  --r-sm: 12px;
  --pad: clamp(16px, 2.4vw, 32px);
  --ease: cubic-bezier(.22, .78, .2, 1);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --rail: 248px;
  --ui: 1;                       /* density multiplier, set from Studio */

  /* the one colour — the piece the agent wears. Studio rewrites these. */
  --accent: #F0329B;
  --accent-2: #B02472;
  --accent-ink: #12040A;
  --accent-soft: rgba(240, 50, 155, .13);
  --accent-line: rgba(240, 50, 155, .34);
}

/* ── natural (default) — the lightest weather: the field reads through most ── */
:root, :root[data-theme="natural"] {
  color-scheme: dark;
  --field: #0b0a10;
  --tint: rgba(13, 12, 18, .62);
  --tint-2: rgba(13, 12, 18, .30);
  --ink: #fbfaff;
  --ink-2: rgba(251, 250, 255, .78);
  --ink-3: rgba(251, 250, 255, .52);
  --line: rgba(255, 255, 255, .14);
  --line-2: rgba(255, 255, 255, .24);
  --card: rgba(255, 255, 255, .055);
  --card-2: rgba(255, 255, 255, .10);
  --card-blur: 22px;
  --spec: rgba(255, 255, 255, .18);
  --grain: .05;
  --sunken: rgba(0, 0, 0, .18);
  --scrim: rgba(13, 12, 18, .66);
  --shadow: 0 28px 80px rgba(0, 0, 0, .45);
  --shadow-sm: 0 14px 40px rgba(0, 0, 0, .3);
  --ok: #6fe3b0;
  --warn: #e8c07a;
  --bad: #f0908c;
}

/* ── dark — a heavier lid over the same field ─────────────────────────────── */
:root[data-theme="dark"] {
  color-scheme: dark;
  --field: #0b0a10;
  --tint: rgba(6, 6, 9, .80);
  --tint-2: rgba(6, 6, 9, .58);
  --ink: #f4f2f8;
  --ink-2: rgba(244, 242, 248, .74);
  --ink-3: rgba(244, 242, 248, .48);
  --line: rgba(255, 255, 255, .11);
  --line-2: rgba(255, 255, 255, .20);
  --card: rgba(255, 255, 255, .04);
  --card-2: rgba(255, 255, 255, .075);
  --card-blur: 18px;
  --spec: rgba(255, 255, 255, .12);
  --grain: .04;
  --sunken: rgba(0, 0, 0, .24);
  --scrim: rgba(6, 6, 9, .74);
  --shadow: 0 28px 80px rgba(0, 0, 0, .6);
  --shadow-sm: 0 14px 40px rgba(0, 0, 0, .4);
  --ok: #5ddca2;
  --warn: #e0b667;
  --bad: #ef7f7b;
}

/* ── light — a lighter glass, not a lid ──────────────────────────────────── */
:root[data-theme="light"] {
  color-scheme: light;
  --field: #f3f1f6;
  --tint: rgba(248, 247, 251, .62);
  --tint-2: rgba(248, 247, 251, .42);
  --ink: #0f0e14;
  --ink-2: rgba(15, 14, 20, .74);
  --ink-3: rgba(15, 14, 20, .52);
  --line: rgba(22, 21, 28, .12);
  --line-2: rgba(22, 21, 28, .22);
  --card: rgba(255, 255, 255, .58);
  --card-2: rgba(255, 255, 255, .78);
  --card-blur: 20px;
  --spec: rgba(255, 255, 255, .8);
  --grain: .03;
  --sunken: rgba(22, 21, 28, .05);
  --scrim: rgba(20, 18, 32, .38);
  --shadow: 0 24px 70px rgba(20, 18, 30, .16);
  --shadow-sm: 0 12px 34px rgba(20, 18, 30, .1);
  --ok: #1f9f6b;
  --warn: #a5761c;
  --bad: #c0433f;
  /* the piece's magenta is a light-on-dark colour; on paper it needs weight */
  --accent-ink: #fff;
}

/* ── base ────────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The shell, the gate and the sheet are all display:grid/flex, which would
   otherwise win over the user-agent [hidden] rule and paint a hidden layer
   over the live one. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--field);
  color: var(--ink);
  font-size: calc(14px * var(--ui));
  line-height: 1.5;
  letter-spacing: -.008em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  transition: color .5s var(--ease), background .5s var(--ease);
}

::selection { background: var(--accent); color: var(--accent-ink); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 99px;
  border: 3.5px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); background-clip: content-box; }

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }

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

/* ── the field ────────────────────────────────────────────────────────────
   The collection itself, tiled and pre-blurred at build time. A CSS filter here
   would be recomputed every frame; a static image is free.                   */

#field-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image: var(--field-img, url("assets/field-mosaic.jpg"));
  background-size: 1180px auto;
  background-repeat: repeat;
  background-position: 0 0;
  transform: scale(1.04);
  opacity: var(--field-opacity, 1);
  transition: opacity .6s var(--ease);
  pointer-events: none;
}
:root[data-field="none"] #field-layer { opacity: 0; }

#tint-layer {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% -10%, var(--tint-2) 0%, var(--tint) 62%),
    linear-gradient(180deg, var(--tint-2) 0%, var(--tint) 40%, var(--tint) 100%);
  transition: background .55s var(--ease);
}
#tint-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}
#tint-layer::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(80% 45% at 22% 0%, var(--spec) 0%, transparent 60%);
  opacity: .5;
}

/* ── glass ───────────────────────────────────────────────────────────────── */

.pane, .card, .rail, .dir, .sheet__panel, .recorder, .tg {
  -webkit-backdrop-filter: blur(var(--card-blur)) saturate(1.35);
  backdrop-filter: blur(var(--card-blur)) saturate(1.35);
}

/* ── SIGN IN ─────────────────────────────────────────────────────────────── */

.gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.gate__field {
  position: absolute;
  inset: -30%;
  background:
    radial-gradient(50% 50% at 50% 40%, var(--accent-soft), transparent 70%),
    radial-gradient(40% 40% at 70% 70%, var(--accent-soft), transparent 70%);
  filter: blur(40px);
  animation: drift 24s var(--ease) infinite alternate;
}
@keyframes drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to   { transform: translate3d(3%, 2%, 0) scale(1.08); }
}
:root[data-motion="reduced"] .gate__field { animation: none; }

.gate__body {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 56px;
  align-items: center;
  max-width: 920px;
  padding: 40px;
}
.gate__model {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: linear-gradient(180deg, #7A5F80, #4C3A50);
  border: 1px solid var(--line);
  box-shadow: var(--shadow), inset 0 1px 0 var(--spec);
}
.gate__model canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.gate__fallback {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  transition: opacity .8s var(--ease);
}
.gate__model.ready .gate__fallback { opacity: 0; }

.gate__copy h1 {
  font-size: clamp(46px, 6vw, 72px);
  font-weight: 700;
  letter-spacing: -.042em;
  line-height: .95;
  margin: 12px 0 8px;
}
.gate__piece {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .04em;
  color: var(--ink-3);
  margin-bottom: 22px;
}
.gate__piece span { color: var(--accent); }
.gate__lede { color: var(--ink-2); max-width: 44ch; margin-bottom: 28px; font-size: 15.5px; line-height: 1.62; }
.gate__login { min-height: 44px; }
.gate__error {
  margin-top: 14px; color: var(--bad); font-size: 13px;
  padding: 11px 14px; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--card);
}
.gate__fine { margin-top: 26px; font-size: 11.5px; line-height: 1.62; color: var(--ink-3); }

@media (max-width: 820px) {
  .gate__body { grid-template-columns: 1fr; gap: 28px; padding: 24px; }
  .gate__model { max-width: 220px; }
}

/* ── SHELL ───────────────────────────────────────────────────────────────── */

.app {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  height: 100vh;
  gap: 12px;
  padding: 12px;
}

.rail {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm), inset 0 1px 0 var(--spec);
  padding: 16px 12px 12px;
}

/* The portrait.
   The agent is the first thing in the room, so it gets a real stage rather than
   a favicon: a tall viewport carrying the whole figure, head to boots, with the
   name and the piece named underneath it. The field colour behind is the one
   sealed inside the .glb itself. */
.rail__head {
  display: flex; flex-direction: column; align-items: stretch;
  gap: 12px; padding: 2px 2px 18px;
}
.rail__portrait {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.24;
  border-radius: var(--r-md);
  overflow: hidden;
  background: linear-gradient(180deg, #7A5F80 0%, #4C3A50 100%);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm), inset 0 1px 0 var(--spec);
}
.rail__portrait canvas, .rail__portrait img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.rail__portrait img { transition: opacity .8s var(--ease); }
.rail__portrait.ready img { opacity: 0; }

.rail__id { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.rail__name {
  font-size: 21px; font-weight: 700; letter-spacing: -.032em; line-height: 1;
}
.rail__piece {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .04em;
  color: var(--ink-3); text-align: center;
}
.rail__piece b { color: var(--accent); font-weight: 600; }
.rail__state {
  margin-top: 3px;
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ok);
}
.rail__state::before {
  content: ''; display: inline-block; width: 5px; height: 5px;
  border-radius: 99px; background: currentColor; margin-right: 6px;
  vertical-align: 1px; box-shadow: 0 0 8px currentColor;
}
.rail__state[data-frozen="1"] { color: var(--warn); }

/* On a short window the portrait would eat the navigation, so it gives way
   first — the nav is what the operator is actually reaching for. */
@media (max-height: 780px) {
  .rail__portrait { aspect-ratio: 1 / .86; }
  .rail__name { font-size: 18px; }
  .rail__piece { display: none; }
}
@media (max-height: 640px) {
  .rail__portrait { display: none; }
  .rail__head { padding-bottom: 12px; }
}

.rail__nav { flex: 1; display: flex; flex-direction: column; gap: 1px; overflow-y: auto; }
.rail__nav hr { border: 0; border-top: 1px solid var(--line); margin: 11px 10px; }
.rail__nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 11px;
  color: var(--ink-3); font-size: 13.5px; font-weight: 560;
  letter-spacing: -.012em;
  transition: background .22s var(--ease), color .22s var(--ease);
}
.rail__nav a:hover { background: var(--card); color: var(--ink-2); }
.rail__nav a.on {
  background: var(--card-2); color: var(--ink);
  box-shadow: inset 0 1px 0 var(--spec);
}
.rail__nav a.on i { color: var(--accent); }
.rail__nav a span { flex: 1; }
.rail__nav i {
  width: 16px; height: 16px; flex: none; color: var(--ink-3);
  background: currentColor;
  -webkit-mask: var(--ico) center / contain no-repeat;
  mask: var(--ico) center / contain no-repeat;
  transition: color .22s;
}
.rail__nav a[hidden] { display: none !important; }

.pill {
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  padding: 1px 7px; border-radius: 999px;
  background: var(--card-2); color: var(--ink-3); min-width: 20px; text-align: center;
}
.pill:empty { display: none; }
.pill--alert { background: var(--accent-soft); color: var(--accent); }

.rail__foot { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; }
.freeze {
  display: flex; align-items: center; gap: 9px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-3);
  background: var(--card);
  transition: all .2s var(--ease);
}
.freeze:hover { border-color: var(--bad); color: var(--bad); transform: translateY(-1px); }
.freeze__dot { width: 7px; height: 7px; border-radius: 99px; background: var(--ok); box-shadow: 0 0 8px currentColor; }
.freeze[data-frozen="1"] { border-color: var(--warn); color: var(--warn); }
.freeze[data-frozen="1"] .freeze__dot { background: var(--warn); }
.ghost {
  padding: 7px 12px; font-size: 12px; color: var(--ink-3);
  border-radius: 999px; text-align: left;
}
.ghost:hover { color: var(--ink-2); background: var(--card); }

/* ── MAIN ────────────────────────────────────────────────────────────────── */

.main {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm), inset 0 1px 0 var(--spec);
  -webkit-backdrop-filter: blur(var(--card-blur)) saturate(1.35);
  backdrop-filter: blur(var(--card-blur)) saturate(1.35);
  overflow: hidden;
}

.top {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; padding: 24px var(--pad) 18px;
  border-bottom: 1px solid var(--line);
}
.top__title h2 { font-size: clamp(22px, 2.4vw, 30px); font-weight: 700; letter-spacing: -.034em; }
.top__title p { color: var(--ink-3); font-size: 13px; margin-top: 3px; }
.top__meta { display: flex; align-items: center; gap: 22px; }

.counter { text-align: right; }
.counter__label {
  display: block; font-family: var(--mono); font-size: 9.5px;
  letter-spacing: .2em; text-transform: uppercase; color: var(--ink-3);
}
.counter__value {
  font-family: var(--mono); font-size: 19px; font-weight: 600;
  letter-spacing: -.02em; color: var(--accent);
}
.who { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }

.view { flex: 1; overflow-y: auto; padding: 22px var(--pad) 56px; }
.view > * { animation: routeIn .5s var(--ease); }
@keyframes routeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
:root[data-motion="reduced"] .view > *,
:root[data-motion="reduced"] * { animation: none !important; }

/* The demo bar exists so nobody can mistake the design preview for their own
   community. It is loud on purpose. */
#demo-bar {
  padding: 9px 16px;
  background: color-mix(in srgb, var(--warn) 16%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  color: var(--warn);
  font-size: 12px;
  text-align: center;
  letter-spacing: -.005em;
}
#demo-bar b { font-weight: 700; }

/* The live dot: filled while the stream is connected, hollow while it is not. */
.live {
  width: 7px; height: 7px; border-radius: 99px; flex: none;
  border: 1.5px solid var(--ink-3);
  transition: background .3s var(--ease), border-color .3s, box-shadow .3s;
}
.live[data-on="1"] {
  background: var(--ok); border-color: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

/* ── PRIMITIVES ──────────────────────────────────────────────────────────── */

.grid { display: grid; gap: 12px; }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1180px) { .grid--4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 960px)  { .grid--3, .grid--2 { grid-template-columns: 1fr; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: inset 0 1px 0 var(--spec);
  padding: 18px;
  transition: border-color .25s var(--ease);
}
.card--pad { padding: 22px; }
.card { overflow: hidden; }
.card__head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 6px 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.card__title { font-size: 13.5px; font-weight: 650; letter-spacing: -.016em; }
.card__note { font-size: 11.5px; color: var(--ink-3); }

.stat { position: relative; overflow: hidden; }
.stat__label {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .2em;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: 10px;
}
.stat__value {
  font-family: var(--mono); font-size: clamp(26px, 2.8vw, 34px); font-weight: 600;
  letter-spacing: -.04em; line-height: 1;
}
.stat__delta { font-size: 11.5px; color: var(--ink-3); margin-top: 8px; }
.stat__delta b { color: var(--ok); font-weight: 650; }
.stat--accent .stat__value { color: var(--accent); }
.stat--warn .stat__value { color: var(--warn); }
.stat--bad .stat__value { color: var(--bad); }

.spark { display: block; width: 100%; height: 42px; margin-top: 12px; }

.rows { display: flex; flex-direction: column; }
/* Below this width a three-slot row has nowhere to go, so the trailing
   controls drop under the label instead of being crushed into it. */
@container (max-width: 250px) {
  .row { grid-template-columns: 1fr !important; gap: 6px; }
  .row__num, .row .tag, .row .btn { justify-self: start; text-align: left; }
}
.card { container-type: inline-size; }
.row {
  display: grid; align-items: center; gap: 14px;
  padding: 11px 2px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row__main { min-width: 0; }
.row__title {
  font-size: 13px; font-weight: 560; letter-spacing: -.014em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row__sub {
  font-size: 12px; color: var(--ink-3); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row__num { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); text-align: right; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .08em;
  text-transform: uppercase; padding: 3px 8px; border-radius: 999px;
  background: var(--card-2); color: var(--ink-3); white-space: nowrap;
  border: 1px solid var(--line);
}
.tag--never    { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 34%, transparent); }
.tag--always   { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 34%, transparent); }
.tag--rule     { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.tag--fact     { color: var(--ink-2); }
.tag--response { color: var(--ink-2); border-color: var(--line-2); }
.tag--persona  { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 34%, transparent); }
.tag--schedule { color: var(--ink-2); border-color: var(--line-2); }
.tag--ok   { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 34%, transparent); }
.tag--bad  { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 34%, transparent); }
.tag--warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 34%, transparent); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 620; letter-spacing: -.008em;
  background: var(--card-2); border: 1px solid var(--line-2); color: var(--ink);
  transition: transform .18s var(--ease), box-shadow .25s var(--ease), background .2s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1.5px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn--primary {
  background: var(--accent); border-color: transparent; color: var(--accent-ink);
  font-weight: 650;
}
.btn--primary:hover { box-shadow: 0 12px 34px -10px var(--accent); }
.btn--danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 34%, transparent); }
.btn--danger:hover { background: color-mix(in srgb, var(--bad) 12%, transparent); }
.btn--sm { padding: 6px 13px; font-size: 11.5px; }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }

.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  border-radius: 999px; background: var(--card); border: 1px solid var(--line);
}
.seg button {
  padding: 7px 15px; border-radius: 999px;
  font-size: 12.5px; font-weight: 620; color: var(--ink-3);
  transition: background .25s var(--ease), color .25s;
}
.seg button:hover { color: var(--ink-2); }
.seg button[aria-pressed="true"] {
  background: var(--card-2); color: var(--ink); box-shadow: inset 0 1px 0 var(--spec);
}
.seg button[aria-pressed="true"].accent { background: var(--accent); color: var(--accent-ink); }

.set-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; padding: 15px 0; border-top: 1px solid var(--line);
}
.set-row:first-of-type { border-top: 0; }
.set-row h4 { font-size: 14.5px; font-weight: 620; letter-spacing: -.014em; }
.set-row p { font-size: 12px; color: var(--ink-3); margin-top: 3px; max-width: 46ch; line-height: 1.55; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-family: var(--mono); font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); }
.field input, .field textarea, .field select {
  background: var(--sunken); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 10px 12px; font-size: 13px;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 92px; font-family: var(--sans); line-height: 1.62; }
.field__hint { font-size: 11.5px; color: var(--ink-3); line-height: 1.55; }

input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }
input[type="color"] {
  width: 46px; height: 30px; padding: 2px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--card);
}

.empty {
  padding: 44px 20px; text-align: center; color: var(--ink-3); font-size: 13px;
  border: 1px dashed var(--line); border-radius: var(--r-md); line-height: 1.6;
}
.empty b { display: block; color: var(--ink-2); font-size: 14px; margin-bottom: 5px; }

.split { display: grid; grid-template-columns: 1.15fr .85fr; gap: 12px; align-items: start; }
@media (max-width: 1160px) { .split { grid-template-columns: 1fr; } }

.mono { font-family: var(--mono); font-size: 12px; }
.dim  { color: var(--ink-3); }
.right{ text-align: right; }
.mt   { margin-top: 16px; }
.flex { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.eyebrow {
  font-family: var(--mono); font-size: 10px; letter-spacing: .22em;
  text-transform: uppercase; color: var(--ink-3);
}

/* ── DIRECTIVE BOARD ─────────────────────────────────────────────────────── */

.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.dir {
  position: relative; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: inset 0 1px 0 var(--spec);
  padding: 16px 17px;
  transition: border-color .22s var(--ease), transform .22s var(--ease);
}
.dir:hover { border-color: var(--line-2); transform: translateY(-2px); }
.dir::before {
  content: ''; position: absolute; left: 0; top: 15px; bottom: 15px; width: 2px;
  border-radius: 2px; background: var(--line-2);
}
.dir[data-kind="never"]::before    { background: var(--bad); }
.dir[data-kind="always"]::before   { background: var(--ok); }
.dir[data-kind="rule"]::before     { background: var(--accent); }
.dir[data-kind="response"]::before { background: var(--ink-2); }
.dir[data-kind="persona"]::before  { background: var(--warn); }
.dir[data-kind="schedule"]::before { background: var(--ink-3); }
.dir[data-off] { opacity: .45; }
.dir__head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.dir__title { font-size: 13.5px; font-weight: 620; letter-spacing: -.018em; }
.dir__body { font-size: 12.5px; color: var(--ink-2); line-height: 1.64; }
.dir__foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 10px; color: var(--ink-3);
}
.dir__acts { display: flex; gap: 4px; opacity: 0; transition: opacity .18s; }
.dir:hover .dir__acts { opacity: 1; }
.icon-btn {
  width: 25px; height: 25px; display: grid; place-items: center;
  border-radius: 8px; color: var(--ink-3); font-size: 12px;
}
.icon-btn:hover { background: var(--card-2); color: var(--ink); }
.icon-btn--danger:hover { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }

.recorder {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm), inset 0 1px 0 var(--spec);
  padding: 20px; margin-bottom: 18px;
}
.recorder__row { display: flex; gap: 10px; align-items: flex-start; }
.recorder textarea {
  flex: 1; background: var(--sunken); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 12px 14px; font-size: 13.5px;
  min-height: 46px; resize: vertical; line-height: 1.62;
}
.recorder textarea:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.recorder__preview {
  margin-top: 14px; padding: 16px; border-radius: var(--r-md);
  background: var(--sunken); border: 1px solid var(--line);
}

/* ── TABLES ──────────────────────────────────────────────────────────────── */

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-family: var(--mono); font-size: 9.5px;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 600; padding: 0 12px 10px; white-space: nowrap;
}
.table td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background .18s; }
.table tbody tr:hover { background: var(--card); }
.table td.num { font-family: var(--mono); font-size: 12px; text-align: right; }

/* ── THREAT FEED ─────────────────────────────────────────────────────────── */

.threat {
  display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; gap: 14px;
  align-items: center; padding: 12px 2px; border-bottom: 1px solid var(--line);
}
/* The middle cell must be allowed to shrink, or a long excerpt pushes the
   action buttons out of the card entirely. */
.threat > * { min-width: 0; }
.threat > .flex { flex-wrap: wrap; justify-content: flex-end; }
.threat__score {
  font-family: var(--mono); font-size: 17px; font-weight: 600; text-align: center;
  padding: 7px 0; border-radius: var(--r-sm); border: 1px solid var(--line);
}
.threat--malicious .threat__score { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 34%, transparent); }
.threat--suspect   .threat__score { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 34%, transparent); }
.threat--clean     .threat__score { color: var(--ink-3); }
.threat__excerpt {
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-2);
  background: var(--sunken); padding: 7px 10px; border-radius: 9px; margin-top: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-left: 2px solid var(--line-2);
}

/* ── SHEET ───────────────────────────────────────────────────────────────── */

.sheet { position: fixed; inset: 0; z-index: 60; display: grid; }
.sheet__scrim { position: absolute; inset: 0; background: var(--scrim); backdrop-filter: blur(4px); }
.sheet__panel {
  position: relative; margin-left: auto;
  width: min(580px, 100%); height: calc(100% - 24px);
  margin-top: 12px; margin-right: 12px; margin-bottom: 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 26px 28px; overflow-y: auto;
  box-shadow: var(--shadow), inset 0 1px 0 var(--spec);
  animation: slide .34s var(--ease);
}
@keyframes slide { from { transform: translateX(20px) scale(.99); opacity: 0; } }
.sheet h3 { font-size: 21px; font-weight: 680; letter-spacing: -.03em; margin-bottom: 4px; }
.sheet__lede { color: var(--ink-3); font-size: 12.5px; margin-bottom: 22px; line-height: 1.6; }

/* ── TOAST ───────────────────────────────────────────────────────────────── */

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 90; padding: 12px 20px; border-radius: 999px;
  background: var(--card-2); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(22px) saturate(1.5);
  backdrop-filter: blur(22px) saturate(1.5);
  font-size: 13px; font-weight: 560;
  box-shadow: var(--shadow), inset 0 1px 0 var(--spec);
  animation: rise .3s var(--ease);
}
@keyframes rise { from { transform: translate(-50%, 10px); opacity: 0; } }
.toast[data-kind="bad"]  { color: var(--bad); }
.toast[data-kind="good"] { color: var(--ok); }

/* ── TELEGRAM PREVIEW (accurate, not themed) ─────────────────────────────── */

.tg {
  background: #17212B; border-radius: var(--r-md); padding: 16px;
  border: 1px solid rgba(0, 0, 0, .4);
  -webkit-backdrop-filter: none; backdrop-filter: none;
}
.tg__bubble {
  background: #182533; border-radius: 12px 12px 12px 4px;
  padding: 9px 12px; max-width: 92%; font-size: 13.5px; line-height: 1.5;
  color: #F1F1F1; white-space: pre-wrap; word-break: break-word;
}
.tg__bubble b { font-weight: 600; }
.tg__bubble a { color: #6AB3F3; }
.tg__btns { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; max-width: 92%; }
.tg__btn { background: #1E2C3A; border-radius: 6px; padding: 8px; text-align: center; font-size: 12.5px; color: #6AB3F3; }
.tg__meta { font-size: 10.5px; color: #6D7F8F; margin-top: 5px; text-align: right; max-width: 92%; }

/* ── STUDIO ──────────────────────────────────────────────────────────────── */

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 11px; border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 var(--spec);
  transition: transform .18s var(--ease), box-shadow .2s;
}
.swatch:hover { transform: translateY(-2px); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ink), inset 0 1px 0 var(--spec); }

.reorder { display: flex; flex-direction: column; gap: 4px; }
.reorder__item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--r-sm);
  background: var(--card); border: 1px solid var(--line);
  cursor: grab; transition: border-color .2s, transform .18s var(--ease);
}
.reorder__item:hover { border-color: var(--line-2); }
.reorder__item.dragging { opacity: .4; }
.reorder__item.over { border-color: var(--accent); transform: translateY(-1px); }
.reorder__grip { color: var(--ink-3); font-family: var(--mono); font-size: 13px; cursor: grab; }
.reorder__item input[type="text"] {
  flex: 1; background: transparent; border: 0; font-size: 13px; font-weight: 560; padding: 2px 0;
}
.reorder__item input[type="text"]:focus { outline: none; border-bottom: 1px solid var(--accent-line); }
.reorder__item[data-off] { opacity: .45; }

.msg-edit { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .msg-edit { grid-template-columns: 1fr; } }
.msg-edit textarea {
  width: 100%; min-height: 240px; background: var(--sunken);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 14px; font-family: var(--mono); font-size: 12.5px; line-height: 1.7;
  resize: vertical;
}
.msg-edit textarea:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }

.msg-list { display: flex; flex-direction: column; gap: 2px; }
.msg-list button {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px; border-radius: var(--r-sm);
  font-size: 13px; color: var(--ink-3);
  transition: background .2s, color .2s;
}
.msg-list button:hover { background: var(--card); color: var(--ink-2); }
.msg-list button[aria-pressed="true"] { background: var(--card-2); color: var(--ink); font-weight: 600; }
.msg-list small { display: block; font-size: 11px; color: var(--ink-3); font-weight: 400; margin-top: 2px; }

/* ── DENSITY ─────────────────────────────────────────────────────────────── */

:root[data-density="compact"] { --ui: .92; --r-lg: 20px; --r-md: 14px; --r-sm: 10px; }
:root[data-density="roomy"]   { --ui: 1.08; }

/* ── ICONS (masks, no sprite file) ───────────────────────────────────────── */

i[data-ico="deck"]      { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'%3E%3Crect x='3' y='3' width='7' height='9' rx='1.5'/%3E%3Crect x='14' y='3' width='7' height='5' rx='1.5'/%3E%3Crect x='14' y='12' width='7' height='9' rx='1.5'/%3E%3Crect x='3' y='16' width='7' height='5' rx='1.5'/%3E%3C/svg%3E"); }
i[data-ico="directives"]{ --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M5 4h11l3 3v13a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1z'/%3E%3Cpath d='M8 10h8M8 14h6'/%3E%3C/svg%3E"); }
i[data-ico="inbox"]     { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M3 12h5l2 3h4l2-3h5'/%3E%3Cpath d='M4 5h16l1 7v6a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-6z'/%3E%3C/svg%3E"); }
i[data-ico="guardian"]  { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linejoin='round'%3E%3Cpath d='M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6z'/%3E%3Cpath d='M9 12l2 2 4-4'/%3E%3C/svg%3E"); }
i[data-ico="community"] { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='9' cy='8' r='3'/%3E%3Cpath d='M3 20a6 6 0 0 1 12 0'/%3E%3Cpath d='M16 6a3 3 0 0 1 0 6M18 20a6 6 0 0 0-3-5'/%3E%3C/svg%3E"); }
i[data-ico="campaigns"] { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linejoin='round'%3E%3Cpath d='M4 9v6h3l6 4V5L7 9z'/%3E%3Cpath d='M17 9a4 4 0 0 1 0 6'/%3E%3C/svg%3E"); }
i[data-ico="commerce"]  { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M4 7h16l-1.5 12H5.5z'/%3E%3Cpath d='M9 7a3 3 0 0 1 6 0'/%3E%3C/svg%3E"); }
i[data-ico="knowledge"] { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linejoin='round'%3E%3Cpath d='M4 5a2 2 0 0 1 2-2h5v18H6a2 2 0 0 0-2 2z'/%3E%3Cpath d='M20 5a2 2 0 0 0-2-2h-5v18h5a2 2 0 0 1 2 2z'/%3E%3C/svg%3E"); }
i[data-ico="fleet"]     { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Ccircle cx='12' cy='4' r='2'/%3E%3Ccircle cx='4.5' cy='18' r='2'/%3E%3Ccircle cx='19.5' cy='18' r='2'/%3E%3Cpath d='M12 6v3M9.6 13.7l-3.4 2.6M14.4 13.7l3.4 2.6'/%3E%3C/svg%3E"); }
i[data-ico="studio"]    { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3a9 9 0 1 0 0 18c1.2 0 1.8-.9 1.8-1.7 0-.6-.3-1-.3-1.5 0-.8.6-1.4 1.5-1.4h1.6A4.4 4.4 0 0 0 21 12c0-4.9-4-9-9-9z'/%3E%3Ccircle cx='7.5' cy='11' r='1.1'/%3E%3Ccircle cx='11' cy='7.5' r='1.1'/%3E%3Ccircle cx='15.5' cy='9' r='1.1'/%3E%3C/svg%3E"); }
i[data-ico="settings"]  { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M19.1 4.9L17 7M7 17l-2.1 2.1'/%3E%3C/svg%3E"); }
