/**
 * Groundfix Studio Layout Shell
 * Clean 3-Zone Architecture:
 * - Top Workspace Bar (48px)
 * - Middle Workspace: [48px Tool Rail | 1fr Center Canvas | 320px Studio Sidebar]
 * - Bottom Status Bar (36px)
 * Zero overlapping drawers, zero fake strips.
 */

#app-container {
  display: grid;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  grid-template-rows: 48px minmax(0, 1fr) 36px;
  background: var(--bg-app);
}

/* Remanet .is-welcome startup architecture */
#app-container.is-welcome {
  grid-template-rows: 100%;
}

#app-container.is-welcome .workspace-bar,
#app-container.is-welcome footer,
#app-container.is-welcome .tool-rail,
#app-container.is-welcome #library-panel,
#app-container.is-welcome .library,
#app-container.is-welcome #inspector-panel,
#app-container.is-welcome .inspector-popout {
  display: none !important;
}

#app-container.is-welcome .workspace {
  grid-row: 1;
  grid-template-columns: 100%;
  height: 100%;
  width: 100%;
}

#app-container.is-welcome #workspace-viewport,
#app-container.is-welcome .stage {
  grid-column: 1;
  width: 100%;
  height: 100%;
}

#start.start {
  display: none;
}

#app-container.is-welcome #start.start {
  display: flex;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  background: var(--bg-dark, #121612);
  overflow-y: auto;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}

#app-container.is-welcome .viewport-layer,
#app-container.is-welcome .stage-hud-caption,
#app-container.is-welcome .stage-drop-overlay {
  display: none !important;
}

/* ==========================================================================
   1. Top Workspace Bar (48px)
   ========================================================================== */
header#studio-header.workspace-bar {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-app);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  height: 48px;
  z-index: 20;
  user-select: none;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  background: var(--bg-panel-sub);
  border: 1px solid var(--border-app);
  border-radius: 6px;
  color: var(--accent-primary);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.brand-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-main);
}

.brand-tld {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 12px;
}

.header-divider {
  width: 1px;
  height: 20px;
  background: var(--border-app);
}

.quick-icons {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  background: var(--bg-input);
  border-color: var(--border-app);
  color: var(--text-main);
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

/* Center Zone: Selection Name & Trail Strip */
.header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.center-selection-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.center-name-input {
  background: var(--bg-input);
  border: 1px solid var(--border-app);
  color: var(--text-main);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  width: 200px;
  outline: none;
  transition: all 0.15s ease;
}

.center-name-input:focus {
  border-color: var(--accent-primary);
  background: var(--bg-hover);
}

.contextual-tool-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--accent-primary);
  padding: 4px 12px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  animation: slideDownFade 0.18s ease-out;
}

@keyframes slideDownFade {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.tool-strip-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-primary);
}

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

/* Right Zone: View modes & Build */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-switcher {
  display: flex;
  background: var(--bg-input);
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--border-app);
  gap: 2px;
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  font-size: 12px;
  transition: all 0.15s ease;
}

.mode-btn:hover {
  color: var(--text-main);
}

.mode-btn.active {
  background: var(--accent-primary);
  color: #0e1117;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* ==========================================================================
   2. Middle Row: Remanet Layout Alignment [Rail 48px | Library 280px | Stage 1fr]
   ========================================================================== */
main#studio-body.workspace {
  grid-row: 2;
  display: grid;
  grid-template-columns: 48px 280px minmax(0, 1fr);
  grid-template-rows: 100%;
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

/* 2.1 Left 48px Slim Tool Rail */
aside#tool-rail.tool-rail {
  grid-column: 1;
  grid-row: 1;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-app);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  width: 48px;
  z-index: 25;
  user-select: none;
  box-sizing: border-box;
}

.tool-rail-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.rail-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.rail-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-sub);
  color: var(--text-main);
}

.rail-btn.active {
  background: var(--bg-hover);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.rail-divider {
  width: 24px;
  height: 1px;
  background: var(--border-app);
  margin: 8px 0;
}

.rail-spacer {
  flex: 1;
}

/* 2.2 Left Library Panel (~280px next to tool rail) */
aside#library-panel.library-panel {
  grid-column: 2;
  grid-row: 1;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-app);
  display: flex;
  flex-direction: column;
  width: 280px;
  min-width: 280px;
  max-width: 280px;
  height: 100%;
  overflow: hidden;
  z-index: 20;
  user-select: none;
  box-sizing: border-box;
}

.library-header {
  height: 40px;
  border-bottom: 1px solid var(--border-app);
  display: flex;
  align-items: center;
  background: var(--bg-panel-sub);
  padding: 0 8px;
  flex-shrink: 0;
}

.library-tabs {
  display: flex;
  width: 100%;
  gap: 4px;
}

.lib-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  text-align: center;
  transition: all 0.12s ease;
}

.lib-tab:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

.lib-tab.active {
  color: var(--text-main);
  background: var(--bg-input);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.library-items {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.library-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 36px;
  padding: 0 12px;
  margin: 1px 6px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-main);
  font-size: 12px;
  border: 1px solid transparent;
  transition: all 0.12s ease;
}

.library-row:hover {
  background: var(--bg-hover);
}

.library-row.selected {
  background: var(--bg-hover);
  border-color: var(--accent-primary);
  color: #ffffff;
}

.library-row-left {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
  gap: 8px;
}

.library-row-icon {
  font-size: 13px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.library-row.selected .library-row-icon {
  color: var(--accent-primary);
}

.library-row-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.library-row-actions {
  display: none;
  align-items: center;
  gap: 4px;
}

.library-row:hover .library-row-actions,
.library-row:focus-within .library-row-actions,
.library-row.selected .library-row-actions {
  display: flex;
}

/* Persistent Library Footer (36px) */
.library-footer {
  height: 38px;
  border-top: 1px solid var(--border-app);
  background: var(--bg-panel-sub);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  flex-shrink: 0;
}

.library-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

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

/* 2.3 Center Stage Canvas (<main> -> .stage / #workspace-viewport) */
section#workspace-viewport.stage,
section#workspace-viewport {
  grid-column: 3;
  grid-row: 1;
  background: var(--bg-app);
  position: relative;
  overflow: hidden;
  display: flex;
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
}

.viewport-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
}

.viewport-layer.active {
  display: flex;
}

/* Discreet Stage Hover HUD Caption */
.stage-hud-caption {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 20, 28, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-app);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-main);
  pointer-events: none;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.stage-hud-caption small {
  color: var(--accent-primary);
  font-size: 9px;
  letter-spacing: 0.8px;
  font-weight: 700;
  text-transform: uppercase;
}

/* Global Stage Frosted Drop Overlay */
.stage-drop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(14, 17, 23, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-overlay-box {
  border: 2px dashed var(--accent-primary);
  background: rgba(22, 25, 34, 0.85);
  border-radius: 16px;
  padding: 40px 60px;
  text-align: center;
}

.drop-overlay-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.drop-overlay-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 6px;
}

.drop-overlay-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* 2.4 Right Inspector Drawer (#inspector-panel / #inspector-popout) */
aside#inspector-panel.inspector-panel.inspector-popout {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-app);
  display: flex;
  flex-direction: column;
  z-index: 30;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.45);
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
}

aside#inspector-panel.inspector-panel.inspector-popout.open {
  transform: translateX(0);
}

aside#inspector-panel.inspector-panel.inspector-popout.collapsed {
  transform: translateX(100%);
  pointer-events: none;
}

.inspector-header-bar {
  height: 38px;
  border-bottom: 1px solid var(--border-app);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--bg-panel);
  flex-shrink: 0;
}

.inspector-header-eyebrow {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

.inspector-header-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   3. Bottom Status Bar (36px)
   ========================================================================== */
footer#studio-footer.status-dock {
  background: var(--bg-header);
  border-top: 1px solid var(--border-app);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 36px;
  font-size: 11px;
  color: var(--text-muted);
  user-select: none;
  z-index: 20;
}

.status-left, .status-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-center {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.status-separator {
  color: var(--text-dim);
  opacity: 0.5;
}

.status-indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}

.status-indicator-dot.saved { background: var(--success); }
.status-indicator-dot.saving { background: var(--warning); animation: pulse 1s infinite; }
.status-indicator-dot.unsaved { background: var(--warning); }
.status-indicator-dot.error { background: var(--danger); }

.status-link-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  text-decoration: none;
}

.status-link-btn:hover {
  color: var(--text-main);
  background: var(--bg-input);
}

/* Shortcuts Dialog */
.shortcuts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 20px;
}

.shortcut-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.shortcut-row kbd {
  background: var(--bg-input);
  border: 1px solid var(--border-app);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-primary);
  min-width: 56px;
  text-align: center;
}

@keyframes pulse {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}
