/* Design Vault Workbench Stylesheet
 * Grounded in design-system/design-vault/MASTER.md (OLED Dark Studio Shell + Optional Light Shell)
 */

:root,
[data-shell-theme="dark"] {
  --shell-bg: #0b1120;
  --shell-surface: #111827;
  --shell-card: #151e30;
  --shell-elevated: #1e293b;
  --shell-hover: #263449;
  --shell-code: #090e1a;

  --shell-text: #f8fafc;
  --shell-text-2: #cbd5e1;
  --shell-muted: #94a3b8;

  --shell-accent: #22c55e;
  --shell-accent-hover: #16a34a;
  --shell-accent-soft: rgba(34, 197, 94, 0.14);
  --shell-on-accent: #052e16;

  --shell-border: rgba(148, 163, 184, 0.16);
  --shell-border-strong: rgba(148, 163, 184, 0.30);
  --shell-shadow: 0 12px 32px rgba(0, 0, 0, 0.36);
}

[data-shell-theme="light"] {
  --shell-bg: #f1f5f9;
  --shell-surface: #ffffff;
  --shell-card: #ffffff;
  --shell-elevated: #f8fafc;
  --shell-hover: #e2e8f0;
  --shell-code: #0f172a;

  --shell-text: #0f172a;
  --shell-text-2: #334155;
  --shell-muted: #64748b;

  --shell-accent: #15803d;
  --shell-accent-hover: #166534;
  --shell-accent-soft: rgba(21, 128, 61, 0.11);
  --shell-on-accent: #ffffff;

  --shell-border: rgba(15, 23, 42, 0.10);
  --shell-border-strong: rgba(15, 23, 42, 0.22);
  --shell-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-padding-top: 76px;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--shell-bg);
  color: var(--shell-text);
  font-family: "Inter", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  font-size: 14.5px;
  line-height: 1.6;
}

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

:focus-visible {
  outline: 2px solid var(--shell-accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--shell-surface) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--shell-border);
}

.topbar-inner {
  max-width: 1380px;
  margin: 0 auto;
  height: 62px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--shell-text);
  text-decoration: none;
  flex-shrink: 0;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--shell-accent-soft);
  border: 1px solid color-mix(in srgb, var(--shell-accent) 40%, transparent);
  color: var(--shell-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-text span {
  font-size: 11.5px;
  color: var(--shell-muted);
}

.view-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--shell-elevated);
  border: 1px solid var(--shell-border);
  border-radius: 10px;
}

.view-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--shell-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.view-tab:hover {
  color: var(--shell-text);
}

.view-tab.is-active {
  background: var(--shell-card);
  color: var(--shell-text);
  box-shadow: inset 0 0 0 1px var(--shell-border-strong);
}

.tab-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--shell-accent-soft);
  color: var(--shell-accent);
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.btn-sm {
  height: 34px;
  padding: 0 12px;
  font-size: 12.5px;
}

.btn-xs {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-primary {
  background: var(--shell-accent);
  color: var(--shell-on-accent);
}

.btn-primary:hover {
  background: var(--shell-accent-hover);
}

.btn-secondary {
  background: var(--shell-elevated);
  color: var(--shell-text);
  border-color: var(--shell-border-strong);
}

.btn-secondary:hover {
  background: var(--shell-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--shell-text-2);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--shell-elevated);
  color: var(--shell-text);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--shell-border-strong);
  background: var(--shell-elevated);
  color: var(--shell-text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.icon-btn:hover {
  background: var(--shell-hover);
  color: var(--shell-text);
}

/* Main Container */
.container {
  max-width: 1380px;
  margin: 0 auto;
  padding: 24px 24px 56px;
}

/* Hero Panel */
.hero-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  padding: 24px 28px;
  margin-bottom: 20px;
  background: var(--shell-card);
  border: 1px solid var(--shell-border);
  border-radius: 14px;
}

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--shell-accent);
  margin-bottom: 8px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--shell-accent);
  box-shadow: 0 0 0 4px var(--shell-accent-soft);
}

.hero-copy h1 {
  margin: 0 0 8px;
  font-size: clamp(22px, 2.4vw, 28px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.hero-copy p {
  margin: 0;
  max-width: 680px;
  color: var(--shell-text-2);
  font-size: 14px;
}

.hero-copy strong {
  color: var(--shell-text);
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(100px, 1fr));
  gap: 12px;
  flex-shrink: 0;
}

.stat-item {
  padding: 12px 14px;
  background: var(--shell-elevated);
  border: 1px solid var(--shell-border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 11.5px;
  color: var(--shell-muted);
}

.stat-value {
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.search-box {
  position: relative;
  flex: 1 1 320px;
  max-width: 480px;
}

.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--shell-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 40px;
  padding: 0 14px 0 38px;
  background: var(--shell-card);
  border: 1px solid var(--shell-border-strong);
  border-radius: 10px;
  font-size: 13.5px;
}

.search-box input::placeholder {
  color: var(--shell-muted);
}

.filter-groups {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--shell-card);
  border: 1px solid var(--shell-border);
  border-radius: 9px;
}

.seg-btn {
  height: 32px;
  padding: 0 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--shell-muted);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.seg-btn:hover {
  color: var(--shell-text);
}

.seg-btn.is-active {
  background: var(--shell-elevated);
  color: var(--shell-text);
  box-shadow: inset 0 0 0 1px var(--shell-border-strong);
}

.scenario-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.scenario-chip {
  height: 29px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--shell-border);
  background: var(--shell-card);
  color: var(--shell-text-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms ease;
}

.scenario-chip:hover {
  border-color: var(--shell-border-strong);
  color: var(--shell-text);
}

.scenario-chip.is-active {
  background: var(--shell-accent-soft);
  border-color: color-mix(in srgb, var(--shell-accent) 45%, transparent);
  color: var(--shell-accent);
}

/* Gallery Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(390px, 1fr));
  gap: 20px;
}

.style-card {
  background: var(--shell-card);
  border: 1px solid var(--shell-border);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.style-card:hover {
  border-color: var(--shell-border-strong);
  box-shadow: var(--shell-shadow);
}

.preview-window {
  position: relative;
  height: 248px;
  overflow: hidden;
  border-bottom: 1px solid var(--shell-border);
  background: var(--shell-code);
  cursor: pointer;
}

.preview-frame-scaled {
  position: absolute;
  top: 0;
  left: 0;
  width: 1180px;
  height: 760px;
  border: 0;
  transform-origin: top left;
  pointer-events: none;
}

.preview-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(11, 17, 32, 0.04) 55%, rgba(11, 17, 32, 0.62) 100%);
  opacity: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 14px 16px;
  transition: opacity 180ms ease;
}

.preview-window:hover .preview-overlay,
.preview-window:focus-within .preview-overlay {
  opacity: 1;
}

.preview-hint {
  color: #f8fafc;
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 5px 10px;
  border-radius: 7px;
}

.card-body {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-titles h3 {
  margin: 0 0 3px;
  font-size: 16.5px;
  font-weight: 700;
  line-height: 1.3;
}

.card-source {
  font-size: 12px;
  color: var(--shell-muted);
}

.mode-pill {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--shell-border);
  background: var(--shell-elevated);
  color: var(--shell-text-2);
}

.mode-pill.is-dark {
  background: #0f172a;
  color: #e2e8f0;
  border-color: rgba(148, 163, 184, 0.3);
}

.mode-pill.is-light {
  background: #f8fafc;
  color: #0f172a;
  border-color: rgba(15, 23, 42, 0.15);
}

.card-tagline {
  margin: 0;
  color: var(--shell-text-2);
  font-size: 13.5px;
  line-height: 1.55;
}

.palette-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 8px 0 5px;
  border-radius: 6px;
  border: 1px solid var(--shell-border);
  background: var(--shell-elevated);
  color: var(--shell-text-2);
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
  font-size: 11px;
  cursor: pointer;
  transition: border-color 150ms ease;
}

.swatch-btn:hover {
  border-color: var(--shell-border-strong);
  color: var(--shell-text);
}

.swatch-color {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(128, 128, 128, 0.35);
  flex-shrink: 0;
}

.tag-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.mini-tag {
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--shell-elevated);
  color: var(--shell-muted);
  font-size: 11.5px;
}

.card-actions {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--shell-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-actions .btn-primary {
  flex: 1;
}

.btn-compare.is-selected {
  background: var(--shell-accent-soft);
  color: var(--shell-accent);
  border-color: color-mix(in srgb, var(--shell-accent) 45%, transparent);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 56px 20px;
  background: var(--shell-card);
  border: 1px dashed var(--shell-border-strong);
  border-radius: 14px;
  color: var(--shell-muted);
}

.empty-state h3 {
  margin: 12px 0 6px;
  color: var(--shell-text);
}

/* Compare View */
.compare-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.compare-header h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.compare-header p {
  margin: 0;
  color: var(--shell-muted);
  font-size: 13.5px;
}

.compare-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.select-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  color: var(--shell-muted);
}

.select-wrap select {
  height: 36px;
  min-width: 200px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--shell-border-strong);
  background: var(--shell-card);
  color: var(--shell-text);
  font-size: 13px;
  cursor: pointer;
}

.compare-matrix {
  margin-bottom: 18px;
  background: var(--shell-card);
  border: 1px solid var(--shell-border);
  border-radius: 12px;
  overflow-x: auto;
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.matrix-table th,
.matrix-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--shell-border);
}

.matrix-table th {
  width: 130px;
  color: var(--shell-muted);
  font-weight: 600;
  background: var(--shell-elevated);
}

.matrix-table tr:last-child th,
.matrix-table tr:last-child td {
  border-bottom: none;
}

.compare-panes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.compare-pane {
  background: var(--shell-card);
  border: 1px solid var(--shell-border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.pane-bar {
  padding: 10px 14px;
  background: var(--shell-elevated);
  border-bottom: 1px solid var(--shell-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.pane-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.compare-iframe {
  width: 100%;
  height: 760px;
  border: 0;
  background: #0b1120;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-shell {
  width: 100%;
  max-height: 92vh;
  background: var(--shell-surface);
  border: 1px solid var(--shell-border-strong);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-xl {
  max-width: 1240px;
  height: 90vh;
}

.modal-md {
  max-width: 720px;
}

.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--shell-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--shell-muted);
}

.modal-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mono-tag {
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--shell-elevated);
  border: 1px solid var(--shell-border);
  color: var(--shell-muted);
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
  font-size: 11.5px;
}

.inspector-toolbar {
  padding: 10px 22px;
  background: var(--shell-card);
  border-bottom: 1px solid var(--shell-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.inspector-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ins-tab {
  height: 32px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--shell-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.ins-tab:hover {
  color: var(--shell-text);
  background: var(--shell-elevated);
}

.ins-tab.is-active {
  background: var(--shell-accent-soft);
  color: var(--shell-accent);
  border-color: color-mix(in srgb, var(--shell-accent) 40%, transparent);
}

.viewport-switcher {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: var(--shell-elevated);
  border: 1px solid var(--shell-border);
  border-radius: 8px;
}

.vp-btn {
  height: 26px;
  padding: 0 10px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--shell-muted);
  font-size: 12px;
  cursor: pointer;
}

.vp-btn.is-active {
  background: var(--shell-card);
  color: var(--shell-text);
}

.modal-body {
  padding: 18px 22px 22px;
  overflow-y: auto;
  flex: 1;
}

.ins-panel {
  height: 100%;
}

.preview-stage {
  height: 100%;
  min-height: 540px;
  display: flex;
  justify-content: center;
  background: repeating-linear-gradient(
    -45deg,
    color-mix(in srgb, var(--shell-elevated) 55%, transparent),
    color-mix(in srgb, var(--shell-elevated) 55%, transparent) 10px,
    transparent 10px,
    transparent 20px
  );
  border: 1px solid var(--shell-border);
  border-radius: 12px;
  padding: 10px;
  overflow: auto;
}

.inspector-iframe {
  width: 100%;
  height: 100%;
  min-height: 520px;
  border: 1px solid var(--shell-border-strong);
  border-radius: 10px;
  background: #ffffff;
  transition: width 220ms ease;
}

/* Code & Agent panels */
.code-box {
  background: var(--shell-code);
  border: 1px solid var(--shell-border-strong);
  border-radius: 10px;
  overflow: hidden;
}

.code-box-head {
  padding: 10px 14px;
  background: rgba(30, 41, 59, 0.72);
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.code-pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  color: #e2e8f0;
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
  font-size: 12.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.code-pre.compact {
  background: var(--shell-code);
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 12px 14px;
}

.agent-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.agent-card {
  padding: 16px 18px;
  background: var(--shell-card);
  border: 1px solid var(--shell-border);
  border-radius: 12px;
}

.agent-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.agent-card h3 {
  margin: 0;
  font-size: 14.5px;
}

.agent-card p {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--shell-muted);
}

.agent-card code {
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
  font-size: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  padding: 10px 18px;
  border-radius: 999px;
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid rgba(34, 197, 94, 0.45);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.42);
  font-size: 13px;
  font-weight: 500;
}

/* Responsive */
@media (max-width: 1024px) {
  .hero-panel {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 820px) {
  .compare-panes {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .topbar-inner {
    padding: 0 14px;
  }
  .brand-text span {
    display: none;
  }
  .container {
    padding: 16px 14px 40px;
  }
  .gallery-grid {
    grid-template-columns: 1fr;
  }
  .hero-stats {
    width: 100%;
  }
  .modal-backdrop {
    padding: 8px;
  }
  .modal-xl {
    height: 95vh;
  }
}
