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

:root {
  /* Demo hospital / K2X HMS theme (matches demo-hospital.k2x.tech) */
  --brand: #4a7ab5;
  --brand-dark: #3b6294;
  --brand-light: rgba(74, 122, 181, 0.12);
  --brand-glow: rgba(74, 122, 181, 0.28);
  --bg: #fafbfc;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #5a5a5a;
  --border: #f0f1f3;
  --sidebar-bg: #0f1419;
  --sidebar-text: #cbd5e1;
  --accent: var(--brand);
  --accent-soft: var(--brand-light);
  --accent-glow: var(--brand-glow);
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.1);
  --font: 'Plus Jakarta Sans', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --topbar-h: 60px;
  --sidebar-w: 280px;
  --sidebar-collapsed-w: 68px;
  --sidebar-transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  scroll-behavior: smooth;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* Prevent global SPA link styles from breaking the manual */
.manual-shell a.nav-link {
  color: var(--sidebar-text);
  text-decoration: none;
}

.manual-shell a.nav-link:hover,
.manual-shell a.nav-link.active {
  color: #ffffff;
}

.manual-shell a.topbar-brand {
  color: inherit;
  text-decoration: none;
}

.manual-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 8px;
  border: none;
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
}

.nav-toggle span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

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

.brand-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 8px;
}

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

.brand-text strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-brand {
  text-decoration: none;
  color: inherit;
}

.topbar-page-title {
  flex: 1;
  min-width: 0;
  margin: 0 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.manual-shell.sidebar-collapsed .topbar-page-title {
  margin-left: 8px;
}

.topbar-search {
  flex: 1;
  max-width: 360px;
  margin-left: auto;
}

.topbar-search input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.156a4.5 4.5 0 1 1 0-9 4.5 4.5 0 0 1 0 9z'/%3E%3C/svg%3E") 12px center no-repeat;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.topbar-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Layout */
.manual-body {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 16px 12px;
  overflow-x: hidden;
  overflow-y: auto;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  transition: width var(--sidebar-transition);
  display: flex;
  flex-direction: column;
}

.manual-shell.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-w);
  padding: 16px 8px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  padding: 0 4px;
}

.sidebar-label {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  white-space: nowrap;
  transition: opacity var(--sidebar-transition);
}

.manual-shell.sidebar-collapsed .sidebar-label {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.sidebar-collapse-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.sidebar-collapse-btn:hover {
  background: var(--brand-light);
}

.collapse-icon {
  width: 14px;
  height: 14px;
  border-left: 2px solid #94a3b8;
  border-bottom: 2px solid #94a3b8;
  transform: rotate(45deg);
  margin-left: 3px;
  transition: transform var(--sidebar-transition);
}

.manual-shell.sidebar-collapsed .collapse-icon {
  transform: rotate(-135deg);
  margin-left: 0;
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px 6px 0;
  font-size: 11px;
  color: #64748b;
  line-height: 1.5;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.manual-shell.sidebar-collapsed .sidebar-foot .nav-text {
  opacity: 0;
  height: 0;
  overflow: hidden;
  display: block;
}

.sidebar-foot code {
  font-family: var(--mono);
  font-size: 10px;
  color: #94a3b8;
}

.nav-group-title {
  margin: 14px 0 6px;
  padding: 0 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #64748b;
  white-space: nowrap;
  transition: opacity var(--sidebar-transition);
}

.manual-shell.sidebar-collapsed .nav-group-title {
  opacity: 0;
  height: 0;
  margin: 0;
  overflow: hidden;
}

.nav-list {
  list-style: none;
  margin: 0 0 4px;
  padding: 0;
}

.nav-list > li {
  margin: 2px 0;
}

.nav-link {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(74, 122, 181, 0.28);
  color: #ffffff;
}

.nav-icon {
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  margin-top: 6px;
  border-radius: 50%;
  background: #475569;
}

.nav-link.active .nav-icon {
  background: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

.nav-text {
  flex: 1;
  min-width: 0;
  transition: opacity var(--sidebar-transition);
}

.manual-shell.sidebar-collapsed .nav-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
  position: absolute;
}

.manual-shell.sidebar-collapsed .nav-link {
  justify-content: center;
  padding: 10px 8px;
}

.manual-shell.sidebar-collapsed .nav-icon {
  margin-top: 0;
  width: 8px;
  height: 8px;
}

/* Page prev/next */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  max-width: 820px;
  margin: 48px auto 0;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.page-nav-link {
  flex: 1;
  max-width: 48%;
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.page-nav-link:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.page-nav-next {
  text-align: right;
  margin-left: auto;
}

.page-nav-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.page-nav-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.content {
  flex: 1;
  min-width: 0;
  padding: 32px 40px 80px;
  overflow-x: hidden;
}

.manual-article {
  max-width: 820px;
  margin: 0 auto;
}

/* Hero banner (overview page) */
.doc-hero {
  margin-bottom: 40px;
  padding: 32px 36px;
  border-radius: var(--radius-lg);
  background: linear-gradient(
    135deg,
    #ffffff 0%,
    #f0f6fc 45%,
    #e3eef9 100%
  );
  border: 1px solid rgba(74, 122, 181, 0.22);
  color: var(--text);
  box-shadow: var(--shadow);
}

.doc-eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--brand-dark);
}

.doc-title {
  margin: 0 0 12px;
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
  line-height: 1.2;
  color: #0f172a;
}

.doc-lead {
  margin: 0;
  font-size: 15px;
  color: #334155;
  max-width: 56ch;
  line-height: 1.65;
}

/* Typography */
.manual-article > h1:first-child {
  margin-top: 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.25;
}

.manual-article h2 {
  margin: 48px 0 16px;
  padding-top: 24px;
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
  border-top: 1px solid var(--border);
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}

.manual-article h2:first-of-type {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

.manual-article h3 {
  margin: 28px 0 12px;
  font-size: 1.15rem;
  font-weight: 600;
  color: #334155;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}

.manual-article h4 {
  margin: 20px 0 8px;
  font-size: 1rem;
  font-weight: 600;
}

.manual-article p,
.manual-article li {
  font-size: 15px;
  color: #334155;
}

.manual-article a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.manual-article a:hover {
  text-decoration: underline;
}

.manual-article ul,
.manual-article ol {
  padding-left: 1.4em;
}

.manual-article li {
  margin: 6px 0;
}

.manual-article hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

.manual-article blockquote {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--brand-dark);
}

.manual-article code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 2px 6px;
  background: #f1f5f9;
  border-radius: 4px;
  color: var(--brand-dark);
}

.manual-article pre {
  margin: 16px 0;
  padding: 16px 18px;
  background: #0f172a;
  border-radius: var(--radius);
  overflow-x: auto;
}

.manual-article pre code {
  padding: 0;
  background: none;
  color: #e2e8f0;
  font-size: 13px;
}

.manual-article pre.mermaid {
  background: transparent;
  padding: 8px 0;
  text-align: center;
}

/* Tables */
.manual-article table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 24px;
  font-size: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.manual-article th,
.manual-article td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.manual-article th {
  background: #f8fafc;
  font-weight: 600;
  color: #0f172a;
}

.manual-article tr:last-child td {
  border-bottom: none;
}

.manual-article tr:nth-child(even) td {
  background: #fafbfc;
}

/* Checklists in MD */
.manual-article input[type='checkbox'] {
  margin-right: 8px;
  accent-color: var(--accent);
}

/* Screenshot gallery */
.screenshot-gallery {
  margin: 24px 0 32px;
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.gallery-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.gallery-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.shot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.shot-card {
  margin: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f8fafc;
  transition: transform 0.2s, box-shadow 0.2s;
}

.shot-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.shot-card img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 220px;
  object-fit: cover;
  object-position: top;
  cursor: zoom-in;
  background: #e2e8f0;
}

.shot-card figcaption {
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
}

/* Lightbox */
.manual-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(6px);
  padding: 24px;
}

.manual-lightbox[hidden] {
  display: none !important;
}

.manual-lightbox__close {
  position: absolute;
  top: 20px;
  right: 24px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}

.manual-lightbox__close:hover {
  background: rgba(255, 255, 255, 0.25);
}

.manual-lightbox__inner {
  max-width: min(96vw, 1400px);
  max-height: 90vh;
  overflow: auto;
}

.manual-lightbox__img {
  display: block;
  max-width: 100%;
  max-height: 88vh;
  margin: 0 auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

/* Loading / error */
.loading-state,
.error-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error-state h2 {
  color: #dc2626;
}

/* Mermaid */
.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* Mobile */
@media (max-width: 900px) {
  .nav-toggle {
    display: flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-h);
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }

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

  .manual-shell.sidebar-collapsed .sidebar {
    width: var(--sidebar-w);
  }

  .topbar-page-title {
    display: none;
  }

  .content {
    padding: 24px 20px 60px;
  }

  .doc-hero {
    padding: 24px 22px;
  }

  .topbar-search {
    max-width: none;
    flex: 1;
  }

  .brand-sub {
    display: none;
  }
}

@media print {
  .topbar,
  .sidebar,
  .screenshot-gallery {
    display: none;
  }

  .content {
    padding: 0;
  }
}
