/* Concourse Admin — ops console */

:root {
  --bg: #0c0d10;
  --surface: #14161b;
  --surface-2: #1a1d24;
  --elevated: #1e222b;
  --ink: #e8eaed;
  --muted: #8b919c;
  --faint: #5c6370;
  --line: #2a2f3a;
  --line-strong: #3a4150;
  --accent: #6ea8fe;
  --accent-dim: rgba(110, 168, 254, 0.12);
  --green: #3dd68c;
  --green-dim: rgba(61, 214, 140, 0.12);
  --red: #f07178;
  --red-dim: rgba(240, 113, 120, 0.12);
  --amber: #e6b450;
  --amber-dim: rgba(230, 180, 80, 0.12);
  --radius: 6px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --sidebar-w: 13.5rem;
}

* { box-sizing: border-box; }

body.admin {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
}

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

/* —— Shell —— */
.admin-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

@media (max-width: 800px) {
  .admin-shell { grid-template-columns: 1fr; }
  .admin-sidebar { display: none; }
}

.admin-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 1rem 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.admin-sidebar .logo {
  font-weight: 650;
  font-size: 0.85rem;
  letter-spacing: -0.02em;
  padding: 0.35rem 0.6rem 1rem;
  color: var(--ink);
  display: block;
  text-decoration: none;
}

.admin-sidebar .logo span { color: var(--faint); font-weight: 500; }

.admin-sidebar nav a {
  display: block;
  color: var(--muted);
  padding: 0.4rem 0.6rem;
  border-radius: 5px;
  font-size: 0.88rem;
  margin-bottom: 0.1rem;
  text-decoration: none;
}

.admin-sidebar nav a:hover {
  background: var(--elevated);
  color: var(--ink);
  text-decoration: none;
}

.admin-sidebar nav a.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 550;
}

.admin-sidebar .user {
  margin-top: auto;
  padding: 0.65rem 0.6rem;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--faint);
}

.admin-sidebar .user a,
.admin-sidebar .user button.linkish {
  color: var(--muted);
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.admin-main {
  padding: 1.25rem 1.5rem 3rem;
  max-width: 72rem;
  min-width: 0;
}

/* —— Page header —— */
.page-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.page-top h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.page-sub {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.45rem;
}

.page-sub .sep { color: var(--faint); }

.crumb {
  font-size: 0.75rem;
  color: var(--faint);
  margin: 0 0 0.3rem;
  font-family: var(--mono);
}

.crumb a { color: var(--faint); }

.actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.7rem;
  background: var(--elevated);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
}

.btn:hover {
  background: #252a35;
  text-decoration: none;
  border-color: #4a5263;
  color: var(--ink);
}

.btn.primary {
  background: var(--accent);
  color: #0c0d10;
  border-color: var(--accent);
  font-weight: 600;
}

.btn.primary:hover {
  filter: brightness(1.08);
  color: #0c0d10;
}

.btn.secondary {
  background: var(--elevated);
  color: var(--ink);
  border-color: var(--line-strong);
}

.btn.danger {
  color: var(--red);
  border-color: #5a3035;
}

.btn.danger:hover {
  background: var(--red-dim);
}

/* —— Health strip —— */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
  margin-bottom: 1rem;
}

@media (max-width: 700px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.85rem;
}

.stat.bad {
  border-color: rgba(240, 113, 120, 0.35);
  background: linear-gradient(180deg, rgba(240, 113, 120, 0.06), var(--surface));
}

.stat .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--faint);
  margin-bottom: 0.3rem;
}

.stat .value {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 550;
  color: var(--ink);
  word-break: break-all;
}

.stat .value.ok { color: var(--green); }
.stat .value.err { color: var(--red); }

.stat .hint {
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--faint);
  font-family: var(--mono);
}

.stat .hint a { font-family: var(--font); }

.stats.dimmed .stat { opacity: 0.85; }

/* —— Cards / panels —— */
.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.card {
  padding: 1rem 1.1rem;
}

.card h1 {
  margin-top: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.card h2,
.panel-head h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.panels {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.85rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.head-actions {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.panel-body { padding: 0.75rem 0.85rem; }
.panel-body.flush { padding: 0; }

/* —— Progressive disclosure —— */
.details-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  margin-top: 0.25rem;
  overflow: visible;
  position: relative;
  z-index: 1;
}

.details-block > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.7rem 0.9rem;
  user-select: none;
}

.details-block > summary::-webkit-details-marker { display: none; }

.details-block > summary:hover {
  background: rgba(255, 255, 255, 0.02);
}

.summary-title {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.summary-meta {
  font-size: 0.8rem;
  color: var(--faint);
  flex: 1;
}

.summary-chevron {
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  margin-left: auto;
  flex-shrink: 0;
}

.details-block[open] > summary {
  border-bottom: 1px solid var(--line);
}

.details-block[open] .summary-chevron {
  transform: rotate(45deg);
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding: 0.75rem;
  overflow: visible;
  position: relative;
  z-index: 1;
}

.details-grid .panel {
  margin: 0;
  background: var(--bg);
  overflow: visible;
  position: relative;
  z-index: 0;
}

/* Lift the panel that owns an open tip above its grid sibling */
.details-grid .panel:has(.tip:hover),
.details-grid .panel:has(.tip:focus),
.details-grid .panel:has(.tip:focus-within) {
  z-index: 10;
}

.details-grid .panel-head {
  border-radius: var(--radius) var(--radius) 0 0;
}

.details-grid .panel-body {
  overflow: visible;
  position: relative;
}

@media (max-width: 900px) {
  .details-grid { grid-template-columns: 1fr; }
}

/* —— Property list —— */
.props {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  overflow: visible;
}

.prop {
  display: grid;
  grid-template-columns: 8rem 1fr;
  gap: 0.5rem;
  align-items: baseline;
  position: relative;
}

.prop dt {
  font-size: 0.75rem;
  color: var(--faint);
  font-weight: 500;
  position: relative;
  z-index: 0;
}

.prop dd { margin: 0; font-size: 0.88rem; }

/* —— Hover / focus tooltip —— */
.tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.95rem;
  height: 0.95rem;
  margin-left: 0.25rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--elevated);
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 700;
  font-family: var(--font);
  line-height: 1;
  cursor: help;
  vertical-align: middle;
  z-index: 1;
}

.tip:hover,
.tip:focus,
.tip:focus-within {
  color: var(--ink);
  border-color: var(--muted);
  outline: none;
  z-index: 50;
}

.tip-text {
  display: none;
  position: absolute;
  left: 0;
  bottom: calc(100% + 0.4rem);
  top: auto;
  width: 16.5rem;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: #1e222b;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
  text-transform: none;
  white-space: normal;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  z-index: 60;
  pointer-events: none;
}

.tip-text::after {
  content: "";
  position: absolute;
  top: 100%;
  bottom: auto;
  left: 0.45rem;
  border: 5px solid transparent;
  border-top-color: var(--line-strong);
}

.tip:hover .tip-text,
.tip:focus .tip-text,
.tip:focus-within .tip-text {
  display: block;
}

/* Legacy detail grid (other pages) */
dl.detail {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 0.4rem 1rem;
}

dl.detail dt {
  font-weight: 600;
  color: var(--muted);
}

dl.detail dd { margin: 0; }

code, .mono {
  font-family: var(--mono);
  font-size: 0.84em;
  color: #c5cad3;
}

.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 0.82rem; }

/* —— Badges —— */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 550;
  font-family: var(--mono);
  background: var(--elevated);
  color: var(--muted);
  vertical-align: middle;
}

.badge .dot,
.badge::before {
  content: none;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  flex-shrink: 0;
  display: inline-block;
}

.badge.on { background: var(--green-dim); color: var(--green); }
.badge.on .dot { background: var(--green); }
.badge.off { background: var(--red-dim); color: var(--red); }
.badge.off .dot { background: var(--red); }
.badge.warn { background: var(--amber-dim); color: var(--amber); }
.badge.warn .dot { background: var(--amber); }

/* —— Key box —— */
.key-box {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  margin-bottom: 0.65rem;
}

.details-grid .key-box {
  background: var(--surface-2);
}

.key-box .prefix {
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--accent);
}

.key-box .faint {
  margin-left: auto;
}

.key-swap {
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

/* —— Attention banners —— */
.attention {
  background: var(--amber-dim);
  border: 1px solid rgba(230, 180, 80, 0.35);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
}

.attention p {
  margin: 0.3rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  max-width: 44rem;
}

.attention-title {
  font-weight: 650;
  font-size: 0.9rem;
  color: var(--amber);
}

.attention.danger {
  background: var(--red-dim);
  border-color: rgba(240, 113, 120, 0.35);
}

.attention.danger .attention-title { color: var(--red); }

/* —— Empty panels —— */
.empty {
  padding: 2rem 1.25rem;
  text-align: center;
}

.empty.compact {
  padding: 1.25rem 1rem;
  text-align: left;
}

.empty-title {
  margin: 0 0 0.35rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
}

.empty-body {
  margin: 0 auto 0.85rem;
  max-width: 28rem;
  color: var(--faint);
  font-size: 0.88rem;
}

.empty.compact .empty-body {
  margin-left: 0;
  margin-right: 0;
}

/* —— Setup checklist —— */
.checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.85rem;
}

.checklist li {
  display: grid;
  grid-template-columns: 1.25rem 1fr;
  gap: 0.75rem;
  align-items: start;
}

.checklist .check {
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 4px;
  border: 1.5px solid var(--line-strong);
  margin-top: 0.15rem;
  background: var(--bg);
  display: block;
}

.checklist .done .check {
  border-color: var(--green);
  background: var(--green-dim);
  box-shadow: inset 0 0 0 2px var(--bg);
  position: relative;
}

.checklist .done .check::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 1px;
  width: 5px;
  height: 8px;
  border: solid var(--green);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

.checklist strong {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
}

.checklist p {
  margin: 0 0 0.55rem;
  color: var(--muted);
  font-size: 0.85rem;
  max-width: 36rem;
}

.checklist .muted-step { opacity: 0.75; }
.checklist .done strong {
  color: var(--muted);
  font-weight: 550;
}

/* —— Tables —— */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: transparent;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--line);
}

th {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--faint);
  font-weight: 600;
  background: var(--surface-2);
}

tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
tbody tr:last-child td { border-bottom: none; }

td a { font-weight: 500; }

/* —— Forms —— */
label {
  display: block;
  font-weight: 600;
  margin: 0.75rem 0 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="number"],
input[type="search"],
textarea,
select {
  width: 100%;
  max-width: 28rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  box-sizing: border-box;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

/* —— Install form: one tracker's credentials at a time —— */
.tracker-fields {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.25rem 1rem 1rem;
  margin: 0.5rem 0 0;
  max-width: 28rem;
}

/* CSS-only toggle keyed off the selected option — no JS in the admin. */
.install-form:has(#install_tracker_kind option[value="github"]:checked)
  .tracker-fields[data-tracker="linear"],
.install-form:has(#install_tracker_kind option[value="linear"]:checked)
  .tracker-fields[data-tracker="github"] {
  display: none;
}

/* —— Flash / secrets —— */
.flash {
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
}

.flash.notice {
  background: var(--green-dim);
  border: 1px solid rgba(61, 214, 140, 0.35);
  color: var(--green);
}

.flash.alert {
  background: var(--red-dim);
  border: 1px solid rgba(240, 113, 120, 0.35);
  color: var(--red);
}

.flash.notice code,
.flash.alert code {
  word-break: break-all;
  color: inherit;
}

.secret-banner {
  background: var(--amber-dim);
  border: 1px solid rgba(230, 180, 80, 0.4);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  word-break: break-all;
  color: #f0d78c;
}

.secret-banner code {
  color: var(--ink);
}

.errors {
  background: var(--red-dim);
  border: 1px solid rgba(240, 113, 120, 0.35);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  color: var(--red);
}

.errors ul {
  margin: 0.25rem 0 0;
  padding-left: 1.25rem;
}

.sha {
  display: inline;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--amber-dim);
  color: var(--amber);
  font-family: var(--mono);
  font-size: 0.9em;
  font-weight: 600;
}

/* Login page (no sidebar content width) */
body.admin.login-page .admin-shell {
  grid-template-columns: 1fr;
}

body.admin.login-page .admin-main {
  max-width: 28rem;
  margin: 3rem auto;
}

/* —— Markdown editor (Write | Preview) —— */
.md-editor {
  max-width: 40rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  margin-bottom: 1rem;
}

.md-editor__tabs {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.md-editor__tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
}

.md-editor__tab:hover { color: var(--ink); background: var(--elevated); }
.md-editor__tab.is-active {
  color: var(--ink);
  background: var(--elevated);
  box-shadow: inset 0 0 0 1px var(--line);
}

.md-editor__upload-btn {
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  padding: 0.3rem 0.5rem;
}

.md-editor__upload-btn:hover { text-decoration: underline; }

.md-editor__drop {
  position: relative;
  padding: 0.5rem;
}

.md-editor__drop.is-dragover {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: var(--accent-dim);
}

.md-editor__textarea {
  width: 100%;
  min-height: 12rem;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
}

.md-editor__hint {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
}

.md-editor__preview {
  padding: 0.85rem 1rem 1rem;
  min-height: 12rem;
}

/* Rendered Markdown (admin preview / show) */
.concourse-md-preview {
  color: var(--ink);
  line-height: 1.55;
  font-size: 0.95rem;
}

.concourse-md-preview p { margin: 0 0 0.65em; }
.concourse-md-preview p:last-child { margin-bottom: 0; }
.concourse-md-preview a { color: var(--accent); }
.concourse-md-preview ul,
.concourse-md-preview ol {
  margin: 0.4em 0 0.7em;
  padding-left: 1.25rem;
}
.concourse-md-preview img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.75em 0;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.concourse-md-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6em 0 0.85em;
  font-size: 0.9rem;
}
.concourse-md-preview th,
.concourse-md-preview td {
  border: 1px solid var(--line);
  padding: 0.35em 0.55em;
  text-align: left;
  vertical-align: top;
}
.concourse-md-preview th {
  background: var(--surface-2);
  font-weight: 600;
}
.concourse-md-preview code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.concourse-md-preview pre {
  margin: 0.5em 0 0.75em;
  padding: 0.75em;
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.concourse-md-preview pre code {
  background: none;
  padding: 0;
}
.concourse-md-preview blockquote {
  margin: 0.5em 0;
  padding-left: 0.85em;
  border-left: 3px solid var(--line-strong);
  color: var(--muted);
}
.concourse-md-preview h2,
.concourse-md-preview h3,
.concourse-md-preview h4 {
  margin: 0.85em 0 0.35em;
  font-weight: 650;
  line-height: 1.3;
}
.concourse-md-preview h2 { font-size: 1.1em; }
.concourse-md-preview h3 { font-size: 1.05em; }
.concourse-md-preview h4 { font-size: 1em; }
