/* TabulaKit shared framework — baseline stylesheet.
   Served statically (public/) and linked from the Base layout, so it loads
   deterministically in both dev and build (no reliance on Astro's dev-mode CSS
   injection, which is fragile inside the embedded preview iframe). A project's
   customization/theme/theme.css is injected after this and overrides it.

   One cohesive palette drives two layouts:
     - portal  — top-nav, centered column, frosted header + footer (modeled on
                 tnman-2026-portal)
     - sidebar — left docs nav with a branded header (modeled on the Mojo docs
                 site, @mojo/static-site-ui)
   Both share a teal primary (links, active states, brand) and a warm accent
   (section headings), the common ground between the two references. Light is the
   default; the toggle (top-right) flips data-theme on <html> and the shell sets
   the initial value from the Kit's default-preview-theme (TABKIT_PREVIEW_THEME). */

:root {
  /* color-scheme paints the browser canvas to match, so page-to-page navigation
     never flashes the wrong background. */
  color-scheme: light;

  --bg: #ffffff;
  --fg: #1b2330;
  --muted: #5b6573;
  --border: #e5e8ec;

  --surface: #f7f8fa; /* sidebar / header fill */
  --surface-2: #eef1f5; /* hover */
  --surface-3: #e8edf2;

  --primary: #1f7078; /* teal — links, active nav, brand */
  --primary-strong: #195a60;
  --primary-soft: #e4f2f3; /* active-nav background */

  --heading: #c2410c; /* warm vermilion — h2 + section labels */

  --accent-dot: #ea580c; /* portal brand dot */

  --code-bg: #f5f6f8;
  --code-inline-bg: #eef1f5;

  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  --radius-sm: 7px;
  --content-max: 820px;
  --portal-max: 900px;
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
    Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
    monospace;
}

/* Navy dark theme (tnman-flavored). Every preview ships light + dark. */
html[data-theme='dark'] {
  color-scheme: dark;

  --bg: #0b1220;
  --fg: #e7ecf5;
  --muted: #94a1ba;
  --border: #25304a;

  --surface: #121b30;
  --surface-2: #1a2742;
  --surface-3: #1c2742;

  --primary: #4fd1d9;
  --primary-strong: #6fe0e7;
  --primary-soft: rgba(79, 209, 217, 0.14);

  --heading: #fb8a3a;

  --accent-dot: #f97316;

  --code-bg: #0f1830;
  --code-inline-bg: #18233c;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

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

/* Astro's view-transition route announcer is for screen readers only — keep it
   functional but visually hidden so it doesn't add a scrollbar or show the page
   title at the bottom on navigation. */
.astro-route-announcer {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --- Typography -------------------------------------------------------------- */
article {
  max-width: var(--content-max);
}

article > :first-child {
  margin-top: 0;
}

h1,
h2,
h3,
h4 {
  line-height: 1.25;
  margin: 1.6em 0 0.6em;
  font-weight: 700;
}
h1 {
  font-size: 2rem;
  letter-spacing: -0.01em;
}
h2 {
  font-size: 1.4rem;
  color: var(--heading);
}
h3 {
  font-size: 1.15rem;
}
h4 {
  font-size: 1rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

p {
  margin: 0.85em 0;
}

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

ul,
ol {
  padding-left: 1.4em;
}
li + li {
  margin-top: 0.25em;
}

strong {
  font-weight: 650;
}

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

code {
  font-family: var(--font-mono);
  background: var(--code-inline-bg);
  padding: 0.12em 0.38em;
  border-radius: 4px;
  font-size: 0.88em;
}

pre {
  background: var(--code-bg);
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: auto;
  line-height: 1.5;
}
pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
}

blockquote {
  margin: 1em 0;
  padding: 0.4em 1em;
  border-left: 3px solid var(--primary);
  background: var(--surface);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--muted);
}
blockquote p {
  margin: 0.3em 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 0.95rem;
}
th,
td {
  border: 1px solid var(--border);
  padding: 0.5em 0.7em;
  text-align: left;
  vertical-align: top;
}
th {
  background: var(--surface-2);
  font-weight: 650;
  border-bottom: 2px solid var(--border);
}
/* Zebra striping for scanability on wide tables. */
tbody tr:nth-child(2n) td {
  background: var(--surface);
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

/* --- Form fields ------------------------------------------------------------
   Themed inputs so forms in content never render as white-on-white on dark
   themes (the browser default when a page sets a dark background but leaves the
   native input unstyled). All palette-driven, so every theme covers forms for
   free. Checkbox/radio/range/color/file keep native chrome (just accent-color). */
input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='color']):not([type='file']),
textarea,
select {
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5em 0.65em;
  max-width: 100%;
}
textarea {
  min-height: 6em;
}
input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.75;
}
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}
input[type='checkbox'],
input[type='radio'],
input[type='range'] {
  accent-color: var(--primary);
}

/* --- Small inline extras (themed for completeness) -------------------------- */
::selection {
  background: var(--primary-soft);
  color: var(--fg);
}
mark {
  background: var(--primary-soft);
  color: var(--fg);
  padding: 0 0.2em;
  border-radius: 3px;
}
kbd {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0.05em 0.4em;
}

/* --- Light/dark toggle (fixed, both layouts) --------------------------------- */
#tk-theme-toggle {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 50;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.95rem;
  cursor: pointer;
  line-height: 1;
  box-shadow: var(--shadow-1);
}
#tk-theme-toggle:hover {
  color: var(--fg);
  border-color: var(--primary);
}
/* Show the icon for the mode you'd switch TO. */
.tk-when-dark {
  display: none;
}
.tk-when-light {
  display: inline;
}
html[data-theme='dark'] .tk-when-dark {
  display: inline;
}
html[data-theme='dark'] .tk-when-light {
  display: none;
}

/* ============================================================================
   SIDEBAR layout — docs (modeled on the Mojo docs site)
   ============================================================================ */
.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  height: 56px;
  flex-shrink: 0;
  padding: 0 1.1rem;
  border-bottom: 1px solid var(--border);
}
/* In-drawer close (X). Hidden on wide screens; shown in the mobile media query. */
.sidebar-close {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
}
.sidebar-close svg {
  width: 1.1rem;
  height: 1.1rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.2px;
  color: var(--primary-strong);
  text-decoration: none;
}
.sidebar-brand > span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-brand:hover {
  text-decoration: none;
}

/* Optional site icon (manifest `icon`) beside the brand, in both layouts. */
.brand-icon {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  object-fit: contain;
  border-radius: 50%;
}

.sidebar nav {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.9rem 0.75rem 1.5rem;
}

/* Thin, themed scrollbars across the rendered site (#981) — thumb in the
   heading color (brand chrome) over a subtle --surface-2 track, so both the
   foreground and background read as themed rather than browser-default. The
   portal nav opts out below (scrollbar-width: none) and keeps winning on
   specificity. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--heading) var(--surface-2);
}
*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
*::-webkit-scrollbar-thumb {
  background-color: var(--heading);
  border-radius: 3px;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: var(--primary);
}
*::-webkit-scrollbar-track {
  background: var(--surface-2);
}
*::-webkit-scrollbar-corner {
  background: var(--surface-2);
}

/* Thin sidebar scrollbar, matching the docs reference. */
.sidebar nav::-webkit-scrollbar {
  width: 6px;
}
.sidebar nav::-webkit-scrollbar-thumb {
  background-color: var(--heading);
  border-radius: 3px;
}
.sidebar nav {
  scrollbar-width: thin;
}

/* Nav links — used for both <a> pages and <button> folder labels. */
.sidebar nav .nav-link {
  display: block;
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.4;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.sidebar nav .nav-link:hover {
  background: var(--surface-2);
  color: var(--fg);
  text-decoration: none;
}
.sidebar nav .nav-link.active {
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 600;
}

/* Section header: a static, uppercase label (the COMPANY / PRODUCTS pattern). */
.nav-section {
  margin-top: 1.25rem;
}
.nav-section:first-child {
  margin-top: 0.25rem;
}
.nav-section-label {
  padding: 0 0.6rem;
  margin-bottom: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--heading);
}

/* Collapsible group: a row (link or folder label + chevron) and its children. */
.nav-row {
  display: flex;
  align-items: center;
  gap: 0.1rem;
}
.nav-row .nav-link {
  flex: 1;
  min-width: 0;
}
.nav-expander {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.nav-expander:hover {
  background: var(--surface-2);
  color: var(--fg);
}
.nav-expander svg {
  width: 1rem;
  height: 1rem;
  transition: transform 0.15s ease;
}
.nav-group.open > .nav-row > .nav-expander svg {
  transform: rotate(90deg);
}
.nav-children {
  display: none;
  margin-left: 0.7rem;
  padding-left: 0.4rem;
  border-left: 1px solid var(--border);
}
.nav-group.open > .nav-children {
  display: block;
}

.content {
  padding: 2.75rem 2.5rem 5rem;
  min-width: 0;
}
.content article {
  margin: 0 auto;
}
/* Docs layout leads with a warm page title, like the reference Handbook. */
.content h1 {
  color: var(--heading);
}

/* Hamburger + scrim: only meaningful on small screens (rules in the media query
   below). The sidebar is static and always visible on wide screens. */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 0.6rem;
  left: 0.6rem;
  z-index: 61;
  width: 2.25rem;
  height: 2.25rem;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  box-shadow: var(--shadow-1);
}
.sidebar-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
}
.sidebar-scrim {
  display: none;
}

/* ============================================================================
   PORTAL layout — top nav (modeled on tnman-2026-portal)
   ============================================================================ */
.portal {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.portal-header {
  position: sticky;
  top: 0;
  z-index: 30;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(150%) blur(10px);
  -webkit-backdrop-filter: saturate(150%) blur(10px);
}

.portal-header-inner {
  max-width: var(--portal-max);
  margin: 0 auto;
  padding: 0.8rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.portal-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  font-size: 1.05rem;
  color: var(--fg);
  text-decoration: none;
  white-space: nowrap;
}
.portal-brand:hover {
  text-decoration: none;
}
.portal-brand .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent-dot);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-dot) 24%, transparent);
  flex-shrink: 0;
}

/* Nav is its own full-width band below the brand header (tnman-style), not
   inline in the header. */
.portal-nav {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.portal-nav-inner {
  max-width: var(--portal-max);
  margin: 0 auto;
  padding: 0.4rem 1.5rem;
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.portal-nav-inner::-webkit-scrollbar {
  display: none;
}
.portal-nav a {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 0.95rem;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.portal-nav a:hover {
  background: var(--surface-2);
  color: var(--fg);
  text-decoration: none;
}
.portal-nav a.active {
  background: var(--surface-2);
  color: var(--fg);
}

.portal-main {
  flex: 1;
  width: 100%;
  max-width: var(--portal-max);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
  font-size: 1.0625rem; /* 17px — the reference reads a touch larger */
}
.portal-main article {
  max-width: none;
}

/* Portal headings follow the tnman palette: warm-orange sections and teal
   sub-headings. */
.portal h2 {
  color: var(--accent-dot);
}
.portal h3 {
  color: var(--primary);
}

.portal-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1.1rem 1.5rem;
}

/* ============================================================================
   HYBRID layout — portal-style top nav of the top-level sections + a secondary
   sidebar of the active section's sub-pages. Reuses .portal-header/.portal-nav
   for the top bar and .sidebar/.content below. The top bar is non-sticky here so
   the sticky secondary sidebar owns the viewport height without offset math.
   ============================================================================ */
.hybrid {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.hybrid .portal-header,
.hybrid .portal-nav {
  position: static;
}
.hybrid-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}
/* No active section (e.g. home / a top-level page) — content spans full width. */
.hybrid-body.no-secondary {
  grid-template-columns: minmax(0, 1fr);
}

/* --- Responsive ------------------------------------------------------------- */
@media (max-width: 720px) {
  /* Docs sidebar becomes a slide-in drawer, closed by default. The hamburger
     opens it; the scrim (or following a link) closes it. */
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar-toggle {
    display: inline-flex;
  }
  /* When the drawer is open the in-drawer X is the control; hide the hamburger. */
  .layout.sidebar-open .sidebar-toggle {
    display: none;
  }
  .sidebar-close {
    display: inline-flex;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    max-width: 82vw;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-1);
  }
  .layout.sidebar-open .sidebar {
    transform: none;
  }
  .layout.sidebar-open .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0, 0, 0, 0.45);
  }
  /* Make room for the fixed hamburger above the page title. */
  .content {
    padding: 3.5rem 1.25rem 4rem;
  }

  .portal-header-inner {
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
  }
  .portal-main {
    padding: 1.75rem 1.25rem 4rem;
  }

  /* Hybrid: the secondary sidebar becomes a slide-in drawer (same pattern as the
     docs sidebar); the top nav stacks above the content. The hamburger sits on
     the right so it clears the brand on the left. */
  .hybrid-body {
    grid-template-columns: 1fr;
  }
  .hybrid .sidebar-toggle {
    left: auto;
    right: 0.6rem;
  }
  .hybrid.sidebar-open .sidebar-toggle {
    display: none;
  }
  .hybrid .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    max-width: 82vw;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-1);
  }
  .hybrid.sidebar-open .sidebar {
    transform: none;
  }
  .hybrid.sidebar-open .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0, 0, 0, 0.45);
  }
}
