/* Unified app chrome: left collapsible sidebar + main content area.
   Loads LAST in the document so its rules win against the host page's
   own stylesheet. The body becomes a two-column grid; the existing page
   content is wrapped in <div class="app-main"> by nav.js before any of
   these rules run. */

/* Self-hosted webfonts (China-safe).
   fonts.googleapis.com / fonts.gstatic.com are blocked in mainland China and
   were render-blocking the whole app. DM Mono is now served from /fonts/; the
   CJK face falls back to the OS-native PingFang / JhengHei / YaHei instead of
   downloading multi-MB Noto Sans TC subsets. No third-party requests remain. */
@font-face {
  font-family: "DM Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/dmmono-400-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "DM Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/dmmono-400-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "DM Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/dmmono-500-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "DM Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/dmmono-500-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --app-bg: #0e1a17;
  --app-surface: #16241f;
  --app-surface-2: #1c2e28;
  --app-line: #2a4a40;
  --app-text: #edf2ec;
  --app-text-muted: #8aa39a;
  --app-accent: #c8f35a;
  --app-accent-strong: #b9e342;
  --app-danger: #ff5c7a;
  --app-shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 60px;
  --chrome-font: "PingFang TC", "Microsoft JhengHei", "PingFang SC", "Microsoft YaHei", "Noto Sans TC", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --chrome-mono: "DM Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

html, body {
  background: var(--app-bg) !important;
  color: var(--app-text);
  font-family: var(--chrome-font);
  margin: 0 !important;
  padding: 0 !important;
  min-height: 100vh;
}

body {
  display: grid !important;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  transition: grid-template-columns 0.22s ease;
}

body.app-sidebar-collapsed {
  --sidebar-w: var(--sidebar-w-collapsed);
}

/* ----- Sidebar ----- */
.app-sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--app-surface);
  border-right: 1px solid var(--app-line);
  overflow: hidden;
  z-index: 20;
  font-family: var(--chrome-font);
}

.app-sidebar-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid var(--app-line);
  min-height: 60px;
}

.app-sidebar-toggle {
  flex: 0 0 28px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--app-line);
  background: transparent;
  color: var(--app-text);
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  font: 16px var(--chrome-mono);
  transition: background 0.15s, border-color 0.15s;
}
.app-sidebar-toggle:hover { background: var(--app-surface-2); border-color: var(--app-accent); }
.app-sidebar-toggle:focus-visible { outline: 2px solid var(--app-accent); outline-offset: 2px; }

.app-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  transition: opacity 0.18s ease;
}
.app-brand-mark {
  color: var(--app-accent);
  font: 700 14px/1.1 var(--chrome-mono);
  letter-spacing: 0.12em;
}
.app-brand-sub {
  color: var(--app-text-muted);
  font: 500 10px/1.4 var(--chrome-mono);
  letter-spacing: 0.18em;
  margin-top: 3px;
}
body.app-sidebar-collapsed .app-brand {
  opacity: 0;
  pointer-events: none;
  width: 0;
}

.app-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 8px;
  flex: 1;
  overflow-y: auto;
}

.app-nav-section-label {
  color: var(--app-text-muted);
  font: 600 10px/1 var(--chrome-mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 12px 12px 8px;
  white-space: nowrap;
  transition: opacity 0.15s ease;
}
body.app-sidebar-collapsed .app-nav-section-label { opacity: 0; }

.app-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--app-text);
  text-decoration: none;
  font: 500 14px var(--chrome-font);
  transition: background 0.14s, color 0.14s;
  position: relative;
  white-space: nowrap;
}
.app-nav a:hover {
  background: var(--app-surface-2);
  color: var(--app-accent);
}
.app-nav a[aria-current="page"] {
  background: var(--app-surface-2);
  color: var(--app-accent);
  font-weight: 600;
}
.app-nav a[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 2px;
  background: var(--app-accent);
}

.app-nav-icon {
  flex: 0 0 22px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: currentColor;
}
.app-nav-icon svg { width: 18px; height: 18px; }
.app-nav-label {
  transition: opacity 0.15s ease;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.app-sidebar-collapsed .app-nav-label { opacity: 0; pointer-events: none; }
body.app-sidebar-collapsed .app-nav a { justify-content: center; padding: 10px 6px; }
body.app-sidebar-collapsed .app-nav a[aria-current="page"]::before { left: 0; }

.app-sidebar-foot {
  padding: 14px 16px;
  border-top: 1px solid var(--app-line);
  color: var(--app-text-muted);
  font: 500 10px/1.4 var(--chrome-mono);
  letter-spacing: 0.1em;
  white-space: nowrap;
  transition: opacity 0.15s ease;
}
body.app-sidebar-collapsed .app-sidebar-foot { opacity: 0; }

/* ----- Main content wrapper ----- */
.app-main {
  min-width: 0;
  min-height: 100vh;
  background: var(--app-bg);
  color: var(--app-text);
  padding: 0;
  display: block;
}

/* ----- Mobile: collapse to icon rail at narrow widths ----- */
@media (max-width: 720px) {
  body { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
  body.app-sidebar-mobile-open { --sidebar-w: 240px; }
  body.app-sidebar-mobile-open { box-shadow: inset 80px 0 80px rgba(0,0,0,0.4); }
}
