/* ======================================================
   rich-html-editor Documentation – Global Styles
   Industry-grade, static-docs friendly
====================================================== */

/* ---------- CSS Variables (Design Tokens) ---------- */
:root {
  --bg: #0f172a;
  --panel: #020617;
  --panel-soft: #020617cc;
  --border: #1e293b;

  --text: #e5e7eb;
  --muted: #94a3b8;
  --subtle: #64748b;

  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --success: #22c55e;
  --danger: #ef4444;

  --code-bg: #020617;
  --code-border: #1e293b;

  --radius: 12px;
  --radius-sm: 8px;
}

/* ---------- Reset & Base ---------- */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, sans-serif;
  background: linear-gradient(180deg, #020617, #0f172a);
  color: var(--text);
  line-height: 1.6;
}

/* ---------- Links ---------- */
a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--panel-soft);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.site-header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-title {
  font-size: 18px;
  font-weight: 600;
}

.site-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

/* ---------- Top Navigation ---------- */
.top-nav {
  display: flex;
  gap: 20px;
}

.top-nav a {
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
}

.top-nav a.active,
.top-nav a:hover {
  color: var(--accent);
}

/* ---------- Main Layout ---------- */
.layout {
  max-width: 1280px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 32px;
  padding: 32px 24px;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 96px;
  align-self: start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.sidebar h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--subtle);
  margin: 16px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar a {
  display: block;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
}

.sidebar a.active,
.sidebar a:hover {
  background: #020617;
  color: var(--accent);
}

/* ---------- Content Area ---------- */
.content {
  background: transparent;
}

.content h1 {
  font-size: 28px;
  margin-top: 0;
}

.content h2 {
  font-size: 22px;
  margin-top: 32px;
}

.content h3 {
  font-size: 18px;
  margin-top: 24px;
}

.content p {
  color: var(--text);
  max-width: 900px;
}

.content ul {
  padding-left: 20px;
}

.content li {
  margin-bottom: 6px;
}

/* ---------- Callouts ---------- */
.callout {
  border-left: 4px solid var(--accent);
  background: #020617;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin: 20px 0;
}

.callout.warning {
  border-color: #f59e0b;
}

.callout.danger {
  border-color: var(--danger);
}

/* ---------- Code Blocks ---------- */
pre,
code {
  font-family: "JetBrains Mono", Consolas, monospace;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
  margin: 16px 0;
}

code {
  background: #020617;
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 13px;
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 64px;
  padding: 24px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 20px 16px;
    gap: 20px;
  }

  /* Sidebar becomes an overlay panel on small screens and is toggled open/closed */
  .sidebar {
    position: fixed;
    left: 0;
    top: 72px;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    transform: translateX(-110%);
    transition: transform 240ms cubic-bezier(0.2, 0.9, 0.2, 1);
    z-index: 120;
    padding: 16px;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(2, 6, 23, 0.6);
  }

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

  /* overlay behind the sidebar when open */
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.6);
    z-index: 110;
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease-in-out;
  }

  .sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* Toggle button (fixed top-right) */
  .sidebar-toggle {
    display: inline-flex;
    position: fixed;
    top: 14px;
    right: 16px;
    z-index: 130;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(2, 6, 23, 0.6);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    backdrop-filter: blur(6px);
  }

  .sidebar-toggle:focus {
    outline: 3px solid rgba(56, 189, 248, 0.16);
    outline-offset: 2px;
  }

  /* visually hidden utility for screen readers */
  .visually-hidden {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
    border: 0;
    padding: 0;
    margin: -1px;
  }

  /* Hamburger icon */
  .sidebar-toggle {
    --hb-width: 20px;
    --hb-height: 14px;
  }

  .sidebar-toggle .hamburger {
    display: inline-block;
    width: var(--hb-width);
    height: var(--hb-height);
    position: relative;
  }

  .sidebar-toggle .hamburger span {
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform 220ms ease, opacity 180ms ease, top 220ms ease,
      bottom 220ms ease;
  }

  .sidebar-toggle .hamburger span:nth-child(1) {
    top: 0;
  }
  .sidebar-toggle .hamburger span:nth-child(2) {
    top: 50%;
    transform: translateY(-50%);
  }
  .sidebar-toggle .hamburger span:nth-child(3) {
    bottom: 0;
  }

  /* Open state: transform into X */
  .sidebar-toggle.open .hamburger span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }
  .sidebar-toggle.open .hamburger span:nth-child(2) {
    opacity: 0;
  }
  .sidebar-toggle.open .hamburger span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  /* subtle entrance animation for sidebar links */
  .sidebar.open a {
    animation: slideIn 220ms ease forwards;
    opacity: 0;
    transform: translateX(-6px);
  }
  .sidebar.open a:nth-child(1) {
    animation-delay: 60ms;
  }
  .sidebar.open a:nth-child(2) {
    animation-delay: 80ms;
  }
  .sidebar.open a:nth-child(3) {
    animation-delay: 100ms;
  }
  .sidebar.open a:nth-child(4) {
    animation-delay: 120ms;
  }
  .sidebar.open a:nth-child(5) {
    animation-delay: 140ms;
  }

  @keyframes slideIn {
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }

  /* hide the large desktop sidebar links styling when overlay is active */
  .sidebar a {
    display: block;
  }

  .site-header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .doc-search {
    width: 100%;
    order: 2;
  }

  .doc-search input {
    width: 100%;
    max-width: 480px;
    box-sizing: border-box;
  }

  .top-nav {
    order: 3;
    width: 100%;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  /* keep sidebar vertical for overlay mode; hide section headings on mobile */
  .sidebar h4 {
    display: none;
  }

  .sidebar a {
    display: block;
    padding: 8px 12px;
    border-radius: 8px;
  }
}

/* Tweak code blocks and spacing on small screens */
@media (max-width: 520px) {
  .content h1 {
    font-size: 22px;
  }
  .content h2 {
    font-size: 18px;
  }
  pre {
    font-size: 12px;
    padding: 12px;
  }
  .doc-search input {
    font-size: 13px;
  }
}

/* ================= Documentation Search ================= */

.doc-search {
  position: relative;
}

.doc-search input {
  background: #020617;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  width: 220px;
}

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

.search-results {
  position: absolute;
  top: 42px;
  right: 0;
  background: #020617;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 260px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.search-result {
  display: block;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}

.search-result:hover {
  background: rgba(56, 189, 248, 0.12);
}

.search-empty {
  padding: 12px;
  font-size: 13px;
  color: var(--muted);
}

.hidden {
  display: none;
}
.sidebar a.active {
  color: var(--accent);
  font-weight: 500;
}

/* Search highlight */
.search-result mark {
  background: rgba(56, 189, 248, 0.25);
  color: var(--text);
  padding: 0 2px;
  border-radius: 4px;
}

/* Code copy button and toolbar */
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(2, 6, 23, 0.6);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.copy-btn.copied {
  background: var(--success);
  color: #020617;
  border-color: rgba(34, 197, 94, 0.8);
}

pre {
  position: relative;
}

/* small helper toast (non-intrusive) */
.copy-toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: rgba(2, 6, 23, 0.9);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 6px 20px rgba(2, 6, 23, 0.6);
  z-index: 300;
  font-size: 13px;
  display: none;
}

.copy-toast.show {
  display: block;
  animation: fadeIn 220ms ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
