/* ==========================================================================
   Apebox Theme — global styles
   Minimal, clean base. Structure inspired by arizto_web, stripped to
   essentials. Plain CSS, no build step.
   ========================================================================== */

/* ---------------------------------------------------------------------------
   1. Design tokens
   --------------------------------------------------------------------------- */
:root {
  /* ---- Terminal TUI palette (btop-style, dark by default). The "light"
     preference maps to a light-terminal scheme in dark-mode.css. ---- */

  /* Palette: muted One Dark-style editor scheme. */
  --color-primary: #6e9fd4;
  --color-primary-hover: #87b3e2;
  /* "Paper" surface token: a raised dark surface in the TUI scheme (form
     fields in tables, range thumbs); flips to real white in light mode. */
  --color-white: #1b212c;
  --color-black: #000000;

  /* Text: soft editor foreground, not bright white. */
  --color-text-primary: #a9b2c4;
  --color-text-secondary: #7a8496;
  --color-text-muted: #545e70;
  /* Inverse-video text: dark ink on accent backgrounds. */
  --color-text-inverse: #0e1117;

  /* Background: content surface sits lighter than the chrome, like an
     editor's buffer vs its tab bar / sidebars. */
  --color-bg-primary: #151a22;
  --color-bg-secondary: #1a2029;
  --color-bg-tertiary: #232b37;
  /* Window chrome: header, nav, breadcrumb and footer bands. */
  --color-bg-chrome: #0e1117;

  /* Borders: desaturated slate. */
  --color-border-light: #232936;
  --color-border-medium: #39424f;

  /* Links: muted cyan. */
  --color-link: #68b8ca;
  --color-link-hover: #8ed2e2;

  /* State: One Dark's muted green/orange/red. */
  --color-success: #98c379;
  --color-warning: #d19a66;
  --color-error: #e06c75;

  /* Status message backgrounds (tinted). Tokenised so light mode can
     override. */
  --color-status-bg: #1e2619;
  --color-warning-bg: #2a2118;
  --color-error-bg: #2a1c1e;

  /* Spacing */
  --space-xxs: 0.25rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-xxl: 3rem;

  /* Font sizes — terminal discipline: exactly three real sizes.
     small (labels, fine print) / body (everything) / large (h1–h2 only).
     The legacy token names stay so component files need no edits. */
  --font-size-xs: 0.875rem;
  --font-size-sm: 0.875rem;
  --font-size-md: 1rem;
  --font-size-mlg: 1rem;
  --font-size-lg: 1rem;
  --font-size-xl: 1.25rem;
  --font-size-xxl: 1.25rem;

  /* Terminal grid: one row of text and the universal border-to-text inset.
     Horizontal rhythm is measured in ch — the font is mono end to end,
     so 1ch is exactly one character cell. */
  --row: 1.5rem;
  --box-pad-y: 0.25rem;
  --box-pad-x: 1ch;
  --container-pad-y: 0.75rem;
  --container-pad-x: 2ch;

  /* Radius: near-square — TUI boxes have barely-rounded corners. */
  --radius-sm: 0.125rem;
  --radius-md: 0.1875rem;
  --radius-lg: 0.25rem;

  /* Shadows: terminals are flat. */
  --shadow-sm: none;
  --shadow-md: none;

  /* ---- Tokens for the ported component CSS (form/table/buttons/pagination).
     All defined in terms of the flip-aware tokens above, so dark mode keeps
     working without extra overrides (the dark overrides live on the same
     html element, so color-mix() recomputes correctly). ---- */

  /* Extra spacing / sizing steps */
  --space-mld: 1.25rem;
  --space-xxxl: 4rem;
  --radius-xl: 0.25rem;
  --radius-full: 9999px;
  --size-s: 2.5rem;
  /* One leading everywhere: every line of text is exactly one grid row. */
  --leading-tight: 1.5;

  /* Buttons: the universal box inset, doubled horizontally. */
  --button-padding-y: var(--box-pad-y);
  --button-padding-x: 2ch;
  --color-primary-light: color-mix(in srgb, var(--color-primary) 15%, transparent);

  /* Tinted state backgrounds (aliases of the status message tints) */
  --color-success-light: var(--color-status-bg);
  --color-warning-light: var(--color-warning-bg);
  --color-error-light: var(--color-error-bg);

  /* Form-specific tokens */
  --form-border: var(--color-border-medium);
  --form-text: color-mix(in srgb, var(--color-text-primary) 60%, transparent);
  --form-label-color: color-mix(in srgb, var(--color-text-primary) 55%, transparent);
  --form-bg-disabled: color-mix(in srgb, var(--color-text-primary) 5%, transparent);
  --form-border-disabled: color-mix(in srgb, var(--color-text-primary) 20%, transparent);
  --form-bg-disabled-hover: color-mix(in srgb, var(--color-text-primary) 30%, transparent);
  --form-bg-disabled-active: color-mix(in srgb, var(--color-text-primary) 40%, transparent);

  /* Layout */
  --max-page-width: 1920px;
  --header-height: 4rem;
  /* Uniform padding applied to every region band's .container (all sides).
     Denser than a regular site — TUIs pack tight. */
  --container-padding: var(--space-md);

  /* Fonts: system monospace stack — the core of the terminal look. */
  --font-family-base: ui-monospace, "SF Mono", Menlo, Consolas,
    "DejaVu Sans Mono", "Liberation Mono", monospace;
}

/* ---------------------------------------------------------------------------
   2. Base / reset
   --------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  margin: 0;
  padding: 0;
  color-scheme: dark;
  /* Editor-density type: 14px base, everything rem-scaled follows. */
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family-base);
  font-weight: 400;
  color: var(--color-text-primary);
  background-color: var(--color-bg-primary);
  overflow-x: clip;
}

body.no-scroll,
html.no-scroll {
  overflow: hidden;
}

img,
picture,
svg,
video,
object {
  max-width: 100%;
  height: auto;
}

pre {
  overflow-x: auto;
  white-space: pre-wrap;
}

/* ---------------------------------------------------------------------------
   3. Typography
   --------------------------------------------------------------------------- */
/* Terminal vertical rhythm: one blank row above a heading, half a row
   below. Hierarchy is expressed by weight and case, not size (h3–h6
   share the body size). Components that manage their own spacing
   (.block-title, .accordion-header, etc.) override these margins locally. */
h1,
h2,
h3,
h4,
h5,
h6 {
  margin: var(--row) 0 calc(var(--row) / 2);
  line-height: var(--row);
  font-weight: 700;
  color: var(--color-text-primary);
}

/* The page title reads like a pane title: upper-case, letter-spaced. */
h1 {
  text-transform: uppercase;
  letter-spacing: 0.25ch;
}

h1:first-child,
h2:first-child,
h3:first-child,
h4:first-child,
h5:first-child,
h6:first-child {
  margin-top: 0;
}

h1 { font-size: var(--font-size-xxl); }
h2 { font-size: var(--font-size-xl); }
h3 { font-size: var(--font-size-lg); }
h4 { font-size: var(--font-size-mlg); }
h5 { font-size: var(--font-size-md); }
h6 { font-size: var(--font-size-sm); }

p {
  /* One blank terminal row between paragraphs. */
  margin: 0 0 var(--row);
}

p:last-child {
  margin-bottom: 0;
}

a,
a:visited {
  color: var(--color-link);
  text-decoration: none;
  /* Terminals know two weights; links are regular, emphasis is bold. */
  font-weight: 400;
}

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

ul,
ol {
  margin: 0;
  padding-left: 1.5rem;
}

blockquote {
  margin: 0;
  padding-left: var(--space-md);
  border-left: 3px solid var(--color-border-medium);
  font-style: italic;
  color: var(--color-text-secondary);
}

.list-unstyled {
  list-style: none;
  padding: 0;
  margin: 0;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   4. Layout container
   --------------------------------------------------------------------------- */
/* Single source of band spacing: every region band wraps one .container,
   which carries one uniform padding on all sides. Do not add padding
   on individual .container instances. */
.container {
  max-width: var(--max-page-width);
  margin: 0 auto;
  /* Band padding on the grid: half a row vertically, 2 cells horizontally. */
  padding: var(--container-pad-y) var(--container-pad-x);
  width: 100%;
}

.region {
  width: 100%;
}

.layout-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
  margin: 0;
}

/* Main content + sidebars */
.site-main {
  flex: 1 0 auto;
}

.layout-content {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: 1fr;
}

@media (min-width: 60em) {
  body.layout-sidebar-first .layout-content {
    grid-template-columns: 16rem 1fr;
  }
  body.layout-sidebar-first .layout-content .layout-sidebar-first {
    order: -1;
  }
  body.layout-sidebar-second .layout-content {
    grid-template-columns: 1fr 16rem;
  }
  body.layout-two-sidebars .layout-content {
    grid-template-columns: 16rem 1fr 16rem;
  }
  body.layout-two-sidebars .layout-content .layout-sidebar-first {
    order: -1;
  }
}

.layout-sidebar-first,
.layout-sidebar-second {
  min-width: 0;
}

/* Region separators: a hairline between the sidebar and content columns.
   On the stacked (mobile) layout the sidebars separate from the content
   with horizontal rules; the 60em media query turns them into vertical
   dividers. The sidebar blocks themselves are framed TUI panels
   (section 16). */
.layout-content .layout-sidebar-first {
  border-bottom: 1px solid var(--color-border-light);
  padding-bottom: var(--space-md);
}

.layout-content .layout-sidebar-second {
  border-top: 1px solid var(--color-border-light);
  padding-top: var(--space-md);
}

@media (min-width: 60em) {
  .layout-content .layout-sidebar-first {
    border-bottom: 0;
    padding-bottom: 0;
    border-right: 1px solid var(--color-border-light);
    padding-right: var(--space-md);
    /* Stretch the aside so the divider runs the full column height. */
    height: 100%;
  }
  .layout-content .layout-sidebar-second {
    border-top: 0;
    padding-top: 0;
    border-left: 1px solid var(--color-border-light);
    padding-left: var(--space-md);
  }
}

/* Hero separates from whatever follows it (breadcrumb or content). */
.region-hero {
  border-bottom: 1px solid var(--color-border-light);
}

/* Full-width bands below the main content separate from the region above. */
.region-content-full-width,
.region-content-grid,
.region-discover-more {
  border-top: 1px solid var(--color-border-light);
}

/* ---------------------------------------------------------------------------
   5. Header
   --------------------------------------------------------------------------- */
.site-header {
  position: relative;
  z-index: 100;
  background-color: var(--color-bg-chrome);
  border-bottom: 1px solid var(--color-border-light);
}

/* Full-bleed header & footer: the bands span the full width (no max-width
   centering), while their region containers keep the standard uniform
   padding like every other band. */
.site-header .container,
.site-footer .container {
  max-width: none;
  margin-left: 0;
  margin-right: 0;
}

.site-header .container {
  display: flex;
  align-items: center;
  gap: 2ch;
}

/* Every header block centres its content on the shared horizontal axis so
   logo, toggle and menu links sit on one line. */
.site-header .container > .block {
  display: inline-flex;
  align-items: center;
}

/* Branding stays left; the auto margin pushes everything after it to the
   right edge. */
.site-header .container > .block-system-branding-block {
  margin-right: auto;
}

.site-header .region-header {
  width: 100%;
}

.site-branding {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
}

.site-branding__logo,
.site-logo {
  display: inline-flex;
  align-items: center;
}

.site-branding__logo img,
.site-logo img {
  display: block;
  height: 2rem;
  width: auto;
}

.site-name {
  font-size: var(--font-size-lg);
  font-weight: 700;
}

.site-name a,
.site-name a:visited {
  color: var(--color-text-primary);
}

/* ---------------------------------------------------------------------------
   6. Navigation / menus
   --------------------------------------------------------------------------- */
.site-navigation {
  background-color: var(--color-bg-chrome);
  border-bottom: 1px solid var(--color-border-light);
}

.site-navigation .container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs) var(--space-md);
}

/* Main menu region: every block (menu blocks, dark mode toggle, anything
   placed here) lays out inline on one row, vertically centred. Blocks align
   to the right edge; a branding block (if placed here) pins itself to the
   left via its auto margin, same pattern as the header. */
.region-main-menu .container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-xs) var(--space-md);
}

.region-main-menu .container > .block-system-branding-block {
  margin-right: auto;
}

.region-main-menu .block {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
}

nav.block-menu ul.menu,
.region-main-menu ul.menu,
.region-secondary-menu ul.menu {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

nav.block-menu ul.menu li,
.region-main-menu ul.menu li,
.region-secondary-menu ul.menu li {
  display: inline-block;
}

nav.block-menu ul.menu a,
.region-main-menu ul.menu a,
.region-secondary-menu ul.menu a {
  display: inline-flex;
  align-items: center;
}

/* Sidebar menus behave like normal lists: items stacked vertically, no
   flex/wrap — the horizontal menu styling above is meant for the nav bar.
   Scoped to the aside inside .layout-content: the layout-sidebar-* classes
   also exist on <body> (see apebox_theme_preprocess_html), and matching the
   body class would stack every menu on the page, including the nav bar. */
.layout-content .layout-sidebar-first nav.block-menu ul.menu,
.layout-content .layout-sidebar-second nav.block-menu ul.menu {
  display: block;
}

.layout-content .layout-sidebar-first nav.block-menu ul.menu li,
.layout-content .layout-sidebar-second nav.block-menu ul.menu li {
  display: block;
}

.layout-content .layout-sidebar-first nav.block-menu ul.menu a,
.layout-content .layout-sidebar-second nav.block-menu ul.menu a {
  display: block;
}

/* Nested sidebar menu levels (e.g. the Tools menu) indent one step per
   level to show the hierarchy. Beats the padding: 0 reset on ul.menu by
   one class of specificity. */
.layout-content .layout-sidebar-first nav.block-menu ul.menu ul.menu,
.layout-content .layout-sidebar-second nav.block-menu ul.menu ul.menu {
  padding-left: var(--space-md);
}

/* ---------------------------------------------------------------------------
   7. Breadcrumb
   --------------------------------------------------------------------------- */
.region-breadcrumb {
  border-bottom: 1px solid var(--color-border-light);
}

.breadcrumb__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1ch;
  font-size: var(--font-size-sm);
}

.breadcrumb__item:not(:last-child)::after {
  content: "/";
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------------
   8. Blocks
   --------------------------------------------------------------------------- */
.block {
  margin: 0;
}

.block-title {
  margin: 0;
  font-size: var(--font-size-lg);
}

.region-highlighted,
.region-help {
  margin: 0;
}

/* Highlighted band separates from the content below it. */
.region-highlighted {
  border-bottom: 1px solid var(--color-border-light);
}

/* The status messages block always renders a hidden JS insertion point
   (<div data-drupal-messages-fallback class="hidden">) even when there are
   no messages, which would otherwise show the highlighted band and its
   border as an empty stripe. Hide the band unless it contains real messages
   or any other block. When message.js inserts a message it swaps the
   fallback attribute for data-drupal-messages, so the band reappears
   automatically. */
.region-highlighted:not(
  :has([data-drupal-messages], .messages, .block:not(.block-system-messages-block))
) {
  display: none;
}

.region-help .container > div {
  padding: calc(var(--row) / 2) 2ch;
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
}

/* ---------------------------------------------------------------------------
   9. Footer
   --------------------------------------------------------------------------- */
.site-footer {
  flex-shrink: 0;
  margin-top: 0;
  border-top: 1px solid var(--color-border-light);
  color: var(--color-text-secondary);
}

/* The blocks live inside the region's .container, so that is the flex
   context (the region div only wraps the container). */
.site-footer .region-footer .container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xl);
}

.site-footer .region-footer .block {
  flex: 1 1 14rem;
}

.site-footer ul.menu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.site-footer ul.menu a {
  display: inline-block;
}

/* The hairline separating footer-bottom from the footer region sits on the
   band, so it spans the full width like the other region separators. The
   bottom strip is chrome — like an editor's status bar. */
.site-footer .region-footer-bottom {
  border-top: 1px solid var(--color-border-light);
  background-color: var(--color-bg-chrome);
}

.footer-bottom {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------------
   10.-12. Buttons, forms and tables
   Moved to dedicated component files: buttons.css, form.css, table.css,
   pagination.css (all loaded via the global-styling library).
   --------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------------
   13. Status messages
   --------------------------------------------------------------------------- */
/* TUI boxes: a full status-colored frame instead of the edge bar. */
.messages {
  margin: 0;
  padding: var(--box-pad-y) var(--box-pad-x);
  border: 1px solid var(--color-border-medium);
  border-radius: var(--radius-md);
  font-weight: 700;
}

.messages--status {
  background-color: var(--color-status-bg);
  color: var(--color-success);
  border-color: var(--color-success);
}

.messages--warning {
  background-color: var(--color-warning-bg);
  color: var(--color-warning);
  border-color: var(--color-warning);
}

.messages--error {
  background-color: var(--color-error-bg);
  color: var(--color-error);
  border-color: var(--color-error);
}

/* ---------------------------------------------------------------------------
   14. Local tasks (tabs)
   --------------------------------------------------------------------------- */
.block-local-tasks-block ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  list-style: none;
  padding: 0;
  margin: 0;
  border-bottom: 2px solid var(--color-border-light);
}

/* Editor-style tabs: inactive tabs are darker chips (like an editor's tab
   bar), the active tab lights up in the accent. */
.block-local-tasks-block a {
  display: block;
  padding: var(--box-pad-y) 2ch;
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-text-secondary);
  background-color: var(--color-bg-chrome);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.block-local-tasks-block a:hover,
.block-local-tasks-block a:focus,
.block-local-tasks-block a.is-active {
  background-color: var(--color-primary);
  color: var(--color-text-inverse);
  text-decoration: none;
}

/* ---------------------------------------------------------------------------
   14b. Local actions ("Add link" etc.)
   --------------------------------------------------------------------------- */
.local-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1ch;
  list-style: none;
  padding: 0;
  margin: 0 0 var(--row);
}

/* Local action links render with class="button" but no variant; give them
   the primary treatment so they read as the page's main action. */
.local-actions .button,
.local-actions .button:visited {
  background-color: var(--color-primary);
  color: var(--color-text-inverse);
}

.local-actions .button:hover,
.local-actions .button:focus {
  background-color: var(--color-primary-hover);
  color: var(--color-text-inverse);
  text-decoration: none;
}

/* ---------------------------------------------------------------------------
   16. TUI panels
   --------------------------------------------------------------------------
   The btop box language: framed panels with the title sitting on the top
   border line. Applied to sidebar and footer blocks (each block = one
   titled panel) and to the main content column (one big untitled frame,
   like btop's process box).
   --------------------------------------------------------------------------- */
.layout-content .layout-sidebar-first .block,
.layout-content .layout-sidebar-second .block,
.site-footer .region-footer .block {
  position: relative;
  border: 1px solid var(--color-border-medium);
  border-radius: var(--radius-lg);
  /* Panel interior: half a row / one character cell, like btop. */
  padding: calc(var(--row) / 2) var(--box-pad-x);
}

.layout-content .layout-sidebar-first .block:not(:last-child),
.layout-content .layout-sidebar-second .block:not(:last-child) {
  margin-bottom: calc(var(--row) / 2);
}

/* Panel titles cut the top border, like btop's ┌─ title ─┐ boxes.
   Covers both h2.block-title and the plain h2 the menu block template emits. */
.layout-content .layout-sidebar-first .block > h2,
.layout-content .layout-sidebar-second .block > h2,
.site-footer .region-footer .block > h2 {
  position: absolute;
  top: -0.6em;
  left: var(--box-pad-x);
  margin: 0;
  padding: 0 0.5ch;
  background: var(--color-bg-primary);
  font-size: var(--font-size-sm);
  font-weight: 700;
  line-height: 1;
  color: var(--color-link);
  max-width: calc(100% - 2ch);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sidebar menu items: dense list rows; hover highlights the row, the active
   item is inverse-video (accent background, dark ink) like a TUI selection. */
.layout-content .layout-sidebar-first nav.block-menu ul.menu a,
.layout-content .layout-sidebar-second nav.block-menu ul.menu a {
  padding: 0 var(--box-pad-x);
  border-radius: var(--radius-sm);
}

.layout-content .layout-sidebar-first nav.block-menu ul.menu a:hover,
.layout-content .layout-sidebar-first nav.block-menu ul.menu a:focus,
.layout-content .layout-sidebar-second nav.block-menu ul.menu a:hover,
.layout-content .layout-sidebar-second nav.block-menu ul.menu a:focus {
  background: var(--color-bg-tertiary);
  text-decoration: none;
}

.layout-content .layout-sidebar-first nav.block-menu ul.menu a.is-active,
.layout-content .layout-sidebar-second nav.block-menu ul.menu a.is-active {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

/* ---------------------------------------------------------------------------
   17. TUI polish: scrollbars, selection, focus
   --------------------------------------------------------------------------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-medium) transparent;
}

::-webkit-scrollbar {
  width: 0.625rem;
  height: 0.625rem;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border-medium);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-track {
  background: transparent;
}

::selection {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

:focus-visible {
  outline: 1px solid var(--color-primary);
  outline-offset: 1px;
}

/* ---------------------------------------------------------------------------
   15. Print
   --------------------------------------------------------------------------- */
@media print {
  .site-header,
  .site-navigation,
  .site-footer,
  .region-breadcrumb,
  nav {
    display: none;
  }

  body {
    color: #000;
    background: #fff;
  }
}
