/* Chat Motor: "workshop console". Warm paper and graphite, ignition orange for actions,
   machine teal for everything bots do. Display: Bricolage Grotesque, text: Instrument Sans, data: JetBrains Mono. */

:root {
  --paper: #f2eee4;
  --paper-2: #e9e4d7;
  --surface: #fffdf7;
  --surface-2: #f7f3ea;
  --surface-3: #efe9dc;
  --ink: #1c1a15;
  --ink-2: #555047;
  --ink-3: #8b8578;
  --line: rgb(28 26 21 / .09);
  --line-2: rgb(28 26 21 / .16);
  --accent: #ff4d17;
  --accent-2: #e23d0a;
  --accent-ink: #fff;
  --accent-soft: rgb(255 77 23 / .12);
  --machine: #0b8f84;
  --machine-2: #08766d;
  --machine-soft: rgb(11 143 132 / .1);
  --machine-line: rgb(11 143 132 / .32);
  --mine: #1c1a15;
  --mine-ink: #f6f1e6;
  --mine-3: rgb(246 241 230 / .55);
  --ok: #2c8a4b;
  --ok-soft: rgb(44 138 75 / .12);
  --bad: #cf3b34;
  --bad-soft: rgb(207 59 52 / .1);
  --warn: #b97c12;
  --warn-soft: rgb(201 138 27 / .14);
  --grid: rgb(28 26 21 / .035);
  --shadow-1: 0 1px 2px rgb(28 26 21 / .06), 0 1px 1px rgb(28 26 21 / .04);
  --shadow-2: 0 18px 40px -18px rgb(28 26 21 / .35), 0 2px 6px rgb(28 26 21 / .06);
  --r-s: 8px;
  --r: 12px;
  --r-l: 18px;
  --f-body: 'Instrument Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --f-display: 'Bricolage Grotesque', var(--f-body);
  --f-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --ease: cubic-bezier(.2, .9, .25, 1);
  --side-w: 340px;
  --panel-w: 360px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12110f;
    --paper-2: #181714;
    --surface: #1f1d19;
    --surface-2: #26241f;
    --surface-3: #2f2c26;
    --ink: #f0eadd;
    --ink-2: #b9b2a3;
    --ink-3: #7f796c;
    --line: rgb(240 234 221 / .08);
    --line-2: rgb(240 234 221 / .15);
    --accent: #ff6b3d;
    --accent-2: #ff8459;
    --accent-ink: #1a0d07;
    --accent-soft: rgb(255 107 61 / .16);
    --machine: #36d6c3;
    --machine-2: #5fe3d3;
    --machine-soft: rgb(54 214 195 / .1);
    --machine-line: rgb(54 214 195 / .3);
    --mine: #efe8da;
    --mine-ink: #191712;
    --mine-3: rgb(25 23 18 / .5);
    --ok: #5cc27e;
    --ok-soft: rgb(92 194 126 / .14);
    --bad: #ff7a70;
    --bad-soft: rgb(255 122 112 / .12);
    --warn: #e6b04a;
    --warn-soft: rgb(230 176 74 / .14);
    --grid: rgb(240 234 221 / .028);
    --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-2: 0 22px 50px -20px rgb(0 0 0 / .8), 0 2px 8px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #12110f;
  --paper-2: #181714;
  --surface: #1f1d19;
  --surface-2: #26241f;
  --surface-3: #2f2c26;
  --ink: #f0eadd;
  --ink-2: #b9b2a3;
  --ink-3: #7f796c;
  --line: rgb(240 234 221 / .08);
  --line-2: rgb(240 234 221 / .15);
  --accent: #ff6b3d;
  --accent-2: #ff8459;
  --accent-ink: #1a0d07;
  --accent-soft: rgb(255 107 61 / .16);
  --machine: #36d6c3;
  --machine-2: #5fe3d3;
  --machine-soft: rgb(54 214 195 / .1);
  --machine-line: rgb(54 214 195 / .3);
  --mine: #efe8da;
  --mine-ink: #191712;
  --mine-3: rgb(25 23 18 / .5);
  --ok: #5cc27e;
  --ok-soft: rgb(92 194 126 / .14);
  --bad: #ff7a70;
  --bad-soft: rgb(255 122 112 / .12);
  --warn: #e6b04a;
  --warn-soft: rgb(230 176 74 / .14);
  --grid: rgb(240 234 221 / .028);
  --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-2: 0 22px 50px -20px rgb(0 0 0 / .8), 0 2px 8px rgb(0 0 0 / .35);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--f-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}
/* Paper grain over everything, very faint. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}
:root[data-theme="dark"] body::after { mix-blend-mode: screen; opacity: .035; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) body::after { mix-blend-mode: screen; opacity: .035; } }

#app { height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; }
a { color: inherit; }
img { max-width: 100%; }
kbd {
  font: 600 11px var(--f-mono);
  padding: 1px 5px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); }

.icon { flex: none; display: block; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.ok { color: var(--ok); display: inline-flex; gap: 6px; align-items: center; }
.danger { color: var(--bad) !important; }
.grow { flex: 1; }
.wide { width: 100%; justify-content: center; }
.center { text-align: center; }

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 15px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, transform .1s, box-shadow .15s, color .15s, border-color .15s;
  border: 1px solid transparent;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.big { min-height: 48px; font-size: 15px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 0 rgb(255 255 255 / .25) inset, 0 6px 16px -8px var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-secondary { background: var(--surface); border-color: var(--line-2); box-shadow: var(--shadow-1); }
.btn-secondary:hover:not(:disabled) { border-color: var(--ink-3); }
.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.btn-danger { background: var(--surface); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn-danger:hover:not(:disabled) { background: var(--bad-soft); }
.btn-success { background: var(--ok); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(1.08); }
.btn.busy { opacity: .75; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  color: var(--ink-2);
  transition: background .15s, color .15s;
  flex: none;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.accent { background: var(--ink); color: var(--paper); }
.icon-btn.accent:hover { background: var(--accent); color: var(--accent-ink); }

/* ---- inputs ---- */
.input {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, textarea::placeholder { color: var(--ink-3); }
select.input { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field label b { color: var(--accent); margin-left: 3px; }
.field.narrow { width: 84px; flex: none; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > .field { margin-bottom: 14px; }
.prefix { display: flex; align-items: center; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface); }
.prefix:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.prefix span { padding-left: 12px; color: var(--ink-3); font-family: var(--f-mono); }
.prefix .input { border: 0; box-shadow: none !important; padding-left: 2px; background: transparent; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.form-error { color: var(--bad); background: var(--bad-soft); padding: 8px 12px; border-radius: 10px; font-size: 14px; }

.toggle { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; margin: 6px 0 14px; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { flex: none; width: 40px; height: 24px; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--line-2); position: relative; transition: background .2s; margin-top: 1px; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-1); transition: transform .2s var(--ease); }
.toggle input:checked + .toggle-track { background: var(--machine); border-color: var(--machine); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-text { display: grid; gap: 2px; }
.toggle-text strong { font-weight: 600; font-size: 14px; }
.toggle-text small { color: var(--ink-2); font-size: 12.5px; line-height: 1.4; }

.segmented { display: flex; padding: 3px; background: var(--surface-3); border-radius: 11px; gap: 2px; margin-bottom: 14px; }
.segmented button { flex: 1; padding: 7px 10px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--ink-2); display: inline-flex; gap: 6px; justify-content: center; align-items: center; }
.segmented button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.segmented button span { font: 600 11px var(--f-mono); color: var(--ink-3); }

/* ---- avatars ---- */
.avatar {
  --s: 36px;
  position: relative;
  flex: none;
  display: inline-grid;
  place-items: center;
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font: 700 calc(var(--s) * .38) / 1 var(--f-display);
  letter-spacing: -.02em;
  user-select: none;
}
.avatar.emoji { background: color-mix(in srgb, var(--c) 18%, var(--surface)); font-size: calc(var(--s) * .52); font-family: var(--f-body); }
.avatar.group { border-radius: 30%; background: color-mix(in srgb, var(--c) 20%, var(--surface)); color: var(--c); font-size: calc(var(--s) * .48); }
.avatar.bot { border-radius: 30%; background: var(--machine-soft); box-shadow: inset 0 0 0 1.5px var(--machine-line); }
.avatar.bot:not(.emoji) { color: var(--machine); }
.avatar .presence { position: absolute; right: -1px; bottom: -1px; width: 32%; height: 32%; min-width: 9px; min-height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 2px var(--paper-2); }
.avatar.bot .presence { background: var(--machine); animation: idle 2.4s ease-in-out infinite; }
@keyframes idle { 50% { box-shadow: 0 0 0 2px var(--paper-2), 0 0 0 5px var(--machine-soft); } }
.avatar-btn { border-radius: 50%; }

.bot-tag {
  display: inline-block;
  font: 700 9.5px/1 var(--f-mono);
  letter-spacing: .08em;
  padding: 3px 5px 2px;
  border-radius: 4px;
  color: var(--machine);
  background: var(--machine-soft);
  border: 1px solid var(--machine-line);
  vertical-align: 2px;
}

/* The brand: three pistons. */
.brand-mark { display: inline-flex; align-items: flex-end; gap: 3px; height: 22px; }
.brand-mark i { width: 6px; border-radius: 3px; background: var(--ink); }
.brand-mark i:nth-child(1) { height: 60%; }
.brand-mark i:nth-child(2) { height: 100%; background: var(--accent); }
.brand-mark i:nth-child(3) { height: 78%; background: var(--machine); }
.brand-mark.big { height: 56px; gap: 7px; }
.brand-mark.big i { width: 15px; border-radius: 8px; animation: piston 1.1s var(--ease) infinite; }
.brand-mark.big i:nth-child(2) { animation-delay: .18s; }
.brand-mark.big i:nth-child(3) { animation-delay: .36s; }
@keyframes piston { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(.55); } }
.brand-mark i { transform-origin: bottom; }

.spinner { --s: 16px; width: var(--s); height: var(--s); border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; display: inline-block; animation: spin .7s linear infinite; opacity: .8; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.splash { height: 100%; display: grid; place-items: center; }

/* ---- toasts ---- */
.toasts { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: 8px; z-index: 900; justify-items: center; pointer-events: none; width: min(92vw, 420px); }
.toast { background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-weight: 500; font-size: 14px; box-shadow: var(--shadow-2); animation: rise .3s var(--ease); max-width: 100%; }
.toast.error { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.alert { background: var(--accent); color: var(--accent-ink); }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.98); } }

.empty { display: grid; justify-items: center; text-align: center; gap: 6px; padding: 32px 16px; color: var(--ink-2); }
.empty h3 { margin: 6px 0 0; font: 700 18px var(--f-display); color: var(--ink); letter-spacing: -.01em; }
.empty p { margin: 0; max-width: 34ch; font-size: 14px; }
.empty-mark { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; background: var(--surface); border: 1px dashed var(--line-2); color: var(--ink-3); }

.list-label { font: 700 10.5px var(--f-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); margin: 18px 0 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
