/* ==========================================================================
   侧边栏 + 顶栏 v1 (2026-08-13 M7 阶段 1 重构)
   老板审美:Linear / Notion SaaS 紧凑
   蓝主色 #3b82f6 + dark mode + WCAG AA + 16-24px 间距 + 8-12px 圆角
   ========================================================================== */

/* === 整体布局 === */
.app-layout {
  display: block;          /* sidebar 已 fixed 脱离 flow,block 避免 .app-main 被双重压缩 */
  min-height: 100vh;
  background: var(--color-bg);
}

/* === 侧边栏 === */
.app-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-bg-elevated);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 200;
  overflow-y: auto;
}

.app-sidebar-brand {
  height: 64px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.app-sidebar-logo {
  width: 32px;
  height: 32px;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  flex-shrink: 0;
}

.app-sidebar-title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.app-sidebar-title-main {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar-title-sub {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.app-sidebar-section {
  margin-top: 16px;
}
.app-sidebar-section:first-child {
  margin-top: 0;
}

.app-sidebar-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 12px;
  margin-bottom: 6px;
}

.app-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  position: relative;
  transition: all 0.15s ease-out;
}

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

.app-nav-item.active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.app-nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--color-primary);
  border-radius: 0 2px 2px 0;
}

.app-nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}

.app-nav-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-nav-badge {
  font-size: 0.6875rem;
  background: var(--color-bg-hover);
  color: var(--color-text-muted);
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 500;
}

.app-nav-item.active .app-nav-badge {
  background: var(--color-primary);
  color: #fff;
}

.app-sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.app-sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}
.app-sidebar-user:hover {
  background: var(--color-bg-hover);
}

.app-sidebar-avatar {
  width: 32px;
  height: 32px;
  background: var(--color-primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8125rem;
  flex-shrink: 0;
}

.app-sidebar-userinfo {
  flex: 1;
  min-width: 0;
}

.app-sidebar-username {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar-userrole {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
}

/* === 主内容区 === */
.app-main {
  flex: 1;
  margin-left: 240px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  height: 64px;
  background: var(--color-bg-elevated);
  border-bottom: 1px solid var(--color-border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-topbar-title {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.app-topbar-title h1 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-topbar-title-sub {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.app-topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-topbar-search {
  position: relative;
  width: 280px;
}

.app-topbar-search input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 36px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 0.8125rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.app-topbar-search input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.app-topbar-search::before {
  content: "🔍";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.875rem;
  pointer-events: none;
  opacity: 0.6;
}

.app-icon-btn {
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  position: relative;
  transition: all 0.15s;
}
.app-icon-btn:hover {
  background: var(--color-bg-hover);
}
.app-icon-btn .badge-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--color-danger);
  border-radius: 50%;
  border: 2px solid var(--color-bg-elevated);
}

/* === 主体内容容器 === */
.app-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.app-page-header {
  margin-bottom: 20px;
}

.app-page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 4px 0;
}

.app-page-subtitle {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin: 0;
}

/* === Stat-Tile (KPI 卡片) === */
.stat-tile {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: border-color 0.2s, transform 0.2s;
}
.stat-tile:hover {
  border-color: var(--color-border-strong);
}
.stat-tile-label {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-bottom: 8px;
  font-weight: 500;
}
.stat-tile-value {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.stat-tile-trend {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.stat-tile-trend-up { color: var(--color-success); }
.stat-tile-trend-down { color: var(--color-danger); }

.stat-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

/* === Card (现代化卡片) === */
.card-modern {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: border-color 0.2s;
}
.card-modern:hover {
  border-color: var(--color-border-strong);
}

.card-modern-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.card-modern-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-modern-title-icon {
  font-size: 1rem;
  opacity: 0.7;
}
.card-modern-body {
  color: var(--color-text);
}

/* === Grid 布局 === */
.grid-2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.grid-2-equal {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 1024px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .grid-2-equal {
    grid-template-columns: 1fr;
  }
}

/* === 状态徽章 === */
.status-modern {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.4;
}
.status-modern-todo { background: rgba(107, 114, 128, 0.15); color: #9ca3af; }
.status-modern-in_progress { background: rgba(59, 130, 246, 0.15); color: var(--color-primary); }
.status-modern-review { background: rgba(245, 158, 11, 0.15); color: var(--color-warning); }
.status-modern-done { background: rgba(16, 185, 129, 0.15); color: var(--color-success); }
.status-modern-cancelled { background: rgba(107, 114, 128, 0.15); color: #6b7280; }

/* === Table (现代化表格) === */
.table-modern {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}
.table-modern thead th {
  text-align: left;
  padding: 10px 12px;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-border);
  background: transparent;
}
.table-modern tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
}
.table-modern tbody tr {
  transition: background 0.15s;
}
.table-modern tbody tr:hover {
  background: var(--color-bg-hover);
}
.table-modern tbody tr:last-child td {
  border-bottom: none;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--color-text-muted);
}
.empty-state-icon {
  font-size: 2.5rem;
  opacity: 0.4;
  margin-bottom: 12px;
}
.empty-state-title {
  font-size: 0.9375rem;
  color: var(--color-text);
  font-weight: 500;
  margin-bottom: 4px;
}
.empty-state-desc {
  font-size: 0.8125rem;
}

/* === Loading === */
.loading-skeleton {
  background: linear-gradient(90deg, var(--color-bg-card) 25%, var(--color-bg-hover) 50%, var(--color-bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  gap: 8px;
}

/* 加载完成后切换为正常 block,避免 flex 把内部 grid 容器压缩 */
.loading-state.is-loaded {
  display: block;
  padding: 0;
  text-align: left;
}

/* === Pending review 列表 === */
.pending-list {
  display: flex;
  flex-direction: column;
}
.pending-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
  gap: 12px;
}
.pending-item:last-child {
  border-bottom: none;
}
.pending-item-info {
  flex: 1;
  min-width: 0;
}
.pending-item-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pending-item-meta {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.pending-item-action {
  flex-shrink: 0;
}

/* === Chart bars (Linear 风格) === */
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 120px;
  padding: 4px 0;
}
.chart-bar {
  flex: 1;
  background: var(--color-primary);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  position: relative;
  transition: background 0.2s, transform 0.2s;
  cursor: pointer;
}
.chart-bar:hover {
  background: var(--color-primary-hover);
  transform: translateY(-2px);
}
.chart-bar[data-zero="true"] {
  background: var(--color-border);
}
.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  color: var(--color-text-muted);
  font-size: 0.6875rem;
}
.chart-axis span {
  flex: 1;
  text-align: center;
}

/* === 月度账单 === */
.billing-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

/* === 工具类 === */
.flex-row { display: flex; align-items: center; }
.flex-col { display: flex; flex-direction: column; }
.flex-1 { flex: 1; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.gap-lg { gap: 24px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb-md { margin-bottom: 16px; }
.text-muted { color: var(--color-text-muted); }
.text-primary { color: var(--color-primary); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.text-sm { font-size: 0.8125rem; }
.text-xs { font-size: 0.75rem; }
.font-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* === 移动端响应式 === */
@media (max-width: 768px) {
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease-out;
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
  }
  .app-topbar-search {
    display: none;
  }
  .app-content {
    padding: 16px;
  }
}

/* 滚动条美化(webkit) */
.app-sidebar::-webkit-scrollbar,
.app-content::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.app-sidebar::-webkit-scrollbar-thumb,
.app-content::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border-radius: 4px;
}
.app-sidebar::-webkit-scrollbar-track,
.app-content::-webkit-scrollbar-track {
  background: transparent;
}

/* ==========================================================================
   Tab 切换 (Linear / Notion 紧凑风, 蓝下划线)
   2026-08-13 从 creative.css 提取到公共
   ========================================================================== */

.tab-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-md);
  overflow-x: auto;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  position: relative;
  bottom: -1px;
  font-family: inherit;
}

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

.tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.tab-btn-icon {
  font-size: 0.9375rem;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 0.25s ease;
}
