:root {
  --paper: #F2EDE4; --paper-2: #E9E2D5; --card: #FBF8F2; --ink: #1D1A16; --ink-2: #5E574C; --ink-3: #8C8476;
  --line: #D6CDBC; --red: #E0482B; --red-soft: #F6D9CF; --mustard: #E5A82E; --mustard-soft: #F7E7C2;
  --teal: #2E7D74; --teal-soft: #D3E8E3; --navy: #263A5A; --green: #3F7D3A; --green-soft: #DCEBD5;
  --radius: 10px; --gutter: 16px; --tabs-h: 64px;
  --sans: "Archivo", system-ui, sans-serif; --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.45 var(--sans); }
body { min-height: 100dvh; overscroll-behavior-y: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
a { color: inherit; }
.muted { color: var(--ink-2); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.err { color: var(--red); font-weight: 600; }

.wordmark { font-family: var(--sans); font-weight: 850; font-stretch: 72%; letter-spacing: .02em; font-size: 22px; line-height: 1; }
.wordmark span { color: var(--red); }

/* ---------- login */
.login { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px var(--gutter); text-align: center; }
.login img { border-radius: 22px; }
.login h1 { font-size: 40px; margin: 18px 0 4px; }
.login form { width: 100%; max-width: 320px; margin-top: 28px; display: grid; gap: 10px; text-align: left; }
.login label { font-weight: 600; font-size: 13px; }
input, select { font: inherit; width: 100%; padding: 12px 14px; border: 1.5px solid var(--ink); border-radius: 8px; background: var(--card); color: var(--ink); }
input:focus, select:focus { outline: 3px solid var(--mustard); outline-offset: 1px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 1.5px solid var(--ink); border-radius: 8px; background: var(--card); font-weight: 650; cursor: pointer; }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { border-color: var(--line); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; }

/* ---------- top bar */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) 10px; background: var(--paper); border-bottom: 1.5px solid var(--ink); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.brand img { border-radius: 7px; }
.pill { margin-left: auto; display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 11px; border-radius: 99px;
  border: 1.5px solid var(--ink); background: var(--card); font: 600 12.5px var(--sans); white-space: nowrap; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dot.warn { background: var(--mustard); }
.dot.bad { background: var(--red); }
.iconbtn { width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: none; cursor: pointer; border-radius: 8px; }

html, body { overflow-x: hidden; }
main { padding: 0 var(--gutter) calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px); max-width: 720px; margin: 0 auto; }
.view { padding-top: 14px; }
.h { font-weight: 850; font-stretch: 75%; font-size: 21px; letter-spacing: .01em; text-transform: uppercase; margin: 22px 0 10px; }
.head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.head-row .h { margin-top: 6px; }
.card { background: var(--card); border: 1.5px solid var(--ink); border-radius: var(--radius); }

/* ---------- tabs */
.tabs { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--ink); }
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none;
  color: #A69E90; font-size: 11.5px; font-weight: 650; letter-spacing: .02em; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tabs svg .f { fill: currentColor; stroke: none; }
.tabs a.on { color: var(--paper); }
.tabs a.on svg { color: var(--mustard); }

/* ---------- factory */
.scene-wrap { border: 1.5px solid var(--ink); border-radius: var(--radius); overflow: hidden; background: #CFE0E4; }
#scene svg { display: block; width: 100%; height: auto; }
.room { cursor: pointer; }
.room .shade { transition: opacity .6s; opacity: 0; }
.room.sleeping .shade { opacity: .38; }
.room .lamp-glow { transition: opacity .6s; opacity: 0; }
.room.working .lamp-glow { opacity: 1; }
.room .beacon { opacity: 0; }
.room.blocked .beacon, .room.error .beacon { opacity: 1; animation: blink 1s steps(2) infinite; }
.room .bubble { opacity: 0; transition: opacity .3s; }
.room.blocked .bubble, .room.error .bubble { opacity: 1; }
.room .zzz { opacity: 0; }
.room.sleeping .zzz { opacity: 1; }
.room.sleeping .zzz text { animation: zzz 3s ease-in infinite; }
.room.sleeping .zzz text:nth-child(2) { animation-delay: 1s; }
.room.sleeping .zzz text:nth-child(3) { animation-delay: 2s; }
.room .head { transition: transform .8s; transform-box: fill-box; transform-origin: 50% 100%; }
.room.sleeping .head { transform: rotate(22deg) translateY(3px); }
.room .eye-open { opacity: 1; } .room .eye-shut { opacity: 0; }
.room.sleeping .eye-open { opacity: 0; } .room.sleeping .eye-shut { opacity: 1; }
.room .arm { transform-box: fill-box; transform-origin: 10% 10%; }
.room.working .arm { animation: type .45s ease-in-out infinite alternate; }
.room.working .bob { animation: bob 1.6s ease-in-out infinite; }
.room .screen { transition: fill .6s; }
.room.working .screen-anim { animation: flicker 2.2s steps(4) infinite; }
.room.sleeping .screen { fill: #2A3346; }
.room .busy-only { opacity: 0; transition: opacity .4s; }
.room.working .busy-only { opacity: 1; }
.belt-box { opacity: 0; }
.running .belt-box { opacity: 1; }
.belt-stripes { animation: none; }
.running .belt-stripes { animation: belt 0.8s linear infinite; }
.smoke circle { opacity: 0; }
.running .smoke circle { animation: smoke 3.2s ease-out infinite; }
.running .smoke circle:nth-child(2) { animation-delay: 1.05s; }
.running .smoke circle:nth-child(3) { animation-delay: 2.1s; }
.pipe-dot { opacity: 0; }
.data-flow .pipe-dot { opacity: 1; }
.leds circle { animation: led 1.3s steps(2) infinite; }
.leds circle:nth-child(odd) { animation-delay: .4s; }
.room.sleeping .leds circle { animation-duration: 4s; }
.night .sky { fill: #1E2A40; }
.night .star { opacity: 1; }
.star { opacity: 0; }

@keyframes blink { 50% { opacity: .15; } }
@keyframes zzz { 0% { transform: translate(0, 0); opacity: 0; } 20% { opacity: 1; } 100% { transform: translate(10px, -22px); opacity: 0; } }
@keyframes type { from { transform: rotate(-6deg); } to { transform: rotate(5deg); } }
@keyframes bob { 50% { transform: translateY(-1.2px); } }
@keyframes flicker { 0% { opacity: 1; } 50% { opacity: .82; } 100% { opacity: 1; } }
@keyframes belt { to { stroke-dashoffset: -12; } }
@keyframes smoke { 0% { transform: translate(0, 0) scale(.6); opacity: 0; } 15% { opacity: .9; } 100% { transform: translate(22px, -46px) scale(1.6); opacity: 0; } }
@keyframes led { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* production line card */
.line { margin-top: 12px; padding: 14px; }
.line .t { font-weight: 750; font-size: 16px; line-height: 1.3; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 12px 0 4px; }
.step { border: 1.5px solid var(--line); border-radius: 8px; padding: 8px; font-size: 12px; font-weight: 650; color: var(--ink-3); }
.step b { display: block; font: 600 11px var(--mono); letter-spacing: .04em; }
.step.done { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); }
.step.now { border-color: var(--ink); color: var(--ink); background: var(--mustard-soft); }
.step.bad { border-color: var(--red); color: var(--red); background: var(--red-soft); }
.kv { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.kv b { color: var(--ink); font-family: var(--mono); font-weight: 600; }

/* feed */
.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.msg { display: grid; grid-template-columns: 36px 1fr; gap: 10px; padding: 10px 12px; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); }
.msg .who { font-size: 12px; font-weight: 750; letter-spacing: .03em; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.msg .who .to { color: var(--ink-3); font-weight: 600; }
.msg .when { margin-left: auto; color: var(--ink-3); font: 500 11px var(--mono); }
.msg p { margin: 3px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.msg.alexia { border-color: var(--red); }
.av { width: 36px; height: 36px; border-radius: 50%; border: 1.5px solid var(--ink); overflow: hidden; background: var(--paper-2); }
.av svg { display: block; width: 100%; height: 100%; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.chip { flex: none; height: 32px; padding: 0 12px; border-radius: 99px; border: 1.5px solid var(--line); background: var(--card); font-weight: 650; font-size: 12.5px; cursor: pointer; }
.chip.on { border-color: var(--ink); background: var(--ink); color: var(--paper); }

/* shorts */
.shorts { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.sh { display: grid; grid-template-columns: 74px 1fr; gap: 12px; padding: 10px; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.sh .th { width: 74px; height: 98px; border-radius: 7px; background: var(--paper-2) center/cover; border: 1.5px solid var(--ink); }
.sh .tt { font-weight: 720; font-size: 14.5px; line-height: 1.3; }
.sh .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 5px; font-size: 12px; color: var(--ink-2); }
.nums { display: grid; grid-template-columns: repeat(4, auto); justify-content: start; gap: 2px 14px; margin-top: 8px; }
.nums div { font: 600 13.5px var(--mono); }
.nums small { display: block; font: 600 10px var(--sans); color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 5px; font: 700 10.5px var(--sans); letter-spacing: .05em; text-transform: uppercase; border: 1.5px solid currentColor; }
.tag.win { color: var(--green); background: var(--green-soft); }
.tag.ok { color: var(--teal); background: var(--teal-soft); }
.tag.flop { color: var(--red); background: var(--red-soft); }
.tag.wait { color: var(--ink-2); }
.tag.prod { color: #8A5A00; background: var(--mustard-soft); }

/* alexia */
.alexia-head { display: grid; grid-template-columns: 76px 1fr; gap: 14px; align-items: center; padding: 14px; margin-top: 6px; background: var(--ink); color: var(--paper); border-radius: var(--radius); }
.alexia-head .av { width: 76px; height: 76px; border-color: var(--paper); }
.alexia-head h2 { margin: 0; font-weight: 850; font-stretch: 75%; font-size: 26px; letter-spacing: .03em; }
.alexia-head p { margin: 2px 0 0; color: #CFC6B6; font-size: 13.5px; }
.dir { padding: 12px; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
.dir.active { border-color: var(--ink); }
.dir.pending { border-color: var(--red); }
.dir .txt { font-weight: 650; font-size: 14px; margin: 6px 0; }
.dir .why { font-size: 13px; color: var(--ink-2); }
.dir .acts { display: flex; gap: 8px; margin-top: 10px; }
.bar { height: 8px; border-radius: 4px; background: var(--paper-2); overflow: hidden; margin-top: 8px; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; background: var(--ink); }
.rev { padding: 12px; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
.rev h4 { margin: 6px 0 4px; font-size: 14.5px; }
.rev ul { margin: 6px 0 0; padding-left: 18px; font-size: 13.5px; color: var(--ink-2); }
.empty { padding: 18px; text-align: center; color: var(--ink-3); border: 1.5px dashed var(--line); border-radius: var(--radius); font-size: 13.5px; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(29, 26, 22, .45); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow-y: auto; background: var(--paper);
  border-top: 1.5px solid var(--ink); border-radius: 16px 16px 0 0; padding: 6px var(--gutter) calc(24px + env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 10px; }
.sheet h3 { margin: 4px 0; font-weight: 850; font-stretch: 75%; font-size: 24px; letter-spacing: .02em; text-transform: uppercase; }
.sheet h5 { margin: 18px 0 8px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.agent-top { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; }
.agent-top .av { width: 64px; height: 64px; }
.state { display: inline-flex; align-items: center; gap: 6px; font: 650 12px var(--sans); }
pre.log { margin: 0; padding: 10px; background: var(--ink); color: #E6DFD2; border-radius: 8px; font: 11.5px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 300px; overflow: auto; }
.set { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set .l { font-weight: 650; }
.set .l small { display: block; font-weight: 500; color: var(--ink-2); font-size: 12.5px; }
.stepper { display: inline-flex; align-items: center; border: 1.5px solid var(--ink); border-radius: 8px; overflow: hidden; }
.stepper button { width: 38px; height: 36px; border: 0; background: var(--card); font-size: 18px; cursor: pointer; }
.stepper span { min-width: 34px; text-align: center; font: 600 14px var(--mono); }
.switch { position: relative; width: 52px; height: 30px; border-radius: 99px; border: 1.5px solid var(--ink); background: var(--paper-2); cursor: pointer; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: var(--ink); transition: left .2s; }
.switch[aria-checked="true"] { background: var(--green-soft); }
.switch[aria-checked="true"]::after { left: 25px; background: var(--green); }
.acc { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.acc .row { display: flex; justify-content: space-between; }
video { width: 100%; max-height: 62dvh; border-radius: 10px; border: 1.5px solid var(--ink); background: #000; }
.chart { width: 100%; height: auto; display: block; }
.script { font-size: 14px; background: var(--card); border: 1.5px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 8px; font-weight: 600; font-size: 13.5px; max-width: calc(100vw - 32px); }
@media (min-width: 760px) { .tabs { left: 50%; width: 720px; transform: translateX(-50%); border-radius: 14px 14px 0 0; } }

/* team legend under the factory */
.legend { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.lg { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border: 1.5px solid var(--line); border-radius: 99px; background: var(--card); cursor: pointer; text-align: left; }
.lg b { display: block; font-size: 12px; letter-spacing: .04em; }
.lg span { display: block; font-size: 11.5px; color: var(--ink-2); white-space: nowrap; }
.av.sm { width: 30px; height: 30px; flex: none; }
/* team cards */
.team-cards { display: grid; gap: 8px; }
.tc { display: grid; grid-template-columns: 48px 1fr; gap: 12px; align-items: center; padding: 10px 12px; text-align: left; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); cursor: pointer; width: 100%; }
.tc .av { width: 48px; height: 48px; }
.tc .nm { font-weight: 800; letter-spacing: .04em; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.tc .rl { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.tc .tx { min-width: 0; }
.tc .lm { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.role { font-weight: 650; color: var(--ink-2); }
/* agent sheet tabs */
.seg { display: grid; grid-template-columns: 1fr 1fr; margin: 14px 0 6px; border: 1.5px solid var(--ink); border-radius: 8px; overflow: hidden; }
.seg button { height: 38px; border: 0; background: var(--card); font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--ink); color: var(--paper); }
/* chat */
.chatbox { display: flex; flex-direction: column; gap: 10px; min-height: 34dvh; max-height: 46dvh; overflow-y: auto; padding: 10px 2px; }
.b { display: flex; gap: 8px; max-width: 88%; }
.b p { margin: 0; padding: 9px 12px; border-radius: 12px; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.b.me { align-self: flex-end; flex-direction: column; align-items: flex-end; }
.b.me p { background: var(--ink); color: var(--paper); border-bottom-right-radius: 4px; }
.b.ag p { background: var(--card); border: 1.5px solid var(--line); border-bottom-left-radius: 4px; }
.bt { display: block; font: 500 10.5px var(--mono); color: var(--ink-3); margin-top: 3px; }
.did { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; }
.did span { font-size: 11.5px; font-weight: 700; color: var(--green); background: var(--green-soft); border-radius: 5px; padding: 2px 7px; }
.typing { display: inline-flex; gap: 4px; padding: 13px 14px !important; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: dots 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes dots { 50% { transform: translateY(-4px); opacity: .5; } }
.sugg { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.sugg .chip { font-weight: 600; }
.chatform { position: sticky; bottom: calc(-24px - env(safe-area-inset-bottom)); background: var(--paper); padding: 6px 0 calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.models { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 99px; overflow: hidden; margin-bottom: 8px; }
.models button { height: 28px; padding: 0 12px; border: 0; background: var(--card); font: 700 12px var(--sans); cursor: pointer; }
.models button[aria-checked="true"] { background: var(--mustard); }
.chatform .row { display: flex; gap: 8px; align-items: flex-end; }
.chatform textarea { flex: 1; resize: none; font: inherit; padding: 11px 12px; border: 1.5px solid var(--ink); border-radius: 10px; background: var(--card); min-height: 44px; max-height: 120px; }
.chatform textarea:focus { outline: 3px solid var(--mustard); outline-offset: 1px; }
.chatform .btn { width: 46px; padding: 0; flex: none; }
