/* 骨架 v2：顶栏 60 / 左侧导航 240 / 内容区 / 右侧抽屉 480 / 底部操作栏 64（§10.5、§10.12）。
   断点：≥1440 抽屉并列；1024–1439 抽屉覆盖；768–1023 导航折叠；≤430 单列堆叠。 */

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100%; }

/* 键盘可达：焦点环统一由品牌色承担（§10.11.6）。 */
:focus-visible {
  outline: 2px solid var(--brand-strong);
  outline-offset: 2px;
  border-radius: var(--radius-control);
}

.shell {
  display: grid;
  /* 内容列用 minmax(0, 1fr) 而不是 1fr：1fr 等价于 minmax(auto, 1fr)，列的最小宽度会取
     "内容的最小内容宽"——顶栏里那段 nowrap 的品牌文字因此能把整条网格顶宽，
     进而把内容区一起撑出横向滚动（430px 下实测溢出 19px）。minmax(0, …) 让列可以被压到 0，
     由各元素自己负责内部溢出（表格用 .table-wrap 横向滚动）。 */
  grid-template-columns: var(--nav-width) minmax(0, 1fr);
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas: "topbar topbar" "nav content";
  min-height: 100vh;
}

/* ---------- 顶栏 ---------- */

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 600;
  letter-spacing: .2px;
  min-width: 0;
}

.topbar__logo {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-nav);
  border: 1px solid var(--border);
  background: var(--brand-soft);
  object-fit: contain;
  flex: none;
}

.topbar__logo--fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--brand-text);
  font-size: var(--fs-xs);
  font-weight: 700;
}

.topbar__titles { display: flex; flex-direction: column; min-width: 0; }
.topbar__site { font-size: var(--fs-base); line-height: 1.2; }
.topbar__console { font-size: var(--fs-xs); color: var(--muted); font-weight: 400; }

.topbar__meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--muted);
  font-size: var(--fs-xs);
  flex-wrap: wrap;
}

/* 版本徽章：对齐参考的顶部版本信息表达方式。 */
.topbar__version {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-alt);
  color: var(--muted);
  white-space: nowrap;
}

/* 汉堡按钮只在窄屏出现。选择器带 .topbar 前缀提高权重：components.css 里的
   `.btn { display: inline-flex }` 与此处同为单类选择器，会因加载顺序覆盖纯 `.topbar__burger`。 */
.topbar .topbar__burger { display: none; }

/* ---------- 侧边导航 ---------- */

.nav {
  grid-area: nav;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--space-3) var(--space-2);
  overflow-y: auto;
}

.nav__group-title {
  font-size: var(--fs-2xs);
  letter-spacing: .08em;
  color: var(--muted);
  margin: var(--space-4) var(--space-3) var(--space-1);
  font-weight: 600;
}

.nav__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-nav);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--fs-sm);
}

.nav__link:hover { background: var(--surface-alt); }

.nav__link[aria-current="page"] {
  background: var(--brand-soft);
  color: var(--brand-text);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--brand-soft-border);
}

.nav__icon { flex: none; width: 18px; height: 18px; color: currentColor; }

/* ---------- 内容区 ---------- */

.content {
  grid-area: content;
  padding: var(--space-5);
  min-width: 0;
  padding-bottom: calc(var(--bottombar-height) + var(--space-5));
  /* 超宽屏（≥2K/带鱼屏）下不能让内容无限横向拉伸：3440 实测卡片会到 3137px、输入框 1531px，
     行长远超舒适区。上限取 1680px —— 比常规断点（1440）宽，所以 1440 及以下完全不受影响，
     只在更宽的屏上生效，居中留白。 */
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
}

.page-header { margin-bottom: var(--space-5); }
.page-header h1 { font-size: var(--fs-xl); margin: 0 0 var(--space-1); letter-spacing: -.01em; }
.page-header p { margin: 0; color: var(--muted); font-size: var(--fs-sm); }

/* ---------- 抽屉与底部栏 ---------- */

.drawer {
  position: fixed;
  top: var(--topbar-height);
  right: 0;
  bottom: 0;
  width: var(--drawer-width);
  max-width: 100%;
  background: var(--surface);
  box-shadow: var(--shadow-drawer);
  padding: var(--space-5);
  overflow-y: auto;
  transform: translateX(102%);
  transition: transform .18s ease-out;
  z-index: 20;
}

.drawer[data-open="true"] { transform: translateX(0); }

.bottombar {
  position: fixed;
  left: var(--nav-width);
  right: 0;
  bottom: 0;
  height: var(--bottombar-height);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-5);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 15;
}

.bottombar[hidden] { display: none; }

/* ---------- 栅格 ---------- */

.grid-kpi {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.grid-split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--space-5);
}

/* ---------- 登录页 ---------- */

/* 登录页样式集中在 styles/login.css（§10.13）：三类身份各一个独立入口页。
   旧版"单卡片 + 身份下拉"的类名已随该改版移除，不留两套并行样式。 */

/* ---------- 断点 ---------- */

@media (max-width: 1439px) {
  .content { padding-right: var(--space-5); }
}

@media (max-width: 1023px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "topbar" "content"; }
  .nav {
    position: fixed;
    top: var(--topbar-height);
    bottom: 0;
    left: 0;
    width: var(--nav-width);
    transform: translateX(-102%);
    transition: transform .18s ease-out;
    z-index: 25;
    box-shadow: var(--shadow-drawer);
  }
  .nav[data-open="true"] { transform: translateX(0); }
  .topbar .topbar__burger { display: inline-flex; }
  .bottombar { left: 0; }
  .topbar__meta .topbar__version { display: none; }
}

@media (max-width: 767px) {
  .content { padding: var(--space-4); padding-bottom: calc(var(--bottombar-height) + var(--space-4)); }
  .table-wrap { overflow-x: auto; }
  .table-wrap table { min-width: 640px; }
  .table-wrap th:first-child, .table-wrap td:first-child,
  .table-wrap th:last-child, .table-wrap td:last-child { position: sticky; background: var(--surface); }
  .table-wrap th:first-child, .table-wrap td:first-child { left: 0; }
  .table-wrap th:last-child, .table-wrap td:last-child { right: 0; }
}

@media (max-width: 430px) {
  .drawer { width: 100%; top: 0; }
  .bottombar { height: auto; padding: var(--space-2) var(--space-3); flex-wrap: wrap; }
  .table-wrap { overflow-x: visible; }
  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  /* display:block 还不够：767px 那段给的 min-width:640px 必须一起撤掉，
     否则表格仍按 640px 排版，把整页撑出横向滚动。 */
  .table-wrap table { min-width: 0; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    margin-bottom: var(--space-3);
    padding: var(--space-2);
  }
  .table-wrap td { border: none; padding: var(--space-1) 0; display: flex; gap: var(--space-2); }
  .table-wrap td::before { content: attr(data-label); color: var(--muted); min-width: 96px; font-size: var(--fs-xs); }
  .grid-kpi { grid-template-columns: 1fr; }
  .topbar__console { display: none; }
}
