/* ========================================================
   Layout — app shell, main area, topbar, file bar.
   Updated for new multi-panel workspace layout.
   ======================================================== */

/* App shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--c-bg-primary);
}

/* Horizontal row that holds sidebar + workspace */
.app-shell-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Main area (legacy, used by existing components) */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Sidebar V2 */
.sidebar-v2 {
  width: var(--sidebar-w, 260px);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--c-bg-surface);
  border-right: 1px solid var(--c-border);
  transition: width 0.2s ease;
  overflow: hidden;
  position: relative; z-index: 10;
}
.sidebar-v2.collapsed { width: 52px; }

.sb2-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  flex-shrink: 0;
}
.sidebar-v2.collapsed .sb2-header { padding: 12px 8px; justify-content: center; }
.sb2-logo { font-size: 15px; font-weight: 700; color: var(--c-text-primary); white-space: nowrap; }
.sidebar-v2.collapsed .sb2-logo { display: none; }
.sb2-toggle {
  width: 24px; height: 24px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--c-text-tertiary);
  background: transparent; border: none; cursor: pointer;
}
.sb2-toggle:hover { background: var(--c-bg-hover); }

.sb2-launchers {
  display: flex; flex-direction: column;
  padding: 0 8px; gap: 2px; flex-shrink: 0;
}
.sb2-launch {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  color: var(--c-text-secondary);
  background: transparent; border: none; cursor: pointer;
  transition: all 0.12s;
  text-align: left;
  position: relative;
}
.sb2-launch:hover { background: var(--c-bg-hover); color: var(--c-text-primary); }
.sb2-launch.active { background: var(--c-bg-hover); color: var(--c-accent); }
.sidebar-v2.collapsed .sb2-launch { justify-content: center; padding: 10px 8px; }
.sidebar-v2.collapsed .sb2-launch-label { display: none; }
.sb2-launch-icon { font-size: 17px; width: 24px; text-align: center; flex-shrink: 0; }

/* Sub-menu */
.sb2-menu-group { display: flex; flex-direction: column; }
.sb2-menu-parent { position: relative; }
.sb2-menu-arrow {
  font-size: 10px; margin-left: auto; transition: transform 0.15s;
  color: var(--c-text-tertiary);
}
.sb2-menu-arrow.open { transform: rotate(-180deg); }
.sb2-menu-children { display: flex; flex-direction: column; margin-left: 8px; }
.sb2-launch-child { padding-left: 32px !important; font-size: 11px; }
.sb2-launch-child .sb2-launch-icon { font-size: 13px; }

.sb2-badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px; border-radius: 8px;
  background: var(--c-rose); color: #fff;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

.sb2-divider { height: 1px; background: var(--c-border); margin: 8px 12px; flex-shrink: 0; }
.sidebar-v2.collapsed .sb2-divider { margin: 8px 6px; }

.sb2-section { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.sb2-section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 14px 8px; flex-shrink: 0;
}
.sb2-section-title { font-size: 11px; font-weight: 600; color: var(--c-text-tertiary); text-transform: uppercase; letter-spacing: 0.5px; }
.sb2-add { width: 22px; height: 22px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 16px; color: var(--c-text-tertiary); background: transparent; border: none; cursor: pointer; }
.sb2-add:hover { background: var(--c-bg-hover); color: var(--c-text-primary); }

.sb2-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.sb2-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  transition: all 0.1s; margin-bottom: 2px;
}
.sb2-item:hover { background: var(--c-bg-hover); }
.sb2-item.active { background: var(--c-bg-hover); border: 1px solid var(--c-border-light); }
.sb2-item-icon { font-size: 14px; flex-shrink: 0; }
.sb2-item-body { flex: 1; min-width: 0; }
.sb2-item-title { font-size: 13px; color: var(--c-text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; }
.sb2-item-input { font-size: 13px; color: var(--c-text-primary); background: var(--c-bg-deep); border: 1px solid var(--c-accent); border-radius: 4px; padding: 2px 6px; width: 100%; box-sizing: border-box; outline: none; font-family: inherit; }
.sb2-item-meta { font-size: 11px; color: var(--c-text-tertiary); margin-top: 1px; }
.sb2-item-del { width: 20px; height: 20px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 14px; color: var(--c-text-tertiary); background: transparent; border: none; cursor: pointer; opacity: 0; }
.sb2-item-rename { width: 20px; height: 20px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--c-text-tertiary); background: transparent; border: none; cursor: pointer; opacity: 0; }
.sb2-item:hover .sb2-item-del, .sb2-item:hover .sb2-item-rename { opacity: 1; }
.sb2-item-del:hover { background: rgba(244,63,94,0.15); color: var(--c-rose); }

.sb2-empty { padding: 24px 0; text-align: center; font-size: 12px; color: var(--c-text-tertiary); }
.sb2-actions { padding: 12px 8px; flex-shrink: 0; display: flex; justify-content: center; }
.sb2-action { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 18px; color: var(--c-accent); background: transparent; border: 1px solid var(--c-border); cursor: pointer; }
.sb2-action:hover { background: var(--c-bg-hover); }

/* Chat panel wrapper */
.chat-panel-wrapper {
  display: flex; flex-direction: column;
  height: 100%; overflow: hidden;
}
.chat-panel-wrapper .messages { flex: 1; min-height: 0; }

/* Topbar */
.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 var(--spacing-2xl);
  gap: var(--spacing-md);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}

.topbar-menu-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--c-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
  margin-right: 2px;
}

.topbar-menu-btn:hover {
  background: var(--c-surface-hover);
  color: var(--c-text);
}

.topbar-menu-btn .menu-icon {
  font-size: 16px;
  line-height: 1;
}

.topbar .phase-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.topbar .phase-dot.idle { background: var(--c-success); }
.topbar .phase-dot.busy { background: var(--c-warning); animation: pulse 1s infinite; }
.topbar .phase-dot.error { background: var(--c-error); }

.topbar .title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--c-text);
}

.topbar .stats {
  margin-left: auto;
  font-size: var(--font-size-sm);
  color: var(--c-text-secondary);
}

/* File bar */
.file-bar {
  flex-shrink: 0;
  background: var(--c-info-light);
  border-bottom: 1px solid var(--c-info-border);
  padding: var(--spacing-sm) var(--spacing-2xl);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--font-size-sm);
  color: #3b5998;
  overflow-x: auto;
  white-space: nowrap;
}

.file-bar:empty { display: none; }

.file-bar .file-label {
  font-weight: 600;
  flex-shrink: 0;
}

.file-bar .file-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--c-surface);
  border: 1px solid var(--c-info-border);
  border-radius: var(--radius-sm);
  padding: var(--spacing-xs) 10px;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: var(--font-size-sm);
  flex-shrink: 0;
}

.file-bar .file-item:hover {
  background: var(--c-accent-light);
  border-color: var(--c-accent);
}

.file-bar .file-item .file-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-bar .file-item .file-size {
  color: var(--c-text-tertiary);
  font-size: var(--font-size-xs);
}

.file-bar .file-item .dl-icon { opacity: 0.5; }

.file-preview-btn {
  flex-shrink: 0;
  background: var(--c-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: var(--spacing-xs) 10px;
  cursor: pointer;
  font-size: var(--font-size-sm);
  line-height: 1;
}
.file-preview-btn:hover { opacity: 0.85; }

.html-preview-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.html-preview-box {
  width: 100%; height: 100%;
  max-width: 1280px; max-height: 820px;
  background: #fff; border-radius: 12px; overflow: hidden;
  display: flex; flex-direction: column;
}
.html-preview-head {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--c-border);
  background: var(--c-bg-deep, #f8fafc);
}
.html-preview-title { font-size: 14px; font-weight: 600; }
.html-preview-close {
  background: none; border: none; cursor: pointer;
  font-size: 16px; color: var(--c-text-secondary, #64748b); line-height: 1;
}
.html-preview-close:hover { color: var(--c-rose, #f43f5e); }
.html-preview-iframe { flex: 1; width: 100%; border: none; }

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-md);
  color: var(--c-text-secondary);
}

.empty-state .logo {
  font-size: 48px;
  opacity: 0.3;
}

.empty-state .title {
  font-size: var(--font-size-2xl);
  font-weight: 600;
  color: var(--c-text);
}

.empty-state .hint {
  font-size: var(--font-size-base);
  max-width: 360px;
  text-align: center;
  line-height: 1.6;
}
