/* ==========================================================================
   秦皇岛市政府文件库 — Apple Human Interface Guidelines Design System
   Two-layer architecture:
     1. Content layer: opaque archival surfaces, high-contrast ink, zero glass
     2. Functional layer: floating Liquid Glass toolbar, sidebar, lightbox HUD
   Follows OS light/dark appearance automatically (HIG Dark Mode best practice).
   ========================================================================== */

:root {
  /* Semantic surfaces (Content Layer) */
  --bg-canvas: #f5f5f7;
  --bg-surface: #ffffff;
  --bg-grouped: #efeff4;
  --bg-elevated: #ffffff;
  --bg-paper: #ffffff;

  /* Semantic ink (Verified WCAG AA/AAA against surfaces) */
  --text-primary: #1d1d1f;     /* 16.9:1 on #fff */
  --text-secondary: #515154;   /* 7.9:1 on #fff */
  --text-tertiary: #6e6e73;    /* 5.0:1 on #fff */

  /* Separators & hairlines */
  --separator: rgba(60, 60, 67, 0.14);
  --separator-strong: rgba(60, 60, 67, 0.24);
  --fill-subtle: rgba(120, 120, 128, 0.10);
  --fill-hover: rgba(120, 120, 128, 0.16);

  /* Brand & Semantic Accents (One color = one meaning) */
  --accent: #0066cc;           /* 5.57:1 on #fff — Interactive controls & links */
  --accent-hover: #0052a3;
  --accent-soft: rgba(0, 102, 204, 0.11);
  --accent-text: #ffffff;

  /* Official Red-Header Signal (Non-interactive semantic badge/rule) */
  --official-red: #b81d24;     /* 6.3:1 on #fff */
  --official-red-soft: rgba(184, 29, 36, 0.09);

  /* Functional Layer: Regular Liquid Glass */
  --glass-bg: rgba(248, 248, 250, 0.78);
  --glass-sidebar-bg: rgba(245, 245, 247, 0.84);
  --glass-border: rgba(60, 60, 67, 0.12);
  --glass-shadow: 0 1px 0 rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);

  /* Card & Paper Elevation */
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 4px rgba(0, 0, 0, 0.03);
  --paper-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), 0 12px 32px rgba(0, 0, 0, 0.05);

  /* Typography */
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-official: "New York", "Songti SC", "STSong", "Noto Serif CJK SC", "SimSun", Georgia, serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  /* Layout metrics */
  --sidebar-width: 312px;
  --toolbar-height: 56px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* Motion */
  --ease-apple: cubic-bezier(0.25, 0.1, 0.25, 1);
  --dur-fast: 160ms;
  --dur-med: 240ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-canvas: #161618;
    --bg-surface: #1e1e21;
    --bg-grouped: #262629;
    --bg-elevated: #28282c;
    --bg-paper: #1e1e21;

    --text-primary: #f5f5f7;   /* 15.1:1 on #1e1e21 */
    --text-secondary: #aeaeb2; /* 7.8:1 on #1e1e21 */
    --text-tertiary: #98989d;  /* 5.9:1 on #1e1e21 */

    --separator: rgba(235, 235, 245, 0.14);
    --separator-strong: rgba(235, 235, 245, 0.26);
    --fill-subtle: rgba(120, 120, 128, 0.22);
    --fill-hover: rgba(120, 120, 128, 0.32);

    --accent: #409cff;         /* 6.4:1 on #1e1e21 */
    --accent-hover: #64b0ff;
    --accent-soft: rgba(64, 156, 255, 0.16);
    --accent-text: #0b1929;

    --official-red: #ff6961;   /* 5.6:1 on #1e1e21 */
    --official-red-soft: rgba(255, 105, 97, 0.14);

    --glass-bg: rgba(28, 28, 32, 0.78);
    --glass-sidebar-bg: rgba(26, 26, 30, 0.86);
    --glass-border: rgba(255, 255, 255, 0.10);
    --glass-shadow: 0 1px 0 rgba(255, 255, 255, 0.05), 0 10px 28px rgba(0, 0, 0, 0.32);

    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
    --paper-shadow: 0 4px 20px rgba(0, 0, 0, 0.42);
  }
}

/* HIG Accessibility: Reduce Transparency -> Opaque fallbacks */
@media (prefers-reduced-transparency: reduce) {
  :root {
    --glass-bg: var(--bg-surface);
    --glass-sidebar-bg: var(--bg-grouped);
  }
  .top-toolbar,
  .sidebar,
  .lightbox-toolbar,
  .status-toast {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
}

/* HIG Accessibility: Increase Contrast */
@media (prefers-contrast: more) {
  :root {
    --separator: rgba(60, 60, 67, 0.42);
    --separator-strong: rgba(60, 60, 67, 0.65);
    --text-secondary: #1d1d1f;
    --text-tertiary: #3a3a3c;
    --accent: #004499;
    --glass-bg: var(--bg-surface);
    --glass-sidebar-bg: var(--bg-surface);
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --separator: rgba(255, 255, 255, 0.42);
      --separator-strong: rgba(255, 255, 255, 0.70);
      --text-secondary: #ffffff;
      --text-tertiary: #e5e5ea;
      --accent: #70b8ff;
    }
  }
}

/* HIG Accessibility: Reduce Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* Visible Focus Rings (HIG Keyboard Accessibility) */
:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: -100px;
  left: 16px;
  z-index: 1000;
  background: var(--accent);
  color: var(--accent-text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus {
  top: 12px;
}

/* ==========================================================================
   Split-View Shell Layout
   ========================================================================== */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Leading Sidebar (Functional Layer — Regular Liquid Glass) */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--glass-sidebar-bg);
  backdrop-filter: blur(28px) saturate(1.4);
  -webkit-backdrop-filter: blur(28px) saturate(1.4);
  border-right: 1px solid var(--glass-border);
  transition: transform var(--dur-med) var(--ease-apple);
}

.app-shell.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 14px 10px;
  flex-shrink: 0;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
  text-decoration: none;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  min-height: 40px;
}

.brand-link:hover {
  background: var(--fill-subtle);
  text-decoration: none;
}

.brand-seal {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--official-red);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(184, 29, 36, 0.28);
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
  color: var(--text-primary);
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  line-height: 1.3;
}

.icon-btn.sidebar-close-mobile {
  display: none;
}

/* Search Field + Scope Bar */
.sidebar-search-wrap {
  padding: 4px 14px 12px;
  border-bottom: 1px solid var(--separator);
  flex-shrink: 0;
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--fill-subtle);
  border: 1px solid transparent;
  border-radius: 10px;
  transition: background var(--dur-fast) var(--ease-apple), border-color var(--dur-fast) var(--ease-apple);
}

.search-field:focus-within {
  background: var(--bg-surface);
  border-color: var(--accent);
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-field input {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px 34px 8px 33px;
  font-size: 0.875rem;
  line-height: 1.4;
  min-height: 36px;
  outline: none;
}

.search-field input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-field input::placeholder {
  color: var(--text-tertiary);
}

.search-kbd {
  position: absolute;
  right: 9px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-tertiary);
  background: var(--bg-surface);
  border: 1px solid var(--separator);
  border-radius: 5px;
  padding: 1px 6px;
  line-height: 1.4;
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 6px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: var(--fill-hover);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.search-clear:hover {
  background: var(--separator-strong);
  color: var(--text-primary);
}

.scope-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  margin-top: 9px;
  padding: 3px;
  background: var(--fill-subtle);
  border-radius: 9px;
}

.scope-pill {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: 500;
  padding: 5px 4px;
  border-radius: 7px;
  cursor: pointer;
  min-height: 28px;
  transition: background var(--dur-fast) var(--ease-apple), color var(--dur-fast) var(--ease-apple);
}

.scope-pill:hover {
  color: var(--text-primary);
}

.scope-pill.is-active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* Sidebar Navigation Tree */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 24px;
  overscroll-behavior: contain;
}

.sidebar-overview-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  margin-bottom: 6px;
  text-decoration: none;
}

.sidebar-overview-btn:hover {
  background: var(--fill-subtle);
  text-decoration: none;
}

.sidebar-overview-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-overview-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.nav-group {
  margin-bottom: 4px;
}

.nav-group-header {
  display: flex;
  align-items: center;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  min-height: 34px;
  gap: 6px;
  color: var(--text-primary);
  transition: background var(--dur-fast) var(--ease-apple);
}

.nav-group-header:hover {
  background: var(--fill-subtle);
}

.nav-group-header.is-active-cat {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-chevron {
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition: transform var(--dur-fast) var(--ease-apple);
}

.nav-group.is-open .nav-chevron {
  transform: rotate(90deg);
}

.nav-group-title {
  flex: 1;
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-count {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-tertiary);
  background: var(--fill-subtle);
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

.nav-group-list {
  list-style: none;
  margin: 2px 0 6px;
  padding: 0 0 0 18px;
  display: none;
}

.nav-group.is-open .nav-group-list {
  display: block;
}

.nav-doc-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 10px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease-apple), color var(--dur-fast) var(--ease-apple);
}

.nav-doc-link:hover {
  background: var(--fill-subtle);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-doc-link.is-active {
  background: var(--accent);
  color: var(--accent-text);
}

.nav-doc-link.is-active .nav-doc-code {
  color: var(--accent-text);
  opacity: 0.88;
}

.nav-doc-code {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-tertiary);
  line-height: 1.25;
}

.nav-doc-title {
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-results-meta {
  font-size: 0.76rem;
  color: var(--text-tertiary);
  padding: 6px 10px 8px;
}

.search-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.86rem;
}

.search-snippet {
  font-size: 0.74rem;
  color: var(--text-tertiary);
  line-height: 1.4;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.nav-doc-link.is-active .search-snippet {
  color: var(--accent-text);
  opacity: 0.82;
}

mark.hl {
  background: rgba(255, 204, 0, 0.34);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

/* ==========================================================================
   Main Content Pane & Floating Liquid Glass Toolbar
   ========================================================================== */

.content-pane {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  transition: margin-left var(--dur-med) var(--ease-apple);
}

.app-shell.sidebar-collapsed .content-pane {
  margin-left: 0;
}

/* Floating Liquid Glass Top Toolbar */
.top-toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--toolbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 20px;
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-bottom: 1px solid var(--glass-border);
}

.toolbar-leading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 44px;
  flex: 1;
}

.toolbar-trailing {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 34px;
  min-height: 34px;
  padding: 0 8px;
  flex-shrink: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-apple);
}

.icon-btn:hover {
  background: var(--fill-subtle);
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-apple), border-color var(--dur-fast) var(--ease-apple);
}

.toolbar-btn:hover {
  background: var(--bg-grouped);
  border-color: var(--separator-strong);
}

.toolbar-btn.is-prominent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.toolbar-btn.is-prominent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.toolbar-segment {
  display: inline-flex;
  align-items: center;
  background: var(--fill-subtle);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.toolbar-segment button {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 6px;
  cursor: pointer;
}

.toolbar-segment button:hover {
  color: var(--text-primary);
}

.toolbar-segment button.is-active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 0.86rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breadcrumb-link {
  color: var(--text-secondary);
  font-weight: 500;
  text-decoration: none;
  flex-shrink: 0;
}

.breadcrumb-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.breadcrumb-sep {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.breadcrumb-current {
  color: var(--text-primary);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Content Stage */
.main-content {
  flex: 1;
  padding: 28px 28px 64px;
  outline: none;
}

.view-container {
  max-width: 980px;
  margin: 0 auto;
}

/* ==========================================================================
   Home / Overview Page (Content Layer — Opaque Surfaces, Clean Hierarchy)
   ========================================================================== */

.home-masthead {
  background: var(--bg-surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  padding: 32px 32px 28px;
  box-shadow: var(--card-shadow);
  margin-bottom: 24px;
}

.red-header-rule {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.red-header-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--official-red);
  background: var(--official-red-soft);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
}

.red-header-line {
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, var(--official-red) 0%, var(--official-red-soft) 100%);
  border-radius: 2px;
}

.home-title {
  margin: 0 0 10px;
  font-family: var(--font-official);
  font-size: clamp(1.65rem, 2.6vw, 2.2rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.25;
  color: var(--text-primary);
}

.home-subtitle {
  margin: 0 0 20px;
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 62ch;
}

.home-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-grouped);
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.stat-chip strong {
  color: var(--text-primary);
  font-weight: 600;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--separator);
}

.quick-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--separator);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.86rem;
  font-weight: 500;
  text-decoration: none;
  min-height: 36px;
  transition: border-color var(--dur-fast) var(--ease-apple), background var(--dur-fast) var(--ease-apple);
}

.quick-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 14px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.section-heading span {
  font-size: 0.82rem;
  color: var(--text-tertiary);
}

.agency-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.agency-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--card-shadow);
  transition: border-color var(--dur-fast) var(--ease-apple), transform var(--dur-fast) var(--ease-apple);
}

.agency-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  text-decoration: none;
}

.agency-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.agency-card-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.agency-card-count {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

.agency-card-desc {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.5;
  flex: 1;
}

.agency-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-tertiary);
  padding-top: 6px;
  border-top: 1px solid var(--separator);
}

/* ==========================================================================
   Category Overview View
   ========================================================================== */

.category-header {
  background: var(--bg-surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 20px;
  box-shadow: var(--card-shadow);
}

.category-title {
  margin: 0 0 8px;
  font-family: var(--font-official);
  font-size: 1.55rem;
  font-weight: 700;
}

.category-desc {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.category-info-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--separator);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.doc-row-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  color: inherit;
  text-decoration: none;
  box-shadow: var(--card-shadow);
  transition: border-color var(--dur-fast) var(--ease-apple);
}

.doc-row-card:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.doc-row-main {
  min-width: 0;
  flex: 1;
}

.doc-row-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.code-badge {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--official-red);
  background: var(--official-red-soft);
  padding: 2px 9px;
  border-radius: 6px;
}

.type-badge {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-grouped);
  padding: 2px 8px;
  border-radius: 6px;
}

.doc-row-title {
  margin: 0 0 6px;
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

.doc-row-excerpt {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.doc-row-arrow {
  color: var(--text-tertiary);
  flex-shrink: 0;
  margin-top: 6px;
}

/* ==========================================================================
   Document Detail View — Official Red-Header Paper Stage
   ========================================================================== */

.doc-article {
  background: var(--bg-paper);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  box-shadow: var(--paper-shadow);
  overflow: hidden;
}

.doc-header {
  padding: 28px 34px 22px;
  border-bottom: 2px solid var(--official-red);
  background: var(--bg-surface);
}

.doc-meta-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.doc-agency-pill {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-grouped);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  text-decoration: none;
}

.doc-agency-pill:hover {
  color: var(--accent);
  text-decoration: none;
}

.doc-title {
  margin: 0 0 12px;
  font-family: var(--font-official);
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  font-weight: 700;
  line-height: 1.38;
  color: var(--text-primary);
}

.doc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.doc-tag {
  font-size: 0.76rem;
  color: var(--text-tertiary);
  background: var(--fill-subtle);
  padding: 2px 9px;
  border-radius: var(--radius-pill);
}

/* Text/HTML Document Reading Body */
.doc-body-text {
  padding: 28px 34px 36px;
  font-size: var(--reading-size, 1.02rem);
  line-height: 1.85;
  color: var(--text-primary);
}

.doc-body-text p {
  margin: 0 0 0.9em;
  max-width: 74ch;
}

.doc-body-text h1,
.doc-body-text h2,
.doc-body-text h3,
.doc-body-text h4 {
  font-family: var(--font-official);
  margin: 1.5em 0 0.6em;
  line-height: 1.35;
  color: var(--text-primary);
}

.doc-body-text .table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 18px 0 22px;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  -webkit-overflow-scrolling: touch;
}

.doc-body-text table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92em;
  line-height: 1.55;
  min-width: 520px;
}

.doc-body-text th,
.doc-body-text td {
  border: 1px solid var(--separator);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

.doc-body-text td:first-child {
  word-break: keep-all;
}

.doc-body-text tr:first-child td,
.doc-body-text th {
  background: var(--bg-grouped);
  font-weight: 600;
}

.doc-body-text ul,
.doc-body-text ol {
  padding-left: 1.5em;
  margin: 0.6em 0 1em;
}

.doc-body-text li {
  margin-bottom: 0.35em;
}

/* Scanned Official Document Gallery */
.doc-body-scans {
  padding: 24px 28px 34px;
  background: var(--bg-grouped);
}

.scans-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.scan-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.scan-figure {
  margin: 0;
  width: 100%;
  max-width: var(--scan-max-width, 820px);
  background: #ffffff;
  border: 1px solid var(--separator);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--paper-shadow);
  transition: max-width var(--dur-med) var(--ease-apple);
}

.scan-img-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.scan-img-btn img {
  display: block;
  width: 100%;
  height: auto;
}

/* HIG Dark Mode: Soften bright white scanned paper to avoid glare */
@media (prefers-color-scheme: dark) {
  .scan-figure {
    background: #ecece8;
  }
  .scan-img-btn img {
    filter: brightness(0.92) contrast(1.03);
  }
}

.scan-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  background: var(--bg-surface);
  border-top: 1px solid var(--separator);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.scan-caption-action {
  color: var(--accent);
  font-weight: 500;
}

/* Previous / Next Document Footer */
.doc-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}

.pager-link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-md);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--card-shadow);
  transition: border-color var(--dur-fast) var(--ease-apple);
}

.pager-link:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.pager-link.is-next {
  text-align: right;
  grid-column: 2;
}

.pager-dir {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-tertiary);
}

.pager-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.site-footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--separator);
  font-size: 0.8rem;
  color: var(--text-tertiary);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
}

/* ==========================================================================
   Full-Screen Archival Lightbox (HIG Dark media viewing + Clear controls)
   ========================================================================== */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(16, 16, 18, 0.94);
  color: #f5f5f7;
  display: flex;
  flex-direction: column;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(28, 28, 32, 0.82);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
}

.lightbox-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.lightbox-title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox-counter {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #aeaeb2;
  flex-shrink: 0;
}

.lightbox-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.lb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 36px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
  color: #f5f5f7;
  font-size: 0.82rem;
  cursor: pointer;
}

.lb-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.lb-zoom-label {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  min-width: 44px;
  text-align: center;
  color: #e5e5ea;
}

.lightbox-stage {
  position: relative;
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 64px;
}

.lightbox-img-wrap {
  margin: auto;
  transition: width var(--dur-fast) var(--ease-apple);
}

.lightbox-img-wrap img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
}

.lb-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(28, 28, 32, 0.78);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
}

.lb-nav:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.22);
}

.lb-nav:disabled {
  opacity: 0.28;
  cursor: default;
}

.lb-prev { left: 16px; }
.lb-next { right: 16px; }

/* Subtle Status Toast */
.status-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  padding: 9px 18px;
  border-radius: var(--radius-pill);
  background: rgba(29, 29, 31, 0.90);
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* ==========================================================================
   Compact / Mobile Adaptation (HIG Size Classes & 44x44pt Touch Targets)
   ========================================================================== */

@media (max-width: 900px) {
  .sidebar {
    width: min(86vw, 340px);
    transform: translateX(-100%);
    box-shadow: 0 0 36px rgba(0, 0, 0, 0.24);
  }

  .app-shell.sidebar-mobile-open .sidebar {
    transform: translateX(0);
  }

  .icon-btn.sidebar-close-mobile {
    display: inline-flex;
    min-width: 44px;
    min-height: 44px;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.36);
  }

  .content-pane {
    margin-left: 0 !important;
  }

  .top-toolbar {
    padding: 8px 12px;
  }

  .icon-btn,
  .toolbar-btn,
  .scope-pill,
  .nav-group-header,
  .lb-btn {
    min-height: 44px;
  }

  .toolbar-segment button {
    min-height: 40px;
    padding: 0 11px;
  }

  .icon-btn,
  .lb-btn {
    min-width: 44px;
  }

  .search-kbd {
    display: none;
  }

  .main-content {
    padding: 16px 14px 48px;
  }

  .home-masthead,
  .category-header,
  .doc-header,
  .doc-body-text {
    padding-left: 18px;
    padding-right: 18px;
  }

  .doc-body-scans {
    padding: 14px 12px 24px;
  }

  .doc-pager {
    grid-template-columns: 1fr;
  }

  .pager-link.is-next {
    grid-column: 1;
    text-align: left;
  }

  .lightbox-stage {
    padding: 16px 12px;
  }

  .lb-prev { left: 8px; }
  .lb-next { right: 8px; }
}

@media (max-width: 640px) {
  .top-toolbar {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .toolbar-leading {
    flex: 1 1 100%;
    min-width: 0;
  }

  .toolbar-trailing:empty {
    display: none;
  }

  .toolbar-trailing:not(:empty) {
    flex: 1 1 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--separator);
  }

  .scan-width-segment {
    display: none;
  }

  .lightbox-toolbar {
    padding: 8px 12px;
    gap: 8px;
  }

  .lightbox-title {
    display: none;
  }

  .lb-zoom-label {
    min-width: 38px;
    font-size: 0.78rem;
  }
}

@media (max-width: 420px) {
  .lb-btn-close span {
    display: none;
  }
}

/* ==========================================================================
   Clean Print Stylesheet
   ========================================================================== */

@media print {
  .sidebar,
  .sidebar-backdrop,
  .top-toolbar,
  .doc-pager,
  .scans-hint,
  .scan-caption-action,
  .site-footer,
  .lightbox,
  .status-toast {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .content-pane {
    margin-left: 0 !important;
  }

  .main-content {
    padding: 0 !important;
  }

  .doc-article,
  .scan-figure {
    border: 0 !important;
    box-shadow: none !important;
  }

  .scan-figure {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 12px;
  }
}
