/* ============================================================================
   DagSmith Documentation — Dark Theme Stylesheet
   ============================================================================ */

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

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --bg-card: #21262d;
  --border: #30363d;
  --border-light: #3d444d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #656d76;
  --accent-blue: #58a6ff;
  --accent-purple: #bc8cff;
  --accent-green: #3fb950;
  --accent-red: #ff7b72;
  --accent-yellow: #d29922;
  --accent-orange: #f0883e;
  --accent-cyan: #39d2c0;
  --gradient: linear-gradient(135deg, #58a6ff, #bc8cff);
  --sidebar-width: 280px;
  --content-max: 920px;
  --header-height: 60px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
  --radius: 6px;
  --radius-lg: 10px;
  --transition: 0.2s ease;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 24px);
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
}

/* --- Header --- */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 20px;
}

.header-logo .logo-icon {
  width: 28px;
  height: 28px;
  background: var(--gradient);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  transition: color var(--transition);
}
.header-link:hover { color: var(--text-primary); }

.header-version {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
  transition: transform 0.3s ease;
}

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

.sidebar-search {
  padding: 0 16px 12px;
}

.sidebar-search input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition);
}
.sidebar-search input::placeholder { color: var(--text-muted); }
.sidebar-search input:focus { border-color: var(--accent-blue); }

.nav-section { margin-bottom: 4px; }

.nav-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  cursor: default;
  user-select: none;
}

.nav-link {
  display: block;
  padding: 6px 16px 6px 28px;
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-link:hover {
  color: var(--text-primary);
  background: rgba(88, 166, 255, 0.04);
}

.nav-link.active {
  color: var(--accent-blue);
  border-left-color: var(--accent-blue);
  background: rgba(88, 166, 255, 0.08);
}

.nav-link.sub {
  padding-left: 40px;
  font-size: 13px;
}

.nav-page-indicator {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
}
.nav-page-indicator.current {
  background: var(--accent-blue);
}

/* --- Main Content --- */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--header-height);
  padding: 40px 48px 80px;
  max-width: calc(var(--content-max) + 96px + var(--sidebar-width));
  min-height: calc(100vh - var(--header-height));
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 { color: var(--text-primary); font-weight: 600; line-height: 1.3; }

h1 {
  font-size: 32px;
  margin-bottom: 8px;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-subtitle {
  font-size: 18px;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-weight: 400;
}

h2 {
  font-size: 24px;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 20px;
  margin-top: 32px;
  margin-bottom: 12px;
}

h4 {
  font-size: 16px;
  margin-top: 24px;
  margin-bottom: 8px;
  color: var(--accent-blue);
}

p { margin-bottom: 16px; color: var(--text-secondary); }
p strong { color: var(--text-primary); }

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

ul, ol {
  margin-bottom: 16px;
  padding-left: 24px;
  color: var(--text-secondary);
}
li { margin-bottom: 6px; }
li strong { color: var(--text-primary); }

/* --- Section anchors --- */
section[id] {
  scroll-margin-top: calc(var(--header-height) + 24px);
}

/* --- Divider --- */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* --- Code (inline) --- */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--accent-cyan);
}

/* --- Code Blocks --- */
.code-block {
  position: relative;
  margin-bottom: 20px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.code-lang {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 4px;
}
.copy-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-light);
  background: var(--bg-tertiary);
}
.copy-btn.copied {
  color: var(--accent-green);
  border-color: var(--accent-green);
}

.code-block pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  background: var(--bg-tertiary);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-primary);
  tab-size: 2;
}

.code-block pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

/* Syntax highlighting */
.syn-key { color: #79c0ff; }
.syn-str { color: #a5d6ff; }
.syn-comment { color: #8b949e; font-style: italic; }
.syn-bool, .syn-null { color: #ff7b72; }
.syn-num { color: #d2a8ff; }
.syn-op { color: #ff7b72; }
.syn-kw { color: #ff7b72; font-weight: 600; }
.syn-fn { color: #d2a8ff; }
.syn-var { color: #ffa657; }
.syn-tag { color: #7ee787; }

/* --- Tables --- */
.table-wrap {
  overflow-x: auto;
  margin-bottom: 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  background: var(--bg-card);
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 16px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover { background: rgba(88, 166, 255, 0.03); }

tbody td code {
  font-size: 0.85em;
  white-space: nowrap;
}

/* --- Cards --- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: border-color var(--transition);
}
.card:hover { border-color: var(--border-light); }

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

.card-desc {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.card-icon {
  font-size: 18px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  flex-shrink: 0;
}

/* --- Badges --- */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-required { background: rgba(255, 123, 114, 0.15); color: var(--accent-red); }
.badge-optional { background: rgba(139, 148, 158, 0.15); color: var(--text-secondary); }
.badge-alias { background: rgba(188, 140, 255, 0.15); color: var(--accent-purple); }
.badge-operator { background: rgba(63, 185, 80, 0.12); color: var(--accent-green); }
.badge-sensor { background: rgba(210, 153, 34, 0.15); color: var(--accent-yellow); }
.badge-util { background: rgba(88, 166, 255, 0.12); color: var(--accent-blue); }

/* --- Info boxes --- */
.info-box {
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  font-size: 14px;
  line-height: 1.6;
  border-left: 3px solid;
}
.info-box p { margin-bottom: 8px; color: inherit; }
.info-box p:last-child { margin-bottom: 0; }

.info-box.tip {
  background: rgba(63, 185, 80, 0.08);
  border-color: var(--accent-green);
  color: var(--text-secondary);
}
.info-box.warning {
  background: rgba(210, 153, 34, 0.08);
  border-color: var(--accent-yellow);
  color: var(--text-secondary);
}
.info-box.note {
  background: rgba(88, 166, 255, 0.06);
  border-color: var(--accent-blue);
  color: var(--text-secondary);
}
.info-box strong { color: var(--text-primary); }

/* --- Feature grid (for overview) --- */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin: 24px 0;
}

.feature-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: all var(--transition);
}
.feature-item:hover {
  border-color: var(--accent-blue);
  transform: translateY(-1px);
}

.feature-icon {
  font-size: 28px;
  margin-bottom: 12px;
}

.feature-item h3 {
  font-size: 16px;
  margin-top: 0;
  margin-bottom: 8px;
}

.feature-item p {
  font-size: 14px;
  margin-bottom: 0;
}

/* --- Operator detail blocks --- */
.operator-block {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  overflow: hidden;
}

.operator-header {
  padding: 16px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.operator-header h4 {
  margin: 0;
  color: var(--text-primary);
  font-size: 16px;
}

.operator-module {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.operator-body {
  padding: 20px;
}

.operator-body p { font-size: 14px; }

/* --- Field list (key-value) --- */
.field-list {
  margin-bottom: 16px;
}

.field-item {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  align-items: baseline;
  flex-wrap: wrap;
}
.field-item:last-child { border-bottom: none; }

.field-name {
  font-family: var(--font-mono);
  color: var(--accent-blue);
  font-size: 13px;
  min-width: 180px;
  flex-shrink: 0;
}

.field-desc {
  color: var(--text-secondary);
  flex: 1;
  min-width: 200px;
}

/* --- Back to top button --- */
.back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 40px;
  height: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition);
  z-index: 40;
}
.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}
.back-to-top:hover {
  color: var(--text-primary);
  border-color: var(--accent-blue);
  transform: translateY(-2px);
}

/* --- Prev/Next navigation --- */
.page-nav {
  display: flex;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.page-nav a {
  flex: 1;
  display: block;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  transition: border-color var(--transition);
}
.page-nav a:hover { border-color: var(--accent-blue); text-decoration: none; }

.page-nav-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.page-nav-title {
  font-size: 15px;
  color: var(--accent-blue);
  font-weight: 500;
}

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

/* --- Responsive --- */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  .main-content {
    margin-left: 0;
    padding: 32px 24px 80px;
  }
  .menu-toggle { display: block; }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: rgba(0,0,0,0.5);
    z-index: 45;
  }
  .sidebar-overlay.visible { display: block; }
}

@media (max-width: 640px) {
  h1 { font-size: 26px; }
  h2 { font-size: 20px; }
  .main-content { padding: 24px 16px 60px; }
  .card-grid { grid-template-columns: 1fr; }
  .feature-grid { grid-template-columns: 1fr; }
  .page-nav { flex-direction: column; }
  .page-nav .next { text-align: left; }
  .code-block pre { font-size: 12.5px; }
  .field-item { flex-direction: column; gap: 2px; }
  .field-name { min-width: auto; }
}

/* --- Print --- */
@media print {
  .sidebar, .site-header, .menu-toggle, .back-to-top, .copy-btn, .sidebar-overlay { display: none !important; }
  .main-content { margin-left: 0; padding: 0; max-width: 100%; }
  body { background: #fff; color: #000; }
  h1, h2, h3 { color: #000; -webkit-text-fill-color: #000; }
  .code-block { border: 1px solid #ccc; }
  .code-block pre { background: #f6f6f6; color: #000; }
  a { color: #0366d6; }
}
