/* Laygent Studio — design tokens and shared primitives.
   One token system for every view (landing, auth, studio). Dark is primary; light is a token swap. */

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  /* neutrals: near-black with a subtle cool bias */
  --bg: #0b0c0f;
  --surface-1: #111318;
  --surface-2: #171a20;
  --surface-3: #1e2229;
  --surface-raised: #15181e;
  --border: #252a32;
  --border-strong: #353b45;
  --text: #e9ecf1;
  --text-muted: #aab1bc;   /* 8.4:1 on --bg */
  --text-subtle: #8e95a1;  /* 5.9:1 on --bg, 5.5:1 on --surface-2 */
  /* one accent */
  --accent: #8aa4ff;
  --accent-hover: #a3b8ff;
  --accent-soft: rgba(138, 164, 255, .14);
  --accent-contrast: #0b0c0f;
  /* status */
  --success: #5ed3a2;
  --warning: #eab45c;
  --danger: #ff8591;
  --danger-soft: rgba(255, 133, 145, .12);
  --warning-soft: rgba(234, 180, 92, .14);
  --focus: #a3b8ff;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 12px 40px rgba(0, 0, 0, .5);
  --scrim: rgba(4, 5, 7, .62);
  --code-bg: #0b0c0f;
  --code-text: #d7dce4;
  --gutter-text: #808793;  /* line numbers, 5.4:1 on --code-bg */
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface-1: #f6f7f9;
  --surface-2: #eef0f4;
  --surface-3: #e4e7ec;
  --surface-raised: #ffffff;
  --border: #dde1e7;
  --border-strong: #c5cbd4;
  --text: #15181d;
  --text-muted: #4a515c;
  --text-subtle: #5b626d;
  --accent: #3a5bd6;
  --accent-hover: #2f4dbd;
  --accent-soft: rgba(58, 91, 214, .1);
  --accent-contrast: #ffffff;
  --success: #17835a;
  --warning: #9a6200;
  --danger: #c2293b;
  --danger-soft: rgba(194, 41, 59, .08);
  --warning-soft: rgba(154, 98, 0, .1);
  --focus: #2f4dbd;
  --shadow-1: 0 1px 2px rgba(20, 24, 31, .08);
  --shadow-2: 0 12px 40px rgba(20, 24, 31, .16);
  --scrim: rgba(20, 24, 31, .38);
  --code-bg: #ffffff;
  --code-text: #1d2129;
  --gutter-text: #6b727d;
}

:root {
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 14px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --dur: 160ms;
  --dur-panel: 260ms;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --rail-w-expanded: 196px;
  --editor-font-size: 13px;
  --editor-line-height: 1.65;
  --rail-w: 48px;
  --topbar-h: 48px;
  --statusbar-h: 26px;
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur: 0ms; --dur-panel: 0ms; }
}
:root[data-motion="reduce"] { --dur: 0ms; --dur-panel: 0ms; }
.theme-switching *, .theme-switching *::before, .theme-switching *::after { transition: none !important; }
:root[data-motion="reduce"] *, :root[data-motion="reduce"] *::before, :root[data-motion="reduce"] *::after {
  animation-duration: 0ms !important;
  transition-duration: 0ms !important;
  transition-delay: 0ms !important;
  scroll-behavior: auto !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0ms !important; transition-duration: 0ms !important; transition-delay: 0ms !important; scroll-behavior: auto !important; }
}

/* ---- base ---- */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--text-md)/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
.hidden { display: none !important; }
::selection { background: var(--accent-soft); color: inherit; }
:root[data-theme="dark"] ::selection { background: rgba(138, 164, 255, .32); }
kbd {
  display: inline-block; min-width: 20px; padding: 1px 5px;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px;
  background: var(--surface-2); color: var(--text);
  font: 500 11px/1.4 var(--font-mono); text-align: center;
}
code { font-family: var(--font-mono); font-size: .92em; }

/* focus: always visible for keyboard users */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.visually-hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.skip-link {
  position: fixed; z-index: 1000; left: 12px; top: -48px;
  padding: 8px 14px; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-contrast); font-weight: 600;
  transition: top var(--dur) var(--ease);
}
.skip-link:focus, .skip-link:focus-visible { top: 10px; outline-offset: 3px; }

.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.muted { color: var(--text-muted); }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }

.view { min-height: 100vh; }

/* ---- brand ---- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.02em; }
.brand-mark { display: block; width: 24px; height: 24px; flex: none; background: url('/assets/laygent-mark-dark.svg') center/contain no-repeat; }
.brand-mark svg { display: none; }
:root[data-theme="light"] .brand-mark { background-image: url('/assets/laygent-mark.svg'); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  font-size: var(--text-sm); font-weight: 500; white-space: nowrap; cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.icon { width: 34px; padding: 0; }

.icon-btn {
  position: relative; display: inline-grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--text); background: var(--surface-2); }
.icon-btn.small { width: 26px; height: 26px; }
.icon-btn:disabled { opacity: .5; cursor: not-allowed; }
.badge {
  position: absolute; top: 1px; right: 0; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 99px; background: var(--accent); color: var(--accent-contrast);
  font: 700 11px/16px var(--font-ui); text-align: center;
}
.needs-values .badge { background: var(--warning); color: #16120a; }

/* ---- form controls ---- */
.field { display: grid; gap: 6px; margin: 0 0 14px; }
.field label { color: var(--text-muted); font-size: var(--text-xs); font-weight: 500; }
.field input, .field select, .select, input.input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface-1); color: var(--text);
}
.field input::placeholder, .select::placeholder, input::placeholder, textarea::placeholder { color: var(--text-subtle); opacity: 1; }
.field input:focus-visible, .field select:focus-visible, .select:focus-visible, input.input:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.select { width: auto; height: 32px; padding: 0 28px 0 10px; font-size: var(--text-sm); appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.select.small { height: 28px; font-size: var(--text-xs); }
.select:disabled { opacity: .6; cursor: not-allowed; }

.switch {
  position: relative; width: 40px; height: 24px; flex: none; border-radius: 99px;
  border: 1px solid var(--border-strong); background: var(--surface-3);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-muted); transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); background: var(--accent-contrast); }

.segmented { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
.segmented button { display: inline-grid; place-items: center; min-width: 28px; height: 26px; padding: 0 6px; border-radius: 5px; color: var(--text-muted); font-size: var(--text-xs); }
.segmented.text button { padding: 0 12px; }
.segmented button:hover { color: var(--text); background: var(--surface-2); }
.segmented button[aria-checked="true"] { color: var(--text); background: var(--surface-3); box-shadow: var(--shadow-1); }

/* ---- dialogs (all overlays share one pattern) ---- */
.dialog-backdrop, .variables-overlay {
  position: fixed; z-index: 200; inset: 0; display: grid; place-items: center; padding: 20px;
  background: var(--scrim); backdrop-filter: blur(3px);
  animation: fadeIn var(--dur) var(--ease);
}
.dialog, .variables-dialog {
  display: flex; flex-direction: column; width: min(560px, 100%); max-height: min(760px, calc(100dvh - 40px));
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  background: var(--surface-raised); box-shadow: var(--shadow-2); overflow: hidden;
  animation: rise var(--dur) var(--ease);
}
.dialog.wide { width: min(760px, 100%); }
.dialog-head, .variables-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 20px 14px; border-bottom: 1px solid var(--border); }
.dialog-head h2, .variables-head h2 { margin: 0 0 4px; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.dialog-head p, .variables-head p { margin: 0; color: var(--text-muted); font-size: var(--text-sm); }
.variables-head .eyebrow { margin-bottom: 6px; font-size: 11px; }
.variables-head .btn.icon { flex: none; width: 32px; min-height: 32px; border-color: transparent; background: transparent; color: var(--text-muted); }
.variables-head .btn.icon:hover { background: var(--surface-2); color: var(--text); }
.variables-body { display: grid; gap: 10px; padding: 16px 20px; overflow: auto; }
.variable-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.variable-row:last-child { border-bottom: 0; }
.variable-row strong { display: block; font: 600 12px/1.4 var(--font-mono); letter-spacing: .02em; }
.variable-row small { display: block; color: var(--text-muted); font-size: var(--text-xs); }
.variable-row input, .variable-row select { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-1); color: var(--text); font-size: var(--text-sm); }
.variable-input-wrap { display: block; }
.variables-empty { padding: 14px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-muted); font-size: var(--text-sm); }
.variables-empty strong { color: var(--text); }
.variables-empty p { margin: 4px 0 0; }
.variables-empty a { color: var(--accent); text-decoration: underline; }
.variables-note, .dialog-note { margin: 0; padding: 12px 20px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: var(--text-xs); line-height: 1.6; }
.variables-actions, .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.connection-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
.connection-title { display: flex; align-items: center; gap: 8px; }
.connection-title i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-subtle); }
.connection-title i.connected { background: var(--success); }
.connection-title h3 { margin: 0; font-size: var(--text-md); text-transform: capitalize; }
.connection-card p { margin: 4px 0; color: var(--text-muted); font-size: var(--text-xs); }
.connection-permissions { color: var(--text-subtle); font-size: var(--text-xs); }
.connection-actions { display: flex; gap: 6px; flex: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
@keyframes sink { from { opacity: 1; transform: none; } to { opacity: 0; transform: scale(.98); } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
/* A dialog that closes is hidden at once; a copy of it fades out on top (see closeDialog in app.js). */
.dialog-ghost { position: fixed; z-index: 260; inset: 0; pointer-events: none; animation: fadeOut 150ms var(--ease) forwards; }
.dialog-ghost > .dialog, .dialog-ghost > .variables-dialog { animation: sink 150ms var(--ease) forwards; }

/* ---- toast ---- */
.toast {
  position: fixed; z-index: 300; left: calc(var(--rail-w) + 16px); bottom: 40px; max-width: min(420px, calc(100vw - var(--rail-w) - 32px));
  padding: 10px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-2); font-size: var(--text-sm);
  animation: rise var(--dur) var(--ease);
}

/* ---- popover (account) ---- */
.popover {
  position: fixed; z-index: 150; min-width: 240px; padding: 6px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  background: var(--surface-raised); box-shadow: var(--shadow-2);
  animation: rise var(--dur) var(--ease);
}
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 34px; padding: 0 10px; border-radius: var(--radius-sm); color: var(--text); font-size: var(--text-sm); text-align: left; }
.menu-item:hover { background: var(--surface-2); }
.account-card { display: flex; align-items: center; gap: 10px; padding: 10px 10px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.account-card strong { display: block; font-size: var(--text-sm); }
.account-card small { display: block; color: var(--text-muted); font-size: var(--text-xs); }
.avatar { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface-3); color: var(--text); font: 600 11px/1 var(--font-ui); letter-spacing: .02em; }
.avatar.large { width: 34px; height: 34px; font-size: 12px; }
