/* =========================================================
 * Home workspace layout
 * 左侧：sidebar(搜索 + 分类 + 工具列表)
 * 右侧：topbar + canvas(iframe 或 welcome)
 * ========================================================= */

html, body { height: 100%; }
body.workspace-body { overflow: hidden; }
body.workspace-body::before { display: none; } /* 复盖 themes.css 的背景光 */

.workspace {
  display: grid;
  grid-template-columns: var(--sidebar-w, 300px) 1fr;
  height: 100dvh;
  min-height: 0;
  background: var(--bg-page);
}

/* ---------- Sidebar ---------- */
.ws-sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-base);
}
.ws-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 700; color: var(--fg-strong); font-size: var(--text-md);
  letter-spacing: -0.01em;
}
.ws-brand .logo-mark {
  width: 28px; height: 28px;
  flex-shrink: 0;
}
.ws-brand .brand-meta { color: var(--fg-muted); font-weight: 500; font-size: var(--text-xs); }

.ws-search {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border-subtle);
}
.ws-search .search-shell { max-width: none; box-shadow: none; }

/* 垂直分类导航（替代原来的工具列表） */
.ws-nav {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  padding: 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--fg-base);
  cursor: pointer;
  text-decoration: none;
  background: none; border: 0; width: 100%;
  text-align: left;
  font-size: var(--text-sm); font-weight: 600;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.nav-item:hover { background: var(--bg-surface-2); }
.nav-item.is-active { background: var(--color-brand-soft); color: var(--color-brand); }
.nav-item .nav-icon {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--bg-surface-2);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-weight: 700; font-size: 14px;
  color: var(--fg-muted);
}
.nav-item.is-active .nav-icon { background: var(--color-brand); color: #fff; }
.nav-item .nav-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item .nav-count {
  font-weight: 500; font-size: var(--text-xs);
  color: var(--fg-subtle);
}
.nav-item.is-active .nav-count { color: var(--color-brand); opacity: .7; }

.ws-sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between;
  color: var(--fg-muted); font-size: var(--text-xs);
}
.ws-sidebar-footer .icon-btn {
  width: 28px; height: 28px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-muted);
}
.ws-sidebar-footer .icon-btn:hover { background: var(--bg-surface-2); color: var(--fg-strong); }

/* ---------- Main ---------- */
.ws-main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--bg-page);
}

.ws-topbar {
  height: 52px; flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-base);
  background: var(--bg-page);
}
.ws-topbar .ws-burger { display: none; }
.ws-crumb {
  display: flex; align-items: center; gap: 8px;
  min-width: 0; flex: 1;
}
.ws-crumb .crumb-cat {
  font-size: var(--text-xs); color: var(--fg-muted);
  padding: 2px 8px; border-radius: 999px; background: var(--bg-surface-2);
  flex-shrink: 0;
}
.ws-crumb .crumb-title {
  font-weight: 650; color: var(--fg-strong); font-size: var(--text-md);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ws-crumb .crumb-desc {
  color: var(--fg-muted); font-size: var(--text-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ws-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.ws-actions .icon-btn {
  width: 34px; height: 34px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-muted);
}
.ws-actions .icon-btn:hover { background: var(--bg-surface-2); color: var(--fg-strong); }
.ws-actions .icon-btn svg { width: 18px; height: 18px; }

.ws-hitokoto {
  font-size: var(--text-xs); color: var(--fg-muted);
  cursor: pointer; max-width: 220px; flex-shrink: 1;
}

.ws-canvas {
  flex: 1; position: relative;
  min-height: 0; overflow: hidden;
  background: var(--bg-page);
}
.ws-frame {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: 0;
  background: transparent;
  display: none;
}
.ws-frame.is-active { display: block; }
body:has(.dock) .ws-welcome { padding-bottom: 70px; }

/* ---------- 右侧工具浏览视图 ---------- */
/* 不设 padding：内部用 .container + .tool-layout，与工具页保持同一水平坐标 */
.ws-welcome {
  position: absolute; inset: 0;
  overflow: auto;
}
.ws-welcome.is-hidden { display: none; }

/* 分组之间的间距：由父容器网格 gap 提供，组内部不设 margin */
[data-welcome-groups] { display: grid; gap: var(--space-8); }
.welcome-group { scroll-margin-top: 16px; }
.welcome-group h3 {
  font-size: var(--text-lg);
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 var(--space-4);
}
.welcome-group h3::before {
  content: ""; width: 4px; height: 18px;
  background: var(--color-brand); border-radius: 2px;
}
.welcome-group h3 .group-count { color: var(--fg-muted); font-size: var(--text-sm); font-weight: 500; }

.welcome-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.welcome-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-base);
  background: var(--bg-surface);
  cursor: pointer;
  transition: transform var(--dur-base) var(--ease-emph),
              border-color var(--dur-base), box-shadow var(--dur-base);
  color: inherit; text-decoration: none;
  min-height: 104px;
}
.welcome-card:hover { transform: translateY(-2px); border-color: var(--color-brand); box-shadow: var(--shadow-md); }
.welcome-card.is-planned { opacity: .5; cursor: not-allowed; }
.welcome-card.is-planned:hover { transform: none; border-color: var(--border-base); box-shadow: none; }
.welcome-card.is-dragging { opacity: .4; border-color: var(--color-brand); box-shadow: 0 0 0 2px var(--color-brand-ring); }
[data-performance="low"] .welcome-card:hover { transform: none; }
.welcome-card .wc-head { display: flex; align-items: center; gap: 10px; }
.welcome-card .wc-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--color-brand-soft); color: var(--color-brand);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  flex-shrink: 0;
}
.welcome-card h4 { margin: 0; font-size: var(--text-md); color: var(--fg-strong); }
.welcome-card p {
  margin: 0; color: var(--fg-muted); font-size: var(--text-sm);
  line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.welcome-card .wc-tag {
  margin-top: auto;
  align-self: flex-start;
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--bg-surface-2); color: var(--fg-subtle);
  border: 1px solid var(--border-subtle);
}

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .ws-sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: min(86vw, 320px);
    z-index: 500;
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease-standard);
    box-shadow: var(--shadow-lg);
  }
  body.ws-sidebar-open .ws-sidebar { transform: translateX(0); }
  body.ws-sidebar-open::after {
    content: "";
    position: fixed; inset: 0; z-index: 450;
    background: hsl(230 30% 10% / 0.4);
  }
  .ws-topbar .ws-burger {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 8px;
    color: var(--fg-base);
  }
  .ws-topbar .ws-burger:hover { background: var(--bg-surface-2); }
  .ws-hitokoto { display: none; }
}
