
/* Tokens: the light theme, then the dark one. */
:root {
  color-scheme: light dark;
  --page: #f6f7fb;
  --surface: #ffffff;
  --raised: #fbfbfe;
  --border: #e4e7ef;
  --border-strong: #d3d8e3;
  --text: #0f172a;
  --muted: #5b6478;
  --faint: #8a93a6;
  --hover: rgba(15, 23, 42, 0.035);
  --code: rgba(15, 23, 42, 0.05);
  --accent: #5b5bd6;
  --accent-hover: #4c4cc4;
  --accent-tint: rgba(91, 91, 214, 0.1);
  --ring: rgba(91, 91, 214, 0.35);
  --primary: #5b5bd6;
  --primary-hover: #4c4cc4;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --info: #2563eb;
  --ok-text: #15803d;
  --warn-text: #b45309;
  --bad-text: #b91c1c;
  --ok-tint: rgba(22, 163, 74, 0.12);
  --warn-tint: rgba(217, 119, 6, 0.12);
  --bad-tint: rgba(220, 38, 38, 0.1);
  --info-tint: rgba(37, 99, 235, 0.1);
  --neutral-tint: rgba(91, 100, 120, 0.12);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 2px 8px rgba(15, 23, 42, 0.04);
  --lift: 0 1px 2px rgba(15, 23, 42, 0.05), 0 16px 40px rgba(15, 23, 42, 0.08);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0b0f1a;
    --surface: #121826;
    --raised: #161d2e;
    --border: #232c40;
    --border-strong: #2f3a52;
    --text: #e6e9f2;
    --muted: #9aa3b8;
    --faint: #6b7489;
    --hover: rgba(255, 255, 255, 0.035);
    --code: rgba(255, 255, 255, 0.07);
    --accent: #8b8cf5;
    --accent-hover: #a5a6f8;
    --accent-tint: rgba(139, 140, 245, 0.14);
    --ring: rgba(139, 140, 245, 0.45);
    --primary-hover: #6b6be2;
    --ok: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --info: #60a5fa;
    --ok-text: #4ade80;
    --warn-text: #fbbf24;
    --bad-text: #f87171;
    --ok-tint: rgba(74, 222, 128, 0.12);
    --warn-tint: rgba(251, 191, 36, 0.12);
    --bad-tint: rgba(248, 113, 113, 0.12);
    --info-tint: rgba(96, 165, 250, 0.12);
    --neutral-tint: rgba(154, 163, 184, 0.14);
    --shadow: none;
    --lift: 0 20px 48px rgba(0, 0, 0, 0.4);
  }
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, p, ol, ul, dl, dd { margin: 0; }
h1 { font-size: 24px; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 15px; line-height: 1.4; font-weight: 650; }
h3 { font-size: 13px; line-height: 1.4; font-weight: 600; color: var(--muted); }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }
strong { font-weight: 650; }
code {
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--code);
  overflow-wrap: anywhere;
}
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }
.icon { flex: none; width: 18px; height: 18px; }

/* The frame: a sidebar and the page beside it. */
.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
  background: linear-gradient(to right, var(--surface) 247px, var(--border) 247px 248px, transparent 248px);
}
.shell > main {
  width: 100%;
  max-width: 1120px;
  justify-self: center;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 32px 40px 64px;
}

/* Sidebar: brand, environment, navigation, and who is signed in. */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 20px 12px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.sidebar-top { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 0 8px; }
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand { color: var(--text); font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
a.brand:hover { color: var(--text); text-decoration: none; }
.logo {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: #ffffff;
  background: linear-gradient(135deg, #7472ec, #5b5bd6 55%, #4a45c4);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), 0 1px 2px rgba(15, 23, 42, 0.16);
}
.logo .icon { width: 16px; height: 16px; }
.env {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 1px 9px 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--raised);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 20px;
  white-space: nowrap;
}
.env::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--warn);
  box-shadow: 0 0 0 3px var(--warn-tint);
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 550;
}
.sidebar nav a .icon { color: var(--faint); }
.sidebar nav a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.sidebar nav a:hover .icon { color: var(--muted); }
.sidebar nav a[aria-current="page"] { background: var(--accent-tint); color: var(--accent); }
.sidebar nav a[aria-current="page"] .icon { color: var(--accent); }
.sidebar nav a[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.account {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--raised);
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 13px;
  font-weight: 650;
}
.who-text { min-width: 0; }
.who-name, .who-groups { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-name { font-size: 13px; font-weight: 600; }
.who-groups { font-size: 12px; color: var(--faint); }

/* Page header */
.page-head { display: flex; flex-direction: column; gap: 4px; padding-bottom: 4px; }
.subtitle { color: var(--muted); }
.section-title {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Cards and the grids that hold them */
.card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 24px; }
.card-head h3 { font-size: 15px; font-weight: 650; color: var(--text); }
.more { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 550; white-space: nowrap; }
.more .icon { width: 14px; height: 14px; }
.sub { display: flex; flex-direction: column; gap: 8px; }
.grid, .split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
@media (min-width: 1000px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  /* The overview: the two short cards side by side, then the lists at full width. */
  .overview {
    align-items: stretch;
    grid-template-areas: "running access" "deploys deploys" "changes changes" "links links";
  }
  .overview > .card-running { grid-area: running; }
  .overview > .card-access { grid-area: access; }
  .overview > .card-deploys { grid-area: deploys; }
  .overview > .card-changes { grid-area: changes; }
  .overview > .card-links { grid-area: links; }
}

/* Tables: full width in their card, scrolling sideways when narrow. */
.table-wrap { overflow-x: auto; margin: 0 -20px; }
.card > .table-wrap:first-child { margin-top: -20px; }
.card > .table-wrap:first-child th { border-top: 0; }
.card > .table-wrap:last-child { margin-bottom: -20px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 8px 12px; text-align: left; vertical-align: middle; }
th {
  height: 36px;
  background: var(--raised);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
td { height: 44px; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
tr:last-child > td { border-bottom: 0; }
tbody tr:hover > td { background: var(--hover); }
td code, td a, td .pill, td .tag { white-space: nowrap; overflow-wrap: normal; }
.end { text-align: right; white-space: nowrap; }
.end form { display: inline-flex; }
.kv th {
  width: 160px;
  height: 44px;
  background: transparent;
  border-top: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}
.kv tr:last-child > th { border-bottom: 0; }
.kv tr:hover > td { background: transparent; }
/* A table of row groups, each led by its name. */
.grouped tbody th {
  height: auto;
  padding-top: 13px;
  vertical-align: top;
  background: transparent;
  border-top: 0;
  border-bottom: 0;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}
.grouped td:first-child { padding-left: 12px; }
.grouped tbody + tbody > tr:first-child > * { border-top: 1px solid var(--border); }

/* Pills and tags */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--neutral-tint);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.pill.ok { background: var(--ok-tint); color: var(--ok-text); }
.pill.warn { background: var(--warn-tint); color: var(--warn-text); }
.pill.bad { background: var(--bad-tint); color: var(--bad-text); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
}
.tag.neutral { background: var(--neutral-tint); color: var(--muted); }

/* Buttons: primary by default, then secondary, danger and plain. */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
button:hover, .button:hover { background: var(--primary-hover); color: #ffffff; text-decoration: none; }
.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05); }
.secondary:hover { background: var(--raised); color: var(--text); border-color: var(--faint); }
.danger { background: var(--surface); color: var(--bad-text); border-color: var(--border-strong); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05); }
.danger:hover { background: var(--bad-tint); color: var(--bad-text); border-color: var(--bad); }
.plain { background: transparent; color: var(--accent); box-shadow: none; padding: 0 6px; }
.plain:hover { background: var(--accent-tint); color: var(--accent); }
.block { width: 100%; }
.small { height: 30px; padding: 0 10px; font-size: 13px; }
.buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* Forms: labels above fields. */
form { margin: 0; }
.fields { display: flex; flex-direction: column; gap: 16px; }
.fields.narrow { max-width: 520px; }
.field { display: flex; flex-direction: column; gap: 6px; }
label { font-size: 13px; font-weight: 600; }
input[type="text"], select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color 0.15s ease;
}
input[type="text"]:hover, select:hover, textarea:hover { border-color: var(--faint); }
input[type="text"]:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 0;
  border-color: var(--accent);
}
textarea { min-height: 120px; resize: vertical; font-family: var(--mono); font-size: 13px; line-height: 1.5; }
.hint { color: var(--muted); font-size: 13px; }

/* Notices: class="note", the tone in data-tone. */
.note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border-left: 3px solid var(--info);
  border-radius: 8px;
  background: var(--info-tint);
  color: var(--text);
}
.note .icon { margin-top: 1px; color: var(--info); }
.note[data-tone="success"] { border-left-color: var(--ok); background: var(--ok-tint); }
.note[data-tone="success"] .icon { color: var(--ok); }
.note[data-tone="warn"] { border-left-color: var(--warn); background: var(--warn-tint); }
.note[data-tone="warn"] .icon { color: var(--warn); }
.note[data-tone="error"] { border-left-color: var(--bad); background: var(--bad-tint); }
.note[data-tone="error"] .icon { color: var(--bad); }

/* Empty states, and a source that couldn't be read */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 12px;
  color: var(--muted);
  text-align: center;
}
.empty .icon { width: 28px; height: 28px; color: var(--faint); }

/* Overview */
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: 12px 20px; }
.facts dt { color: var(--muted); }
.facts dd { min-width: 0; overflow-wrap: anywhere; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; padding: 0; list-style: none; }
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--raised);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.tile:hover { border-color: var(--accent); background: var(--accent-tint); }
.tile a { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 600; }
.tile a:hover { color: var(--text); text-decoration: none; }
.tile a .icon { color: var(--accent); }
.tile a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.tile a:focus-visible { outline: 0; }
.tile a:focus-visible::after { outline: 3px solid var(--ring); outline-offset: 2px; }
.tile p { color: var(--muted); font-size: 13px; }

/* A new API key: the key in a highlighted card, then the setup. */
.key-card { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-tint), var(--shadow); }
.key-card textarea { min-height: 0; background: var(--raised); font-size: 14px; }
code.block {
  display: block;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--raised);
  line-height: 1.6;
  white-space: pre-wrap;
}
.steps { display: flex; flex-direction: column; gap: 8px; padding-left: 20px; }
.confirm { max-width: 640px; }

/* Signed out and error pages: one centered card. */
.solo {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 48px 16px;
  background: radial-gradient(1100px 520px at 50% -120px, var(--accent-tint), transparent 70%), var(--page);
}
.solo > main { width: 100%; max-width: 400px; }
.solo-card, .error-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px 28px 28px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--lift);
}
.solo-card > .logo { width: 44px; height: 44px; border-radius: 12px; }
.solo-card > .logo .icon { width: 24px; height: 24px; }
.solo-card h1 { font-size: 22px; }
.solo-card h1 .brand { font-size: inherit; font-weight: inherit; letter-spacing: inherit; }
.solo-card .note, .error-card .note { width: 100%; text-align: left; }
.solo-card .buttons, .error-card .buttons { width: 100%; justify-content: center; }
.lede { color: var(--muted); }
.error-wrap { display: grid; place-items: center; min-height: 60vh; }
.error-card { width: 100%; max-width: 440px; box-shadow: var(--shadow); }
.status {
  color: var(--faint);
  font-size: 64px;
  font-weight: 750;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  opacity: 0.55;
}

/*
 * Phone: the sidebar becomes a top bar. The brand and the environment share the first row; the navigation's pills and
 * Sign out flow inline after it, wrapping onto as many rows as they need, so every item is always in view.
 */
@media (max-width: 760px) {
  /* The top bar keeps its own height; the page below takes the rest of a short screen. */
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; background: none; }
  .sidebar {
    position: static;
    height: auto;
    overflow: visible;
    display: block;
    padding: 12px 16px 6px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-top {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
    padding: 0;
  }
  .sidebar-top .brand-row { gap: 8px; }
  .sidebar-top .logo { width: 24px; height: 24px; border-radius: 7px; }
  .sidebar-top .logo .icon { width: 14px; height: 14px; }
  .sidebar-top .brand { font-size: 14px; }
  .sidebar-top .env { gap: 6px; padding: 0 8px 0 7px; font-size: 11px; }
  .sidebar nav, .account, .account form { display: inline; }
  .sidebar nav a {
    display: inline-flex;
    vertical-align: middle;
    height: 32px;
    margin: 0 6px 6px 0;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    white-space: nowrap;
  }
  .sidebar nav a[aria-current="page"] { border-color: transparent; }
  .sidebar nav a[aria-current="page"]::before { display: none; }
  .account { margin: 0; padding: 0; border: 0; background: none; }
  .who { display: none; }
  .account .block { width: auto; height: 32px; margin: 0 0 6px; padding: 0 12px; vertical-align: middle; }
  .shell > main { gap: 16px; padding: 20px 16px 48px; }
  h1 { font-size: 22px; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; }
  .card > .table-wrap:first-child { margin-top: -16px; }
  .card > .table-wrap:last-child { margin-bottom: -16px; }
  th:first-child, td:first-child { padding-left: 16px; }
  th:last-child, td:last-child { padding-right: 16px; }
  .kv th { width: auto; }
  .solo { padding: 24px 16px; }
  .solo-card, .error-card { padding: 28px 20px 24px; }
  .status { font-size: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
