/* ============================================================
   TEMPLATE A — "SLATE"
   Modern dark-sidebar documentation style
   ============================================================ */

/* ── Custom Properties ── */
:root {
  --sidebar-bg:      #1e2a3a;
  --sidebar-hover:   #263548;
  --sidebar-active:  #2d3f52;
  --sidebar-border:  #2d3f52;
  --accent:          #3b82f6;
  --accent-hover:    #2563eb;
  --accent-light:    rgba(59,130,246,.12);
  --sidebar-text:    #cbd5e1;
  --sidebar-muted:   #64748b;
  --logo-text:       #f1f5f9;

  --content-bg:      #f8fafc;
  --surface:         #ffffff;
  --border:          #e2e8f0;
  --text:            #1e293b;
  --text-muted:      #64748b;
  --heading:         #0f172a;

  --topbar-bg:       #ffffff;
  --topbar-border:   #e2e8f0;

  --sidebar-w:       280px;
  --topbar-h:        56px;
  --radius:          8px;
  --radius-lg:       12px;
  --transition:      0.2s ease;

  --shadow-sm:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:       0 4px 12px rgba(0,0,0,.12);
  --shadow-lg:       0 8px 30px rgba(0,0,0,.18);
}

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

html { height: 100%; font-size: 16px; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--content-bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

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

/* ── App Shell ── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ══════════════════════════════
   SIDEBAR
══════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  z-index: 40;
  transition: transform var(--transition);
}

/* Top logo + search block */
.sidebar-top {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
  flex-shrink: 0;
}

.logo-text-wrap {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.logo-company {
  font-size: 15px;
  font-weight: 700;
  color: var(--logo-text);
  letter-spacing: -.02em;
}

.logo-subtitle {
  font-size: 11px;
  color: var(--sidebar-muted);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* Search */
.search-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--sidebar-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius);
  padding: 8px 10px 8px 32px;
  font-size: 13px;
  color: var(--sidebar-text);
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}

.search-input::placeholder { color: var(--sidebar-muted); }

.search-input:focus {
  border-color: var(--accent);
  background: rgba(59,130,246,.08);
}

/* Search results dropdown */
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #1a2332;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 320px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}

.search-results.visible { display: block; }

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.05);
  transition: background var(--transition);
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--sidebar-hover); }

.search-result-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--logo-text);
  margin-bottom: 2px;
}

.search-result-section {
  font-size: 11px;
  color: var(--sidebar-muted);
}

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

.search-no-results {
  padding: 14px;
  text-align: center;
  color: var(--sidebar-muted);
  font-size: 13px;
}

/* ── Nav Tree ── */
.nav-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--sidebar-border) transparent;
}

.nav-tree::-webkit-scrollbar { width: 4px; }
.nav-tree::-webkit-scrollbar-track { background: transparent; }
.nav-tree::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 2px; }

/* Section groups */
.nav-section {
  margin-bottom: 2px;
}

.nav-section-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 16px;
  background: none;
  border: none;
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
  letter-spacing: -.01em;
}

.nav-section-toggle:hover {
  background: var(--sidebar-hover);
  color: var(--logo-text);
}

.nav-section-icon {
  font-size: 15px;
  flex-shrink: 0;
}

.nav-section-label { flex: 1; }

.nav-chevron {
  width: 14px;
  height: 14px;
  color: var(--sidebar-muted);
  transition: transform var(--transition);
  flex-shrink: 0;
}

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

/* Subsection items */
.nav-subsections {
  list-style: none;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}

.nav-section.open .nav-subsections {
  max-height: 600px;
}

.nav-sub-item {
  position: relative;
}

.nav-sub-link {
  display: block;
  padding: 7px 16px 7px 40px;
  font-size: 13px;
  color: var(--sidebar-muted);
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  user-select: none;
}

.nav-sub-link::before {
  content: '';
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--sidebar-muted);
  opacity: .5;
  transition: background var(--transition), opacity var(--transition);
}

.nav-sub-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.nav-sub-link:hover::before { opacity: 1; }

.nav-sub-link.active {
  color: var(--accent);
  background: var(--accent-light);
  font-weight: 500;
}

.nav-sub-link.active::before {
  background: var(--accent);
  opacity: 1;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
  font-size: 11px;
  color: var(--sidebar-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.admin-footer-link {
  color: var(--sidebar-muted);
  opacity: 0.35;
  display: flex;
  align-items: center;
  text-decoration: none;
  transition: opacity 0.2s;
}
.admin-footer-link:hover { opacity: 0.8; }

/* ══════════════════════════════
   MAIN CONTENT AREA
══════════════════════════════ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Top bar */
.topbar {
  height: var(--topbar-h);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

/* Hamburger (mobile) */
.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
}

.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: transform var(--transition), opacity var(--transition);
}

.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Breadcrumb */
.breadcrumb {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
}

.breadcrumb-section {
  color: var(--text-muted);
  white-space: nowrap;
}

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

.breadcrumb-page {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Ask AI button */
.ask-ai-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}

.ask-ai-btn:hover { background: var(--accent-hover); }
.ask-ai-btn:active { transform: scale(.98); }

.ask-ai-btn svg {
  width: 15px;
  height: 15px;
}

/* Scrollable content container */
.content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 40px 48px 60px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.content-scroll::-webkit-scrollbar { width: 6px; }
.content-scroll::-webkit-scrollbar-track { background: transparent; }
.content-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Content article */
.content {
  max-width: 780px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 48px 56px;
  box-shadow: var(--shadow-sm);
  outline: none;
  min-height: 200px;
}

/* Content typography */
.content h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 8px;
  letter-spacing: -.03em;
  line-height: 1.25;
}

.content h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--heading);
  margin: 28px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -.02em;
}

.content h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--heading);
  margin: 20px 0 6px;
}

.content p {
  line-height: 1.75;
  color: var(--text);
  margin-bottom: 14px;
  font-size: 15px;
}

.content ul, .content ol {
  margin: 12px 0 16px 20px;
}

.content li {
  line-height: 1.7;
  margin-bottom: 6px;
  font-size: 15px;
  color: var(--text);
}

.content strong {
  font-weight: 600;
  color: var(--heading);
}

.content em { font-style: italic; }

.content blockquote {
  border-left: 3px solid var(--accent);
  background: var(--accent-light);
  padding: 12px 16px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 16px 0;
  font-size: 14px;
  color: var(--text-muted);
}

.content blockquote p { margin: 0; color: var(--text-muted); font-size: 14px; }

.content code {
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* Tables */
.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
}

.content th {
  background: var(--content-bg);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--heading);
}

.content td {
  padding: 9px 12px;
  border: 1px solid var(--border);
  color: var(--text);
}

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

/* Images always fit within the content column */
.content img {
  max-width: 100% !important;
  height: auto !important;
  display: block;
  border-radius: 6px;
  margin: 12px 0;
}

/* Horizontal rule */
.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

/* Content divider after h1 */
.content h1 + p { color: var(--text-muted); }

/* Empty / loading states */
.content-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--text-muted);
  font-size: 14px;
  gap: 10px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

/* Pagination */
.pagination {
  max-width: 780px;
  margin: 24px auto 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.page-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  font-family: inherit;
}

.page-btn:hover {
  background: var(--content-bg);
  border-color: var(--accent);
  color: var(--accent);
}

.page-btn svg { width: 14px; height: 14px; }

.page-btn-label {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.page-btn-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

/* ══════════════════════════════
   CHAT DRAWER
══════════════════════════════ */
.chat-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 49;
  backdrop-filter: blur(2px);
}

.chat-backdrop.visible { display: block; }

.chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  height: 100vh;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(.32,.72,0,1);
  border-left: 1px solid var(--border);
}

.chat-drawer.open { transform: translateX(0); }

.chat-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: #fff;
}

.chat-header-text h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--logo-text);
  margin-bottom: 2px;
}

.chat-header-text p {
  font-size: 12px;
  color: var(--sidebar-muted);
  margin: 0;
}

.chat-close {
  background: rgba(255,255,255,.1);
  border: none;
  border-radius: var(--radius);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--sidebar-text);
  transition: background var(--transition);
  flex-shrink: 0;
}

.chat-close:hover { background: rgba(255,255,255,.2); }
.chat-close svg { width: 16px; height: 16px; }

/* Chat messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.chat-welcome {
  text-align: center;
  padding: 20px 10px;
}

.chat-welcome-icon {
  font-size: 36px;
  margin-bottom: 10px;
}

.chat-welcome p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 16px;
}

.chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.suggestion-btn {
  padding: 8px 14px;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: border-color var(--transition), background var(--transition);
}

.suggestion-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

/* Message bubbles */
.chat-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.chat-msg.user { flex-direction: row-reverse; }

.chat-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.chat-msg.ai .chat-avatar { background: var(--sidebar-bg); }
.chat-msg.user .chat-avatar { background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; }

.chat-bubble {
  max-width: calc(100% - 50px);
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
}

.chat-msg.ai .chat-bubble {
  background: var(--content-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg);
}

.chat-msg.user .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-lg) 4px var(--radius-lg) var(--radius-lg);
}

.chat-bubble p { margin: 0 0 8px; }
.chat-bubble p:last-child { margin: 0; }
.chat-bubble strong { font-weight: 600; }
.chat-bubble ul, .chat-bubble ol { margin: 6px 0 6px 16px; }
.chat-bubble li { margin-bottom: 4px; }

/* Typing indicator */
.chat-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* API warning */
.chat-api-warning {
  display: none;
  align-items: center;
  gap: 8px;
  margin: 0 16px;
  padding: 10px 12px;
  background: #fff8ed;
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  font-size: 12px;
  color: #92400e;
}

.chat-api-warning.visible { display: flex; }
.chat-api-warning svg { width: 16px; height: 16px; flex-shrink: 0; }
.chat-api-warning code { background: rgba(0,0,0,.06); padding: 1px 4px; border-radius: 3px; }

/* Chat input */
.chat-input-wrap {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: var(--surface);
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--content-bg);
  outline: none;
  transition: border-color var(--transition);
}

.chat-input:focus { border-color: var(--accent); background: var(--surface); }

.chat-send-btn {
  width: 42px;
  height: 42px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}

.chat-send-btn:hover { background: var(--accent-hover); }
.chat-send-btn:disabled { background: var(--border); cursor: not-allowed; }
.chat-send-btn svg { width: 16px; height: 16px; }

/* Sidebar mobile backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 39;
}

.sidebar-backdrop.visible { display: block; }

/* ══════════════════════════════
   RESPONSIVE
══════════════════════════════ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    z-index: 40;
  }

  .sidebar.open { transform: translateX(0); }
  .hamburger { display: flex; }

  .content-scroll { padding: 24px 20px 48px; }
  .content { padding: 32px 28px; }
}

@media (max-width: 600px) {
  .chat-drawer { width: 100%; }
  .ask-ai-btn span { display: none; }
  .topbar { padding: 0 16px; }
}

/* ══════════════════════════════
   MANUAL LOGIN OVERLAY
══════════════════════════════ */
.manual-login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.manual-login-overlay.hidden { display: none; }

.manual-login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.manual-login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  color: var(--accent);
}
.manual-login-logo h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
  line-height: 1.3;
}
.manual-login-logo h1 span {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
}

.manual-login-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0 0 24px;
}

.manual-pw-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  box-sizing: border-box;
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}
.manual-pw-input:focus { border-color: var(--accent); }

.manual-login-error {
  color: #f87171;
  font-size: 0.82rem;
  margin-bottom: 12px;
}
.manual-login-error.hidden { display: none; }

.manual-login-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.manual-login-btn:hover { opacity: 0.9; }
.manual-login-btn:disabled { opacity: 0.6; cursor: default; }
