/* ==========================================================================
   Cachly Documentation — stylesheet
   Modern, polished docs theme (sidebar · content · on-page TOC) with
   light/dark support, a mobile off-canvas drawer, and Cachly-green accents.
   ========================================================================== */

:root {
  /* Brand */
  --cachly-green: #31a350;
  --cachly-green-strong: #2a8f45;
  --cachly-green-soft: rgba(49, 163, 80, 0.12);

  /* Light theme */
  --bg: #ffffff;
  --bg-subtle: #f7f8fa;
  --bg-sidebar: #fbfcfd;
  --bg-code: #f4f5f7;
  --bg-elevated: #ffffff;
  --border: #e6e8eb;
  --border-strong: #d4d8dd;
  --text: #1a1f24;
  --text-secondary: #515861;
  --text-muted: #79818b;
  --accent: var(--cachly-green);
  --accent-strong: var(--cachly-green-strong);
  --accent-soft: var(--cachly-green-soft);
  --link: #1f7a3a;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.10);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.18);

  /* Layout */
  --header-h: 60px;
  --sidebar-w: 280px;
  --toc-w: 232px;
  --content-max: 760px;
  --radius: 10px;
  --radius-sm: 7px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

html[data-theme="dark"] {
  --bg: #0e1116;
  --bg-subtle: #161b22;
  --bg-sidebar: #0f1318;
  --bg-code: #161b22;
  --bg-elevated: #161b22;
  --border: #242b33;
  --border-strong: #313a44;
  --text: #e7ebef;
  --text-secondary: #aab2bc;
  --text-muted: #79818b;
  --accent: #4bc16c;
  --accent-strong: #5fd07e;
  --accent-soft: rgba(75, 193, 108, 0.14);
  --link: #6fd58c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

/* ---------- Header ---------------------------------------------------- */
.doc-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.doc-header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  white-space: nowrap;
}
.doc-header .brand:hover { text-decoration: none; }
.brand-logo {
  height: 28px;
  width: auto;
  display: block;
}
.brand-sub {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 13px;
  border-left: 1px solid var(--border-strong);
  padding-left: 10px;
  margin-left: 2px;
}
.header-spacer { flex: 1; }

.search-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  min-width: 240px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.search-trigger:hover { border-color: var(--accent); }
.search-trigger .kbd-hint {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  padding: 1px 6px;
  background: var(--bg);
}
.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 17px;
}
.icon-btn:hover { border-color: var(--accent); color: var(--text); }
.menu-toggle { display: none; }

/* ---------- Layout shell --------------------------------------------- */
.doc-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  max-width: 1480px;
  margin: 0 auto;
  padding-top: var(--header-h);
}

/* ---------- Sidebar --------------------------------------------------- */
.doc-sidebar {
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 24px 14px 60px 20px;
  border-right: 1px solid var(--border);
  background: var(--bg-sidebar);
}
.nav-group { margin-bottom: 22px; }
.nav-group-title {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 10px 8px;
}
.nav-link {
  display: block;
  padding: 7px 10px;
  margin: 1px 0;
  border-radius: 7px;
  font-size: 14.5px;
  color: var(--text-secondary);
  line-height: 1.35;
}
.nav-link:hover { background: var(--bg-subtle); color: var(--text); text-decoration: none; }
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}
.nav-link .pro-tag {
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: var(--cachly-green);
  border-radius: 4px;
  padding: 0 5px;
  margin-left: 6px;
  vertical-align: 1px;
}

/* ---------- Content --------------------------------------------------- */
.doc-content {
  min-width: 0;
  padding: 36px 52px 100px;
}
.doc-article { max-width: var(--content-max); }

.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }

.doc-content h1 {
  font-size: 34px;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}
.doc-lead {
  font-size: 18px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0 0 32px;
}
.doc-content h2 {
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 44px 0 14px;
  padding-top: 6px;
}
.doc-content h3 {
  font-size: 18px;
  font-weight: 650;
  margin: 30px 0 10px;
}
.doc-content h4 {
  font-size: 15.5px;
  font-weight: 700;
  margin: 22px 0 8px;
  color: var(--text-secondary);
}
.doc-content h2 .anchor,
.doc-content h3 .anchor {
  opacity: 0;
  margin-left: 8px;
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.8em;
}
.doc-content h2:hover .anchor,
.doc-content h3:hover .anchor { opacity: 1; }

.doc-content p { margin: 0 0 16px; }
.doc-content ul, .doc-content ol { margin: 0 0 16px; padding-left: 24px; }
.doc-content li { margin: 6px 0; }
.doc-content li > ul, .doc-content li > ol { margin: 6px 0; }

.doc-content code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--text);
}
pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.55;
  margin: 0 0 20px;
}
pre code { font-family: var(--font-mono); }

kbd {
  font-family: var(--font);
  font-size: 12.5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 7px;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}

/* Path / UI breadcrumb inline (e.g. More ▸ Settings ▸ Map) */
.ui-path {
  font-weight: 600;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 1px 7px;
  font-size: 0.92em;
  white-space: nowrap;
}

/* ---------- Callouts -------------------------------------------------- */
.callout {
  display: flex;
  gap: 12px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 0 0 20px;
  background: var(--bg-subtle);
  font-size: 15px;
}
.callout .callout-icon { font-size: 18px; line-height: 1.5; flex-shrink: 0; }
.callout .callout-body { min-width: 0; }
.callout .callout-body > :last-child { margin-bottom: 0; }
.callout-title { font-weight: 700; margin-bottom: 2px; }
.callout.note    { border-left-color: #3b82f6; }
.callout.tip     { border-left-color: var(--cachly-green); }
.callout.warning { border-left-color: #e0a106; }
.callout.danger  { border-left-color: #dc2626; background: rgba(220, 38, 38, .07); }
.callout.pro     { border-left-color: var(--cachly-green); background: var(--accent-soft); }

/* ---------- Pro badge ------------------------------------------------- */
.pro-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(135deg, var(--cachly-green), var(--cachly-green-strong));
  border-radius: 5px;
  padding: 1px 7px;
  vertical-align: 2px;
}

/* ---------- Tables ---------------------------------------------------- */
.doc-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 22px;
  font-size: 14.5px;
}
.doc-content th, .doc-content td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.doc-content th {
  font-weight: 650;
  background: var(--bg-subtle);
  border-bottom-color: var(--border-strong);
}
.doc-content tr:last-child td { border-bottom: none; }
.doc-content table { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

/* ---------- Cards (home) ---------------------------------------------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
  margin: 0 0 28px;
}
.card {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.card:hover {
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}
.card .card-emoji { font-size: 24px; }
.card .card-title { font-weight: 700; color: var(--text); margin: 8px 0 4px; font-size: 16px; }
.card .card-desc { font-size: 14px; color: var(--text-secondary); line-height: 1.5; }

/* ---------- Screen-mock figure --------------------------------------- */
.screen-fig {
  margin: 0 0 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-subtle);
}
.screen-fig .screen-cap {
  font-size: 13px;
  color: var(--text-muted);
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.screen-fig pre {
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
}

/* ---------- Screenshots ---------------------------------------------- */
.shots {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin: 0 0 30px;
}
figure.shot { margin: 0; width: 248px; max-width: 100%; }
figure.shot img {
  width: 100%;
  display: block;
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  background: var(--bg-subtle);
}
figure.shot figcaption {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 9px;
  text-align: center;
  line-height: 1.4;
}
@media (max-width: 520px) {
  .shots { gap: 14px; justify-content: center; }
  figure.shot { width: 46%; }
}

/* Inline article images (e.g. imported help-article screenshots) — kept to a
   consistent, modest size so the page reads like the rest of the docs. */
figure.article-img { margin: 20px 0; text-align: center; }
figure.article-img img {
  width: auto;
  max-width: 440px;
  max-height: 420px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* Wide (landscape, e.g. CarPlay) figures */
figure.shot-wide { margin: 0 0 8px; width: 100%; max-width: 520px; }
figure.shot-wide img {
  width: 100%;
  display: block;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}
figure.shot-wide figcaption {
  font-size: 13px; color: var(--text-muted); margin-top: 9px; text-align: center; line-height: 1.4;
}

/* ---------- Screen reference ----------------------------------------- */
.screen-ref { margin: 0 0 22px; }
.screen-name {
  font-size: 16.5px;
  font-weight: 650;
  margin: 26px 0 6px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  scroll-margin-top: calc(var(--header-h) + 12px);
}
.screen-class {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 7px;
}
.screen-sections { font-size: 14px; color: var(--text-secondary); margin: 0 0 10px; }
.screen-sections .seclabel { color: var(--text-muted); font-weight: 600; margin-right: 4px; }
.control-table { font-size: 14px; }
.control-table td:first-child { white-space: nowrap; width: 1%; }
.ctrl-kind { font-size: 12px; font-weight: 700; color: var(--accent-strong); letter-spacing: .01em; }
.control-table td .doaction { color: var(--text-secondary); }
.screen-empty { font-size: 13.5px; color: var(--text-muted); font-style: italic; margin: 0 0 8px; }
.ref-area-count { font-weight: 400; color: var(--text-muted); font-size: 0.7em; }

/* ---------- Prev / Next ---------------------------------------------- */
.page-nav {
  display: flex;
  gap: 16px;
  margin-top: 56px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}
.page-nav a {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color .12s, background .12s;
}
.page-nav a:hover { border-color: var(--accent); background: var(--bg-subtle); text-decoration: none; }
.page-nav .pn-label { font-size: 12px; color: var(--text-muted); display: block; }
.page-nav .pn-title { font-weight: 650; color: var(--text); }
.page-nav .next { text-align: right; }

.doc-footer {
  max-width: var(--content-max);
  margin-top: 40px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- On-page TOC ---------------------------------------------- */
.doc-toc {
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 36px 20px 60px 8px;
}
.doc-toc .toc-title {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.doc-toc a {
  display: block;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--text-muted);
  padding: 5px 12px;
  border-left: 2px solid var(--border);
}
.doc-toc a:hover { color: var(--text); text-decoration: none; }
.doc-toc a.active { color: var(--accent-strong); border-left-color: var(--accent); font-weight: 600; }
.doc-toc a.lvl-3 { padding-left: 24px; font-size: 13px; }

/* ---------- Search modal --------------------------------------------- */
.search-overlay {
  position: fixed; inset: 0;
  background: rgba(8, 12, 18, 0.5);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: none;
  padding-top: 12vh;
}
.search-overlay.open { display: block; }
.search-box {
  max-width: 580px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.search-input-row {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.search-input-row input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 17px;
  color: var(--text);
  font-family: var(--font);
}
.search-results { max-height: 56vh; overflow-y: auto; padding: 8px; }
.search-result {
  display: block;
  padding: 11px 14px;
  border-radius: 9px;
  color: var(--text);
}
.search-result:hover, .search-result.active { background: var(--accent-soft); text-decoration: none; }
.search-result .sr-title { font-weight: 600; font-size: 15px; }
.search-result .sr-crumb { font-size: 12.5px; color: var(--text-muted); }
.search-result .sr-snip { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.search-empty { padding: 28px; text-align: center; color: var(--text-muted); font-size: 14px; }
.search-foot {
  display: flex; gap: 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}

/* ---------- Mobile drawer backdrop ----------------------------------- */
.scrim {
  position: fixed; inset: 0;
  background: rgba(8, 12, 18, 0.45);
  z-index: 90;
  display: none;
}
.scrim.open { display: block; }

/* ---------- Responsive ------------------------------------------------ */
@media (max-width: 1180px) {
  .doc-shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .doc-toc { display: none; }
  .doc-content { padding: 36px 40px 100px; }
}

@media (max-width: 860px) {
  :root { --header-h: 56px; }
  .doc-shell { grid-template-columns: minmax(0, 1fr); }
  .menu-toggle { display: grid; }
  .search-trigger { min-width: 0; }
  .search-trigger .search-label, .search-trigger .kbd-hint { display: none; }
  .search-trigger { width: 38px; padding: 0; justify-content: center; }
  .brand-sub { display: none; }

  .doc-sidebar {
    position: fixed;
    top: var(--header-h); bottom: 0; left: 0;
    width: 86%;
    max-width: 320px;
    height: auto;
    transform: translateX(-105%);
    transition: transform .24s ease;
    z-index: 95;
    box-shadow: var(--shadow-lg);
  }
  .doc-sidebar.open { transform: translateX(0); }
  .doc-content { padding: 24px 20px 80px; }
  .doc-content h1 { font-size: 28px; }
  .doc-lead { font-size: 16.5px; }
  .page-nav { flex-direction: column; }
}

@media (min-width: 861px) {
  .scrim { display: none !important; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

/* ---------- Feedback / issue reporting -------------------------------- */
.feedback-box {
  margin: 48px 0 8px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
}
.feedback-text { font-size: 14.5px; color: var(--text-secondary); margin-bottom: 14px; }
.feedback-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn-feedback {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.btn-feedback:hover { border-color: var(--accent); color: var(--accent-strong); text-decoration: none; }
.feedback-browse { font-size: 13.5px; margin-left: 4px; }

/* ---------- Inline SVG icons (replacing emoji) ---------------------- */
.icon-btn svg { width: 18px; height: 18px; display: block; }
.search-trigger .search-ico { width: 17px; height: 17px; flex-shrink: 0; }
.search-input-row .search-ico { width: 18px; height: 18px; color: var(--text-muted); flex-shrink: 0; }
.callout .callout-icon svg { width: 18px; height: 18px; display: block; }
.card .card-emoji svg { width: 26px; height: 26px; color: var(--accent); }
