:root {
  --bg: #f6f7f9;
  --card: #fff;
  --text: #1c2024;
  --muted: #6b7280;
  --border: #e3e5e8;
  --accent: #2563eb;
  --danger: #c2261d;
  --warn-bg: #fff6e0;
  --warn-text: #8a5a00;
  --ok-bg: #e5f6ea;
  --ok-text: #1f7a3a;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --card: #1b1e22;
    --text: #e6e8eb;
    --muted: #9aa1aa;
    --border: #2c3036;
    --accent: #6ea0ff;
    --danger: #ff6b61;
    --warn-bg: #3a2e12;
    --warn-text: #f2c66d;
    --ok-bg: #16331f;
    --ok-text: #7ad69a;
  }
}

* { box-sizing: border-box; }

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

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; color: var(--text); text-decoration: none; }
nav { display: flex; gap: 16px; }
nav a { color: var(--muted); text-decoration: none; }
nav a.active { color: var(--text); font-weight: 600; }
.logout { margin-left: auto; display: flex; gap: 12px; align-items: center; }

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

h1, h2 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }

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

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.narrow { max-width: 420px; margin: 40px auto; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stats div {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
}
.stats span { font-size: 13px; }

.meters { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; }
.meter { display: flex; flex-direction: column; gap: 6px; }
.meter-head { display: flex; justify-content: space-between; }
.bar { height: 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--ok-text); transition: width 0.3s; }
.bar.mid span { background: #d99a00; }
.bar.high span { background: var(--danger); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 13px; color: var(--muted); font-weight: 500; }
td.actions { text-align: right; }
td.actions > * { margin-left: 12px; }
td.actions form { display: inline; }

select,
input:not([type="checkbox"]) {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

button {
  font: inherit;
  padding: 8px 16px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: default; }
button.danger { background: var(--danger); }
a.button {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.narrow-wide { max-width: 640px; margin: 0 auto 20px; }
.hint { font-size: 13px; }
.links { display: flex; gap: 20px; flex-wrap: wrap; }

button.link { background: none; color: var(--accent); padding: 0; }
a.button.secondary { background: none; color: var(--text); border: 1px solid var(--border); }
.refresh { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-bottom: 12px; font-size: 14px; }

button.secondary { background: none; color: var(--text); border: 1px solid var(--border); }

/* Native <dialog> modals (static/app.js). The padding lives on the inner
   form, so a click on the dialog element itself is a click on the backdrop. */
.modal {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.25);
}
.modal::backdrop { background: rgb(0 0 0 / 0.45); }
.modal > form { padding: 20px; }
.modal p { margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.modal[open] { animation: modal-in 0.15s ease-out; }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px); }
}
a.danger { color: var(--danger); }

.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; }
.stack label.check { flex-direction: row; align-items: center; gap: 8px; }
.row { display: flex; gap: 8px; max-width: 480px; }

.tag {
  display: inline-block;
  font-size: 12px;
  padding: 1px 8px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
}
.tag.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.tag.ok { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }

.notice, .error, .warn-box { padding: 10px 14px; border-radius: 8px; }
.notice { background: var(--ok-bg); color: var(--ok-text); }
.error { background: var(--warn-bg); color: var(--danger); }
.warn-box { background: var(--warn-bg); color: var(--warn-text); }

.env-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 16px 0 8px; }
.env-head h2 { margin: 0; font-size: 15px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.log.env { font-size: 13px; margin: 0 0 20px; }
.creds dt { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.creds { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; }
.creds dt { color: var(--muted); }
.creds dd { margin: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.break { word-break: break-all; }


details summary { cursor: pointer; margin-bottom: 8px; }
.run { border-top: 1px solid var(--border); padding: 10px 0; }
.run summary { margin: 0; }
.run[open] summary { margin-bottom: 8px; }
.run .tag { margin: 0 6px 0 0; }

.log {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  max-height: 360px;
  overflow: auto;
  font-size: 12px;
  white-space: pre-wrap;
}

@media (max-width: 600px) {
  .creds { grid-template-columns: 1fr; }
  .creds dt { margin-top: 8px; }
}
