/* DeployBot UI, layout layer: the page frame (ambient background, main shell, top bar), the
   page structure (heads, rows, columns, key-value lists) and the auth shell. */

@layer layout {
  /* ---- skip link: the first focusable thing on a page, visible only while focused */

  .skip-link {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 100;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
    text-decoration: none;
    transform: translateY(-200%);
  }

  .skip-link:focus-visible {
    transform: none;
  }

  /* ---- ambient background */

  /* ambient artwork: a fixed-height layer at the top of every page (layouts/Main.cfm), masked so it
     fades into --bg before the tables start. Static on purpose: glass over a moving backdrop would
     re-blur every frame in a tab that stays open all day. */
  .ambient {
    position: absolute;
    inset: 0 0 auto;
    height: var(--ambient-height);
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, #000 0%, rgb(0 0 0 / .55) 45%, transparent 100%);
    mask-image: linear-gradient(to bottom, #000 0%, rgb(0 0 0 / .55) 45%, transparent 100%);
  }

  /* background.avif is the artwork pre-blurred (a soft glow, not detail). At least 1400px wide, so
     narrow windows still show the bright edges. */
  .ambient::before {
    content: "";
    position: absolute;
    top: -4%;
    bottom: -4%;
    left: min(-4%, calc(50% - 700px));
    right: min(-4%, calc(50% - 700px));
    background: url(../images/background.avif) center top / cover no-repeat;
    opacity: var(--ambient-opacity);
    z-index: -1;
  }

  /* vignette: keeps the centre calm behind the tables */
  .ambient::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(1200px 500px at 50% 0%, transparent 0%, color-mix(in oklch, var(--bg) 55%, transparent) 70%, var(--bg) 100%);
  }

  /* ---- main shell */

  body.main {
    min-height: 100vh;
    background: radial-gradient(1200px 600px at 50% -10%, color-mix(in oklch, var(--accent) 84%, transparent), transparent 70%), var(--bg);
  }

  /* ---- top bar */

  /* a floating glass bar; the transparent wrapper lets clicks through its 14px top band */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: var(--space-6) var(--space-9) 0;
    pointer-events: none;
  }

  .topbar-inner {
    pointer-events: auto;
    max-width: 1240px;
    height: 52px;
    margin: 0 auto;
    padding: 0 var(--space-3) 0 var(--space-6);
    display: flex;
    align-items: center;
    gap: var(--space-7);
    border-radius: var(--radius-xl);
    background: var(--glass-bg-strong);
    -webkit-backdrop-filter: blur(20px) saturate(150%);
    backdrop-filter: blur(20px) saturate(150%);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-highlight), 0 10px 30px -12px rgba(0,0,0,.6);
  }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-4);
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -.01em;

    &:hover {
      color: var(--text);
      text-decoration: none;
    }
  }

  .brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
  }

  .brand-version {
    font-family: var(--font-mono);
    font-variant-ligatures: none;
    font-size: var(--text-1);
    font-weight: 400;
    letter-spacing: 0;
    color: var(--muted);
  }

  .logo {
    width: 26px;
    height: 26px;
  }

  .logo-img {
    display: block;
    width: 26px;
    height: 26px;
    border-radius: 7px;
  }

  .chip {
    display: inline-block;
    padding: 3px 8px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-pill);
    background: color-mix(in oklch, var(--text) 3%, transparent);
    font-family: var(--font-mono);
    font-variant-ligatures: none;
    font-feature-settings: "calt" 0;
    font-size: var(--text-1);
    color: var(--muted);
    white-space: nowrap;
  }

  .nav {
    display: flex;
    gap: 2px;
    margin-left: var(--space-3);
  }

  .nav a {
    padding: 7px 12px;
    border-radius: 9px;
    font-size: var(--text-6);
    font-weight: 500;
    color: var(--muted);
  }

  .nav a:hover {
    background: var(--hover-fill);
    color: var(--text);
    text-decoration: none;
  }

  .nav a.active {
    background: color-mix(in oklch, var(--text) 7%, transparent);
    color: var(--text);
  }

  .topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .topbar-right > *,
  .nav,
  .brand {
    flex: none;
    white-space: nowrap;
  }

  .topbar-right .divider {
    width: 1px;
    height: 20px;
    border-left: 1px solid var(--glass-border);
    margin: 0 var(--space-1);
  }

  .avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--raised), var(--surface));
    border: 1px solid var(--glass-border);
    display: inline-grid;
    place-items: center;
    font-size: var(--text-3);
    font-weight: 600;
    text-transform: uppercase;
  }

  .user {
    font-size: var(--text-5);
    font-weight: 500;
  }

  .topbar form {
    margin: 0;
    display: inline;
  }

  /* ---- page */

  /* sits straight on the ambient layer; legibility comes from the glass surfaces. No db-rise here:
     an ancestor fading in (opacity < 1) stops backdrop-filter seeing the art until it ends. */
  .content {
    position: relative;
    z-index: 1;
    max-width: 1240px;
    margin: 0 auto;
    padding: 32px 24px 64px;
  }

  .crumbs {
    font-size: var(--text-4);
    color: var(--muted);
    margin-bottom: var(--space-6);
    display: flex;
    gap: var(--space-2);
    align-items: center;
    flex-wrap: wrap;
  }

  .crumbs a {
    color: var(--muted);
  }

  .crumbs a:hover {
    color: var(--text);
  }

  .crumbs .current {
    color: var(--text);
  }

  .page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: var(--space-7);
    flex-wrap: wrap;
    margin-bottom: 22px;
  }

  .page-head > :first-child {
    flex: 1 1 320px;
    min-width: 0;
  }

  .page-head .meta > span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-head .title-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
  }

  .page-head .sub {
    color: var(--muted);
    font-size: var(--text-5);
    margin-top: var(--space-1);
  }

  .page-head .meta {
    display: flex;
    gap: var(--space-6);
    flex-wrap: wrap;
    margin-top: var(--space-3);
    font-family: var(--font-mono);
    font-variant-ligatures: none;
    font-feature-settings: "calt" 0;
    font-size: var(--text-4);
    color: var(--muted);
  }

  .head-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--space-3);
  }

  .head-actions .row {
    justify-content: flex-end;
  }

  .head-note {
    font-size: var(--text-3);
    color: var(--muted);
  }

  /* a monitor or dependency check queued/running: pulsing dot before the text */
  .head-note.is-checking,
  .checking-text {
    color: var(--info);
  }

  .head-note.is-checking::before,
  .checking-text::before,
  .badge.checking::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: var(--space-2);
    border-radius: 50%;
    background: currentColor;
    vertical-align: middle;
    animation: db-pulse 1.2s ease-in-out infinite;
  }

  /* dashboard: a larger title with the monitor note above it behind a neutral dot ("Oldest
     check" says how fresh the data is, not that checks passed) */
  .page-head-hero {
    padding-top: var(--space-9);
    margin-bottom: 28px;
    gap: var(--space-8);
  }

  .page-head-hero h1 {
    font-size: 40px;
    line-height: 1.05;
    letter-spacing: -.03em;
  }

  .page-head-hero .sub {
    font-size: 15px;
    margin-top: var(--space-3);
  }

  .page-head-hero .head-note {
    display: flex;
    align-items: center;
    font-size: var(--text-4);
    margin-bottom: var(--space-4);
  }

  .page-head-hero .head-note:empty {
    display: none;
  }

  .page-head-hero .head-note:not(.is-checking)::before {
    content: "";
    width: 6px;
    height: 6px;
    margin-right: var(--space-3);
    border-radius: 50%;
    background: var(--muted);
    flex: none;
  }

  .section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-5);
    margin: 34px 0 12px;
  }

  .section-head .note {
    font-size: var(--text-3);
    color: var(--muted);
  }

  .row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
  }

  .stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
  }

  .two-col {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    gap: var(--space-6);
    margin-bottom: var(--space-6);
  }

  .two-col.deploy {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
    align-items: start;
  }

  .two-col.settings {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
    align-items: start;
  }

  #finish-setup .list {
    font-size: var(--text-3);
    line-height: 1.7;
  }

  #finish-setup code,
  .tbl-checks .help,
  .auth-card code {
    overflow-wrap: anywhere;
  }

  .tbl-checks > .help {
    padding: 0 18px;
  }

  /* .mb and .mt stay in layout, not utilities: .disclosure > .mb, .disclosure > .card and
     .help ("help mt" keeps margin-top: 6px) override them */
  .mb {
    margin-bottom: var(--space-6);
  }

  .mt {
    margin-top: var(--space-6);
  }

  .notes {
    padding-left: 18px;
    font-size: var(--text-3);
    color: var(--muted);
  }

  .notes li + li {
    margin-top: 2px;
  }

  .list {
    padding-left: 18px;
    font-size: var(--text-5);
  }

  .list li + li {
    margin-top: var(--space-1);
  }

  .kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--space-2) var(--space-6);
    font-size: var(--text-4);
    align-items: baseline;
  }

  .kv dt {
    color: var(--muted);
  }

  .kv dd {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .kv.tight {
    gap: 3px 14px;
    font-size: var(--text-3);
  }

  .kv .mono,
  .kv code {
    font-size: var(--text-3);
  }

  .pre {
    padding: var(--space-5) var(--space-6);
    border-radius: var(--radius-lg);
    background: var(--bg);
    border: 1px solid var(--border);
    font-family: var(--font-mono);
    font-variant-ligatures: none;
    font-feature-settings: "calt" 0;
    font-size: var(--text-2);
    line-height: 1.55;
    color: var(--muted);
    overflow: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  .pre.text {
    color: var(--text);
    font-size: var(--text-3);
    line-height: 1.6;
  }

  .file-list {
    max-height: 40vh;
    overflow: auto;
    padding: 8px 12px 8px 26px;
    border-radius: var(--radius-lg);
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: var(--text-3);
  }

  .file-list code {
    font-size: var(--text-2);
  }

  /* ---- auth shell */

  body.auth {
    min-height: 100vh;
    background: radial-gradient(1200px 600px at 50% -10%, color-mix(in oklch, var(--accent) 14%, transparent), transparent 70%), var(--bg);
  }

  .auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 16px;
  }

  .auth-col {
    width: 100%;
    max-width: 400px;
    animation: db-rise .5s ease both;
  }

  .auth-brand {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: var(--space-4);
    margin-bottom: 18px;
    font-size: 24px;
    font-weight: 600;
  }

  .auth-brand .logo {
    display: block;
    width: 96px;
    height: 96px;
  }

  .auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 28px;
    box-shadow: var(--shadow);
  }

  .auth-card h1 {
    font-size: 20px;
    letter-spacing: -.02em;
    margin-bottom: var(--space-1);
  }

  .auth-card .sub {
    font-size: var(--text-5);
    color: var(--muted);
    margin-bottom: 22px;
  }

  .auth-foot {
    text-align: center;
    font-size: var(--text-3);
    color: var(--muted);
    margin-top: 18px;
  }

  .progress {
    display: flex;
    gap: var(--space-2);
    margin-bottom: 18px;
  }

  .progress span {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
  }

  .progress span.done {
    background: var(--accent);
  }

  /* ---- narrow screens */

  @media (max-width: 640px) {
    .topbar {
      padding: var(--space-3) var(--space-4) 0;
    }

    .topbar-inner {
      height: auto;
      padding: var(--space-3) var(--space-4);
      border-radius: 12px;
      gap: var(--space-2) var(--space-5);
      flex-wrap: wrap;
      min-height: 52px;
    }

    .topbar-right {
      flex-wrap: wrap;
    }

    .topbar-right .divider {
      display: none;
    }

    .content {
      padding: 20px 16px 40px;
    }

    .nav a {
      padding: var(--space-2) var(--space-3);
    }

    .user {
      display: none;
    }
  }
}
