/* Root scale + color tokens (auto light/dark) */
:root {
  --bg: #ffffff;
  --fg: #1d1f23;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #0ea5e9;
  --accent-ink: #073b4c;
  --surface: #f8fafc;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 16px rgba(0, 0, 0, 0.06);

  --font-sys:
    ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu,
    Cantarell, Noto Sans, Helvetica Neue, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  --font-mono:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    monospace;

  --step--1: clamp(0.86rem, 0.8rem + 0.2vw, 0.95rem);
  --step-0: clamp(1rem, 0.98rem + 0.2vw, 1.08rem);
  --step-1: clamp(1.25rem, 1.15rem + 0.6vw, 1.45rem);
  --step-2: clamp(1.6rem, 1.35rem + 0.9vw, 1.85rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d10;
    --fg: #e5e7eb;
    --muted: #9aa1ab;
    --border: #1f2937;
    --surface: #0f1318;
    --accent: #38bdf8;
    --accent-ink: #031c24;
  }
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
html {
  color-scheme: light dark;
}
body {
  margin: 0;
  font-family: var(--font-sys);
  font-size: var(--step-0);
  line-height: 1.55;
  background: var(--bg);
  color: var(--fg);
}

/* Page frame */
.site {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* Width constraint + breathing room */
.container {
  width: min(72ch, 92vw);
  margin-inline: auto;
  padding-inline: 1rem;
}

/* --- Header/Nav --- */
/* Sticky header */
.header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
}

/* Layout */
.navbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 56px;
  position: relative; /* anchor for the mobile dropdown */
  border: 0;
}

.inline {
  display: inline;
}

/* --- Mobile behavior --- */
@media (max-width: 768px) {
  .menu-toggle {
    display: inline-flex;
    margin-left: auto;
  }
  .navspacer {
    display: none;
  }

  /* Start hidden; toggled open via .open */
  .nav {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: #fff;
    padding: 0.75rem 1rem;
    flex-direction: column;
    gap: 0.5rem;
    border: 0;
    box-shadow: none;
  }
  .nav.open {
    display: flex;
    border: 0;
  }
  .nav.open a {
    color: #16161d;
    border: 0;
  }

  /* Make logout button look like a link inside the dropdown */
  .nav form.inline {
    display: block;
  }
  .nav form.inline .btn {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    padding: 0;
    margin: 0;
    color: #0a58ca;
    font: inherit;
    cursor: pointer;
    border: 0;
  }
}

/* Optional: animate the icon into an "X" when open */
@media (max-width: 768px) {
  .menu-toggle[aria-expanded="true"] .menu-icon {
    background: transparent;
  }
  .menu-toggle[aria-expanded="true"] .menu-icon::before {
    transform: translateY(7px) rotate(45deg);
  }
  .menu-toggle[aria-expanded="true"] .menu-icon::after {
    transform: translateY(-7px) rotate(-45deg);
  }
}

.brand {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.2px;
  font-size: var(--step-1);
}

.nav a,
.nav button.link {
  text-decoration: none;
  color: var(--fg);
  opacity: 0.9;
  border: 0;
}
.nav a:hover,
.nav button.link:hover {
  opacity: 1;
  border: 0;
}

/* Main content */
.main {
  padding-block: 1.4rem 2.2rem;
}
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}
.section h1,
.section h2 {
  margin: 0 0 0.4rem;
  font-size: var(--step-1);
  font-weight: 700;
}
.lead {
  color: var(--muted);
  margin-top: 0.3rem;
}

/* Preserve legacy card heading style (if used) */
.card h2 {
  margin-top: 0;
  font-size: var(--step-0);
}

/* Buttons & forms */
.btn {
  display: inline-block;
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover {
  box-shadow: var(--shadow);
}
.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: white;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.55rem 0.6rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--step--1);
  padding-block: 1rem;
}

/* Messages */
.messages {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.msg {
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.msg.success {
  border-color: #16a34a33;
}
.msg.info {
  border-color: #0ea5e933;
}
.msg.warning {
  border-color: #f59e0b33;
}
.msg.error {
  border-color: #ef444433;
}

/* Cards */
.cards {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
}
.card-title {
  margin: 0 0 0.25rem;
  font-size: var(--step-0);
}
.card-text {
  margin: 0 0 0.75rem;
  color: var(--muted);
}

/* insert a pipe before every item after the first */
.nav a + a::before,
.nav a + button.link::before,
.nav button.link + a::before,
.nav button.link + button.link::before {
  content: "|";
  color: var(--muted);
  opacity: 0.65;
  margin: 0 0.5rem 0 0.35rem; /* spacing around the pipe */
}

/* optional: brighten on hover/focus for a nice feel */
.nav a:hover::before,
.nav button.link:hover::before,
.nav a:focus-visible::before,
.nav button.link:focus-visible::before {
  opacity: 0.85;
}

/* (optional) keep the browser’s focus ring for accessibility */
a.brand:focus-visible {
  outline: auto;
  outline-offset: 2px;
}

/* Logo link should look like plain text; only underline on hover/focus */
a.brand,
a.brand:link,
a.brand:visited {
  color: inherit;
  text-decoration: none !important; /* kill Safari’s persistent underline */
  -webkit-text-decoration: none; /* older Safari */
  text-underline-offset: 0.15em; /* nice hover underline position */
}

a.brand:hover,
a.brand:focus-visible {
  text-decoration-line: underline;
  text-decoration-thickness: 0.08em;
}

@media (max-width: 768px) {
  .nav a + a::before,
  .nav a + button.link::before,
  .nav button.link + a::before,
  .nav button.link + button.link::before {
    content: none;
    display: none;
    border: 0;
  }
}

/* --- Safari fixes + mobile-first nav --- */

/* 1) Reset Safari's default button chrome + ensure icon color inherits */
.menu-toggle {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  border: 0;
  padding: 0.5rem;
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0; /* avoids stray inline box in Safari */
}

/* 2) Robust hamburger bars (Safari-safe) */
.menu-icon {
  display: block;
  position: relative;
  width: 24px;
  height: 2px;
  background-color: currentColor;
  border-radius: 1px;
}
.menu-icon::before,
.menu-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 24px;
  height: 2px;
  background-color: currentColor;
  border-radius: 1px;
}
.menu-icon::before {
  top: -7px;
}
.menu-icon::after {
  top: 7px;
}

/* 3) Mobile-first nav: hidden by default, opened via .open */
.nav {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: var(--surface);
  border-bottom: 0;
  padding: 0.75rem 1rem;
  flex-direction: column;
  gap: 0.5rem;
}
.nav.open {
  display: flex;
  border: 0;
}
.navspacer {
  display: none;
  border: 0;
}

/* Desktop (>=769px) restores inline nav and hides the toggle */
@media (min-width: 769px) {
  .menu-toggle {
    display: none;
  }
  .navspacer {
    display: block;
    flex: 1;
  }
  .nav {
    display: flex;
    position: static;
    background: transparent;
    padding: 0;
    flex-direction: row;
    gap: 1rem;
    border: 0;
  }
}

/* Keep the "X" animation when open */
.menu-toggle[aria-expanded="true"] .menu-icon {
  background-color: transparent;
}
.menu-toggle[aria-expanded="true"] .menu-icon::before {
  transform: translateY(7px) rotate(45deg);
}
.menu-toggle[aria-expanded="true"] .menu-icon::after {
  transform: translateY(-7px) rotate(-45deg);
}

/* Fix: vertical centering on desktop */
@media (min-width: 769px) {
  .nav {
    align-items: center;
  }
}

/* Fix: right-justify items in the open hamburger */
@media (max-width: 768px) {
  .nav {
    align-items: flex-end; /* right edge in column layout */
    text-align: right;
  }
  .nav a,
  .nav button.link,
  .nav form.inline {
    /* ensure each flex item hugs the right edge */
    align-self: flex-end;
  }
  .nav form.inline .btn {
    /* undo earlier full-width/link-like look */
    display: inline-block;
    width: auto;
    text-align: right;
  }
}

/* Subtle bottom-right shadow for the open mobile menu */
@media (max-width: 768px) {
  .nav.open {
    position: absolute;
  } /* already true, but explicit */

  .nav.open::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    box-shadow:
      3px 7px 14px rgba(0, 0, 0, 0.14),
      1px 2px 4px rgba(0, 0, 0, 0.1);
    /* allow extension only to right & bottom (t r b l) */
    clip-path: inset(0 -40px -40px 0 round var(--radius));
  }
}

/* Fix: dark mode link colors in open mobile nav */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
  .nav.open a {
    color: #fff;
  }
}

/* Bottom/right-only hamburger shadow with fallback + dark-mode tune */
@media (max-width: 768px) {
  /* Primary path: clip top/left so shadow only shows on right/bottom */
  @supports (clip-path: inset(0 round 1px)) {
    .nav.open::after {
      content: "";
      position: absolute;
      inset: 0;
      border-radius: inherit;
      pointer-events: none;
      /* soft bottom-right bias */
      box-shadow:
        3px 7px 14px rgba(0, 0, 0, 0.14),
        1px 2px 4px rgba(0, 0, 0, 0.1);
      /* allow extension only to right & bottom (t r b l) */
      clip-path: inset(0 -40px -40px 0 round var(--radius));
    }
  }

  /* Fallback: directional drop-shadows (no top/left) */
  @supports not (clip-path: inset(0 round 1px)) {
    .nav.open {
      filter: drop-shadow(1px 2px 4px rgba(0, 0, 0, 0.1))
        drop-shadow(4px 8px 14px rgba(0, 0, 0, 0.14));
    }
  }
}

/* Slightly stronger in dark mode for equivalent perceived depth */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
  @supports (clip-path: inset(0 round 1px)) {
    .nav.open::after {
      box-shadow:
        3px 7px 14px rgba(0, 0, 0, 0.28),
        1px 2px 4px rgba(0, 0, 0, 0.18);
    }
  }
  @supports not (clip-path: inset(0 round 1px)) {
    .nav.open {
      filter: drop-shadow(1px 2px 4px rgba(0, 0, 0, 0.18))
        drop-shadow(4px 8px 14px rgba(0, 0, 0, 0.28));
    }
  }
}

/* Safe mobile default */
@media (max-width: 480px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

/* [> If you want to target iOS WebKit only <] */
/* @supports (-webkit-touch-callout: none) { */
/*   input, */
/*   select, */
/*   textarea { */
/*     font-size: 16px; */
/*   } */
/* } */
