/* ==========================================================
   AGE Logistics QMS — Modern Documentation Site
   Inspired by Apple Human Interface Guidelines
   ========================================================== */

/* ——— Design Tokens ——— */
:root {
  --primary:          #0071e3;
  --primary-rgb:      0, 113, 227;
  --primary-hover:    #0077ed;
  --primary-light:    rgba(0, 113, 227, 0.10);

  --text:             #1d1d1f;
  --text-2:           #6e6e73;
  --text-3:           #86868b;

  --bg:               #ffffff;
  --surface:          #f5f5f7;
  --surface-2:        #e8e8ed;
  --border:           #d2d2d7;
  --border-subtle:    #e8e8ed;

  --sidebar-width:    260px;
  --navbar-h:         52px;
  --radius:           12px;
  --radius-sm:        8px;
  --radius-xs:        6px;

  --shadow-sm:  0 1px 4px rgba(0,0,0,.06);
  --shadow:     0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.12);

  --font:       -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                "Helvetica Neue", Arial, sans-serif;
  --font-mono:  "SF Mono", "Fira Code", Consolas, monospace;

  --ease:       cubic-bezier(.4, 0, .2, 1);
  --dur:        .2s;
}

/* Dark mode — system preference (default) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary:        #2997ff;
    --primary-rgb:    41, 151, 255;
    --primary-hover:  #409cff;
    --primary-light:  rgba(41, 151, 255, .14);

    --text:           #f5f5f7;
    --text-2:         #a1a1a6;
    --text-3:         #6e6e73;

    --bg:             #000000;
    --surface:        #1c1c1e;
    --surface-2:      #2c2c2e;
    --border:         #3a3a3c;
    --border-subtle:  #2c2c2e;

    --shadow-sm:  0 1px 4px rgba(0,0,0,.3);
    --shadow:     0 4px 16px rgba(0,0,0,.4);
    --shadow-lg:  0 8px 32px rgba(0,0,0,.5);
  }
}

/* Dark mode — explicit user preference */
:root[data-theme="dark"] {
  --primary:        #2997ff;
  --primary-rgb:    41, 151, 255;
  --primary-hover:  #409cff;
  --primary-light:  rgba(41, 151, 255, .14);

  --text:           #f5f5f7;
  --text-2:         #a1a1a6;
  --text-3:         #6e6e73;

  --bg:             #000000;
  --surface:        #1c1c1e;
  --surface-2:      #2c2c2e;
  --border:         #3a3a3c;
  --border-subtle:  #2c2c2e;

  --shadow-sm:  0 1px 4px rgba(0,0,0,.3);
  --shadow:     0 4px 16px rgba(0,0,0,.4);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.5);
}

/* ——— Reset ——— */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* ——— Navbar ——— */
.navbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--navbar-h);
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(0,0,0,.08);
  z-index: 1000;
}
@media (prefers-color-scheme: dark) {
  .navbar { background: rgba(0,0,0,.85); border-bottom-color: rgba(255,255,255,.08); }
}
:root[data-theme="dark"] .navbar { background: rgba(0,0,0,.85); border-bottom-color: rgba(255,255,255,.08); }
:root[data-theme="light"] .navbar { background: rgba(255,255,255,.85); border-bottom-color: rgba(0,0,0,.08); }

.navbar-inner {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 20px;
  gap: 12px;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
}
.navbar-brand:hover { text-decoration: none; color: var(--text); }

.brand-logo-img {
  flex-shrink: 0;
  height: 34px;
  width: auto;
  max-width: 120px;
  object-fit: contain;
}

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

.brand-name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-2);
  line-height: 1;
}

/* Hamburger */
.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-xs);
  transition: background var(--dur) var(--ease);
}
.menu-toggle:hover { background: var(--surface); }
.menu-toggle span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
/* Open state */
.menu-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.open span:nth-child(2) { opacity: 0; }
.menu-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 768px) {
  .menu-toggle { display: flex; }
  .brand-sub { display: none; }
  .brand-name { display: none; }
}

/* ——— PDF Download Button (navbar) ——— */
.navbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
}

.pdf-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--primary, #0071e3);
  color: #fff;
  border-radius: var(--radius-xs, 6px);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur, .15s) var(--ease, ease);
  line-height: 1;
}
.pdf-btn:hover {
  background: var(--primary-hover, #005bb5);
  color: #fff;
  text-decoration: none;
}
.pdf-btn svg {
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .pdf-btn-label { display: none; }
  .pdf-btn { padding: 6px 9px; }
}

/* ——— User Profile ——— */
.navbar-actions {
  gap: 8px;
}

.user-profile {
  position: relative;
}

.user-profile-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
  flex-shrink: 0;
}
.user-profile-btn:hover,
.user-profile-btn[aria-expanded="true"] {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 220px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1100;
  opacity: 0;
  transform: translateY(-6px) scale(.98);
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.user-dropdown.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.user-dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}

.user-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--primary-light);
  border-radius: 50%;
  color: var(--primary);
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 1px;
}

.user-dropdown-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 0 8px;
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  cursor: pointer;
  border-radius: 0;
  transition: background var(--dur) var(--ease);
  text-align: left;
  text-decoration: none;
}
.user-dropdown-item:last-child {
  border-radius: 0 0 var(--radius) var(--radius);
}
.user-dropdown-item:hover {
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.user-admin-link,
.user-admin-link:hover {
  color: var(--text);
  text-decoration: none;
}

.user-signout {
  color: #d93025;
}
.user-signout:hover {
  background: rgba(217, 48, 37, .08);
  color: #d93025;
}

@media (prefers-color-scheme: dark) {
  .user-signout { color: #f28b82; }
  .user-signout:hover { background: rgba(242, 139, 130, .1); color: #f28b82; }
}

/* ——— Layout ——— */
.layout {
  display: flex;
  padding-top: var(--navbar-h);
  min-height: 100vh;
}

/* ——— Sidebar ——— */
.sidebar {
  position: fixed;
  top: var(--navbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 200;
  transition: transform var(--dur) var(--ease);
  -webkit-overflow-scrolling: touch;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

@media (max-width: 768px) {
  .sidebar {
    top: 0;
    padding-top: var(--navbar-h);
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    z-index: 900;
  }
  .sidebar.open { transform: translateX(0); }
}

/* Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
  z-index: 800;
}
.sidebar-overlay.visible { display: block; }

/* Nav inner */
.sidebar-nav {
  padding: 12px 0 80px;
}

.sidebar-home {
  padding: 0 10px 4px;
}

.sidebar-home-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  border-radius: var(--radius-xs);
  text-decoration: none;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sidebar-home-link:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.sidebar-home-link.active {
  background: var(--primary-light);
  color: var(--primary);
}

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 16px 20px 4px;
}

.sidebar-item { position: relative; }

/* Parent link (with chevron) */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px 7px 20px;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  line-height: 1.4;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  border-radius: 0;
  position: relative;
}
.sidebar-link:hover {
  background: rgba(0,0,0,.04);
  color: var(--text);
  text-decoration: none;
}
@media (prefers-color-scheme: dark) {
  .sidebar-link:hover { background: rgba(255,255,255,.06); }
}
.sidebar-link.active {
  color: var(--primary);
  background: var(--primary-light);
  font-weight: 500;
}
.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.sidebar-section-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  min-width: 20px;
  flex-shrink: 0;
}

.sidebar-chevron {
  margin-left: auto;
  display: flex;
  align-items: center;
  color: var(--text-3);
  transition: transform var(--dur) var(--ease);
  flex-shrink: 0;
}
.sidebar-item.expanded .sidebar-chevron { transform: rotate(90deg); }

/* Children */
.sidebar-children {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s var(--ease);
}
.sidebar-item.expanded .sidebar-children { max-height: 600px; }

.sidebar-child-link {
  display: block;
  padding: 6px 20px 6px 48px;
  font-size: 13px;
  color: var(--text-2);
  text-decoration: none;
  line-height: 1.4;
  position: relative;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.sidebar-child-link::before {
  content: '';
  position: absolute;
  left: 30px; top: 0; bottom: 0;
  width: 1px;
  background: var(--border);
}
.sidebar-child-link:hover {
  color: var(--text);
  background: rgba(0,0,0,.04);
  text-decoration: none;
}
@media (prefers-color-scheme: dark) {
  .sidebar-child-link:hover { background: rgba(255,255,255,.06); }
}
.sidebar-child-link.active {
  color: var(--primary);
  font-weight: 500;
}

/* ——— Main Content ——— */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}
@media (max-width: 768px) {
  .main-content { margin-left: 0; }
}

.content-wrapper {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 32px 60px;
  flex: 1;
}
@media (max-width: 768px) {
  .content-wrapper { padding: 24px 20px 48px; }
}

/* ——— Page Content Typography ——— */
.page-content h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: 20px;
}
.page-content h2 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--text);
  margin: 40px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}
.page-content h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin: 28px 0 8px;
}
.page-content h4 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 20px 0 6px;
}
.page-content p {
  font-size: 16px;
  line-height: 1.75;
  color: var(--text);
  margin-bottom: 16px;
}
.page-content ul, .page-content ol {
  padding-left: 24px;
  margin-bottom: 16px;
}
.page-content li {
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 4px;
}
.page-content strong { font-weight: 600; }
.page-content em { font-style: italic; color: var(--text-2); }

.page-content blockquote {
  border-left: 3px solid var(--primary);
  padding: 12px 20px;
  background: var(--surface);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  margin: 20px 0;
}
.page-content blockquote p { color: var(--text-2); font-style: italic; margin: 0; }

.page-content code {
  font-family: var(--font-mono);
  font-size: .875em;
  background: var(--surface);
  color: var(--text);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
}
.page-content pre {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 20px;
  overflow-x: auto;
  margin: 20px 0;
}
.page-content pre code { background: none; border: none; padding: 0; font-size: 14px; line-height: 1.6; }

/* Tables */
.page-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 15px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}
.page-content th {
  background: var(--surface);
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-2);
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.page-content td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text);
  line-height: 1.5;
  vertical-align: top;
}
.page-content tr:last-child td { border-bottom: none; }
.page-content tr:hover td { background: var(--surface); }

/* HR */
.page-content hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 36px 0;
}

/* Back nav links */
.page-content a[href*="README"], .page-content p > a:first-child {
  /* keep default link styling */
}

/* ——— Home Page ——— */
.home-hero {
  padding: 56px 0 40px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 48px;
}

.hero-logo {
  height: 64px;
  width: auto;
  max-width: 220px;
  object-fit: contain;
  display: block;
  margin-bottom: 20px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) img { filter: none; }
}
:root[data-theme="dark"] img { filter: none; }

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 20px;
}

.home-hero h1 {
  font-size: clamp(2.4rem, 6vw, 3.8rem);
  font-weight: 700;
  letter-spacing: -.04em;
  line-height: 1.08;
  color: var(--text);
  margin-bottom: 16px;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--text-2);
  line-height: 1.6;
  max-width: 580px;
  margin-bottom: 24px;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 13px;
  color: var(--text-3);
}
.hero-meta-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Hero search bar */
.hero-search-wrap {
  margin-top: 32px;
  max-width: 620px;
}

.hero-search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 20px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  cursor: text;
  font-size: 1rem;
  color: var(--text-3);
  text-align: left;
  transition: border-color .15s, box-shadow .15s;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.hero-search-bar:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(0,113,227,.12);
}

.hero-search-bar:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,113,227,.18);
}

.hero-search-icon {
  flex-shrink: 0;
  color: var(--text-3);
}

.hero-search-placeholder {
  flex: 1;
  font-size: 1rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hero-search-kbd {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text-3);
  line-height: 1.6;
}

@media (max-width: 480px) {
  .hero-search-kbd { display: none; }
  .hero-search-bar { padding: 13px 16px; }
}

/* Home sections */
.home-section { margin-bottom: 52px; }

.home-section-title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--text);
  margin-bottom: 16px;
  border: none !important;
  padding: 0 !important;
}

/* Intro docs list */
.intro-docs-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.intro-doc-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
  box-shadow: var(--shadow-sm);
}
.intro-doc-link:hover {
  border-color: var(--border);
  box-shadow: var(--shadow);
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
}

.intro-doc-icon {
  font-size: 22px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.intro-doc-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.intro-doc-body strong {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: block;
}
.intro-doc-body span {
  font-size: 13px;
  color: var(--text-2);
}

.intro-doc-arrow {
  color: var(--text-3);
  flex-shrink: 0;
}

/* Section cards */
.section-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.section-card {
  display: flex;
  flex-direction: column;
  padding: 20px;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
  cursor: pointer;
}
.section-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border);
  text-decoration: none;
  color: var(--text);
}

.section-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.section-card-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary) 0%, #34aadc 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.section-card-number {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--primary);
}

.section-card h3 {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 6px;
  color: var(--text);
}

.section-card p {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  margin: 0;
  flex: 1;
}

.section-card-subsections {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 14px;
}

.subsection-pill {
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border-radius: 100px;
  padding: 2px 8px;
}

.section-card-arrow {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--primary);
  margin-top: 14px;
}

/* Document Control Card */
.doc-control-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 48px;
}

.doc-control-card h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-2);
  margin-bottom: 16px;
}

.doc-control-card table {
  width: 100%;
  font-size: 14px;
  border: none !important;
  border-radius: 0;
  overflow: visible;
  margin: 0 0 20px;
}
.doc-control-card td {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text);
  font-size: 14px;
}
.doc-control-card td:first-child {
  font-weight: 500;
  color: var(--text-2);
  width: 45%;
}
.doc-control-card tr:last-child td { border-bottom: none; }

/* Document hierarchy */
.doc-hierarchy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 16px;
}

.doc-level {
  font-size: 13px;
  color: var(--text-2);
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  border-left: 3px solid transparent;
}

.doc-level-1 { border-left-color: var(--primary); background: var(--primary-light); color: var(--text); }
.doc-level-2 { border-left-color: var(--border); }
.doc-level-3 { border-left-color: var(--border); padding-left: 24px; }

/* ——— Last Updated Badge ——— */
.page-last-updated {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--primary);
  background: var(--primary-light);
  border: 1px solid rgba(var(--primary-rgb), 0.20);
  border-radius: 20px;
  padding: 2px 10px 2px 7px;
  margin: 16px 0 0;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.page-last-updated svg {
  flex-shrink: 0;
  opacity: 0.85;
}
.page-last-updated strong {
  font-weight: 600;
}

/* ——— Chapter Prev/Next Navigation ——— */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 48px 0 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border-subtle);
}

.page-nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
  flex: 1;
  min-width: 0;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.page-nav-btn:hover {
  background: var(--surface-2);
  border-color: var(--primary-hover);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--text);
}

.page-nav-prev { flex-direction: row; }
.page-nav-next { flex-direction: row; }

.page-nav-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.page-nav-prev .page-nav-content { align-items: flex-start; }
.page-nav-next .page-nav-content { align-items: flex-end; }

.page-nav-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 4px;
}

.page-nav-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.page-nav-disabled { visibility: hidden; pointer-events: none; }

@media (max-width: 600px) {
  .page-nav { flex-direction: column; }
  .page-nav-next { flex-direction: row; }
  .page-nav-next .page-nav-content { align-items: flex-end; }
}

/* ——— Site Footer ——— */
.site-footer {
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
  padding: 28px 20px;
  border-top: 1px solid var(--border-subtle);
  line-height: 1.8;
}
.footer-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0 0.35em;
  margin: 0 0 2px;
}
.footer-meta span { white-space: nowrap; }
.footer-sep { color: var(--text-4, var(--text-3)); }
@media (max-width: 480px) {
  .footer-meta {
    flex-direction: column;
    gap: 0;
  }
  .footer-sep { display: none; }
}

/* ——— Utilities ——— */
.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;
}

/* ——— Search Button (navbar) ——— */
.search-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-family: var(--font);
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
  flex-shrink: 0;
}
.search-btn:hover {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.search-kbd {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-3);
  background: var(--bg);
  line-height: 1.5;
}

@media (max-width: 768px) {
  .search-btn-label,
  .search-kbd { display: none; }
  .search-btn { padding: 6px 8px; }
}

/* ——— Theme Toggle Button ——— */
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  cursor: pointer;
  color: var(--text-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
  flex-shrink: 0;
  padding: 0;
}
.theme-toggle-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.theme-toggle-btn .icon-sun,
.theme-toggle-btn .icon-moon { display: none; }
:root:not([data-theme="dark"]) .theme-toggle-btn .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle-btn .icon-sun { display: block; }

/* When system is dark and no explicit theme is set, show sun */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) .theme-toggle-btn .icon-sun { display: block; }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .theme-toggle-btn .icon-moon { display: none; }
}

/* ——— Search Modal ——— */
.search-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  align-items: flex-start;
  justify-content: center;
  padding: 72px 16px 40px;
}
.search-modal.open { display: flex; }

@media (prefers-color-scheme: dark) {
  .search-modal { background: rgba(0, 0, 0, .72); }
}

.search-modal-inner {
  width: 100%;
  max-width: 640px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: searchReveal .14s var(--ease) both;
}

@keyframes searchReveal {
  from { opacity: 0; transform: translateY(-10px) scale(.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.search-input-wrap > svg { flex-shrink: 0; color: var(--text-3); }

.search-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  min-width: 0;
}
.search-input::placeholder { color: var(--text-3); }

.search-close-btn {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 11px;
  font-family: var(--font);
  color: var(--text-3);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--dur) var(--ease);
}
.search-close-btn:hover { background: var(--surface-2); }

/* Results list */
.search-results {
  overflow-y: auto;
  max-height: 380px;
  padding: 6px;
}
.search-results:empty { padding: 0; }

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.search-result-item:hover,
.search-result-item.selected {
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.search-result-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
  line-height: 1;
}

.search-result-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.search-result-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-title mark {
  background: transparent;
  color: var(--primary);
  font-weight: 700;
}

.search-result-section {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-snippet {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-snippet mark {
  background: transparent;
  color: var(--primary);
  font-weight: 700;
}

.search-result-arrow {
  flex-shrink: 0;
  color: var(--text-3);
}

.search-no-results {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
}

/* Footer hints */
.search-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  border-top: 1px solid var(--border-subtle);
}

.search-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-3);
}
.search-hint kbd {
  display: inline-flex;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--surface);
  color: var(--text-2);
}

/* ——— Print ——— */
@media print {
  .navbar, .sidebar, .sidebar-overlay, .menu-toggle, .navbar-actions { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .content-wrapper { padding: 0; max-width: 100%; }
  a { color: var(--text) !important; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #666; }
}

/* ——— Admin Panel ——— */
.admin-main {
  margin-left: 0 !important;
  padding-top: calc(var(--navbar-h) + 32px);
}

.admin-page {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 24px 48px;
}

.admin-access-denied {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
  color: var(--text-2);
  text-align: center;
}

.admin-access-denied svg { color: var(--text-3); }
.admin-access-denied h2 { font-size: 22px; font-weight: 600; color: var(--text); }
.admin-access-denied p  { font-size: 15px; color: var(--text-2); }

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.admin-title    { font-size: 26px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.admin-subtitle { font-size: 14px; color: var(--text-2); }

.admin-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.admin-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 20px;
}

/* Form */
.admin-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}
@media (max-width: 640px) { .admin-form-row { grid-template-columns: 1fr; } }

.admin-form-group { display: flex; flex-direction: column; gap: 6px; }
.admin-form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}
.admin-form-group input,
.admin-form-group select {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color var(--dur) var(--ease);
  width: 100%;
  box-sizing: border-box;
}
.admin-form-group input:focus,
.admin-form-group select:focus { border-color: var(--primary); }

.admin-form-actions { margin-top: 20px; }

/* Buttons */
.admin-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--dur) var(--ease), opacity var(--dur);
  white-space: nowrap;
}
.admin-btn:hover { background: var(--primary-hover); color: #fff; text-decoration: none; }
.admin-btn:disabled { opacity: .55; cursor: not-allowed; }

.admin-btn-secondary {
  background: var(--surface-2);
  color: var(--text);
}
.admin-btn-secondary:hover { background: var(--border); color: var(--text); }

.admin-btn-danger {
  background: #dc2626;
}
.admin-btn-danger:hover { background: #b91c1c; }

.admin-btn-sm { padding: 5px 12px; font-size: 12px; }

/* Messages */
.admin-msg {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.admin-msg-success { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.admin-msg-error   { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }

/* Table */
.admin-table-wrap { overflow-x: auto; }
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.admin-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
}
.admin-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }

.admin-username { font-weight: 500; }

/* Role badges */
.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.role-admin  { background: rgba(0,113,227,.12); color: var(--primary); }
.role-editor { background: rgba(147,51,234,.12); color: #7c3aed; }
.role-user   { background: var(--surface-2);     color: var(--text-2); }

/* Source badges */
.source-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  font-weight: 500;
}
.source-built-in { background: var(--surface-2); color: var(--text-3); }
.source-dynamic  { background: rgba(22,163,74,.10); color: #16a34a; }

.admin-note {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.5;
}
.admin-note svg { flex-shrink: 0; margin-top: 1px; }
.admin-note code { font-family: var(--font-mono); font-size: 11px; }
.admin-note-inline { font-size: 12px; color: var(--text-3); }
