/* ============================================================
   Stirling MILL Docs — stylesheet
   Warm, community-focused. Inspired by stirlingmill.ca.
   ============================================================ */

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

:root {
  /* Brand palette — warm neutrals with a teal accent */
  --color-brand:        #2a7d6f;   /* teal — primary accent */
  --color-brand-dark:   #1f5e54;   /* hover state */
  --color-brand-light:  #e8f4f2;   /* tinted backgrounds */

  --color-bg:           #ffffff;
  --color-surface:      #f7f6f3;   /* sidebar / footer bg */
  --color-border:       #e2ddd6;
  --color-text:         #2c2c2c;
  --color-text-muted:   #6b6560;
  --color-link:         #2a7d6f;
  --color-link-hover:   #1f5e54;

  --color-header-bg:    #1f3832;   /* deep forest green */
  --color-header-text:  #f0ede8;
  --color-footer-bg:    #1f3832;
  --color-footer-text:  #c8c2ba;

  --font-body:    Georgia, "Times New Roman", serif;
  --font-ui:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono:    "JetBrains Mono", "Fira Code", monospace;

  --sidebar-width:  260px;
  --header-height:  56px;
  --content-max:    740px;
  --radius:         6px;
}

/* ── Reset & base ── */
html { font-size: 16px; line-height: 1.7; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--color-link); }
a:hover { color: var(--color-link-hover); }

img { max-width: 100%; height: auto; border-radius: var(--radius); }

/* ── Site header ── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-header-bg);
  color: var(--color-header-text);
  height: var(--header-height);
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 100%;
}

.site-header__logo {
  font-family: var(--font-ui);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-header-text);
  text-decoration: none;
  letter-spacing: 0.01em;
}

.site-header__logo:hover { color: #ffffff; }

/* ── Header search ── */
.site-header__search {
  position: relative;
  flex: 1;
  max-width: 360px;
  margin: 0 1.5rem;
}

.search-input {
  width: 100%;
  padding: 0.4rem 0.875rem;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  color: var(--color-header-text);
  outline: none;
  transition: background 0.15s, border-color 0.15s;
}

.search-input::placeholder { color: rgba(255,255,255,0.45); }

.search-input:focus {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.4);
}

.search-results {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  z-index: 200;
  max-height: 420px;
  overflow-y: auto;
}

.search-results__item a {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.625rem 1rem;
  text-decoration: none;
  color: var(--color-text);
  transition: background 0.1s;
}

.search-results__item a:hover,
.search-results__item--focused a {
  background: var(--color-brand-light);
}

.search-results__title {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
}

.search-results__snippet {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-results__snippet mark {
  background: #fff3b0;
  color: var(--color-text);
  border-radius: 2px;
  padding: 0 1px;
}

.search-results__empty {
  padding: 0.75rem 1rem;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  list-style: none;
}

.site-header__nav a {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: #a8c5bf;
  text-decoration: none;
  transition: color 0.15s;
}

.site-header__nav a:hover { color: #ffffff; }

/* ── Main layout: sidebar + content ── */
.site-layout {
  display: flex;
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ── Sidebar details wrapper ── */
.sidebar-details {
  height: 100%;
}

/* Desktop: hide the summary — sidebar is always open via [open] attribute in HTML */
.sidebar-details > summary {
  display: none;
}

/* ── Sidebar ── */
.site-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1.5rem 0;
  /* stick below header */
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0 0.75rem;
  gap: 0.125rem;
}

.sidebar-nav__home {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  text-decoration: none;
  padding: 0.35rem 0.625rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}

.sidebar-nav__home:hover { background: var(--color-border); color: var(--color-text); }

.sidebar-nav__link {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-text);
  text-decoration: none;
  padding: 0.3rem 0.625rem;
  border-radius: var(--radius);
  display: block;
  line-height: 1.4;
  transition: background 0.1s;
}

.sidebar-nav__link:hover { background: var(--color-brand-light); color: var(--color-brand-dark); }

.sidebar-nav__link--active {
  background: var(--color-brand-light);
  color: var(--color-brand);
  font-weight: 600;
}

/* Folder accordion */
.sidebar-nav__folder {
  margin: 0.125rem 0;
}

.sidebar-nav__folder-label {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0.35rem 0.625rem;
  border-radius: var(--radius);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  user-select: none;
}

.sidebar-nav__folder-label::-webkit-details-marker { display: none; }

.sidebar-nav__folder-label::before {
  content: '▶';
  font-size: 0.6rem;
  transition: transform 0.15s;
  color: var(--color-text-muted);
}

details.sidebar-nav__folder[open] > .sidebar-nav__folder-label::before {
  transform: rotate(90deg);
}

.sidebar-nav__folder-label:hover { background: var(--color-border); color: var(--color-text); }

.sidebar-nav__children {
  display: flex;
  flex-direction: column;
  padding-left: 0.75rem;
  border-left: 2px solid var(--color-border);
  margin-left: 0.875rem;
  margin-top: 0.125rem;
  gap: 0.125rem;
}

/* ── Page content ── */
.site-content {
  flex: 1;
  min-width: 0;
  padding: 2.5rem 4rem;
}

.page-title {
  font-family: var(--font-ui);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 1.5rem 0;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--color-brand);
  line-height: 1.3;
}

/* ── Breadcrumbs ── */
.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}

.breadcrumbs a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.breadcrumbs a:hover { color: var(--color-brand); }

.breadcrumbs__sep {
  color: var(--color-border);
  margin: 0 0.1rem;
}

.breadcrumbs__current {
  color: var(--color-text);
  font-weight: 500;
}

/* ── Edit source link ── */
.doc-edit {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--color-border);
}

.doc-edit a {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-decoration: none;
}

.doc-edit a:hover {
  color: var(--color-brand);
}

/* ── Page meta (last updated + commit hash) ── */
.page-meta {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  margin: -0.75rem 0 1.75rem;
}

.page-meta__date {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.page-meta__hash {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-border);
  text-decoration: none;
  transition: color 0.15s;
}

.page-meta__hash:hover {
  color: var(--color-text-muted);
}

/* ── Doc body typography ── */
.doc-body { max-width: var(--content-max); }

.doc-body p {
  margin: 0 0 1rem 0;
}

.doc-body h2 {
  font-family: var(--font-ui);
  font-size: 1.375rem;
  font-weight: 700;
  margin: 2rem 0 0.625rem;
  color: var(--color-text);
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--color-border);
}

.doc-body h3 {
  font-family: var(--font-ui);
  font-size: 1.125rem;
  font-weight: 700;
  margin: 1.5rem 0 0.5rem;
  color: var(--color-text);
}

.doc-body h4, .doc-body h5, .doc-body h6 {
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
  margin: 1.25rem 0 0.375rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.doc-body ul, .doc-body ol {
  padding-left: 1.75rem;
  margin: 0 0 1rem 0;
}

.doc-body li { margin: 0.25rem 0; }

/* Nested lists — indent and vary marker per level */
.doc-body ul ul, .doc-body ol ol,
.doc-body ul ol, .doc-body ol ul {
  padding-left: 1.75rem;
  margin: 0.25rem 0;
}

.doc-body ul ul ul,
.doc-body ol ol ol { padding-left: 1.75rem; }

.doc-body ul           { list-style-type: disc; }
.doc-body ul ul        { list-style-type: circle; }
.doc-body ul ul ul     { list-style-type: square; }

.doc-body ol           { list-style-type: decimal; }
.doc-body ol ol        { list-style-type: lower-alpha; }
.doc-body ol ol ol     { list-style-type: lower-roman; }

.doc-body a { color: var(--color-link); }
.doc-body a:hover { color: var(--color-link-hover); }

.doc-body strong { font-weight: 700; }
.doc-body em { font-style: italic; }
.doc-body u { text-decoration: underline; }
.doc-body s { text-decoration: line-through; color: var(--color-text-muted); }

.doc-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

.doc-body pre {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  font-size: 0.875rem;
}

.doc-body blockquote {
  margin: 1rem 0;
  padding: 0.625rem 1rem;
  border-left: 3px solid var(--color-brand);
  background: var(--color-brand-light);
  color: var(--color-text-muted);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.doc-body img {
  margin: 1rem 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.doc-body br { display: block; content: ''; margin: 0.25rem 0; }

/* Index intro text */
.intro {
  font-size: 1.05rem;
  color: var(--color-text-muted);
  max-width: var(--content-max);
  margin-bottom: 1rem;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.8em;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 0.1em 0.4em;
  box-shadow: 0 1px 0 var(--color-border);
}

/* ── Footer ── */
.site-footer {
  background: var(--color-footer-bg);
  color: var(--color-footer-text);
  padding: 2rem 1.5rem 1rem;
  margin-top: auto;
}

.site-footer__inner {
  display: flex;
  gap: 3rem;
  max-width: 1200px;
  margin: 0 auto;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.site-footer__col {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  font-family: var(--font-ui);
  font-size: 0.875rem;
}

.site-footer__col strong { color: #ffffff; font-size: 0.9rem; }

.site-footer__col a {
  color: #a8c5bf;
  text-decoration: none;
}

.site-footer__col a:hover { color: #ffffff; }

.site-footer__copy {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: #6b7e7b;
  max-width: 1200px;
  margin: 0.875rem auto 0;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .site-layout { flex-direction: column; }

  /* Sidebar becomes a collapsible panel on mobile */
  .site-sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    padding: 0;
    overflow: visible;
  }

  .sidebar-nav { padding: 0; }

  /* Sidebar <details> on mobile */
  .sidebar-details {
    border-bottom: 1px solid var(--color-border);
  }

  /* Override desktop forced-open rule — let mobile control visibility */
  .sidebar-details > .sidebar-nav {
    display: none !important;
  }

  .sidebar-details[open] > .sidebar-nav {
    display: flex !important;
  }

  .sidebar-details > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.25rem;
    font-family: var(--font-ui);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
    list-style: none;
    user-select: none;
    background: var(--color-surface);
  }

  .sidebar-details > summary::-webkit-details-marker { display: none; }

  .sidebar-details > summary::after {
    content: '▾';
    font-size: 1.25rem;
    line-height: 1;
    color: var(--color-text-muted);
    transition: transform 0.2s;
  }

  .sidebar-details[open] > summary::after {
    transform: rotate(180deg);
  }

  .sidebar-details .sidebar-nav {
    padding: 0.5rem 0.75rem 1rem;
  }

  .site-content {
    padding: 1.5rem 1.25rem;
  }

  .site-footer__inner {
    flex-direction: column;
    gap: 1.5rem;
  }

  /* Hide desktop search bar at mobile widths */
  .site-header__search { display: none; }
}

@media (max-width: 480px) {
  .site-content { padding: 1rem 0.875rem; }
  .page-title { font-size: 1.375rem; }
  .site-header__inner { padding: 0 1rem; }
}

/* ── Mobile search toggle button ── */
/* Visible by default; hidden on desktop via min-width query below */
.search-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-header-text);
  padding: 0.375rem;
  border-radius: var(--radius);
  margin-left: auto;
  margin-right: 0.5rem;
}

.search-toggle:hover { color: #ffffff; }

.search-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Hide toggle on desktop where the full search bar is visible */
@media (min-width: 901px) {
  .search-toggle { display: none; }
}

/* ── Search overlay (mobile) ── */
.search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.6);
  padding: 1rem;
  align-items: flex-start;
  justify-content: center;
}

.search-overlay.is-open {
  display: flex;
}

.search-overlay__inner {
  background: var(--color-bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  margin-top: 3rem;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.search-overlay__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
}

.search-overlay__input {
  flex: 1;
  border: none;
  outline: none;
  font-family: var(--font-ui);
  font-size: 1rem;
  color: var(--color-text);
  background: transparent;
}

.search-overlay__input::placeholder { color: var(--color-text-muted); }

/* Hide native browser clear button — we have our own close button */
.search-overlay__input::-webkit-search-cancel-button { display: none; }
.search-overlay__input::-ms-clear { display: none; }

.search-overlay__close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 1.25rem;
  padding: 0.25rem;
  line-height: 1;
}

.search-overlay__close:hover { color: var(--color-text); }

.search-overlay__results {
  /* Override desktop .search-results absolute positioning */
  position: static !important;
  box-shadow: none !important;
  border: none !important;
  border-top: 1px solid var(--color-border) !important;
  border-radius: 0 !important;
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  max-height: 60vh;
  overflow-y: auto;
}

/* Allow inner to grow to fit results */
.search-overlay__inner {
  overflow: visible;
  display: flex;
  flex-direction: column;
}

.search-overlay__results .search-results__item a {
  padding: 0.75rem 1rem;
}

.search-overlay__results .search-results__empty {
  padding: 1rem;
  text-align: center;
}
