/* CI/CD Promotion Console - shared styles */

:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1c2230;
  --border: #2a3240;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #3b82f6;
  --accent-hover: #2f6fd8;
  --ok: #34d399;
  --ok-dim: #0f3d30;
  --warn: #fbbf24;
  --warn-dim: #40320c;
  --bad: #f87171;
  --bad-dim: #40201f;
  --run: #60a5fa;
  --run-dim: #12294a;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f0f3f8;
    --border: #d8dee9;
    --text: #16202c;
    --muted: #5c6b7f;
    --ok-dim: #dcfce7;
    --warn-dim: #fef3c7;
    --bad-dim: #fee2e2;
    --run-dim: #dbeafe;
    --ok: #047857;
    --warn: #92400e;
    --bad: #b91c1c;
    --run: #1d4ed8;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

/* --- layout --------------------------------------------------------------- */

header.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

nav.tabs { display: flex; gap: 4px; margin-left: 8px; }

nav.tabs a {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

nav.tabs a:hover { background: var(--surface-2); color: var(--text); }
nav.tabs a.active { background: var(--accent); color: #fff; }

.spacer { flex: 1; }

.identity { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }

main { max-width: 1180px; margin: 0 auto; padding: 24px; }

section { margin-bottom: 32px; }

h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 12px; }

.hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

/* --- lists ---------------------------------------------------------------- */

/* One row per app.  The column template is set per list (see .app-list and
   .admin-list) so the dashboard and the admin page can carry different
   columns while sharing the row chrome. */
.list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.list-row {
  display: grid;
  gap: 18px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.list-row:last-child { border-bottom: none; }
.list-row:not(.list-head):hover { background: var(--surface-2); }

.list-head {
  padding: 9px 18px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
}

/* Every row is its own grid, so the tracks must not be content-sized - a
   minmax(0, Nfr) template plus min-width:0 children keeps the header and all
   rows on identical column boundaries whatever they contain. */
.list-row > * { min-width: 0; }

.app-list .list-row {
  grid-template-columns: minmax(0, 2fr) 130px minmax(0, 1.5fr) minmax(0, 1.2fr) 250px;
}

.admin-list .list-row {
  grid-template-columns: minmax(0, 1.5fr) 100px minmax(0, 2.2fr) minmax(0, 1.3fr) 210px;
}

.list-name { font-weight: 640; }
.list-sub { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.list-desc { color: var(--muted); font-size: 13px; margin-top: 3px; }

.list-cell { font-size: 13.5px; min-width: 0; overflow-wrap: anywhere; }
.list-cell .muted { color: var(--muted); font-size: 12.5px; display: block; }
.list-cell.paths { display: grid; gap: 3px; }
.list-cell.paths span { font-family: var(--mono); font-size: 12px; }
.list-cell.paths b { color: var(--muted); font-weight: 600; }

/* Left-aligned so the Refresh button sits at the same x on every row, even
   when a row has no output to view yet. */
.list-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.list-actions a { margin-left: auto; }

.list-problems { grid-column: 1 / -1; }

/* Below the column widths the grid needs, fall back to stacked rows. */
@media (max-width: 900px) {
  .list-head { display: none; }
  .app-list .list-row,
  .admin-list .list-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .list-actions { justify-content: flex-start; }
  .list-cell::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }
}

/* --- cards (sign-in, settings panel, dialogs) ----------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-head { display: flex; align-items: start; gap: 10px; }
.card-title { font-weight: 640; font-size: 16px; }
.card-slug { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.card-desc { color: var(--muted); font-size: 13px; margin: 0; }

.meta { display: grid; gap: 6px; font-size: 13px; }
.meta div { display: flex; justify-content: space-between; gap: 12px; }
.meta span.label { color: var(--muted); white-space: nowrap; }
.meta span.value { text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* --- badges --------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.success { background: var(--ok-dim); color: var(--ok); }
.badge.failed,
.badge.error,
.badge.timeout { background: var(--bad-dim); color: var(--bad); }
.badge.running { background: var(--run-dim); color: var(--run); }
.badge.never { background: var(--surface-2); color: var(--muted); }
.badge.warn { background: var(--warn-dim); color: var(--warn); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.running .dot { animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* --- controls ------------------------------------------------------------- */

button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.danger { color: var(--bad); }
button.small { padding: 4px 10px; font-size: 13px; }
button.link { background: none; border: none; color: var(--accent); padding: 0; }

input, textarea, select {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.field { margin-bottom: 12px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* --- tables --------------------------------------------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.wrap { white-space: normal; }

/* --- output / log viewer -------------------------------------------------- */

pre.output {
  margin: 0;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  max-height: 45vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- dialogs -------------------------------------------------------------- */

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(760px, 94vw);
  max-height: 90vh;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog .dialog-head,
dialog .dialog-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
}
dialog .dialog-head { border-bottom: 1px solid var(--border); font-weight: 640; }
dialog .dialog-foot { border-top: 1px solid var(--border); justify-content: flex-end; }
dialog .dialog-body { padding: 20px; overflow: auto; max-height: 70vh; }

/* --- toast / empty state -------------------------------------------------- */

#toast-stack { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 100; }

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 11px 15px;
  font-size: 14px;
  max-width: 380px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }

.empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
}

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 170px; }

.problem-list { margin: 0; padding-left: 18px; color: var(--bad); font-size: 13px; }

/* --- Test Stager: pipeline stages + smoke checks + log highlighting ------- */
.stages { display: flex; flex-direction: column; gap: 8px; }
.stage {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}
.stage > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.stage > summary::-webkit-details-marker { display: none; }
.stage > summary strong { text-transform: capitalize; }
.stage[open] > summary { border-bottom: 1px solid var(--border); }
.stage .output { margin: 0; border: 0; border-radius: 0; max-height: 320px; }
.stage .output .cmd { color: var(--accent); }
.stage .output .err { color: var(--bad); }

.smoke-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
}

/* --- Better Auth pages -------------------------------------------------- */
.auth-card { max-width: 420px; margin: 8vh auto; }
.auth-links { margin-top: 16px; text-align: center; }
.auth-links a { white-space: nowrap; }
