/* ============================================================
   base.css — CSS reset, base typography, layout, nav, footer
   SecurePass — no external dependencies
   Imports tokens.css first (linked before this in HTML)
   ============================================================ */

/* ── Modern CSS reset ─────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Remove list styling on lists with a role attribute */
ul[role],
ol[role] {
  list-style: none;
}

[hidden] {
  display: none !important;
}

/* Set core root defaults */
html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* FOUC prevention: apply theme before paint */
  background-color: var(--color-bg);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* ── Base body ────────────────────────────────────────────── */
body {
  font-family: var(--font-base);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Typography base ──────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.25;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

h1 { font-size: var(--text-4xl); font-weight: 800; }
h2 { font-size: var(--text-3xl); font-weight: 800; }
h3 { font-size: var(--text-xl);  font-weight: 700; }
h4 { font-size: var(--text-lg);  font-weight: 700; }
h5 { font-size: var(--text-base); }
h6 { font-size: var(--text-sm); }

@media (max-width: 767px) {
  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }
}

p {
  line-height: 1.7;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: opacity var(--transition);
}

a:hover {
  opacity: 0.8;
}

a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: var(--radius-xs);
}

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background-color: var(--color-bg-secondary);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-xs);
  color: var(--color-text);
}

/* ── Images & media ───────────────────────────────────────── */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

/* ── Form base resets ─────────────────────────────────────── */
input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── Layout: page wrapper ─────────────────────────────────── */
.page-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ── Layout: content container ────────────────────────────── */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--spacing-lg);
}

.container--wide {
  max-width: var(--max-width-wide);
}

/* ── Main content area ────────────────────────────────────── */
main {
  flex: 1;
  padding-top: calc(var(--nav-height) + var(--spacing-xl)); /* clear fixed nav */
  padding-bottom: var(--spacing-2xl);
  padding-inline: var(--spacing-lg);
  max-width: var(--max-width);
  margin-inline: auto;
  width: 100%;
}

@media (max-width: 767px) {
  main {
    padding-top: calc(var(--nav-height) + var(--spacing-lg));
    padding-inline: var(--spacing-md);
  }
}

/* ── Navigation ───────────────────────────────────────────── */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: var(--nav-height);
  background-color: rgba(250, 249, 254, 0.80);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-nav);
  /* FOUC prevention: reserve space */
  min-height: var(--nav-height);
}

[data-theme="dark"] .nav {
  background-color: rgba(26, 27, 31, 0.80);
}

.nav__inner {
  max-width: var(--max-width-wide);
  margin-inline: auto;
  padding-inline: var(--spacing-lg);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-xl);
}

.nav__brand {
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: -0.03em;
  text-decoration: none;
  flex-shrink: 0;
}

.nav__brand:hover {
  opacity: 1;
  color: var(--color-text);
}

.nav__links {
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
  list-style: none;
}

.nav__link {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color var(--transition);
  white-space: nowrap;
}

.nav__link:hover {
  color: var(--color-text);
  opacity: 1;
}

.nav__link--active {
  color: var(--color-primary);
  font-weight: 600;
  border-bottom: 2px solid var(--color-primary);
  padding-bottom: 2px;
}

.nav__actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex-shrink: 0;
}

/* Hamburger — mobile only */
.nav__hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--spacing-xs);
  transition: background-color var(--transition);
}

.nav__hamburger:hover {
  background-color: var(--color-bg-secondary);
}

.nav__hamburger-bar {
  display: block;
  width: 22px;
  height: 2px;
  background-color: var(--color-text);
  border-radius: 2px;
  transition: transform var(--duration-default) var(--ease-default),
              opacity var(--duration-default) var(--ease-default);
}

.nav__hamburger[aria-expanded="true"] .nav__hamburger-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav__hamburger[aria-expanded="true"] .nav__hamburger-bar:nth-child(2) {
  opacity: 0;
}

.nav__hamburger[aria-expanded="true"] .nav__hamburger-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Mobile nav drawer */
.nav__mobile-menu {
  display: none;
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  z-index: 49;
  background-color: var(--color-bg);
  border-bottom: 1px solid var(--color-border-medium);
  box-shadow: var(--shadow-md);
  padding: var(--spacing-md) var(--spacing-lg);
  flex-direction: column;
  gap: var(--spacing-xs);
}

.nav__mobile-menu.is-open {
  display: flex;
}

.nav__mobile-link {
  display: block;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  color: var(--color-text);
  text-decoration: none;
  font-weight: 500;
  transition: background-color var(--transition);
}

.nav__mobile-link:hover {
  background-color: var(--color-bg-secondary);
  opacity: 1;
}

.nav__mobile-link--active {
  color: var(--color-primary);
  background-color: var(--color-primary-subtle);
}

/* Language selector */
.nav__lang {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 4px var(--spacing-sm);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.nav__lang:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

@media (max-width: 767px) {
  .nav__links {
    display: none;
  }

  .nav__hamburger {
    display: flex;
  }
}

/* ── Footer ───────────────────────────────────────────────── */
footer {
  border-top: 1px solid var(--color-border);
  background-color: var(--color-bg);
  padding: var(--spacing-2xl) var(--spacing-lg);
  /* FOUC prevention: reserve min-height */
  min-height: 80px;
}

.footer__inner {
  max-width: var(--max-width-wide);
  margin-inline: auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-md);
  flex-wrap: wrap;
}

.footer__copy {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.footer__links {
  display: flex;
  align-items: center;
  gap: var(--spacing-xl);
  list-style: none;
}

.footer__link {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color var(--transition);
}

.footer__link:hover {
  color: var(--color-primary);
  opacity: 1;
}

.footer__link--btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

@media (max-width: 767px) {
  .footer__inner {
    flex-direction: column;
    text-align: center;
  }

  .footer__links {
    gap: var(--spacing-lg);
  }
}

/* ── Page hero header ─────────────────────────────────────── */
.page-hero {
  text-align: center;
  margin-bottom: var(--spacing-xl);
}

.page-hero__title {
  margin-bottom: var(--spacing-sm);
}

.page-hero__subtitle {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  font-weight: 500;
  max-width: 56ch;
  margin-inline: auto;
}

/* ── Utility classes ──────────────────────────────────────── */

/* Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Select all text on click */
.select-all {
  user-select: all;
  -webkit-user-select: all;
  cursor: text;
}

/* Visually hidden but focusable */
.sr-only:focus {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Skip to main content — hidden off-screen until focused via keyboard.
   Injected by common.js as <a class="skip-link" href="#main-content">. */
.skip-link {
  position: fixed;
  top: var(--spacing-sm);
  left: var(--spacing-sm);
  z-index: 1000; /* above nav (50); below modals (>=9990) */
  transform: translateY(calc(-100% - var(--spacing-md)));
  padding: var(--spacing-sm) var(--spacing-md);
  background-color: var(--color-bg-elevated);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: transform var(--transition), opacity var(--transition);
}

.skip-link:focus,
.skip-link:focus-visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Text truncation */
.truncate {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Flex helpers */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }
.gap-lg { gap: var(--spacing-lg); }

/* Spacing helpers */
.mt-sm  { margin-top: var(--spacing-sm); }
.mt-md  { margin-top: var(--spacing-md); }
.mt-lg  { margin-top: var(--spacing-lg); }
.mt-xl  { margin-top: var(--spacing-xl); }
.mb-sm  { margin-bottom: var(--spacing-sm); }
.mb-md  { margin-bottom: var(--spacing-md); }
.mb-lg  { margin-bottom: var(--spacing-lg); }
.mb-xl  { margin-bottom: var(--spacing-xl); }

/* Text utils */
.text-center { text-align: center; }
.text-sm     { font-size: var(--text-sm); }
.text-xs     { font-size: var(--text-xs); }
.font-bold   { font-weight: 700; }
.font-mono   { font-family: var(--font-mono); }
.text-primary        { color: var(--color-primary); }
.text-secondary      { color: var(--color-text-secondary); }
.text-error          { color: var(--color-error); }
