/* ppz server GUI — minimal, modern, readable. No framework. */

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --border: #e5e5e3;
  --text: #1c1c1a;
  --muted: #71716e;
  /* Sampled from the logo's pipe blue — a deeper royal that gives
     enough contrast against white button text. Used by buttons,
     active tab markers, and the primary CTA. */
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  /* Buttons stay this saturated cobalt in BOTH light and dark mode
     so they match the pipe in the logo. --accent itself shifts in
     dark mode (for link legibility on near-black bg) — buttons do
     not, because they always have white text on top. */
  --btn-bg: #1d4ed8;
  --btn-bg-hover: #1e40af;
  --code-bg: #f1f1ef;
  --row-hover: #f5f5f3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a18;
    --surface: #232321;
    --border: #353532;
    --text: #ececea;
    --muted: #92928e;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --code-bg: #2c2c2a;
    --row-hover: #2a2a28;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* Wide layout — opt-in container for pages that show data tables
   (e.g. the org page's pipes table). The default 960px cap left
   huge gutters on desktops and squeezed table cells onto multiple
   lines; this lifts the cap so the page uses available horizontal
   space. Falls back to 95vw on viewports narrower than 1440px so
   we never overflow. */
main.wide {
  max-width: min(1440px, 95vw);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { color: var(--accent-hover); text-decoration: underline; }
a:visited { color: var(--accent); }

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.1rem; margin: 2rem 0 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }

small, .meta { color: var(--muted); font-size: 0.85rem; }

code, pre {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
}
pre {
  padding: 0.75rem 1rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}

/* Header / brand */
.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.brand img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}
.brand h1 a { color: inherit; }
.brand .crumbs { color: var(--muted); font-size: 0.95rem; }

.back {
  display: inline-block;
  margin: 1.5rem 0 0;
  font-size: 0.9rem;
}

/* Lists & cards */
ul.tidy {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}
ul.tidy li {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
}
ul.tidy li:last-child { border-bottom: 0; }
ul.tidy li:hover { background: var(--row-hover); }

/* Invitations row: text on the left, action buttons clustered on
   the right. The .actions wrapper holds the two inline forms so we
   can `margin-left: auto` once instead of per-form. */
#invites li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
#invites .actions {
  margin-left: auto;
  display: inline-flex;
  gap: 0.5rem;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:last-child td { border-bottom: 0; }
th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--bg);
  font-weight: 600;
}
tbody tr:hover { background: var(--row-hover); }

/* Pipes table cell rules. The pipe / last-message / namespace /
   source cells carry short content but were wrapping because column
   widths were squeezed by the long payload preview. Cell-nowrap
   keeps short cells on one line; cell-truncate ellipsises overflow
   on the payload column (the elastic one — content can be
   arbitrarily long up to TruncatePayload's 60-byte cap, but at
   narrower viewports even 60 chars exceeds the column). Headers
   nowrap too so "LAST MESSAGE" doesn't break onto two lines.
   `max-width: 0` is the standard ellipsis-in-a-table-cell trick:
   forces the cell to defer its width to the table layout while
   still applying text-overflow. */
#pipes th { white-space: nowrap; }
#pipes td.cell-nowrap { white-space: nowrap; }
#pipes td.cell-truncate {
  max-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Forms */
form { display: inline-flex; align-items: center; gap: 0.5rem; margin-top: 1rem; }
label { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; color: var(--muted); }
input[type="text"], input:not([type]) {
  font: inherit;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  min-width: 200px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
button {
  font: inherit;
  padding: 0.4rem 0.85rem;
  background: var(--btn-bg);
  color: #fff;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}
button:hover { background: var(--btn-bg-hover); }

/* Empty / muted */
.empty { color: var(--muted); font-style: italic; }

/* Revoked API keys: dim + strike-through, no Revoke button. The
   row stays in the list for audit. */
[data-key-state="revoked"] {
  text-decoration: line-through;
  opacity: 0.55;
}
[data-key-state="revoked"] .revoked { color: var(--muted); }

/* Org page tab nav (Pipes / Users / API keys). Each link is a
   plain horizontal item; the active tab gets a coloured underline
   so the user can tell where they are without depending on URL. */
nav.tabs {
  display: flex;
  gap: 1.25rem;
  border-bottom: 1px solid var(--border);
  margin: 1rem 0 1rem;
}
nav.tabs a {
  padding: 0.5rem 0;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px; /* sit on top of the bottom border */
}
nav.tabs a:hover { color: var(--text); }
nav.tabs a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* Keys list + Users subsections (owner + members): flex rows so
   the trailing action (Revoke form, Remove form, Transfer-ownership
   button) hugs the right edge instead of inlining after the row's
   text content. */
#keys li,
[data-users-subsection] li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
#keys form.inline,
[data-users-subsection] li > form.inline,
[data-users-subsection] li > button[data-todo] {
  margin: 0 0 0 auto;
}

/* ──────────────────────────────────────────────────────────────────
   Landing page (`/`). The operator dashboard is at /dashboard; this
   surface is purely marketing — logo + tagline + animated demos.
   The hero sits on a black background so the existing logo PNG
   blends in seamlessly without alpha-channel surgery.
   ────────────────────────────────────────────────────────────── */

body[data-page="landing"] {
  background: var(--bg);
  margin: 0;
}

.hero {
  background: #000;
  color: #fff;
  padding: 4rem 1.5rem 3rem;
  text-align: center;
}
.hero-logo {
  display: block;
  margin: -3rem auto -3rem;
  max-width: min(480px, 70vw);
  height: auto;
  /* The source PNG has ~20% black padding baked in above + below
     the artwork. clip-path crops it visually; the matching negative
     margins above pull adjacent content into the void left behind
     so the tagline hugs the logo instead of floating in dead space.
     Swap when we have a properly cropped PNG. */
  clip-path: inset(20% 0);
}
.hero-tag {
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  margin: 0 0 0.8rem;
}
.hero-title {
  font-size: clamp(2.6rem, 6vw, 4.5rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.05;
  margin: 0 0 1.4rem;
}
.hero-sub {
  color: #b9b9b3;
  max-width: 640px;
  margin: 0 auto 1.6rem;
  font-size: 1rem;
  line-height: 1.5;
}
.hero-cta {
  margin: 0;
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
}
.btn-primary,
.btn-primary:visited {
  display: inline-block;
  padding: 0.75rem 1.4rem;
  background: var(--btn-bg);
  /* :visited would otherwise paint the text the browser's default
     visited-link colour and clash with the button background. Lock
     it to white in both states. */
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  border-radius: 6px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--btn-bg-hover); }

/* Device-flow approval form. The shared .hero-cta is a centred,
   wrapping flex ROW (landing/login put a single button in it). The
   device-verify form holds three stacked controls — org picker, the
   pairing code, then the Approve button — so we override it to a
   centred COLUMN here. (The old row layout let the full-width
   .org-field shrink and sit beside the button, squeezing it until
   "Approve as me" wrapped onto two lines.) */
body[data-page="device-verify"] .hero-cta {
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
/* Match the button width to the <select> so the column lines up, and
   never let the label wrap regardless of how narrow it gets. */
body[data-page="device-verify"] .btn-primary {
  white-space: nowrap;
  min-width: 240px;
  text-align: center;
}

/* Device-flow org picker: a label + <select> stacked on their own
   row above the pairing code. */
.org-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
}
.org-field label { color: var(--muted); font-size: 0.85rem; }
.org-select {
  font: inherit;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  min-width: 240px;
}
.org-select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* Pairing code, shown above the Approve button. The user reads this
   off the page to confirm it matches what the CLI printed, so it
   needs to be legible — large spaced monospace in a bordered pill,
   outlined in the pipe-blue cobalt (--btn-bg) to tie it to the brand
   without competing with the solid CTA below it. */
.device-code {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
.device-code-label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.device-code-value {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.5rem;
  font-weight: 600;
  /* trailing letter-spacing adds phantom space on the right; the
     extra left padding re-centres the glyphs in the pill. */
  letter-spacing: 0.18em;
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--btn-bg);
  border-radius: 8px;
  padding: 0.45rem 1rem 0.45rem 1.18rem;
}
/* Secondary button: subtle outline against the black hero, sits
   beside the primary CTA. Used for "GitHub →" today. */
.btn-secondary,
.btn-secondary:visited {
  display: inline-block;
  padding: 0.75rem 1.4rem;
  background: transparent;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  border: 1px solid #555;
  border-radius: 6px;
  transition: background 0.15s, border-color 0.15s;
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: #888;
}

/* ─── pipescloud marketing chrome ─── */
/* Admin server footer — version pin shown on /dashboard. */
.hero-footer .server-version { margin-left: 1rem; font-size: 0.75rem; opacity: 0.5; }
.server-footer { text-align: center; padding: 1rem; font-size: 0.75rem; color: var(--muted); opacity: 0.6; }

/* Get-started onboarding panel on /dashboard. Each step has a
   pre+copy-btn pair — reuses the .hero-install copy-btn pattern. */
.onboarding-steps {
  counter-reset: step;
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}
.onboarding-steps > li {
  counter-increment: step;
  position: relative;
  margin: 0 0 1.25rem;
  padding-left: 2.25rem;
}
.onboarding-steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
}
.onboarding-cmd {
  position: relative;
  background: #0d1117;
  color: #d6deeb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  border-radius: 8px;
  padding: 0.75rem 2.75rem 0.75rem 1rem;
  margin: 0.5rem 0 0;
  border: 1px solid #1f2933;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.onboarding-cmd code { font: inherit; color: inherit; background: transparent; padding: 0; }
.onboarding-cmd .copy-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  padding: 0.25rem 0.45rem;
  border: 1px solid #2a3a47;
  background: rgba(255, 255, 255, 0.05);
  color: #8a9bab;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.onboarding-cmd .copy-btn:hover { background: rgba(255, 255, 255, 0.1); color: #d6deeb; }
.onboarding-cmd .copy-btn .check-icon { display: none; }
.onboarding-cmd .copy-btn.copied { color: #5fb87a; border-color: #5fb87a; }
.onboarding-cmd .copy-btn.copied .copy-icon { display: none; }
.onboarding-cmd .copy-btn.copied .check-icon { display: inline; }

/* Admin-page mobile rules. Co-located with the existing demo-pair
   @media block above for cohesion; viewport meta tag landed alongside
   these — without it the breakpoint never fires on phones and the
   page renders at 980px-scaled-to-fit ("tiny on mobile"). */
@media (max-width: 720px) {
  main {
    padding: 0 0.75rem;
  }
  .brand h1 {
    font-size: 1.1rem;
    line-height: 1.3;
  }
  .brand .crumbs {
    font-size: 0.85rem;
    word-break: break-all;
  }
  nav.tabs {
    flex-direction: column;
    gap: 0.25rem;
    margin: 0.75rem 0;
  }
  nav.tabs a {
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid transparent;
    margin-bottom: 0;
  }
  nav.tabs a.active {
    background: rgba(37, 99, 235, 0.06);
    border-left: 3px solid var(--accent);
    border-bottom-color: transparent;
    padding-left: 0.5rem;
  }
  .panel-form,
  main form {
    width: 100%;
    box-sizing: border-box;
  }
  .panel-form input,
  .panel-form button,
  main form input,
  main form button {
    width: 100%;
    box-sizing: border-box;
    margin-top: 0.25rem;
  }
  .panel-form label,
  main form label {
    display: block;
    margin-bottom: 0.5rem;
  }
  #pipes {
    display: block;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }
  #pipes thead, #pipes tbody, #pipes tr {
    display: table;
    width: 100%;
    table-layout: auto;
  }
  .hero-cta {
    flex-direction: column;
    align-items: stretch;
  }
  .hero-cta .btn-primary,
  .hero-cta .btn-secondary {
    width: 100%;
    text-align: center;
  }
  .hero-install {
    max-width: 100%;
    font-size: 0.78rem;
    white-space: pre-wrap;
    word-break: break-all;
  }
  .onboarding-cmd {
    font-size: 0.75rem;
    padding: 0.6rem 2.5rem 0.6rem 0.75rem;
  }
}
