/* ==========================================================================
   UBIK Help Portal - Premium Modern Design System (styles/modern.css)
   Brand Identity: Augmensys (Vibrant Orange Accent #ff8700, Headings: Dosis, Body: Inter)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Dosis:wght@400;500;600;700&family=Inter:wght@400;500;600;700&display=swap');

/* Brand Design Variables */
:root {
  --font-display: 'Dosis', sans-serif;
  --font-body: 'Inter', sans-serif;

  /* Brand Accent: Augmensys Orange */
  --brand-primary: #ff8700;
  --brand-gradient: linear-gradient(135deg, #ff9f3b 0%, #ff5500 100%);
  --brand-glow: rgba(255, 135, 0, 0.15);

  /* Light Theme Variables (Subtle Warm Glowing Mesh) */
  --bg-main: radial-gradient(circle at 85% 15%, rgba(255, 135, 0, 0.04) 0%, transparent 40%),
              radial-gradient(circle at 15% 85%, rgba(255, 135, 0, 0.02) 0%, transparent 40%),
              #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-sidebar: rgba(255, 255, 255, 0.8);
  --border-color: rgba(226, 232, 240, 0.8);
  --border-darker: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --hover-bg: rgba(241, 245, 249, 0.6);
  --active-bg: rgba(255, 135, 0, 0.08);
  --active-text: #e07300;
  --code-bg: #f1f5f9;
  
  --scrollbar-track: #f1f5f9;
  --scrollbar-thumb: #cbd5e1;
}

/* Dark Theme Variables (Futuristic Glowing Dark Mesh) */
[data-theme="dark"] {
  --bg-main: radial-gradient(circle at 85% 15%, rgba(255, 135, 0, 0.08) 0%, transparent 45%),
              radial-gradient(circle at 15% 85%, rgba(255, 135, 0, 0.05) 0%, transparent 45%),
              #030712;
  --bg-card: rgba(15, 23, 42, 0.7);
  --bg-sidebar: rgba(11, 15, 25, 0.8);
  --border-color: rgba(30, 41, 59, 0.5);
  --border-darker: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --hover-bg: rgba(30, 41, 59, 0.5);
  --active-bg: rgba(255, 135, 0, 0.12);
  --active-text: #ff9d24;
  --code-bg: #1e293b;
  
  --scrollbar-track: #0f172a;
  --scrollbar-thumb: #334155;
}

/* Core Settings */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

body {
  font-family: var(--font-body);
  background: var(--bg-main) !important; /* Forces the beautiful glowing mesh background */
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

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

/* Scrollbar customization */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--brand-primary);
}

/* Layout Grid */
.portal-container {
  display: grid;
  grid-template-columns: 310px 1fr;
  grid-template-rows: 64px 1fr;
  grid-template-areas: 
    "header header"
    "sidebar main";
  height: 100vh;
  width: 100vw;
}

/* Header with Glassmorphism */
.portal-header {
  grid-area: header;
  background-color: var(--bg-sidebar);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
  box-shadow: 0 1px 2px rgba(0,0,0,0.01);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-logo {
  height: 38px;
  width: 38px;
  background: var(--brand-gradient);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px var(--brand-glow);
}

.brand-logo img {
  height: 24px;
  width: 24px;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  text-transform: lowercase;
  letter-spacing: 0.01em;
  color: var(--text-main);
}

.brand-name span {
  color: var(--brand-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Search Box (Trigger) */
.search-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--hover-bg);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13.5px;
  color: var(--text-muted);
  cursor: pointer;
  width: 260px;
  transition: all 0.2s ease;
}

.search-trigger:hover {
  border-color: var(--brand-primary);
  background-color: var(--bg-card);
  box-shadow: 0 0 0 3px var(--brand-glow);
}

.search-shortcut {
  margin-left: auto;
  font-size: 11px;
  background-color: var(--border-darker);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: bold;
}

/* Theme Toggle Button */
.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border-color);
  padding: 8px;
  border-radius: 50%;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
  border-color: var(--brand-primary);
  background-color: var(--hover-bg);
}

.theme-toggle-btn svg {
  width: 18px;
  height: 18px;
}

.sun-icon { display: block; }
.moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }

/* Sidebar with Glassmorphism */
.portal-sidebar {
  grid-area: sidebar;
  background-color: var(--bg-sidebar);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-search {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-size: 13.5px;
  outline: none;
  transition: all 0.2s ease;
}

.sidebar-search-input:focus {
  border-color: var(--brand-primary);
  background-color: var(--bg-card);
  box-shadow: 0 0 0 3px var(--brand-glow);
}

/* Sidetoc Tree Structure */
.sidetoc {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
}

.sidetoc ul {
  list-style: none;
}

.sidetoc .level1 {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Base style for sidebar tree items */
.sidetoc li {
  position: relative;
}

/* Sidebar lists indentation and structural lines */
.sidetoc .level2, .sidetoc .level3, .sidetoc .level4 {
  display: none;
  margin-left: 12px;
  padding-left: 10px;
  border-left: 1px dashed var(--border-color);
  margin-top: 4px;
  margin-bottom: 4px;
}

.sidetoc li.expanded > .level2,
.sidetoc li.expanded > .level3,
.sidetoc li.expanded > .level4 {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Folder structure style (nodes with children) */
.sidetoc .expand-stub {
  position: absolute;
  left: 8px;
  top: 9px;
  width: 14px;
  height: 14px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='9 18 15 12 9 6'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  transition: transform 0.2s ease;
  z-index: 2;
}

/* Rotate expand stub arrow when folder is expanded */
.sidetoc li.expanded > .expand-stub {
  transform: rotate(90deg);
}

/* Beautiful tree node anchors styling */
.sidetoc a {
  font-size: 13.5px;
  color: var(--text-main);
  padding: 8px 12px 8px 14px; /* default padding for leaf nodes (no arrow) */
  border-radius: 8px;
  display: block;
  font-weight: 500;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}

/* Sibling selector: If an <a> is preceded by an .expand-stub (meaning it has children/folders), indent it more to leave room for the arrow */
.sidetoc span.expand-stub + a {
  padding-left: 28px;
}

.sidetoc a:hover {
  background-color: var(--hover-bg);
  color: var(--brand-primary);
}

/* Active Page Highlights */
.sidetoc li.active-page > a {
  background-color: var(--active-bg);
  color: var(--active-text) !important;
  font-weight: 600;
  box-shadow: inset 4px 0 0 var(--brand-primary);
  border-radius: 0 8px 8px 0;
}

/* Filter Hide styling */
.sidetoc li.filtered-out {
  display: none !important;
}

/* Main Content Area */
.portal-main {
  grid-area: main;
  display: grid;
  grid-template-columns: 1fr 260px;
  overflow: hidden;
  position: relative;
}

.portal-main.no-outline {
  grid-template-columns: 1fr;
}

/* Dynamic Content Pane styles */
.content-pane {
  overflow-y: auto;
  padding: 40px 48px;
  display: flex;
  flex-direction: column;
}

/* CRITICAL FIX: Iframe Container Mode (Removes borders, margins, double scrollbars completely) */
.content-pane.iframe-mode {
  padding: 0 !important;
  overflow: hidden !important;
  background-color: var(--bg-card);
}

.content-pane.iframe-mode #reader-content {
  height: 100% !important;
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
}

.iframe-reader {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Reader View styling (Served SPA Mode) */
.reader-container {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}

/* Outline (Dynamic Right Sidebar) with Glassmorphism */
.outline-pane {
  border-left: 1px solid var(--border-color);
  background-color: var(--bg-sidebar);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 40px 20px;
  overflow-y: auto;
}

.outline-title {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.outline-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.outline-item a {
  font-size: 13px;
  color: var(--text-muted);
  display: block;
  line-height: 1.4;
  padding: 6px 12px;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.outline-item a:hover {
  color: var(--brand-primary);
  background-color: var(--hover-bg);
}

.outline-item.active a {
  color: var(--brand-primary);
  font-weight: 600;
  background-color: var(--active-bg);
}

/* Search Modal (Spotlight style Command Palette) */
.search-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(9, 13, 22, 0.4);
  backdrop-filter: blur(12px);
  z-index: 100;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 100px;
}

.search-modal-overlay.active {
  display: flex;
}

.search-modal {
  width: 100%;
  max-width: 640px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.15);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 520px;
  animation: modalSlide 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlide {
  from {
    transform: translateY(-20px) scale(0.97);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.search-modal-header {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding: 16px 20px;
  gap: 12px;
}

.search-modal-icon svg {
  width: 20px;
  height: 20px;
  color: var(--brand-primary);
}

.search-modal-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 16px;
  background: transparent;
  color: var(--text-main);
}

.search-modal-close {
  background-color: var(--hover-bg);
  border: 1px solid var(--border-color);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
}

.search-results {
  overflow-y: auto;
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.search-result-group-title {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 8px 12px 4px;
}

.search-result-item {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.search-result-item:hover, 
.search-result-item.selected {
  background-color: var(--hover-bg);
}

.search-result-item.selected {
  box-shadow: inset 4px 0 0 var(--brand-primary);
}

.search-result-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-result-title mark {
  background-color: rgba(255, 135, 0, 0.2);
  color: var(--brand-primary);
  font-weight: bold;
  border-radius: 2px;
}

.search-result-namespace {
  font-size: 11px;
  color: var(--text-muted);
  background-color: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
}

.search-result-summary {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

.search-result-summary mark {
  background-color: rgba(255, 135, 0, 0.2);
  color: var(--brand-primary);
  border-radius: 2px;
}

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

/* Loading spinner */
.loader-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spinner 0.8s linear infinite;
  margin: 100px auto;
}

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

/* Responsiveness */
@media (max-width: 992px) {
  .portal-container {
    grid-template-columns: 260px 1fr;
  }
  .outline-pane {
    display: none;
  }
  .portal-main {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .portal-container {
    grid-template-columns: 1fr;
    grid-template-areas: 
      "header"
      "main";
  }
  .portal-sidebar {
    display: none;
  }
}
