/* ============================================================================
   Knights Run Studio | v2 design system
   Drop-in replacement stylesheet. Preserves every class name and state hook
   that src/app.js toggles. Used by index-v2.html alongside the existing app.
   ============================================================================ */

:root {
  /* Surface */
  --bg:           #0b0d12;
  --surface-0:    #0f1218;
  --surface-1:    #161a23;
  --surface-2:    #1d222e;
  --surface-3:    #252b3a;

  /* Borders */
  --border:        rgba(255,255,255,0.06);
  --border-strong: rgba(255,255,255,0.10);
  --border-accent: rgba(91,139,255,0.35);

  /* Text */
  --text:         #e8eaf0;
  --text-muted:   #a8b0c4;   /* was #8b93a7 | bumped for readability */
  --text-subtle:  #7e8a9e;   /* was #5b6479 | bumped for readability */

  /* Brand */
  --accent:        #5b8bff;
  --accent-hover:  #739dff;
  --accent-soft:   rgba(91,139,255,0.12);

  /* Status */
  --success:  #4eb784;
  --warn:     #e0a64a;
  --danger:   #e06b5e;

  /* Radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  /* Spacing */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Legacy tokens kept for any inline computed styles in app.js */
  --muted: var(--text-muted);
  --radius: var(--r-lg);
  --surface: var(--surface-1);
  --surface2: var(--surface-2);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

canvas {
  max-width: 100%;
  display: block;
}

.hidden { display: none !important; }

/* ============================================================================
   File-protocol warning
   ============================================================================ */

.file-protocol-warning {
  margin: 0;
  padding: 12px 24px;
  background: rgba(224, 166, 74, 0.08);
  border-bottom: 1px solid rgba(224, 166, 74, 0.25);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}
.file-protocol-warning a { color: var(--accent); }
.file-protocol-warning code {
  background: var(--surface-0);
  padding: 1px 6px;
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 12px;
}
.file-protocol-warning p { margin: 0; }

/* ============================================================================
   App shell
   ============================================================================ */

.app-shell {
  display: grid;
  grid-template-rows: 56px 1fr 64px;
  height: 100vh;
}

.file-protocol-warning:not(.hidden) ~ .app-shell {
  height: calc(100vh - 50px);
}

/* ============================================================================
   Topbar
   ============================================================================ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s-4);
  background: var(--surface-0);
  border-bottom: 1px solid var(--border);
  gap: var(--s-3);
  height: 52px;
  flex-shrink: 0;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-shrink: 0;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, #5b8bff 0%, #8b6bff 100%);
  display: grid; place-items: center;
  color: white;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name {
  font-weight: 600;
  letter-spacing: -0.005em;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-divider {
  color: var(--text-subtle);
  margin: 0 4px;
  font-weight: 400;
}
/* "Knights Run" link back to the monorepo launcher. Inherits the surrounding
   brand-name styling so it looks like text, with a subtle hover state. */
.brand-home-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: color 120ms ease;
}
.brand-home-link:hover {
  color: var(--accent);
}
.brand-sub {
  font-size: 11px;
  color: var(--text-subtle);
  margin: 0;
}

/* eyebrow class kept since older code might style it */
.eyebrow {
  margin: 0 0 4px;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  font-weight: 600;
}

/* Track toggle | segmented control in the topbar.
   Blue when VRE active, green when LOA active.
   The hidden #track-select stays in DOM so app.js wiring is untouched. */
.track-toggle {
  display: inline-flex;
  align-items: center;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  position: relative;
}
.track-toggle-btn {
  padding: 6px 16px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background .18s ease, color .18s ease, box-shadow .18s ease, transform .18s ease;
  white-space: nowrap;
  position: relative;
}
.track-toggle-btn:hover {
  color: var(--text);
}
.track-toggle-btn:focus-visible {
  outline: 2px solid var(--border-accent);
  outline-offset: 2px;
}

/* VRE active: blue */
.track-toggle-btn.is-active[data-track="VRE"] {
  background: #2f6dff;
  color: #ffffff;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.18),
    0 1px 2px rgba(0,0,0,0.25),
    0 6px 18px rgba(47,109,255,0.35);
}

/* LOA active: green */
.track-toggle-btn.is-active[data-track="LOA"] {
  background: #2fb673;
  color: #ffffff;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.18),
    0 1px 2px rgba(0,0,0,0.25),
    0 6px 18px rgba(47,182,115,0.32);
}

/* Subtle ambient glow on the wrapper that shifts color with track */
.track-toggle[data-active-track="VRE"] {
  border-color: rgba(47,109,255,0.35);
  box-shadow: 0 0 0 1px rgba(47,109,255,0.08), 0 8px 24px -8px rgba(47,109,255,0.18);
}
.track-toggle[data-active-track="LOA"] {
  border-color: rgba(47,182,115,0.32);
  box-shadow: 0 0 0 1px rgba(47,182,115,0.08), 0 8px 24px -8px rgba(47,182,115,0.18);
}

/* Narrower screens | show short labels */
.track-toggle-btn .track-label-long { display: inline; }
.track-toggle-btn .track-label-short { display: none; }
@media (max-width: 1280px) {
  .track-toggle-btn .track-label-long { display: none; }
  .track-toggle-btn .track-label-short { display: inline; }
  .track-toggle-btn { padding: 6px 14px; }
}

.topbar-divider {
  height: 20px;
  margin: 0 var(--s-1);
}

.topbar-signin-btn {
  color: var(--accent);
  font-weight: 500;
  white-space: nowrap;
}
.topbar-signin-btn:hover {
  color: var(--accent-hover);
}

/* ============================================================================
   Status / meta pills
   ============================================================================ */

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-pill::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-subtle);
  flex-shrink: 0;
}
.status-pill.is-connected::before {
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(78, 183, 132, 0.2);
}
.status-pill--multiline {
  border-radius: var(--r-md);
  white-space: pre-line;
  line-height: 1.45;
  text-align: left;
  max-width: 360px;
  padding: 8px 12px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  border: 1px solid var(--border);
}

/* ============================================================================
   Buttons
   ============================================================================ */

.icon-button,
.ghost-button,
.primary-button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s, opacity .12s;
  white-space: nowrap;
  text-decoration: none;
}
.icon-button:hover,
.ghost-button:hover,
.btn:hover {
  background: var(--surface-3);
  border-color: var(--border-accent);
}

.primary-button {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 600;
}
.primary-button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Track-aware theming | when LOA is active, primary buttons turn green to
   match the brand. Applies to Export all, Save settings, Transform Headshot,
   etc. | anything using .primary-button. */
body[data-active-track="LOA"] .primary-button {
  background: #2fb673;
  border-color: #2fb673;
}
body[data-active-track="LOA"] .primary-button:hover {
  background: #36c984;
  border-color: #36c984;
}
/* The track toggle's own active state is hardcoded per data-track attribute,
   so it stays correct regardless of body theming. */

.ghost-button {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.ghost-button:hover {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--text);
}

.btn--sm { padding: 5px 10px; font-size: 12px; border-radius: 5px; }

.icon-button {
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.icon-button:hover {
  background: var(--surface-2);
  color: var(--text);
}

button:disabled, .btn:disabled, .ghost-button:disabled, .primary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Override the legacy ID-based button colors so the design system wins.
   These IDs still exist (app.js needs them) but their colors come from .btn variants. */
#export-all { /* primary, see button on the element directly */ }
#export-zip,
#export-digital-png,
#export-email-png,
#export-headshot-png,
#export-business-pdf,
#gemini-generate {
  /* No special styling | they take the class assigned in HTML */
}

/* ============================================================================
   Layout | three-zone shell
   ============================================================================ */

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 360px;
  gap: var(--s-4);
  padding: var(--s-4);
  overflow: hidden;
  min-height: 0;
}

.layout-rail,
.layout-inspector {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-height: 0;
  padding-right: 4px;
}

.layout-hero {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-height: 0;
  min-width: 0;
}

/* ============================================================================
   Card primitive
   ============================================================================ */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}
.panel-header h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.panel-header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

/* ============================================================================
   Search
   ============================================================================ */

.search-wrap {
  position: relative;
}
.search-wrap input,
input[type="search"]#agent-search {
  width: 100%;
  padding: 10px 12px 10px 36px;
  background: var(--surface-0);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, background .15s;
}
.search-wrap input:focus { border-color: var(--border-accent); }

.search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}

.search-results {
  margin-top: var(--s-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 280px;
  overflow-y: auto;
}

.search-result {
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 1px;
  transition: background .12s;
}
.search-result:hover { background: var(--surface-2); }
.search-result.is-selected {
  background: var(--accent-soft);
  outline: 1px solid var(--border-accent);
}
.search-result strong {
  display: block;
  font-weight: 500;
  font-size: 13px;
}
.search-result span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ============================================================================
   Forms
   ============================================================================ */

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding-bottom: var(--s-3);
  margin-bottom: var(--s-3);
  border-bottom: 1px solid var(--border);
}
.form-group:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.form-group-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin: 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--text-muted);
  font-size: 12px;
}
label > span:first-child {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="search"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-accent);
}

input:disabled,
select:disabled,
textarea:disabled {
  color: var(--text);
  opacity: 0.85;
  cursor: not-allowed;
}

select {
  appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b93a7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
}

/* ============================================================================
   Agent details locked state
   ============================================================================ */

.agent-details-card {
  transition: border-color 140ms ease, background 140ms ease;
}
.agent-details-card.is-locked input,
.agent-details-card.is-locked select {
  background: var(--surface-0);
  color: var(--text);
  border-color: var(--border);
  cursor: default;
  opacity: 0.85;
}
.agent-details-card.is-locked input::placeholder {
  color: var(--text-subtle);
}

.locked-hint,
.form-lock-hint {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: 11px;
  color: var(--text-subtle);
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  margin: 0 0 var(--s-3);
  line-height: 1.4;
}

/* hint class for general use */
.hint {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
  margin: 0 0 var(--s-3);
}

.hint-inline {
  font-size: 11px;
  opacity: 0.65;
  font-weight: 400;
}

/* ============================================================================
   Headshot dropzone
   ============================================================================ */

.dropzone {
  position: relative;
  aspect-ratio: 1;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-0);
  overflow: hidden;
  display: grid;
  place-items: center;
  color: var(--text-subtle);
  font-size: 12px;
  transition: border-color .15s;
}
.dropzone:hover { border-color: var(--border-accent); }
.dropzone img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.dropzone-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 60%);
  opacity: 0;
  transition: opacity .15s;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--s-3);
  gap: var(--s-2);
}
.dropzone:hover .dropzone-overlay { opacity: 1; }

.dropzone-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--s-2);
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================================
   Hero (preview surface)
   ============================================================================ */

.hero-tabs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
}
.hero-tab-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

/* Copy-signature button | only visible when Email Signature pane is active */
.signature-copy-btn { display: none; }
body[data-active-pane="signature"] .signature-copy-btn {
  display: inline-flex;
}

.hero-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-1);
  padding: 4px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  width: fit-content;
}
.hero-tab {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  min-width: 100px;
}
.hero-tab:hover {
  background: var(--surface-2);
  color: var(--text);
}
.hero-tab.is-active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04);
}
.hero-tab[hidden] { display: none; }

/* Accent tab variant | used by Email Signature so it stands out from
   the asset preview tabs as a different kind of output. */
.hero-tab--accent {
  color: #5b8bff;
}
.hero-tab--accent:hover {
  color: #ffffff;
  background: rgba(47, 109, 255, 0.18);
}
.hero-tab--accent .hero-tab-meta {
  color: rgba(91, 139, 255, 0.7);
}
.hero-tab--accent.is-active {
  background: #2f6dff;
  color: #ffffff;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.18),
    0 1px 2px rgba(0,0,0,0.25),
    0 6px 18px rgba(47,109,255,0.35);
}
.hero-tab--accent.is-active .hero-tab-meta {
  color: rgba(255,255,255,0.85);
}

.hero-tab--accent.is-loa {
  color: #2fb673;
}
.hero-tab--accent.is-loa:hover {
  color: #ffffff;
  background: rgba(47, 182, 115, 0.18);
}
.hero-tab--accent.is-loa .hero-tab-meta {
  color: rgba(47, 182, 115, 0.7);
}
.hero-tab--accent.is-loa.is-active {
  background: #2fb673;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2), 0 6px 18px rgba(47,182,115,0.35);
}
.hero-tab--accent.is-loa.is-active .hero-tab-meta {
  color: rgba(255,255,255,0.85);
}

.hero-tab-label { font-weight: 500; }
.hero-tab-meta {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.hero-tab.is-active .hero-tab-meta { color: var(--text); }

.hero-canvas {
  flex: 1;
  background:
    linear-gradient(45deg, var(--surface-0) 25%, transparent 25%) 0 0/16px 16px,
    linear-gradient(-45deg, var(--surface-0) 25%, transparent 25%) 0 8px/16px 16px,
    linear-gradient(45deg, transparent 75%, var(--surface-0) 75%) 8px -8px/16px 16px,
    linear-gradient(-45deg, transparent 75%, var(--surface-0) 75%) -8px 0/16px 16px,
    var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  display: grid;
  place-items: center;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* The canvas elements themselves get sized to fit */
.hero-canvas-pane {
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
}
.hero-canvas-pane.is-active { display: flex; }

.hero-canvas canvas {
  max-height: 100%;
  max-width: 100%;
  height: auto;
  width: auto;
  border-radius: var(--r-md);
  background: #0b0d13;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.04),
    0 30px 60px -20px rgba(0,0,0,0.5);
}

/* Email preview: canvas is rendered at 4× export dimensions for legibility.
   Cap height so the tall LOA format (140×300 × 4 = 560×1200) doesn't overflow. */
.hero-canvas-pane[data-pane="email"] canvas {
  max-height: 80%;
  width: auto;
}

/* Email signature pane | iframe preview + copy actions */
.hero-canvas-pane[data-pane="signature"] {
  align-items: stretch;
  justify-content: stretch;
}
.signature-stage {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-height: 0;
}
.signature-iframe {
  flex: 1 1 auto;
  width: 100%;
  max-width: 640px;
  height: 100%;
  max-height: 620px;  /* cap so blank space below long panes stays minimal */
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04), 0 30px 60px -20px rgba(0,0,0,0.5);
}
.signature-copy-status {
  font-size: 12px;
  color: var(--success);
  opacity: 0;
  transition: opacity .2s;
}
.signature-copy-status.is-visible { opacity: 1; }
.signature-copy-status.is-error { color: var(--danger); }
.signature-copy-status.is-visible { opacity: 1; }
.signature-copy-status.is-error { color: var(--danger); }

.signature-source {
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-0);
  padding: var(--s-2) var(--s-3);
}
.signature-source summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  user-select: none;
}
.signature-source summary:hover { color: var(--text); }
.signature-source[open] { padding-bottom: var(--s-3); }
.signature-source textarea {
  width: 100%;
  margin-top: var(--s-2);
  min-height: 120px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px;
  white-space: pre;
  overflow-x: auto;
}

/* Business pane shows two PDF pages side by side */
.hero-canvas-pane[data-pane="business"] {
  align-items: stretch;
}
.business-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-4);
  align-items: center;
  width: 100%;
  height: 100%;
  justify-items: center;
}
.business-grid canvas {
  border: 1px solid var(--border);
  background: white;
  max-height: 100%;
}

.preview-draggable {
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.preview-draggable:active { cursor: grabbing; }

.canvas-overlay-hint {
  position: absolute;
  top: var(--s-3);
  right: var(--s-3);
  display: flex;
  gap: 4px;
  background: rgba(15,18,24,0.85);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 3px;
  font-size: 11px;
  color: var(--text-muted);
}
.canvas-overlay-hint .ghost-button {
  padding: 3px 8px;
  font-size: 11px;
}

/* Zoom slider | vertical control to the right of the active preview canvas.
   Reads/writes the active preset's scale (1.0–2.5) via window.__krSetZoom. */
.zoom-slider {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: rgba(15, 18, 24, 0.9);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 12px 8px;
  z-index: 5;
  user-select: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
body[data-active-pane="business"] .zoom-slider,
body[data-active-pane="signature"] .zoom-slider { display: none; }

.zoom-slider-icon {
  width: 16px; height: 16px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 2px;
  border-radius: 4px;
  transition: color .12s, background .12s;
}
.zoom-slider-icon:hover { color: var(--text); background: var(--surface-2); }

.zoom-slider-track {
  width: 14px;
  height: 200px;
  display: flex;
  justify-content: center;
  align-items: stretch;
  position: relative;
}

.zoom-slider input[type="range"].zoom-range {
  -webkit-appearance: slider-vertical;
  appearance: slider-vertical;
  writing-mode: bt-lr; /* Firefox legacy */
  height: 100%;
  width: 14px;
  margin: 0;
  padding: 0;
  cursor: pointer;
  background: transparent;
  accent-color: var(--accent);
}

.zoom-slider-value {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  min-width: 36px;
  text-align: center;
  letter-spacing: 0.02em;
}

/* ============================================================================
   Hero controls bar
   ============================================================================ */

.hero-controls {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  flex-wrap: wrap;
}
.control-group {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.control-group > label,
.control-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  margin: 0;
}
.control-group select {
  width: auto;
  min-width: 160px;
  max-width: 220px;
  padding: 6px 28px 6px 10px;
}
.control-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

/* Hide template selectors when their pane isn't active */
.hero-controls .template-variant-select { width: auto; min-width: 160px; }

/* Toggle (compare to reference, etc.) */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  user-select: none;
}
.toggle input { display: none; }
.toggle-track {
  width: 30px; height: 16px;
  background: var(--surface-3);
  border-radius: 999px;
  position: relative;
  transition: background .15s;
  flex-shrink: 0;
}
.toggle-track::after {
  content: '';
  position: absolute;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
  top: 2px; left: 2px;
  transition: all .15s;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after {
  background: white;
  left: 16px;
}

/* Business panel hide/show toggle (legacy class) */
.business-panel-toggle-label {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
}
.business-panel-toggle-label input { width: auto; margin: 0; }

/* ============================================================================
   Inspector (right rail)
   ============================================================================ */

.inspector-nav {
  display: flex;
  gap: 2px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 4px;
}
.inspector-tab {
  flex: 1;
  padding: 7px 10px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.inspector-tab:hover { color: var(--text); background: var(--surface-2); }
.inspector-tab.is-active {
  background: var(--surface-3);
  color: var(--text);
}

.inspector-pane {
  display: none;
  flex-direction: column;
  gap: var(--s-2);
}
.inspector-pane.is-active { display: flex; }

/* ============================================================================
   Layout & Typography (slider system)
   ============================================================================ */

.layout-tuning-matched {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  min-width: 0;
}

.layout-tuning-headers {
  display: none; /* hidden in v2; per-row labels are clearer */
}

.layout-tuning-pair-row {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-1);
  padding: 10px 12px 12px;
  transition: border-color .12s, opacity .12s;
}
.layout-tuning-pair-row[data-vre-only].hidden { display: none; }
.layout-tuning-pair-row.is-locked { opacity: 0.65; }

.lt-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.lt-row-label {
  letter-spacing: 0.01em;
}
.lt-row-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.layout-slider-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
  min-width: 0;
}
.layout-slider-row[data-vre-only].hidden { display: none; }
.layout-slider-row:first-of-type { margin-top: 6px; }

.layout-slider-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.layout-slider-controls {
  display: grid;
  grid-template-columns: 26px 1fr 26px 48px;
  gap: 6px;
  align-items: center;
}

.layout-nudge {
  width: 26px; height: 26px;
  border: 1px solid var(--border);
  background: var(--surface-0);
  color: var(--text-muted);
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: grid;
  place-items: center;
  user-select: none;
  padding: 0;
  transition: all .12s;
}
.layout-nudge:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.layout-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--surface-3);
  border-radius: 999px;
  outline: none;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}
.layout-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
}
.layout-range::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg);
}

.layout-num {
  width: 100%;
  min-width: 0;
  padding: 4px 6px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--surface-0);
  border-radius: 5px;
  color: var(--text);
  outline: none;
}
.layout-num:focus { border-color: var(--border-accent); }
.layout-num::-webkit-outer-spin-button,
.layout-num::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"].layout-num { -moz-appearance: textfield; }

.layout-tuning-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.layout-tuning-cell--empty {
  min-height: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px dashed var(--border);
  border-radius: var(--r-sm);
  color: var(--text-subtle);
  font-size: 14px;
  line-height: 1;
  opacity: 0.55;
}
.layout-tuning-cell-note {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Lock button | keeps emoji from app.js but styled tight */
.layout-lock-button {
  width: 26px; height: 26px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-0);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  display: grid;
  place-items: center;
  transition: all .12s;
  color: var(--text-muted);
}
.layout-lock-button:hover {
  border-color: var(--border-strong);
  color: var(--text);
}
.layout-lock-button.is-locked {
  border-color: var(--border-accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ============================================================================
   Business mirror | the duplicate slider block.
   In v2 it lives inside the Business Card hero pane. Same DOM as before
   so app.js bidirectional sync still works untouched.
   ============================================================================ */

.layout-biz-mirror {
  margin-top: var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px solid var(--border);
}
.layout-biz-mirror.hidden { display: none; }
.layout-biz-mirror-hint { margin: 0 0 var(--s-3); }

/* ============================================================================
   Gemini AI transform card (lives in Inspector → AI tab)
   ============================================================================ */

/* Gemini quick-prompt preset buttons | click to load a canonical prompt
   into the textarea below. User can edit before clicking Transform. */
.gemini-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 var(--s-3);
}
.gemini-presets .ghost-button {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-muted);
}
.gemini-presets .ghost-button:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-3);
}

.gemini-prompt {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-0);
  color: var(--text);
  resize: vertical;
  font: inherit;
  font-size: 12px;
  line-height: 1.5;
  outline: none;
}
.gemini-prompt:focus { border-color: var(--border-accent); }

.gemini-actions {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  align-items: center;
  margin-top: var(--s-3);
}

.gemini-generating {
  position: relative;
  padding-left: 22px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Stop button | visible only while a Gemini transform is in flight.
   Tinted danger so it reads as a cancel action distinct from Revert. */
.gemini-stop-btn {
  background: rgba(224, 107, 94, 0.1);
  border-color: rgba(224, 107, 94, 0.4);
  color: #e06b5e;
}
.gemini-stop-btn:hover {
  background: rgba(224, 107, 94, 0.18);
  border-color: rgba(224, 107, 94, 0.6);
  color: #ee8276;
}
.gemini-generating::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 12px; height: 12px;
  margin-top: -6px;
  border-radius: 50%;
  border: 2px solid rgba(91, 139, 255, 0.3);
  border-top-color: var(--accent);
  animation: kr-spin 0.9s linear infinite;
}
@keyframes kr-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ============================================================================
   Settings panel | slide-in drawer
   ============================================================================ */

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 480px;
  max-width: 92vw;
  background: var(--surface-1);
  border-left: 1px solid var(--border-strong);
  box-shadow: -20px 0 60px rgba(0,0,0,0.4);
  z-index: 90;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.22s ease;
  overflow: hidden;
}
.settings-panel.hidden {
  transform: translateX(100%);
  display: flex !important;
  pointer-events: none;
}

.settings-panel .panel-header {
  padding: var(--s-4) var(--s-5);
  margin: 0;
  border-bottom: 1px solid var(--border);
}
.settings-panel .panel-header h2 {
  font-size: 16px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  font-weight: 600;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: var(--s-4);
  row-gap: var(--s-3);
  padding: var(--s-5);
  overflow-y: auto;
  flex: 1;
  align-content: start; /* keep rows hugging the top instead of stretching */
}

.settings-full-width {
  grid-column: 1 / -1;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--border);
  background: var(--surface-0);
}

.folder-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.folder-input-row input[type="text"] {
  flex: 1;
  min-width: 0;
}
.folder-browse-btn {
  flex-shrink: 0;
  white-space: nowrap;
  padding: 8px 12px;
}

.api-key-wrap {
  position: relative;
}
.api-key-wrap input[type="password"] {
  width: 100%;
  padding-right: 90px;
}
input.api-key-locked {
  color: var(--text-muted);
  opacity: 0.7;
  cursor: pointer;
  letter-spacing: 2px;
}
.api-key-badge {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  font-weight: 600;
  color: var(--success);
  background: rgba(78, 183, 132, 0.12);
  border: 1px solid rgba(78, 183, 132, 0.35);
  border-radius: var(--r-sm);
  padding: 2px 8px;
  pointer-events: none;
  white-space: nowrap;
}

.google-auth-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
}
.google-auth-status {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.google-auth-status::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-subtle);
  flex-shrink: 0;
}
.google-auth-status.signed-in { color: var(--success); }
.google-auth-status.signed-in::before {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(78, 183, 132, 0.15);
}
.google-auth-actions {
  display: flex;
  gap: var(--s-2);
  flex-shrink: 0;
}

/* Export destination radio group (Settings drawer) */
.settings-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: var(--s-2);
  opacity: 0.8;
}
.export-dest-row {
  display: flex;
  gap: var(--s-4);
  align-items: center;
}
.radio-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.radio-option input[type="radio"] {
  cursor: pointer;
  accent-color: var(--accent);
}
.drive-signin-hint {
  margin-top: var(--s-2);
  font-size: 11px;
  color: var(--accent);
  opacity: 0.85;
}

/* Settings overlay backdrop */
.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 80;
  opacity: 1;
  transition: opacity 0.22s ease;
}
.settings-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
  display: block !important;
}

/* ============================================================================
   Summary / export list (left rail or footer area)
   ============================================================================ */

.summary-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.summary-item {
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 12px;
}
.summary-item span:last-child { color: var(--text-muted); }

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

/* ============================================================================
   Sticky export bar
   ============================================================================ */

.exportbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s-5);
  background: var(--surface-0);
  border-top: 1px solid var(--border);
  gap: var(--s-3);
}
.exportbar-status {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: 12px;
  color: var(--text-muted);
  min-width: 0;
}
.exportbar-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
}
/* Export bar individual asset buttons | full white so they're clearly readable */
.exportbar-btn {
  color: var(--text);
}
.exportbar-btn:hover {
  color: var(--text);
}

/* ============================================================================
   Dialog
   ============================================================================ */

.app-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
}
.app-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}
.app-dialog-card {
  min-width: min(440px, calc(100vw - 32px));
  margin: 0;
  padding: var(--s-5);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.app-dialog-card h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.app-dialog-card p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.5;
  font-size: 13px;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  margin-top: var(--s-2);
}

/* ============================================================================
   Scrollbars
   ============================================================================ */

.layout-rail::-webkit-scrollbar,
.layout-inspector::-webkit-scrollbar,
.search-results::-webkit-scrollbar,
.settings-grid::-webkit-scrollbar,
.gemini-prompt::-webkit-scrollbar { width: 8px; }

.layout-rail::-webkit-scrollbar-thumb,
.layout-inspector::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb,
.settings-grid::-webkit-scrollbar-thumb,
.gemini-prompt::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 999px;
}
.layout-rail::-webkit-scrollbar-track,
.layout-inspector::-webkit-scrollbar-track,
.search-results::-webkit-scrollbar-track,
.settings-grid::-webkit-scrollbar-track,
.gemini-prompt::-webkit-scrollbar-track { background: transparent; }

/* ============================================================================
   Responsive
   ============================================================================ */

@media (max-width: 1280px) {
  .layout {
    grid-template-columns: 280px minmax(0,1fr) 320px;
  }
  .topbar {
    grid-template-columns: 240px 1fr auto;
  }
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    overflow-y: auto;
  }
  .layout-rail,
  .layout-inspector,
  .layout-hero {
    overflow: visible;
  }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .signature-stage { flex-direction: column; }
  .signature-actions { width: 100%; }
}

@