/* 基础重置与骨架布局（顶栏 + 侧栏 + 内容区） */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font: var(--fs) / 1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; }
p { margin: 0 0 var(--sp-3); }
a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--font-mono); }

/* ---------- 骨架 ---------- */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) auto minmax(0, 1fr) auto;
  grid-template-areas: "brand topbar" "sidebar ad" "sidebar main" "sidebar footer";
  height: 100vh;
  height: 100dvh;
}

.site-registration {
  grid-area: footer;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 4px 20px; min-width: 0;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--c-line);
  color: var(--c-muted); background: var(--c-bg);
  font-size: var(--fs-sm); line-height: 1.6; text-align: center;
}
.site-registration a { color: inherit; }
.site-registration a:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 3px; }
@media print { .site-registration { display: none; } }

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  background: var(--c-panel);
  border-right: 1px solid var(--c-line);
  border-bottom: 1px solid var(--c-line);
}
.brand__mark {
  width: 26px; height: 26px; flex: 0 0 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, #1f6feb, #38bdf8);
  color: #fff; font-size: var(--fs-sm); font-weight: 700;
  display: grid; place-items: center;
}
.brand__text { line-height: 1.2; min-width: 0; }
.brand__title { font-size: var(--fs); font-weight: 700; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.brand__sub { font-size: var(--fs-xs); color: var(--c-faint); }

.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-5);
  background: var(--c-panel);
  border-bottom: 1px solid var(--c-line);
}
.topbar__hint { white-space: nowrap; }
.topbar .nav-toggle { display: none; }
.topbar__spacer { flex: 1; }
.topbar { position: relative; z-index: 25; }
.account-menu { position: relative; flex: 0 0 auto; }
.account-menu__trigger { list-style: none; min-height: 40px; }
.account-menu__trigger::-webkit-details-marker { display: none; }
.account-menu__trigger::after { content: '⌄'; margin-left: 6px; font-size: 16px; }
.account-menu__panel {
  position: absolute; z-index: 120; top: calc(100% + 8px); right: 0;
  display: grid; gap: 8px; width: min(310px, calc(100vw - 24px));
  padding: 14px; border: 1px solid var(--c-line); border-radius: var(--radius-lg);
  background: var(--c-panel); box-shadow: var(--shadow-lg);
}
.account-menu__panel .btn, .account-menu__panel .select { width: 100%; justify-content: flex-start; }
.account-menu__identity { color: var(--c-text-2); overflow-wrap: anywhere; font-size: var(--fs-sm); }
.btn--simple { border-color: var(--c-accent); color: var(--c-accent); font-weight: 700; }
.btn--simple[aria-pressed="true"] { background: var(--c-accent); color: #fff; }
/* 激活态的 hover 必须显式声明。
 * 原因：components.css 里的 `.btn:hover { color: var(--c-accent) }` 在
 * base.css **之后**加载，而两者特异性又接近，结果就是鼠标停在"已激活的
 * 简易模式按钮"上时，前景色被改回主色 —— 与它自身的背景色（也是主色）
 * 撞成一片，文字像凭空消失了。这个现象只在 hover 时出现，肉眼很难稳定复现，
 * 是靠计算样式对比（前景 rgb == 背景 rgb）才查出来的。 */
.btn--simple[aria-pressed="true"]:hover {
  background: var(--c-accent-hover);
  border-color: var(--c-accent-hover);
  color: #fff;
}

.sidebar {
  grid-area: sidebar;
  background: var(--c-panel);
  border-right: 1px solid var(--c-line);
  padding: var(--sp-3) var(--sp-2);
  overflow-y: auto;
}
.sidebar__group {
  font-size: var(--fs-xs); color: var(--c-faint);
  padding: var(--sp-3) var(--sp-3) var(--sp-1);
  letter-spacing: .06em;
}
.nav-item {
  width: 100%; border: 0; background: transparent; text-align: left;
  display: flex; align-items: center; gap: var(--sp-2);
  min-height: 40px; padding: 8px var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--c-text-2);
  cursor: pointer;
  font-size: var(--fs);
  user-select: none;
}
.nav-item:hover { background: var(--c-panel-2); color: var(--c-text); }
.nav-item.is-active { background: var(--c-accent-soft); color: var(--c-accent); font-weight: 700; }
.nav-item:focus-visible { outline: 3px solid rgba(31, 111, 235, .24); outline-offset: 1px; }
.nav-item__icon { width: 16px; text-align: center; opacity: .85; }
.nav-item__badge {
  margin-left: auto; font-size: var(--fs-xs);
  background: var(--c-bg); color: var(--c-muted);
  border-radius: 999px; padding: 0 6px;
}

.main {
  grid-area: main;
  overflow-y: auto;
  padding: var(--sp-5);
}
.view { max-width: 1320px; margin: 0 auto; }
.view__head { margin-bottom: var(--sp-4); }
.view__title { font-size: var(--fs-2xl); letter-spacing: .02em; }
.view__desc { color: var(--c-muted); font-size: var(--fs-sm); margin-top: 2px; }
.simple-nav-hint { margin: 10px; padding: 12px; border-radius: var(--radius);
  background: var(--c-accent-soft); color: var(--c-text-2); font-size: var(--fs-sm); }

/* ---------- 状态灯 ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm);
  color: var(--c-muted); }
.status__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c-faint); }
.status__dot.is-ok { background: var(--c-ok); box-shadow: 0 0 0 3px var(--c-ok-soft); }
.status__dot.is-err { background: var(--c-danger); box-shadow: 0 0 0 3px var(--c-danger-soft); }
.status__dot.is-loading { background: var(--c-warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .35 } }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: var(--topbar-h) 54px auto minmax(0, 1fr) auto;
    grid-template-areas: "brand" "topbar" "ad" "main" "footer"; }
  .brand { border-right: 0; }
  .brand__sub, .topbar__hint { display: none; }
  .topbar { padding: 0 var(--sp-3); }
  .topbar .nav-toggle { display: inline-flex; }
  .sidebar { display: block; position: fixed; z-index: 100; left: 0; top: calc(var(--topbar-h) + 54px);
    bottom: 0; width: min(288px, 82vw); padding: var(--sp-3) var(--sp-2);
    box-shadow: var(--shadow-lg); transform: translateX(-105%); transition: none; }
  .sidebar.is-open { transform: translateX(0); }
  .main { padding: var(--sp-3); }
}

/* Login is a full-page gate; the application shell only appears after auth. */
body.auth-locked #app {
  grid-template-columns: 1fr;
  grid-template-rows: 64px minmax(0, 1fr) auto;
  grid-template-areas: "brand" "main" "footer";
}
body.auth-locked .topbar,
body.auth-locked .sidebar { display: none; }
body.auth-locked .brand { justify-content: center; }
body.auth-locked .main { display: grid; place-items: center; padding: 20px; }

@media (max-width: 650px) {
  .topbar { gap: 8px; overflow: visible; padding: 0 10px; }
  .topbar .status, .topbar #topbar-hint { display: none; }
  .topbar__spacer { min-width: 0; }
  .topbar .btn { min-height: 42px; }
  .topbar .btn--simple { padding-inline: 10px; }
  .main { padding: 10px; }
  .view { min-width: 0; }
  .card { padding: 14px; }
  .table-wrap { max-width: calc(100vw - 48px); -webkit-overflow-scrolling: touch; }
  .toolbar { flex-wrap: wrap; }
  .toolbar > .field, .toolbar > .field input { width: 100%; min-width: 0 !important; }
  .pager { flex-wrap: wrap; }
  .pager .btn { min-height: 42px; }
}

body.simple-mode {
  --c-bg: #ffffff; --c-panel-2: #f3f6fb; --c-line: #aebaca;
  --c-line-strong: #7f90a5; --c-text: #101820; --c-text-2: #172333;
  --c-muted: #34465d; --c-faint: #465970;
  --c-accent: #064a92; --c-accent-hover: #033a73; --c-accent-soft: #dcecff;
  --fs-xs: 15px; --fs-sm: 16px; --fs: 18px;
  --fs-lg: 20px; --fs-xl: 24px; --fs-2xl: 30px;
  --sp-3: 16px; --sp-4: 20px; --sp-5: 28px;
}
body.simple-mode .btn, body.simple-mode .input, body.simple-mode .select,
body.simple-mode .textarea, body.simple-mode .nav-item,
body.simple-mode .auth-form input, body.simple-mode .admin-form input,
body.simple-mode .admin-form select { min-height: 48px; }
body.simple-mode .btn:focus-visible, body.simple-mode .nav-item:focus-visible,
body.simple-mode summary:focus-visible { outline: 4px solid #f8aa16; outline-offset: 2px; }
body.simple-mode .view__desc, body.simple-mode .card__hint,
body.simple-mode .help { line-height: 1.7; }
body.simple-mode .sidebar__group { font-weight: 800; }
@media (max-width: 650px) {
  body.simple-mode .topbar .btn { min-height: 44px; font-size: 15px; }
  body.simple-mode .topbar .btn--simple { padding-inline: 7px; }
}
/* V1.10 shell: the content scrolls beneath a small floating navigation surface.
   Tables and reading surfaces remain solid. Mobile uses the same 1024px boundary. */
#app { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.brand { gap: 10px; padding-inline: 22px; border-bottom: 0; }
.brand__mark { width: 36px; height: 36px; flex-basis: 36px; border-radius: 12px;
  background: var(--c-accent); box-shadow: 0 4px 10px var(--c-aura); }
.brand__title { font-size: 14px; letter-spacing: -.02em; }
.brand__sub { margin-top: 4px; font-size: 11px; }
.ui-icon { display: inline-block; flex-shrink: 0; vertical-align: middle; }
.topbar { align-self: start; margin: 12px 28px 0; min-width: 0; min-height: 52px;
  padding: 8px 16px; gap: 12px; border: 1px solid var(--glass-edge);
  border-radius: 18px; }
.topbar__page { font-weight: 700; font-size: var(--fs-sm); white-space: nowrap; }
.topbar__hint { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.topbar .status { margin-left: 10px; padding-left: 14px; border-left: 1px solid var(--c-line);
  white-space: nowrap; font-size: var(--fs-xs); }
.topbar .btn { min-height: 36px; font-size: var(--fs-sm); padding: 6px 11px; }
.sidebar { padding: 12px 14px 24px; }
.sidebar__group { padding: 20px 14px 8px; font-size: 11px; letter-spacing: .12em; }
.nav-item { min-height: 43px; padding: 9px 14px; gap: 12px; margin-bottom: 3px;
  font-size: 14px; border-radius: 11px; }
.nav-item.is-active { box-shadow: inset 0 0 0 1px var(--c-aura-soft); }
.nav-item__icon { width: 20px; height: 20px; display: inline-flex; align-items: center; }
.nav-item:focus-visible { outline: 3px solid var(--c-accent); }
.sidebar .sidebar__close { display: none; }
.nav-scrim { display: none; position: fixed; inset: 0; border: 0;
  background: rgba(25, 35, 45, .28); z-index: 100; }
.main { grid-column: 2; grid-row: 1 / -1; min-height: 0; min-width: 0;
  padding: calc(var(--topbar-h) + 24px) 32px 40px; overflow: auto; scrollbar-gutter: stable; }
.main > * { min-width: 0; }
.view { max-width: 1380px; }
.view__head { margin-bottom: 24px; }
.view__title { letter-spacing: -.035em; font-weight: 750; line-height: 1.3; }
.view__desc { margin-top: 7px; max-width: 860px; line-height: 1.7; }
body.auth-locked #app { grid-template-rows: 64px 1fr; }
body.auth-locked .brand { background: transparent; border-bottom: 1px solid var(--c-line); }
body.auth-locked .main { grid-column: 1; grid-row: 2; padding: 40px 20px; }
body.auth-locked .brand__sub { display: block; }
@media (max-width: 1180px) and (min-width: 1025px) {
  .topbar__hint { display: none; }
  .main { padding-inline: 24px; }
  .topbar { margin-inline: 20px; }
}
@media (max-width: 1024px) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--topbar-h) minmax(0, 1fr);
    grid-template-areas: "topbar" "main"; }
  body:not(.auth-locked) .brand { display: none; }
  .main { grid-column: 1; grid-row: 1 / -1; padding: calc(var(--topbar-h) + 16px) 22px 28px; }
  .topbar { margin: 10px 18px 0; min-height: 54px; padding-inline: 12px; }
  .topbar .nav-toggle { display: inline-flex; }
  .topbar .status { margin-left: 0; }
  .sidebar { position: fixed; z-index: 105; top: 0; bottom: 0; width: min(288px, 84vw);
    background: var(--c-panel); transform: translateX(-105%); box-shadow: var(--shadow-lg); }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar .sidebar__close { display: flex; width: 100%; justify-content: space-between;
    margin-bottom: 10px; min-height: 44px; font-weight: 700; }
  body.nav-open .nav-scrim { display: block; }
  .topbar__hint { display: none; }
  body.auth-locked #app { grid-template-areas: "brand" "main"; }
}
@media (max-width: 650px) {
  .topbar { margin: 8px 10px 0; border-radius: 15px; gap: 8px; }
  .topbar .btn { min-height: 42px; padding-inline: 9px; }
  .topbar__page { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
  .topbar .status { display: none; }
  .topbar__spacer { min-width: 0; }
  .account-menu__trigger { font-size: 12px !important; }
  .topbar .btn--simple { font-size: 12px; }
  .main { padding: calc(var(--topbar-h) + 8px) 12px 24px; scrollbar-gutter: auto; }
  .view__head { margin-bottom: 20px; }
  .view__title { font-size: 25px; }
  .table-wrap { max-width: 100%; }
  body.auth-locked .main { padding: 24px 14px; }
  .sidebar__group { font-size: 12px; }
  .nav-item { min-height: 48px; font-size: 15px; }
}
body.simple-mode .nav-item { font-size: var(--fs); }
body.simple-mode .topbar { border-color: var(--c-line-strong); }
@media (max-width: 650px) {
  body.simple-mode .topbar__page { display: none; }
  body.simple-mode .view__title { font-size: var(--fs-2xl); }
}
@media (forced-colors: active) {
  .nav-item.is-active { outline: 2px solid Highlight; }
  .status__dot { border: 1px solid CanvasText; }
}

/* Registration remains outside the scrolling pane; a published ad gets its own row. */
body:not(.auth-locked) .main { grid-row: 1 / -2; }
body.has-site-ad:not(.auth-locked) .main { grid-area: main; padding-top: 24px; }
body.auth-locked #app { grid-template-rows: 64px minmax(0,1fr) auto; grid-template-areas: "brand" "main" "footer"; }
@media(max-width:1024px) {
  body:not(.auth-locked) #app { grid-template-rows:var(--topbar-h) auto minmax(0,1fr) auto; grid-template-areas:"topbar" "ad" "main" "footer"; }
}

