/* Investment OS — Layout：侧栏 / 顶栏 / 移动端底栏 / 响应式体系
   合并原 menu.css + responsive.css；断点纪律：仅 768px / 480px。 */

/* ═══════════════ App Shell ═══════════════ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  width: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }

.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed ~ .main-wrapper { margin-left: var(--sidebar-collapsed); }

body.sidebar-hidden .sidebar { width: 0; border-right-width: 0; }
body.sidebar-hidden .main-wrapper { margin-left: 0; }
body.sidebar-hidden .topbar { display: flex; }

/* ═══════════════ 侧栏头部 ═══════════════ */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 16.5px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  min-width: 0;
}

.sidebar-logo-icon { width: 28px; height: 28px; flex-shrink: 0; }
.sidebar-logo-text { transition: opacity 0.2s ease; }
.sidebar.collapsed .sidebar-logo-text { opacity: 0; width: 0; }

.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0; /* 覆盖全局 button padding:0 16px，避免图标被压缩 */
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s, transform 0.25s;
  flex-shrink: 0;
}

.sidebar-collapse-btn:hover { background: var(--accent-soft); color: var(--accent); }
.sidebar.collapsed .sidebar-collapse-btn { transform: rotate(180deg); }

/* ═══════════════ 侧栏导航 ═══════════════ */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 8px;
}

.sidebar-group { margin-bottom: 8px; }

.sidebar-group-label {
  display: block;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .sidebar-group-label { text-align: center; padding: 4px 0; font-size: 0; }
.sidebar.collapsed .sidebar-group-label::after { content: "···"; font-size: 10px; }

.sidebar-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 2px 0;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-nav-item:hover { background: var(--bg-surface-muted); color: var(--text); text-decoration: none; }

.sidebar-nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.sidebar-nav-icon { display: flex; align-items: center; justify-content: center; width: 20px; height: 20px; flex-shrink: 0; }
.sidebar-nav-icon svg { width: 20px; height: 20px; }
.sidebar-nav-label { transition: opacity 0.2s ease; }
.sidebar.collapsed .sidebar-nav-label { opacity: 0; width: 0; }

/* ═══════════════ 侧栏底部 ═══════════════ */
.sidebar-footer { padding: 12px 8px; border-top: 1px solid var(--border); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-md);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-info { display: flex; flex-direction: column; transition: opacity 0.2s ease; }
.sidebar.collapsed .sidebar-user-info { opacity: 0; width: 0; }
.sidebar-user-name { font-size: var(--text-sm); font-weight: 600; color: var(--text); line-height: 1.3; }
.sidebar-user-role { font-size: 11px; color: var(--text-muted); line-height: 1.3; }

.sidebar-logout button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-sm);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-logout button:hover { background: var(--danger-soft); color: var(--danger); }
.sidebar-logout span { transition: opacity 0.2s ease; }
.sidebar.collapsed .sidebar-logout span { opacity: 0; width: 0; }

/* ── 侧栏主题切换（PC 端常驻入口；顶栏按钮仅在移动端/侧栏隐藏时可见） ── */
.sidebar-theme-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-sm);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-theme-btn:hover { background: var(--accent-soft); color: var(--accent); }
.sidebar-theme-btn span { transition: opacity 0.2s ease; }
.sidebar.collapsed .sidebar-theme-btn span { opacity: 0; width: 0; }

.sidebar-theme-btn .icon-moon { display: none; }
:root[data-theme="dark"] .sidebar-theme-btn .icon-sun { display: none; }
:root[data-theme="dark"] .sidebar-theme-btn .icon-moon { display: block; }

/* ═══════════════ 顶栏（移动端 / 侧栏隐藏时） ═══════════════ */
.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  position: sticky;
  top: 0;
  z-index: 90;
}

.topbar-hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0; /* 覆盖全局 button padding:0 16px，避免图标被压缩 */
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.topbar-hamburger:hover { background: var(--bg-surface-muted); }
.topbar-title { font-size: var(--text-lg); font-weight: 700; color: var(--text); margin: 0; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.topbar-theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0; /* 覆盖全局 button padding:0 16px，避免图标被压缩成 0 宽 */
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.topbar-theme-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.topbar-theme-btn .icon-moon { display: none; }
:root[data-theme="dark"] .topbar-theme-btn .icon-sun { display: none; }
:root[data-theme="dark"] .topbar-theme-btn .icon-moon { display: block; }

/* 顶栏退出登录（与主题切换按钮风格一致，侧栏隐藏时仍可用） */
.topbar-logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0; /* 覆盖全局 button padding:0 16px，避免图标被压缩成 0 宽 */
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.topbar-logout-btn:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

/* ═══════════════ 页面内容区 ═══════════════ */
.page-content {
  flex: 1;
  padding: 24px;
  max-width: 100%;
  width: 100%;
  margin: 0 auto;
}

/* ═══════════════ 移动端底部标签栏 ═══════════════ */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-tabbar);
  display: none; /* 桌面隐藏，<768px 显示 */
  height: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}

.tabbar-item {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--tabbar-height);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  transition: color 0.15s;
}

.tabbar-item:hover { color: var(--text); text-decoration: none; }

.tabbar-item.active { color: var(--accent); }

.tabbar-item.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 2.5px;
  background: var(--accent);
  border-radius: 0 0 3px 3px;
}

.tabbar-icon { display: flex; align-items: center; justify-content: center; }
.tabbar-icon svg { width: 22px; height: 22px; }
.tabbar-label { line-height: 1; }

/* "更多"按钮：与 tabbar-item 视觉一致，但为 button 元素 */
.tabbar-more-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.tabbar-more-btn:active { color: var(--accent); }

/* ═══════════════ 侧栏抽屉遮罩（移动端） ═══════════════ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-overlay.active { opacity: 1; }

/* ═══════════════ 响应式工具类（mobile-first） ═══════════════ */
.grid-responsive {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-4);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-responsive > table { min-width: min(560px, 100%); }

.stack-mobile { display: flex; flex-direction: column; gap: var(--space-3); }

.bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) 0;
}
.bar > * { min-width: 0; }

/* ═══════════════ 移动端（≤768px） ═══════════════ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 240px !important;
    z-index: 200;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .main-wrapper { margin-left: 0 !important; }
  .topbar { display: flex; }
  .sidebar-collapse-btn { display: none; }

  .tabbar { display: flex; }

  .page-content {
    padding: var(--space-4);
    padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + var(--space-4));
  }

  .bar { flex-wrap: wrap; gap: var(--space-2); align-items: center; }
  .bar .header-actions { margin-left: auto; }

  .btn-row, .toolbar-actions, .actions { flex-wrap: wrap; gap: var(--space-2); }

  .grid-responsive { grid-template-columns: 1fr; }

  .modal-dialog, .dialog, .modal {
    width: calc(100vw - 32px);
    max-width: 100%;
    margin: 16px auto;
  }
}

/* ═══════════════ 超小屏（≤480px） ═══════════════ */
@media (max-width: 480px) {
  .page-content { padding: var(--space-3); padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + var(--space-3)); }
  .topbar-title { font-size: var(--text-base); }
}
