/* ============================================================
   应用层布局 — 建立在 colors_and_type.css 之上
   只消费框架令牌，不新造颜色；不依赖 Tailwind CDN（离线可用）
   结构对齐 pages/admin-dashboard.html：sidebar + topbar + page
   ============================================================ */

body { min-height: 100vh; }

/* ---------- 外壳 ---------- */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  width: 240px;
  flex-shrink: 0;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 56px;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.logo-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-lg);
  background-color: var(--color-primary-600);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--text-sm);
  font-weight: 600;
}

.logo-text { font-size: var(--text-base); font-weight: 600; color: var(--text-primary); white-space: nowrap; }

.sidebar-nav {
  flex: 1;
  padding: var(--space-3);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.nav-section + .nav-section, .sidebar-nav-item + .nav-section { margin-top: var(--space-4); }

.sidebar-nav-item .nav-dot {
  width: 16px; height: 16px; flex-shrink: 0;
  border-radius: var(--radius-sm);
  background-color: currentColor;
  opacity: .28;
}
.sidebar-nav-item.active .nav-dot { opacity: .85; }

.sidebar-user {
  padding: var(--space-3);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.user-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2);
}
.avatar {
  width: 36px; height: 36px; flex-shrink: 0;
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); font-weight: 500;
  background-color: var(--color-primary-100);
  color: var(--color-primary-700);
}
.user-meta { min-width: 0; line-height: 1.35; }
.user-meta b { display: block; font-size: var(--text-sm); font-weight: 500; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta span { font-size: var(--text-xs); color: var(--text-tertiary); }
.sidebar-user .signout {
  display: block; margin-top: var(--space-2);
  padding: 0 var(--space-2);
  font-size: var(--text-xs); color: var(--text-link);
}
.sidebar-user .signout:hover { text-decoration: underline; }

/* ---------- 工作区 ---------- */
.workspace {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
  height: 56px; flex-shrink: 0;
  padding: 0 var(--space-6);
  background-color: var(--bg-topbar);
  border-bottom: 1px solid var(--border-subtle);
}
.breadcrumb {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-sm); color: var(--text-tertiary);
}
.breadcrumb .current { color: var(--text-primary); font-weight: 500; }
.breadcrumb .sep { color: var(--text-tertiary); }
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); }
.divider-v { width: 1px; height: 20px; background-color: var(--border-subtle); margin: 0 var(--space-1); }

.page {
  flex: 1; overflow-y: auto;
  padding: var(--space-6);
  background-color: var(--bg-body);
}
.page-inner { max-width: 1440px; margin: 0 auto; }

.page-head { margin-bottom: var(--space-6); }
.page-title { font-size: var(--text-xl); font-weight: 600; line-height: var(--leading-tight); color: var(--text-primary); margin-bottom: var(--space-1); }
.page-desc { font-size: var(--text-sm); color: var(--text-secondary); }

/* ---------- KPI 卡片（对齐参考：3px 左边 + p-5）---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.kpi {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border-left: 3px solid var(--color-primary-600);
  padding: var(--space-5);
  overflow: hidden;
}
.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); }
.kpi-label { font-size: var(--text-sm); color: var(--text-secondary); }
.kpi-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background-color: var(--color-primary-50);
  color: var(--color-primary-600);
  font-size: var(--text-xs); font-weight: 600;
}
.kpi-value { font-size: var(--text-2xl); font-weight: 600; line-height: 1.2; color: var(--text-primary); white-space: nowrap; }
.kpi-foot { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--text-tertiary); }

/* ---------- 卡片标题/正文（补足框架未含的间距）---------- */
.card { margin-bottom: var(--space-4); }
.card:last-child { margin-bottom: 0; }
.card-title { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); }
.card-header .link { font-size: var(--text-xs); color: var(--text-link); }
.card-header .link:hover { text-decoration: underline; }

/* ---------- 表格容器 ---------- */
.table-wrap { overflow-x: auto; }
.table th { white-space: nowrap; }
.table td.nowrap { white-space: nowrap; }

/* ---------- 表单 ---------- */
.form-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.form-row > .input { width: auto; flex: 1 1 180px; min-width: 0; }
.form-grid { display: grid; gap: var(--space-3); }
.form-label { display: block; margin-bottom: var(--space-1); font-size: var(--text-sm); font-weight: 500; color: var(--text-secondary); }
select.input { appearance: none; -webkit-appearance: none; padding-right: var(--space-8); background-image: none; }
button.input { cursor: pointer; }
textarea.input { min-height: 96px; resize: vertical; }

/* ---------- 提示条（复用框架状态色）---------- */
.notice {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  border: 1px solid transparent;
  white-space: pre-wrap;
  margin-bottom: var(--space-4);
  line-height: var(--leading-relaxed);
}
.notice-error { background-color: var(--state-error-bg); border-color: #fecaca; color: #b91c1c; }
.notice-success { background-color: var(--state-success-bg); border-color: #a7f3d0; color: #047857; }
.notice:empty { display: none; }

/* ---------- 代码块 ---------- */
.code {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-relaxed);
  background-color: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow: auto;
  max-height: 360px;
  color: var(--text-secondary);
  white-space: pre;
}
.mono { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-secondary); }

/* ---------- 徽章补充：状态点 ---------- */
.badge::before {
  content: "";
  width: 5px; height: 5px; border-radius: 50%;
  background-color: currentColor;
  margin-right: 4px;
  flex-shrink: 0;
}

/* ---------- 登录页 ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-6);
  background-color: var(--bg-body);
}
.auth-card { width: 100%; max-width: 460px; }
.auth-brand {
  display: flex; align-items: center; gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.auth-brand-name { font-size: var(--text-base); font-weight: 600; color: var(--text-primary); }
.auth-title { font-size: var(--text-xl); font-weight: 600; color: var(--text-primary); margin-bottom: var(--space-1); }
.auth-sub { font-size: var(--text-sm); color: var(--text-secondary); margin-bottom: var(--space-5); }
.auth-hint { margin-top: var(--space-4); text-align: center; font-size: var(--text-xs); color: var(--text-tertiary); }
.card-section { padding: var(--space-4) var(--space-5); }
.card-section + .card-section { border-top: 1px solid var(--border-subtle); }
.section-title { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); margin-bottom: var(--space-1); }
.section-desc { font-size: var(--text-xs); color: var(--text-secondary); margin-bottom: var(--space-3); line-height: var(--leading-relaxed); }

.btn-icon { padding: 0.375rem; line-height: 1; }

footer.app-footer {
  padding: var(--space-6);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; height: auto; min-height: 100vh; overflow: visible; }
  .sidebar {
    width: 100%;
    flex-direction: row; align-items: center; gap: var(--space-2);
    border-right: none; border-bottom: 1px solid var(--border-subtle);
    overflow-x: auto; padding: 0 var(--space-3);
  }
  .sidebar-logo { height: 48px; padding: 0; border-bottom: none; flex-shrink: 0; }
  .logo-text { display: none; }
  .sidebar-nav { flex-direction: row; flex: 0 0 auto; padding: var(--space-1); gap: var(--space-1); }
  .nav-section { display: none; }
  .sidebar-nav-item { white-space: nowrap; padding: var(--space-2); }
  .sidebar-user { border-top: none; margin-left: auto; padding: 0; }
  .sidebar-user .user-meta, .sidebar-user .signout { display: none; }
  .workspace { overflow: visible; }
  .page { padding: var(--space-4); overflow: visible; }
  .topbar { padding: 0 var(--space-4); }
}
/* ---------- 兼容层：页面内联脚本仍会输出少量旧类名 ---------- */
/* 统一映射到框架的 badge / btn / 文本语义，不新造颜色 */
.sub { font-size: var(--text-sm); color: var(--text-secondary); }

.tag {
  display: inline-flex; align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: var(--text-xs); font-weight: 500; line-height: 1.5;
  border-radius: var(--radius-full); border: 1px solid transparent;
}
.t-ok   { background-color: var(--state-success-bg); color: #047857; border-color: #a7f3d0; }
.t-warn { background-color: var(--state-warning-bg); color: #b45309; border-color: #fde68a; }
.t-bad  { background-color: var(--state-error-bg);   color: #b91c1c; border-color: #fecaca; }
.t-mut  { background-color: var(--color-gray-100);   color: var(--text-secondary); border-color: var(--border-subtle); }

/* 未显式加 .btn 的原生按钮，默认按次要按钮呈现，保证视觉一致 */
button:not(.btn) {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 0.375rem 0.75rem;
  font-family: var(--font-sans); font-size: var(--text-xs); font-weight: 500;
  line-height: 1.5; cursor: pointer;
  color: var(--text-secondary);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}
button:not(.btn):hover {
  background-color: var(--bg-surface-2);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

/* 原生控件补足到框架视觉基线（页内 input 未加 class 时） */
input:not(.input), select:not(.input) {
  font-family: var(--font-sans); font-size: var(--text-sm);
  color: var(--text-primary);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.375rem 0.625rem;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
input:not(.input):focus, select:not(.input):focus {
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.err, .ok {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  white-space: pre-wrap;
  margin-bottom: var(--space-4);
  border: 1px solid transparent;
}
.err { background-color: var(--state-error-bg); border-color: #fecaca; color: #b91c1c; }
.ok  { background-color: var(--state-success-bg); border-color: #a7f3d0; color: #047857; }
