:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --border: #e3e5ea;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #b45309;
  --warn-bg: #fff7e6;
  --info-bg: #eef4ff;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #171a21;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2a2f39;
    --primary: #3b82f6;
    --warn: #f0b45b;
    --warn-bg: #2a2112;
    --info-bg: #142036;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.15rem; }
code { font: 0.85em ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 0.9rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

button, .button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
button:hover, .button:hover { filter: brightness(0.96); }
button:disabled { opacity: 0.55; cursor: default; }
button.primary, .button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.small { padding: 4px 10px; font-size: 0.85rem; }
button.wide { width: 100%; justify-content: center; }

input {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type="checkbox"] { width: auto; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; padding: 32px 28px; display: grid; gap: 12px; text-align: center; }
.logo { font-size: 2.2rem; }

/* Top bar */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; font-size: 1.05rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.drive-status { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--danger); }

.container { max-width: 980px; margin: 0 auto; padding: 24px; display: grid; gap: 16px; }
.section-head { display: flex; justify-content: space-between; align-items: center; }
.notice { padding: 10px 14px; border-radius: 10px; background: var(--info-bg); border: 1px solid var(--border); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.err { color: var(--danger); }

/* Database cards */
.db-list { display: grid; gap: 12px; }
.db-card { padding: 16px 18px; display: grid; gap: 10px; }
.db-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.db-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.db-title h3 { font-size: 1.05rem; }
.hint { font-size: 0.85rem; word-break: break-all; }
.badge {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted);
}
.badge.postgres { color: #336791; border-color: #33679155; }
.badge.mysql { color: #c26a00; border-color: #c26a0055; }
@media (prefers-color-scheme: dark) {
  .badge.postgres { color: #7fb0e0; }
  .badge.mysql { color: #f0a54a; }
}
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px 16px; font-size: 0.9rem; }
.meta dt { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.meta dd { margin: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.msg { font-size: 0.85rem; color: var(--muted); word-break: break-word; }
.msg.err { color: var(--danger); }

.pill { font-size: 0.8rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; display: inline-block; }
.pill.success { background: #16a34a22; color: var(--ok); }
.pill.failed { background: #dc262622; color: var(--danger); }
.pill.running, .pill.queued { background: #2563eb22; color: var(--primary); }

.empty { padding: 36px; text-align: center; color: var(--muted); }

/* Dialogs */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
  background: var(--card); color: var(--text); width: min(560px, calc(100vw - 24px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
#runs-dialog { width: min(820px, calc(100vw - 24px)); }
.dialog-body { padding: 22px; display: grid; gap: 14px; }
.dialog-body label { display: grid; gap: 5px; font-weight: 550; font-size: 0.92rem; }
.dialog-body label small { font-weight: 400; }
.dialog-body label.check { display: flex; align-items: center; gap: 8px; align-self: end; padding-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-row { display: flex; gap: 6px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.runs-body { max-height: 60vh; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
