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

:root {
  --bg:        #f9fafb;
  --surface:   #ffffff;
  --border:    #e5e7eb;
  --text:      #111827;
  --muted:     #6b7280;
  --accent:    #0070d2;
  --accent-bg: #eff6ff;
  --sidebar-w: 260px;
  --topbar-h:  48px;
  --radius:    6px;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.screen { height: 100vh; }
.hidden { display: none !important; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius);
  font-size: 14px; font-weight: 500;
  padding: 8px 18px; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #005fb2; }

.icon-btn {
  background: none; border: none; cursor: pointer;
  color: var(--muted); padding: 6px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--border); color: var(--text); }

/* ── Config screen ────────────────────────────────────────── */
#config-screen {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.config-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 40px 36px;
  width: 100%; max-width: 420px;
  box-shadow: 0 4px 24px rgba(0,0,0,.07);
}
.config-card h1   { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.config-card .subtitle { color: var(--muted); margin-bottom: 24px; }

#config-form label {
  display: block; margin-bottom: 14px;
  font-size: 13px; font-weight: 500; color: var(--muted);
}
#config-form input[type=url],
#config-form input[type=password] {
  display: block; width: 100%;
  margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; color: var(--text); background: var(--surface);
}
#config-form input:focus { outline: none; border-color: var(--accent); }
.cfg-row { margin-bottom: 14px; }
.checkbox-label {
  display: flex !important; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); cursor: pointer;
}
.checkbox-label input { width: auto !important; margin: 0 !important; }
#config-form .btn-primary { width: 100%; margin-top: 6px; padding: 10px; }
.error { color: #d93025; font-size: 12px; margin-top: 8px; }

/* ArcGIS Online sign-in button */
.btn-ago {
  width: 100%; padding: 9px 14px; margin-top: 4px;
  background: #f0f4ff; color: #0070d2;
  border: 1px solid #c2d4f5; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 8px; justify-content: center;
  cursor: pointer;
}
.btn-ago:hover { background: #e0eaff; }

.token-toggle-wrap { margin-top: 10px; text-align: center; }
.link-btn {
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-size: 12px; text-decoration: underline; padding: 0;
}
.link-btn:hover { color: #005fb2; }

#cfg-token-wrap { margin-top: 10px; }
#cfg-token-wrap label {
  display: block; font-size: 13px; font-weight: 500; color: var(--muted);
}
#cfg-token-wrap input {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; background: var(--surface);
}
#cfg-token-wrap input:focus { outline: none; border-color: var(--accent); }

.signed-in-info {
  font-size: 12px; color: #1a7a3c; background: #f0faf4;
  border: 1px solid #c3e6cb; border-radius: var(--radius);
  padding: 7px 10px; margin-bottom: 8px;
}

/* Top-bar user badge */
.user-badge {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted);
  border-left: 1px solid var(--border); padding-left: 12px; margin-left: 4px;
}
#user-badge-name { font-weight: 500; color: var(--text); }

/* ── Top bar ──────────────────────────────────────────────── */
#top-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.top-left  { display: flex; align-items: center; gap: 10px; }
.top-right { display: flex; align-items: center; gap: 8px; }
.site-title { font-weight: 700; font-size: 15px; }

.search-wrap {
  position: relative; display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 8px; color: var(--muted); pointer-events: none;
}
#search-input {
  padding: 5px 10px 5px 28px;
  border: 1px solid var(--border); border-radius: 20px;
  font-size: 13px; width: 200px; background: var(--bg); color: var(--text);
}
#search-input:focus { outline: none; border-color: var(--accent); }

/* ── Layout ───────────────────────────────────────────────── */
#layout {
  display: flex;
  height: 100vh;
  padding-top: var(--topbar-h);
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  height: calc(100vh - var(--topbar-h));
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 0;
  transition: margin-left 0.2s ease;
}
#sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }

/* Sidebar portal branding */
#sidebar-branding {
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
#sidebar-thumbnail {
  width: 100%; display: block;
  border-radius: 6px;
  object-fit: cover;
  max-height: 120px;
}

/* Category group */
.nav-category {
  margin-bottom: 4px;
}
.nav-cat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
  cursor: pointer; user-select: none;
}
.nav-cat-header:hover { color: var(--text); }
.nav-cat-chevron {
  transition: transform 0.15s;
  flex-shrink: 0;
}
.nav-cat-header.collapsed .nav-cat-chevron { transform: rotate(-90deg); }

.nav-doc-list { }
.nav-doc-item {
  display: block; padding: 6px 16px 6px 28px;
  font-size: 13px; color: var(--muted);
  cursor: pointer; border-radius: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 2px solid transparent;
  transition: background 0.1s, color 0.1s;
}
.nav-doc-item:hover { background: var(--bg); color: var(--text); }
.nav-doc-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* Search results mode */
.nav-search-result {
  display: block; padding: 7px 16px;
  font-size: 13px; color: var(--muted);
  cursor: pointer;
}
.nav-search-result:hover { background: var(--bg); color: var(--text); }
.nav-search-result.active { background: var(--accent-bg); color: var(--accent); font-weight: 500; }
.nav-search-result .result-cat { font-size: 11px; color: var(--muted); }
mark { background: #fff3b0; border-radius: 2px; padding: 0 1px; }

/* ── Content area ─────────────────────────────────────────── */
#content-area {
  flex: 1; overflow-y: auto;
}

/* Landing */
#landing {
  display: flex; align-items: center; justify-content: center;
  height: 100%;
}
.landing-inner { text-align: center; color: var(--muted); }
.landing-inner svg { margin-bottom: 16px; opacity: 0.3; }
.landing-inner h2 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.landing-inner p  { font-size: 14px; }

/* Article */
#article {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 40px 80px;
}
.article-breadcrumb {
  font-size: 12px; color: var(--muted); margin-bottom: 10px;
}
#article-title {
  font-size: 28px; font-weight: 700;
  line-height: 1.25; margin-bottom: 10px;
}
.article-meta {
  font-size: 12px; color: var(--muted); margin-bottom: 32px;
  padding-bottom: 16px; border-bottom: 1px solid var(--border);
}

/* ── Quill content (read-only) ────────────────────────────── */
#article-body.ql-editor {
  padding: 0;
  font-size: 15px; line-height: 1.7;
  color: var(--text);
}
#article-body h1 { font-size: 22px; margin: 28px 0 10px; }
#article-body h2 { font-size: 18px; margin: 24px 0 8px; }
#article-body h3 { font-size: 15px; margin: 20px 0 6px; }
#article-body p  { margin-bottom: 14px; }
#article-body ul, #article-body ol { margin: 0 0 14px 24px; }
#article-body li { margin-bottom: 4px; }
#article-body blockquote {
  border-left: 3px solid var(--border);
  padding: 4px 0 4px 16px;
  color: var(--muted); margin: 16px 0;
}
#article-body pre {
  background: #f3f4f6; border-radius: 6px;
  padding: 14px 16px; overflow-x: auto;
  font-size: 13px; margin-bottom: 14px;
}
#article-body a { color: var(--accent); }
#article-body img {
  max-width: 100%; height: auto; display: block;
  margin: 16px 0; border-radius: 6px;
  border: 1px solid var(--border);
  /* Click to enlarge */
  cursor: zoom-in;
}

/* ── Lightbox ─────────────────────────────────────────────── */
#lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; cursor: zoom-out;
}
#lightbox img {
  max-width: 92vw; max-height: 90vh;
  border-radius: 6px; object-fit: contain;
  box-shadow: 0 8px 48px rgba(0,0,0,.6);
}

/* ── Loading spinner ──────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.loading-spinner {
  display: flex; justify-content: center; align-items: center;
  padding: 64px 0;
}
.loading-spinner::after {
  content: '';
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Print ────────────────────────────────────────────────── */
@media print {
  #top-bar, #sidebar { display: none !important; }
  #content-area { overflow: visible; }
  #article { max-width: 100%; padding: 0; }
  #article-body img { max-width: 100%; page-break-inside: avoid; }
  #lightbox { display: none !important; }
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 640px) {
  #sidebar { position: fixed; top: var(--topbar-h); left: 0; bottom: 0; z-index: 9; }
  #article  { padding: 24px 20px 60px; }
  #search-input { width: 140px; }
}

/* Theme colors are now injected as inline CSS custom properties on :root by
   viewer.js (applyPortalBranding). No static [data-theme] blocks needed.

   Dark themes: Quill stores color:rgb(0,0,0) on unstyled spans. When the
   background is dark the viewer adds .theme-dark to <body> so we can override
   those hardcoded black values and let --text win instead. */
.theme-dark #article-body [style*="color"] { color: inherit !important; }
