/* ==========================================================================
   BKI Kalijaga — base & layout
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--ink-900);
  background-color: var(--bg-page);
  background-image:
    radial-gradient(1120px 620px at 8% -8%, rgba(79, 70, 229, 0.18), transparent 62%),
    radial-gradient(940px 560px at 100% 0%, rgba(139, 92, 246, 0.16), transparent 58%),
    radial-gradient(760px 620px at 44% 108%, rgba(14, 165, 233, 0.1), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  line-height: var(--leading-tight);
  color: var(--ink-900);
  margin: 0 0 var(--space-4);
  letter-spacing: -0.015em;
}

h1 { font-size: clamp(1.9rem, 1.4rem + 2.1vw, var(--text-4xl)); }
h2 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, var(--text-3xl)); }
h3 { font-size: clamp(1.2rem, 1.05rem + 0.6vw, var(--text-2xl)); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }

p { margin: 0 0 var(--space-4); }

a {
  color: var(--brand-600);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--accent-600); text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

ul, ol { padding-left: 1.25rem; }

hr {
  border: none;
  border-top: 1px solid var(--line-300);
  margin: var(--space-8) 0;
}

code, pre, kbd {
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
  font-size: 0.9em;
}
code {
  background: rgba(99, 95, 130, 0.1);
  padding: 2px 6px;
  border-radius: 6px;
}
pre {
  background: rgba(31, 27, 58, 0.06);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

/* ------------------------------------------------------------- a11y -------- */

:focus-visible {
  outline: 3px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 999;
  background: var(--brand-600);
  color: #fff;
  padding: var(--space-3) var(--space-5);
  border-radius: 0 0 var(--radius-md) 0;
  font-weight: var(--weight-semibold);
}
.skip-link:focus {
  left: 0;
}

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

/* ---------------------------------------------------------- containers ----- */

/* Container family.
   All three variants are self-sufficient: each one centres itself and carries its own
   padding, so `class="container-wide"` works on its own. Writing only `container-wide`
   (without `container`) used to leave the block with no `margin-inline: auto`, which
   pushed every page hard against the left edge. */
.container,
.container-narrow,
.container-wide {
  width: 100%;
  margin-inline: auto;
  padding-inline: var(--space-5);
}

.container { max-width: var(--container-max); }
.container-narrow { max-width: 780px; }
.container-wide { max-width: 1440px; }

.section { padding-block: var(--space-12); }
.section-sm { padding-block: var(--space-8); }
.section + .section { border-top: 1px solid var(--line-300); }

.stack > * + * { margin-top: var(--space-4); }
.stack-lg > * + * { margin-top: var(--space-8); }
.stack-sm > * + * { margin-top: var(--space-2); }

.grid {
  display: grid;
  gap: var(--space-5);
}

/* Explicit gaps everywhere — cards must never sit flush against each other. */
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-5); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--space-5); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--space-5); }

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

.between {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: center;
  justify-content: space-between;
}

.sidebar-layout {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  gap: var(--space-8);
  align-items: start;
}

@media (max-width: 1024px) {
  .sidebar-layout { grid-template-columns: 1fr; gap: var(--space-6); }
}

/* --------------------------------------------------------------- shell ----- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 60;
  backdrop-filter: blur(var(--blur-glass)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--blur-glass)) saturate(180%);
  background: color-mix(in srgb, var(--bg-page) 78%, transparent);
  border-bottom: 1px solid var(--line-300);
}

.site-header .container-wide {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 72px;
  /* min-width:0 on the flex children is what prevents a long nav from forcing the
     page wider than the viewport (a flex item will not shrink below its content
     width by default). */
  flex-wrap: wrap;
  padding-block: var(--space-3);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  color: var(--ink-900);
  text-decoration: none;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; color: var(--ink-900); }

.brand__mark {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand-500), var(--accent-500));
  color: #fff;
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  letter-spacing: 0.04em;
  box-shadow: var(--shadow-soft);
  flex-shrink: 0;
  overflow: hidden;
}
.brand__mark img { width: 100%; height: 100%; object-fit: contain; }

.brand__text { display: flex; flex-direction: column; line-height: 1.2; }
.brand__name { font-size: var(--text-base); }
.brand__sub {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--ink-500);
}

.main-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
  min-width: 0;
}

/* Hamburger: only shown when the horizontal menu no longer fits. */
.nav-toggle { display: none; }

.site-search {
  position: relative;
  display: flex;
  align-items: center;
}
.site-search input {
  width: 168px;
  padding: 8px 34px 8px 12px;
}
.site-search__submit {
  position: absolute;
  right: 4px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--ink-500);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.site-search__submit:hover { color: var(--brand-600); background: rgba(79, 70, 229, 0.1); }

@media (max-width: 1080px) {
  .nav-toggle { display: inline-grid; }
  .main-nav {
    display: none;
    order: 10;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: var(--space-3) 0 0;
    border-top: 1px solid var(--line-300);
  }
  .main-nav.is-open { display: flex; }
  .main-nav a { padding: var(--space-3) var(--space-3); border-radius: var(--radius-sm); }
}

@media (max-width: 720px) {
  .site-header .container-wide { gap: var(--space-2); }
  .site-search { order: 20; width: 100%; }
  .site-search input { width: 100%; }
  .brand__sub { display: none; }
  .header-actions { gap: var(--space-1); }
}

@media (max-width: 420px) {
  .brand__name { font-size: var(--text-sm); max-width: 132px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-actions .btn { padding: var(--space-2) var(--space-3); }
}
.main-nav a {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--ink-700);
  white-space: nowrap;
}
.main-nav a:hover { background: rgba(79, 70, 229, 0.1); color: var(--brand-700); text-decoration: none; }
.main-nav a.is-active { background: rgba(79, 70, 229, 0.14); color: var(--brand-700); font-weight: var(--weight-semibold); }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.site-footer {
  margin-top: var(--space-16);
  padding-block: var(--space-12) var(--space-6);
  background: rgba(31, 27, 58, 0.04);
  border-top: 1px solid var(--line-300);
}
.site-footer__grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1.2fr;
  gap: var(--space-8);
}
@media (max-width: 900px) { .site-footer__grid { grid-template-columns: 1fr 1fr; gap: var(--space-6); } }
@media (max-width: 560px) { .site-footer__grid { grid-template-columns: 1fr; } }

.site-footer h4 {
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-500);
  margin-bottom: var(--space-3);
}
.site-footer ul { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-2); }
.site-footer a { color: var(--ink-700); font-size: var(--text-sm); }
.site-footer__bottom {
  margin-top: var(--space-8);
  padding-top: var(--space-5);
  border-top: 1px solid var(--line-300);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--ink-500);
}

/* ------------------------------------------------------------ portal ------- */

.app-shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
}

/* Collapsing the sidebar must also drop its COLUMN.
   Hiding only the aside with `display: none` leaves the 272px track in place, so the
   remaining `.app-main` is placed inside that narrow first column and the whole page
   looks broken. Collapsing the track to a single 1fr column is what actually gives the
   content the full width.

   Driven by an attribute on <html> so it can be applied in <head>, before first paint —
   see the inline script in partials/head.ejs. A class applied by app.js alone would let
   the sidebar flash back in on every navigation. */
html[data-sidebar='hidden'] .app-shell { grid-template-columns: minmax(0, 1fr); }
html[data-sidebar='hidden'] .app-sidebar { display: none; }

/* The toggle itself is meaningless once the sidebar is hidden on a wide screen only
   because the user hid it — keep it visible so they can bring the menu back. */
html[data-sidebar='hidden'] .app-topbar [data-sidebar-toggle] {
  background: rgba(79, 70, 229, 0.12);
  color: var(--brand-700);
}

@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 1fr; }
  /* On narrow screens the sidebar stacks above the content, so "hidden" simply hides it. */
  html[data-sidebar='hidden'] .app-shell { grid-template-columns: 1fr; }
}

.app-sidebar {
  padding: var(--space-6) var(--space-5);
  background: rgba(255, 255, 255, 0.42);
  backdrop-filter: blur(var(--blur-glass));
  -webkit-backdrop-filter: blur(var(--blur-glass));
  border-right: 1px solid var(--line-200);
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
}

@media (max-width: 1024px) {
  .app-sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--line-200);
  }
  .app-sidebar .nav-list { display: flex; flex-wrap: wrap; gap: var(--space-2); }
  .app-sidebar .nav-list a { padding: var(--space-2) var(--space-3); }
  .app-sidebar .nav-section__title { display: none; }
}

.nav-section { margin-bottom: var(--space-6); }
.nav-section__title {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-400);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-2);
}
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-list a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--ink-700);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.nav-list a:hover { background: rgba(79, 70, 229, 0.1); color: var(--brand-700); text-decoration: none; }
.nav-list a.is-active {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.16), rgba(139, 92, 246, 0.14));
  color: var(--brand-700);
  font-weight: var(--weight-semibold);
}
.nav-list a .icon { flex-shrink: 0; opacity: 0.85; }

.app-main { min-width: 0; display: flex; flex-direction: column; }

.app-topbar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--line-300);
  background: color-mix(in srgb, var(--bg-page) 82%, transparent);
  backdrop-filter: blur(var(--blur-glass));
  -webkit-backdrop-filter: blur(var(--blur-glass));
  position: sticky;
  top: 0;
  z-index: 40;
}

.app-content { padding: var(--space-8) var(--space-6) var(--space-16); flex: 1; }
@media (max-width: 640px) { .app-content { padding: var(--space-5) var(--space-4) var(--space-12); } }

.page-header { margin-bottom: var(--space-8); }
.page-header h1 { margin-bottom: var(--space-2); }
.page-header p { color: var(--ink-500); margin: 0; max-width: 68ch; }

.breadcrumbs { font-size: var(--text-sm); color: var(--ink-500); margin-bottom: var(--space-3); }
.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-2); padding: 0; margin: 0; }
.breadcrumbs li + li::before { content: '/'; margin-right: var(--space-2); color: var(--ink-400); }
.breadcrumbs a { color: var(--ink-500); }
.breadcrumbs [aria-current='page'] { color: var(--ink-700); font-weight: var(--weight-medium); }
