/* ========================================================
   css/studio.css — 3-Zone Developer Workbench Architecture
   Universal Portfolio Studio — v3.8 Workbench Architecture
   Inspired by Linear, Raycast, and Framer IDE Layout
   ======================================================== */

/* === Root Layout Shell === */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--fg-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

.wb-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg-canvas);
}

/* ========================================================
   Zone 1: Top Command Bar (.wb-topbar)
   Fibonacci Height: 55px (var(--topbar-height))
   ======================================================== */
.wb-topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  max-height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  gap: var(--space-4);
  z-index: 50;
  position: relative;
  box-sizing: border-box;
}

.wb-topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.wb-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  color: var(--fg-primary);
}

.wb-brand-icon {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  background: var(--color-primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 0.875rem;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.wb-brand-title {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--fg-primary);
  line-height: 1;
}

.wb-brand-version {
  display: inline-block;
  font-size: 0.625rem;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-pill);
  background: rgba(59, 130, 246, 0.12);
  color: var(--color-primary-light);
  border: 1px solid rgba(59, 130, 246, 0.25);
  margin-left: 0.25rem;
}

/* Center Command & Persona Strip */
.wb-topbar-center {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  justify-content: center;
  min-width: 0;
}

.wb-persona-strip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.wb-persona-strip::-webkit-scrollbar {
  display: none;
}

.wb-persona-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--fg-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-base);
}

.wb-persona-pill:hover {
  background: var(--bg-hover);
  border-color: var(--color-primary-light);
  color: var(--fg-primary);
}

.traffic-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.traffic-dot-green { background: #10b981; }
.traffic-dot-red { background: #f43f5e; }
.traffic-dot-amber { background: #f59e0b; }
.traffic-dot-cyan { background: #06b6d4; }

/* Command Palette Trigger */
.wb-cmd-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--fg-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition-base);
}

.wb-cmd-trigger:hover {
  border-color: var(--border-medium);
  color: var(--fg-primary);
}

.kbd-badge {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--fg-secondary);
}

/* Right Actions */
.wb-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-pill);
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--accent-amber);
}

.score-pill.score-ready {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.3);
  color: var(--accent-emerald);
}

/* ========================================================
   Workbench 3-Zone Workspace (.wb-main)
   Strict Golden Ratio Grid: 233px Rail | 1fr Editor | 1.618fr Stage
   ======================================================== */
.wb-main {
  display: grid;
  grid-template-columns: var(--rail-width) minmax(380px, 1fr) minmax(520px, 1.618fr);
  height: calc(100vh - var(--topbar-height));
  width: 100vw;
  max-width: 100vw;
  overflow: hidden;
  position: relative;
  box-sizing: border-box;
}

/* ========================================================
   Zone 2A: Left Architectural Step Rail (.wb-rail)
   Fibonacci Dimension: 233px (144 + 89)
   ======================================================== */
.wb-rail {
  width: var(--rail-width);
  min-width: var(--rail-width);
  max-width: var(--rail-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--space-4) var(--space-3);
  overflow-y: auto;
  z-index: 20;
  box-sizing: border-box;
}

[dir="rtl"] .wb-rail {
  border-right: none;
  border-left: 1px solid var(--border-subtle);
}

.wb-rail-list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.wb-rail-tab {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-base);
  width: 100%;
}

[dir="rtl"] .wb-rail-tab {
  text-align: right;
}

.wb-rail-tab:hover {
  background: var(--bg-hover);
}

.wb-rail-tab.active {
  background: var(--bg-surface-elevated);
  border-color: var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.wb-rail-tab.active .wb-rail-num {
  background: var(--color-primary-gradient);
  color: #ffffff;
}

.wb-rail-tab.done .wb-rail-num {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border-color: rgba(16, 185, 129, 0.3);
}

.wb-rail-num {
  width: 1.625rem;
  height: 1.625rem;
  border-radius: var(--radius-xs);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--fg-muted);
  flex-shrink: 0;
  transition: all var(--transition-base);
}

.wb-rail-text {
  flex: 1;
  min-width: 0;
}

.wb-rail-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--fg-primary);
  line-height: 1.2;
}

.wb-rail-sub {
  font-size: 0.6875rem;
  color: var(--fg-subtle);
  margin-top: 0.15rem;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wb-rail-sub.ready {
  color: var(--color-primary-light);
  font-weight: 600;
}

/* Rail Bottom Stats & Health Card */
.wb-rail-stats {
  padding: 0.75rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.wb-health-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.wb-health-label {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--fg-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.wb-health-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.wb-health-fill {
  height: 100%;
  background: var(--color-primary-gradient);
  border-radius: var(--radius-pill);
  width: 0%;
  transition: width var(--transition-smooth);
}

.wb-rail-shortcuts {
  font-size: 0.6875rem;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ========================================================
   Zone 2B: Center Inspector / Form Editor (.wb-editor)
   Golden Proportional Width: 1fr (38.2% of Content Split)
   ======================================================== */
.wb-editor {
  min-width: 0;
  overflow-y: auto;
  padding: var(--space-5) var(--space-5) var(--space-8);
  background: var(--bg-canvas);
  box-sizing: border-box;
}

.wb-editor-inner {
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

/* ========================================================
   Zone 2C: Right Device Simulator Stage (.wb-stage)
   Golden Proportional Width: 1.618fr (61.8% of Content Split)
   ======================================================== */
.wb-stage {
  min-width: 0;
  background: var(--bg-canvas);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

[dir="rtl"] .wb-stage {
  border-left: none;
  border-right: 1px solid var(--border-subtle);
}

/* Blueprint Grid Backdrop */
.wb-stage::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: 
    linear-gradient(to right, var(--border-subtle) 1px, transparent 1px),
    linear-gradient(to bottom, var(--border-subtle) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.45;
  pointer-events: none;
}

/* Simulator Titlebar Mockup */
.simulator-titlebar {
  height: 2.75rem;
  min-height: 2.75rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.875rem;
  gap: 0.625rem;
  z-index: 10;
  position: relative;
}

.mac-traffic-lights {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.mock-url-bar {
  flex: 1;
  max-width: 320px;
  height: 1.625rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  padding: 0 0.625rem;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.simulator-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Live Quick Theme Switcher Select right in Simulator Bar */
.preview-theme-dropdown {
  height: 1.625rem;
  padding: 0 0.6rem;
  border-radius: var(--radius-xs);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--fg-primary);
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  cursor: pointer;
}

.sim-btn {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-xs);
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.sim-btn:hover {
  background: var(--bg-surface-elevated);
  color: var(--fg-primary);
}

.sim-btn.active {
  background: var(--bg-surface-elevated);
  border-color: var(--border-subtle);
  color: var(--color-primary-light);
}

/* Simulator Viewport Area */
.simulator-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  position: relative;
  z-index: 5;
  overflow: hidden;
}

.simulator-viewport iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #030712;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  transition: all var(--transition-smooth);
}

/* Tablet Viewport (768px) */
.simulator-viewport.tablet iframe {
  max-width: 768px;
  height: 95%;
  border: 1px solid var(--border-medium);
  border-radius: 18px;
}

/* Mobile Viewport (375px) */
.simulator-viewport.mobile iframe {
  max-width: 375px;
  height: 92%;
  border: 8px solid #1e293b;
  border-radius: 36px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

/* ========================================================
   Command Palette Modal (#cmd-palette-modal)
   ======================================================== */
.cmd-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
}

.cmd-palette-box {
  width: 90%;
  max-width: 580px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  animation: cmdSlideDown 180ms ease-out forwards;
}

@keyframes cmdSlideDown {
  from { opacity: 0; transform: translateY(-14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.cmd-search-wrap {
  display: flex;
  align-items: center;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  gap: 0.75rem;
}

.cmd-search-icon {
  font-size: 0.875rem;
  color: var(--color-primary-light);
}

.cmd-search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--fg-primary);
}

.cmd-list {
  max-height: 340px;
  overflow-y: auto;
  padding: 0.5rem;
}

.cmd-group-label {
  font-size: 0.625rem;
  font-weight: 700;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.35rem 0.625rem;
}

.cmd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--fg-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.cmd-item:hover, .cmd-item.selected {
  background: var(--color-primary);
  color: #ffffff;
}

.cmd-item-lead {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.cmd-item-shortcut {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  opacity: 0.7;
}

/* ========================================================
   Loading Overlay & Pro Tip Modal
   ======================================================== */
.wb-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.loading-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-modal);
}

.loading-spinner {
  width: 2.25rem;
  height: 2.25rem;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--color-primary-light);
  border-radius: 50%;
  animation: wbSpin 700ms linear infinite;
}

@keyframes wbSpin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--fg-primary);
}

.tip-modal-card {
  width: 90%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-modal);
}

.tip-modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--fg-primary);
  margin-bottom: 0.5rem;
}

.tip-modal-text {
  font-size: 0.8125rem;
  color: var(--fg-secondary);
  line-height: 1.5;
  margin-bottom: 1.25rem;
}

/* ========================================================
   Mobile Golden Workspace Switcher Bar (.mobile-golden-bar)
   ======================================================== */
.mobile-golden-bar {
  display: none;
  height: 48px;
  min-height: 48px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  gap: var(--space-3);
  z-index: 45;
  box-sizing: border-box;
  overflow: hidden;
}

.mobile-ws-switcher {
  display: inline-flex;
  background: var(--bg-surface-elevated);
  padding: 3px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.ws-seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: none;
  background: transparent;
  color: var(--fg-secondary);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.ws-seg-btn.active {
  background: var(--color-primary);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.35);
}

.mobile-step-strip {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  justify-content: flex-end;
}

.mobile-step-strip::-webkit-scrollbar {
  display: none;
}

.m-step-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--fg-muted);
  font-family: var(--font-sans);
  font-size: 0.688rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.m-step-pill span {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 700;
}

.m-step-pill.active {
  background: var(--bg-surface);
  border-color: var(--color-primary-light);
  color: var(--color-primary-light);
}

.m-step-pill.done {
  color: var(--accent-emerald);
  border-color: rgba(16, 185, 129, 0.35);
}

/* Mobile Sticky Bottom Action Bar */
.mobile-action-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: 0.5rem 1rem;
  z-index: 40;
}

/* Responsive Media Queries (<= 1024px) */
@media (max-width: 1024px) {
  .mobile-golden-bar {
    display: flex;
  }

  .wb-rail {
    display: none !important;
  }

  .wb-topbar-center .wb-persona-strip {
    display: none !important;
  }

  .wb-main {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-height) - 48px);
    width: 100vw;
    max-width: 100vw;
    overflow: hidden;
  }

  /* Default on mobile: show editor, hide stage */
  .wb-editor {
    display: block !important;
    flex: 1;
    width: 100%;
    padding: var(--space-4) var(--space-3) var(--space-8);
    overflow-y: auto;
  }

  .wb-stage {
    display: none !important;
  }

  /* Live Preview active mode */
  body.mobile-preview-active .wb-editor {
    display: none !important;
  }

  body.mobile-preview-active .wb-stage {
    display: flex !important;
    flex: 1;
    width: 100%;
    border-left: none;
    border-right: none;
  }

  body.mobile-preview-active .mobile-action-bar {
    display: none !important;
  }

  .simulator-viewport {
    padding: var(--space-2);
  }

  .simulator-viewport iframe {
    border-radius: var(--radius-sm);
  }

  .mobile-action-bar {
    display: block;
  }
}

/* Brand Responsive Switcher */
.brand-short {
  display: none;
}

@media (max-width: 640px) {
  .wb-topbar {
    padding: 0 var(--space-4);
  }

  .wb-topbar-center {
    display: none !important;
  }

  .hide-on-mobile {
    display: none !important;
  }

  .wb-brand-title {
    font-size: 0.8125rem;
  }

  .wb-brand-version {
    display: none;
  }

  .score-pill {
    display: none;
  }

  .m-step-pill small {
    display: none;
  }

  .m-step-pill {
    padding: 4px 6px;
  }

  /* Simulator Toolbar mobile adaptation */
  .simulator-titlebar {
    padding: 0 var(--space-4);
    gap: var(--space-2);
    height: 40px;
    min-height: 40px;
  }

  .mac-traffic-lights,
  .mock-url-bar,
  .sim-btn[data-viewport] {
    display: none !important;
  }

  .simulator-controls {
    flex: 1;
    width: 100%;
    justify-content: space-between;
    gap: 4px;
  }

  .preview-theme-dropdown {
    flex: 1;
    min-width: 0;
    max-width: 190px;
    height: 28px;
    font-size: 0.6875rem;
  }
}

@media (max-width: 480px) {
  .brand-full {
    display: none !important;
  }

  .brand-short {
    display: inline-block !important;
    font-size: 0.8125rem;
    font-weight: 700;
  }

  .wb-topbar {
    padding: 0 var(--space-4) !important;
    gap: 6px !important;
  }

  .wb-topbar-left {
    gap: 6px !important;
  }

  .wb-topbar-right {
    gap: 5px !important;
  }

  .wb-topbar-right .btn-sm {
    padding: 0.25rem 0.5rem !important;
    font-size: 0.72rem !important;
  }

  #lang-label {
    font-size: 0.72rem;
  }
}
