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

:root {
  --rh-red: #ee0000;
  --rh-red-dark: #a30000;
  --rh-teal: #009596;
  --rh-gold: #f0ab00;
  --rh-green: #3e8635;
  --bg: #0d1117;
  --bg-surface: #161b22;
  --bg-card: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --sidebar-w: 260px;
}

html { scroll-behavior: smooth; scroll-padding-top: 24px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }

/* Sidebar */
.sidebar {
  position: fixed; top: 0; left: 0; width: var(--sidebar-w); height: 100vh;
  background: var(--bg-surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 20px 0; z-index: 100;
}
.sidebar-title {
  font-size: 1.1rem; font-weight: 700; color: #fff; padding: 0 20px 16px;
  border-bottom: 1px solid var(--border); margin-bottom: 12px;
}
.sidebar-title span { color: var(--rh-red); }
.sidebar nav a {
  display: block; padding: 6px 20px; color: var(--text-muted);
  text-decoration: none; font-size: 0.85rem; transition: all 0.15s;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { color: #fff; background: rgba(255,255,255,0.04); }
.sidebar nav a.active { color: var(--rh-gold); border-left-color: var(--rh-red); background: rgba(238,0,0,0.06); }
.sidebar nav .section-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); padding: 14px 20px 4px; font-weight: 600;
}

/* Main content */
.main { margin-left: var(--sidebar-w); padding: 32px 48px 80px; max-width: 960px; }

h1 { font-size: 2rem; color: #fff; margin-bottom: 8px; }
h2 {
  font-size: 1.5rem; color: var(--rh-gold); margin: 48px 0 16px;
  padding-bottom: 8px; border-bottom: 2px solid var(--rh-red);
}
h3 { font-size: 1.1rem; color: var(--rh-teal); margin: 24px 0 10px; }

h1, h2, h3 { position: relative; }
.heading-anchor {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 400;
  margin-right: 0.3em;
}
.heading-anchor:hover { color: var(--rh-red); }

p { margin-bottom: 12px; color: var(--text); }

.subtitle { color: var(--text-muted); font-size: 1.1rem; margin-bottom: 20px; }

/* Badges */
.badge-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 24px; }
.badge {
  background: var(--bg-card); border: 1px solid var(--rh-red); border-radius: 16px;
  padding: 4px 14px; font-size: 0.8rem; color: var(--rh-gold); font-weight: 600;
}

/* Cards */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 16px 0; }
.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px;
}
.card h3 { margin-top: 0; }

/* Tables */
table { width: 100%; border-collapse: collapse; margin: 12px 0 20px; font-size: 0.9rem; }
th { background: var(--rh-red-dark); color: #fff; padding: 8px 12px; text-align: left; font-weight: 600; }
td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

/* Lists */
ul, ol { margin: 8px 0 16px 20px; }
li { margin-bottom: 4px; }

/* Code */
code { font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace; font-size: 0.88em; background: rgba(255,255,255,0.06); padding: 2px 6px; border-radius: 4px; }
pre { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; overflow-x: auto; margin: 12px 0 20px; }
pre code { background: none; padding: 0; font-size: 0.85rem; }

/* Dir tree */
.dir-tree { font-family: monospace; font-size: 0.85rem; line-height: 1.6; background: var(--bg-card); padding: 14px 18px; border-radius: 8px; border: 1px solid var(--border); margin: 10px 0; }

/* Callout boxes */
.callout {
  background: rgba(238,0,0,0.07); border-left: 4px solid var(--rh-red);
  padding: 12px 16px; margin: 16px 0; border-radius: 0 8px 8px 0; font-size: 0.9rem;
}
.callout-teal { background: rgba(0,149,150,0.08); border-left-color: var(--rh-teal); }

/* Flow steps */
.flow-steps { margin: 12px 0; }
.flow-step { display: flex; align-items: center; gap: 12px; padding: 8px 0; font-size: 0.9rem; }
.flow-step .num {
  background: var(--rh-red); color: #fff; border-radius: 50%;
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  font-weight: 700; flex-shrink: 0; font-size: 0.8rem;
}
.flow-step .num.teal { background: var(--rh-teal); }

/* Security layers */
.security-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.security-item {
  display: flex; gap: 12px; padding: 14px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 8px; font-size: 0.88rem;
}
.security-item .icon { font-size: 1.3rem; flex-shrink: 0; }
.security-item strong { color: var(--rh-gold); }

/* Glossary */
.glossary-term {
  cursor: help; color: var(--rh-teal); text-decoration: underline;
  text-decoration-style: dotted; text-underline-offset: 3px;
  position: relative;
}
.glossary-term:hover .glossary-tip,
.glossary-term:focus .glossary-tip {
  display: block;
}
.glossary-tip {
  display: none; position: absolute; bottom: 100%; left: 0;
  background: var(--bg-card); border: 1px solid var(--rh-teal); border-radius: 8px;
  padding: 10px 14px; width: 320px; font-size: 0.82rem; color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4); z-index: 200; line-height: 1.5;
  cursor: default; text-decoration: none;
}

/* Glossary section */
.glossary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.glossary-card {
  padding: 12px 16px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; font-size: 0.88rem;
}
.glossary-card strong { color: var(--rh-gold); display: block; margin-bottom: 4px; font-size: 0.95rem; }
.glossary-card a { color: var(--rh-teal); font-size: 0.8rem; }

/* Mermaid */
.mermaid { margin: 20px 0; text-align: center; }
.diagram-wrap { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin: 16px 0; overflow-x: auto; }

/* Scroll spy highlight for sections */
section[id] { scroll-margin-top: 24px; }

/* Back to top */
.back-to-top {
  position: fixed; bottom: 24px; right: 24px; background: var(--rh-red);
  color: #fff; border: none; border-radius: 50%; width: 40px; height: 40px;
  cursor: pointer; font-size: 1.2rem; display: none; z-index: 100;
  align-items: center; justify-content: center;
}
.back-to-top.visible { display: flex; }

/* Responsive */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 20px; }
  .two-col { grid-template-columns: 1fr; }
  .security-grid { grid-template-columns: 1fr; }
  .glossary-grid { grid-template-columns: 1fr; }
}
