/* =========================================================
 * 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: 42px; height: 42px;
  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: 380px; 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);
}

/* ---------- 最近使用 / 搜索结果 下拉面板（两入口共用样式） ---------- */
.ws-search { position: relative; }
.recent-menu { position: relative; display: inline-flex; }

.recent-panel {
  position: absolute;
  z-index: var(--z-dropdown);
  display: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.recent-panel.is-open {
  display: block;
  animation: recent-pop var(--dur-base) var(--ease-standard);
}
@keyframes recent-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.recent-panel--header {
  top: calc(100% + 8px);
  right: 0;
  width: 300px;
  max-width: calc(100vw - 24px);
}
.recent-panel--sidebar {
  top: 100%;
  left: 12px;
  right: 12px;
}

.recent-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.recent-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: 0; border-radius: var(--radius-md);
  background: none;
  text-align: left;
  cursor: pointer;
  color: inherit;
  transition: background var(--dur-fast);
}
.recent-item:hover { background: var(--bg-surface-2); }
.recent-item .ri-icon {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--color-brand-soft); color: var(--color-brand);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
}
.recent-item .ri-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 1px;
}
.recent-item .ri-title {
  font-size: var(--text-sm); font-weight: 600; color: var(--fg-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.recent-item .ri-desc {
  font-size: var(--text-xs); color: var(--fg-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.recent-item .ri-cat {
  flex-shrink: 0;
  font-size: var(--text-xs); color: var(--fg-subtle);
  padding: 2px 8px; border-radius: var(--radius-pill);
  background: var(--bg-surface-2);
}
.recent-empty {
  padding: 24px 16px;
  text-align: center;
  font-size: var(--text-sm);
  color: var(--fg-muted);
}
.recent-footer { border-top: 1px solid var(--border-subtle); }
.recent-clear-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%;
  padding: 9px 12px;
  border: 0; background: none;
  font-size: var(--text-xs); color: var(--fg-muted);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.recent-clear-btn:hover { background: var(--bg-surface-2); color: var(--color-danger, #ef4444); }

/* 顶栏「最近使用」按钮打开态 */
.ws-actions .recent-menu .icon-btn.is-active {
  background: var(--color-brand-soft);
  color: var(--color-brand);
}

/* ---------- 侧边栏底部：友链浮层 ---------- */
.ws-footer-actions { display: flex; align-items: center; gap: 4px; }
.friend-menu { position: relative; display: inline-flex; }
.friend-panel {
  position: fixed;
  width: 240px;
  max-width: calc(100vw - 24px);
  z-index: var(--z-dropdown);
  display: none;
  padding: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.friend-menu.is-open .friend-panel {
  display: block;
  animation: friend-pop var(--dur-base) var(--ease-standard);
}
@keyframes friend-pop {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
.friend-panel-title {
  padding: 6px 8px;
  font-size: var(--text-xs); font-weight: 600;
  color: var(--fg-subtle);
}
.friend-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius-md);
  color: inherit; text-decoration: none;
  transition: background var(--dur-fast);
}
.friend-item:hover { background: var(--bg-surface-2); }
.friend-item .fi-icon {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--color-brand-soft); color: var(--color-brand);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
}
.friend-item .fi-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 1px;
}
.friend-item .fi-title {
  font-size: var(--text-sm); font-weight: 600; color: var(--fg-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.friend-item .fi-url {
  font-size: var(--text-xs); color: var(--fg-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.friend-item .fi-ext {
  width: 14px; height: 14px; flex-shrink: 0;
  color: var(--fg-subtle);
}
.friend-item:hover .fi-ext { color: var(--color-brand); }
.ws-sidebar-footer .friend-menu .icon-btn.is-active {
  background: var(--color-brand-soft);
  color: var(--color-brand);
}

/* ---------- 侧边栏底部：设置浮层 ---------- */
.settings-menu { position: relative; display: inline-flex; }
.settings-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  width: 240px;
  max-width: calc(100vw - 24px);
  z-index: var(--z-dropdown);
  display: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.settings-menu.is-open .settings-panel {
  display: block;
  animation: friend-pop var(--dur-base) var(--ease-standard);
}
.settings-header {
  padding: 8px 12px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--fg-subtle);
  border-bottom: 1px solid var(--border-subtle);
}
.settings-body { padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.setting-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  border-radius: var(--radius-md);
}
.setting-row:hover { background: var(--bg-surface-2); }
.setting-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.setting-label { font-size: var(--text-sm); font-weight: 600; color: var(--fg-strong); }
.setting-desc { font-size: var(--text-xs); color: var(--fg-muted); }
.setting-row .switch { flex-shrink: 0; cursor: pointer; outline: none; }
.setting-row .switch:focus-visible { box-shadow: 0 0 0 2px var(--color-brand-soft); border-radius: 999px; }
.setting-row .setting-select {
  width: auto; min-width: 96px; flex-shrink: 0;
  padding: 6px 10px; font-size: var(--text-sm);
  border-radius: var(--radius-md); background: var(--bg-surface-2);
  border: 1px solid var(--border-base); color: var(--fg-strong); cursor: pointer;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.setting-row .setting-select:hover { border-color: var(--border-strong); }
.setting-row .setting-select:focus { border-color: var(--color-brand); box-shadow: var(--shadow-focus); outline: none; }
.ws-sidebar-footer .settings-menu .icon-btn.is-active {
  background: var(--color-brand-soft);
  color: var(--color-brand);
}

/* Dock 被设置隐藏 */
.dock.is-disabled { display: none !important; }

/* ---------- 响应式 ---------- */
@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; }
}
