/* Surgio Manager — clean product UI, same design language as Pulsebox:
   light neutral surfaces, Geist type, monochrome accent, rounded cards. */

/* ---- Fonts (self-hosted, latin subset) ------------------------------- */
@font-face { font-family: "Geist"; font-style: normal; font-weight: 400; font-display: swap; src: url(/static/fonts/geist-400.woff2) format("woff2"); }
@font-face { font-family: "Geist"; font-style: normal; font-weight: 500; font-display: swap; src: url(/static/fonts/geist-500.woff2) format("woff2"); }
@font-face { font-family: "Geist"; font-style: normal; font-weight: 600; font-display: swap; src: url(/static/fonts/geist-600.woff2) format("woff2"); }
@font-face { font-family: "Geist"; font-style: normal; font-weight: 700; font-display: swap; src: url(/static/fonts/geist-700.woff2) format("woff2"); }
@font-face { font-family: "Geist Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url(/static/fonts/geist-mono-400.woff2) format("woff2"); }
@font-face { font-family: "Geist Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url(/static/fonts/geist-mono-500.woff2) format("woff2"); }

/* ---- Tokens ---------------------------------------------------------- */
:root {
  color-scheme: light;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e8eaed;
  --border-strong: #d7dbe0;

  --text: #0d1117;
  --text-2: #51596b;
  --muted: #8b93a3;

  --accent: #18181b;
  --accent-hover: #000000;
  --accent-weak: #f0f0f1;
  --ring: 0 0 0 3px rgba(24, 24, 27, 0.14);

  --up: #047a55;
  --up-bg: #e6f6ef;
  --down: #d4332b;
  --down-bg: #fdeceb;
  --running: #b06a00;
  --running-bg: #fdf1dd;

  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --r-lg: 14px;
  --r: 10px;
  --r-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(13, 17, 23, 0.05);
  --shadow: 0 1px 3px rgba(13, 17, 23, 0.06), 0 8px 24px -12px rgba(13, 17, 23, 0.12);
  --maxw: 1120px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.55;
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--accent-weak);
  border-radius: 5px;
  padding: 1px 5px;
}

.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); font-weight: 400; }

/* ---- Top bar --------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  min-height: 60px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--text);
}

.brand .mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  box-shadow: 0 2px 6px -1px rgba(24, 24, 27, 0.4);
}

.nav { display: flex; flex-wrap: wrap; gap: 4px; }

.nav a {
  padding: 7px 12px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  color: var(--text-2);
  transition: color 0.15s ease, background 0.15s ease;
}

.nav a:hover { color: var(--text); background: var(--surface-2); }

.nav a.active { color: var(--accent); background: var(--accent-weak); }

.session { margin-left: auto; display: flex; align-items: center; gap: 14px; }

/* ---- Layout ---------------------------------------------------------- */
.page {
  width: min(var(--maxw), calc(100% - 48px));
  margin: 36px auto 80px;
}

.auth-shell {
  min-height: calc(100vh - 220px);
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel { width: min(420px, 100%); }

.auth-sub { margin-bottom: 22px; }

/* ---- Headings -------------------------------------------------------- */
.eyebrow {
  display: inline-block;
  margin-bottom: 10px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-weak);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent);
}

.eyebrow a { text-decoration: none; }
.eyebrow a:hover { text-decoration: underline; }

h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

h2 {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

p { margin: 6px 0 0; color: var(--text-2); }

.subtitle {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  word-break: break-all;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
}

.page-head p { font-size: 14px; color: var(--muted); max-width: 640px; }

.head-actions { margin-top: 0; }

/* ---- Cards / sections ------------------------------------------------ */
.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

.panel { padding: 22px; margin-bottom: 18px; }

.form-panel { max-width: 480px; padding: 28px; }

.wide-panel { max-width: 720px; }

.setup-form { max-width: 720px; }

/* ---- Notices --------------------------------------------------------- */
.notice {
  display: flex;
  gap: 10px;
  margin-bottom: 22px;
  padding: 13px 16px;
  border: 1px solid #f3c9c6;
  border-radius: var(--r);
  background: var(--down-bg);
  color: #a3231c;
  font-weight: 500;
  font-size: 14px;
}

.notice.success { border-color: #bce5d3; background: var(--up-bg); color: #056043; }

/* ---- Forms ----------------------------------------------------------- */
label { display: grid; gap: 7px; margin-bottom: 18px; }

label > span { font-size: 13px; font-weight: 500; color: var(--text-2); }

.field-hint { font-size: 12.5px; font-weight: 400; color: var(--muted); }

.field-hint code { font-size: 11.5px; padding: 1px 5px; }

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  color: var(--text);
  background: var(--surface);
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input { min-height: 42px; }

select { min-height: 42px; }

input::placeholder,
textarea::placeholder { color: var(--muted); }

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

textarea {
  min-height: 150px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
}

input[readonly] {
  color: var(--text-2);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 12.5px;
}

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

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid label { margin-bottom: 0; }

.field-narrow { max-width: 220px; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}

.inline-form label { margin-bottom: 0; flex: 0 1 220px; }
.inline-form .grow { flex: 1 1 220px; }
.inline-form button { margin-bottom: 1px; }

.auth-form label { margin-bottom: 16px; }

.raw-form { margin-top: 14px; display: grid; gap: 12px; }

/* ---- Buttons --------------------------------------------------------- */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.04s ease;
  width: auto;
}

button:hover,
.button:hover { background: var(--surface-2); border-color: var(--border-strong); }

button:active,
.button:active { transform: translateY(1px); }

button.primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(24, 24, 27, 0.3), 0 4px 12px -4px rgba(24, 24, 27, 0.4);
}

button.primary:hover { background: var(--accent-hover); }

button.danger { border-color: #f0c4c1; background: var(--surface); color: var(--down); }

button.danger:hover { background: var(--down-bg); border-color: #e8a9a4; }

button.wide { width: 100%; }

.small-button { min-height: 32px; padding: 5px 11px; font-size: 12.5px; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 4px; }

/* Space between a form's trailing action row and whatever follows it
   (e.g. Save settings → Admin account panel). */
.setup-form .actions { margin-bottom: 26px; }
.setup-form + .setup-form { margin-top: 26px; }

/* ---- Stat cards ------------------------------------------------------ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat { padding: 18px 20px; min-width: 0; }

.stat-label {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

.stat-meta {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
  min-height: 1em;
  overflow-wrap: anywhere;
  /* Server-side meta uses explicit line breaks (last … / next …); keep
     runaway error text to 3 lines. */
  white-space: pre-line;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  background: var(--muted);
  vertical-align: 2px;
}

.dot-ready { background: var(--up); }
.dot-error { background: var(--down); }
.dot-cloning, .dot-installing { background: var(--running); animation: pulse 1.4s ease-in-out infinite; }

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

@media (max-width: 880px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-head { flex-direction: column; align-items: flex-start; }
}

/* ---- Output block ---------------------------------------------------- */
.output {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 360px;
  white-space: pre-wrap;
  margin: 0;
}

/* ---- Row lists (dashboard artifacts, artifacts page) ------------------ */
.row-list { display: grid; }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 2px;
  border-bottom: 1px solid var(--border);
}

.row:last-child { border-bottom: none; }

.row-meta { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

.row-list-card { padding: 6px 18px; }

.artifact-row { padding: 14px 2px; }

.row-main { display: grid; gap: 2px; }

.row-name { font-weight: 500; }

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  flex: 1 1 320px;
  max-width: 620px;
}

.copy-row input { min-width: 0; min-height: 32px; padding: 5px 10px; }

/* ---- Rule groups list -------------------------------------------------- */
.group-list { overflow: hidden; }

.group-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto 24px;
  gap: 18px;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  transition: background 0.15s ease;
}

.group-row:last-child { border-bottom: none; }

.group-row:hover { background: var(--surface-2); }

.group-row:hover .group-arrow { color: var(--accent); transform: translateX(3px); }

.group-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }

.group-file { color: var(--muted); font-size: 12px; }

.badge {
  justify-self: end;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-weak);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}

.group-arrow { color: var(--muted); transition: transform 0.15s ease, color 0.15s ease; }

@media (max-width: 720px) {
  .group-row { grid-template-columns: minmax(0, 1fr) auto 24px; }
  .group-file { display: none; }
}

/* ---- Rule sheet --------------------------------------------------------- */
.rule-sheet { display: grid; }

.rule-comment {
  font-size: 11.5px;
  color: var(--muted);
  padding: 12px 2px 4px;
}

.rule-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.rule-row:last-child { border-bottom: none; }

.rule-edit { display: flex; gap: 8px; flex: 1; align-items: center; }

.rule-edit select {
  flex: 0 0 170px;
  min-height: 36px;
  padding: 5px 10px;
  font-size: 12.5px;
}

.rule-edit input {
  flex: 1;
  min-height: 36px;
  padding: 5px 10px;
}

@media (max-width: 720px) {
  .rule-edit { flex-wrap: wrap; }
  .rule-edit select { flex-basis: 100%; }
}

/* ---- Activity log ---------------------------------------------------- */
.log-card { padding: 6px 18px; }

.log-row {
  display: grid;
  grid-template-columns: 150px 110px minmax(0, 1fr) 80px 80px;
  gap: 14px;
  align-items: center;
  padding: 9px 2px;
  border-bottom: 1px solid var(--border);
}

.log-row:last-child { border-bottom: none; }

.log-head {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.log-time { font-size: 11.5px; color: var(--text-2); }

.log-message {
  font-size: 13px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-elapsed { font-size: 11.5px; color: var(--muted); text-align: right; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}

.pill-ok { background: var(--up-bg); color: var(--up); }
.pill-failed { background: var(--down-bg); color: var(--down); }

@media (max-width: 720px) {
  .log-row { grid-template-columns: 110px minmax(0, 1fr) 70px; }
  .log-row > :nth-child(2), .log-row > :nth-child(5) { display: none; }
}

/* ---- Disclosure ------------------------------------------------------ */
.usage-details summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  list-style: none;
}

.usage-details summary::-webkit-details-marker { display: none; }
.usage-details summary::before { content: "＋ "; font-weight: 600; }
.usage-details[open] summary::before { content: "－ "; }
