:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #e3e6eb;
  --accent: #2456c7;
  --accent-text: #ffffff;
  --row-hover: #f2f5fa;
  --new-bg: #fff8e6;
  --ok: #157a3c;
  --ok-bg: #e5f5ea;
  --warn: #9a5b00;
  --warn-bg: #fff1d6;
  --error: #b42318;
  --error-bg: #fde8e7;
  --info: #2456c7;
  --info-bg: #e7eefc;
  --neutral-bg: #eef0f3;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2028;
    --text: #e4e8ee;
    --muted: #98a2b3;
    --border: #2c3440;
    --accent: #7aa2ff;
    --accent-text: #0d1320;
    --row-hover: #212934;
    --new-bg: #2d2714;
    --ok: #6fd394;
    --ok-bg: #173323;
    --warn: #f0b75a;
    --warn-bg: #362a13;
    --error: #ff8f86;
    --error-bg: #3a1c1a;
    --info: #9bb8ff;
    --info-bg: #1d2a47;
    --neutral-bg: #262d38;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.error-text { color: var(--error); }
.clip { max-width: 28rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Layout */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; color: var(--text); }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.topbar nav a { padding: .35rem .7rem; border-radius: 6px; color: var(--muted); }
.topbar nav a:hover { background: var(--row-hover); text-decoration: none; color: var(--text); }
.topbar nav a[aria-current="page"] { background: var(--info-bg); color: var(--info); font-weight: 600; }
.logout { margin: 0; }
main { max-width: 1400px; margin: 0 auto; padding: 1.25rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.page-head h1 a { color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 1rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin-bottom: 1rem; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: .5rem; margin-bottom: .5rem; }
.tile {
  display: flex; flex-direction: column; padding: .55rem .7rem; border-radius: 6px;
  background: var(--neutral-bg); color: var(--text);
}
.tile:hover { text-decoration: none; outline: 1px solid var(--border); }
.tile strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: .85em; }
.tile-warn { background: var(--error-bg); }
.tile-new { background: var(--warn-bg); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
th.num { text-align: right; }
tbody tr:hover { background: var(--row-hover); }
tr.is-new { background: var(--new-bg); }
.details { display: flex; flex-wrap: wrap; gap: .1rem .9rem; margin-top: .15rem; }

/* Badges */
.badge {
  display: inline-block; padding: .05rem .45rem; border-radius: 999px; font-size: .78rem;
  font-weight: 600; background: var(--neutral-bg); color: var(--muted); white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-error, .badge-failed { background: var(--error-bg); color: var(--error); }
.badge-partial, .badge-not_found { background: var(--warn-bg); color: var(--warn); }
.badge-running, .src-register_event { background: var(--info-bg); color: var(--info); }
.badge-new { background: var(--warn-bg); color: var(--warn); }
.src-procedural_step { background: var(--ok-bg); color: var(--ok); }

/* Forms */
input, select, button { font: inherit; color: inherit; }
input[type=search], input[type=password], input[type=date], select {
  padding: .4rem .55rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
}
button {
  padding: .45rem .9rem; border: 0; border-radius: 6px; background: var(--accent);
  color: var(--accent-text); font-weight: 600; cursor: pointer;
}
button:disabled { opacity: .55; cursor: default; }
button.link { background: none; color: var(--muted); padding: .35rem .5rem; font-weight: 500; }
button.link:hover { color: var(--text); }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.filters input[type=search] { min-width: 16rem; }
label.inline { display: inline-flex; gap: .35rem; align-items: center; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Misc */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs a { padding: .45rem .8rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--text); border-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; padding: .75rem 0 0; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.alert { padding: .55rem .75rem; border-radius: 6px; background: var(--info-bg); color: var(--info); }
.alert-error { background: var(--error-bg); color: var(--error); }
pre.log {
  margin: 0; padding: .75rem; background: var(--neutral-bg); border-radius: 6px;
  font: .82rem/1.45 var(--mono); white-space: pre-wrap; max-height: 32rem; overflow: auto;
}
progress { width: 100%; height: .6rem; accent-color: var(--accent); }
.spinner {
  display: inline-block; width: .8em; height: .8em; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
  vertical-align: -.1em; margin-right: .3rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
.login { max-width: 360px; margin: 12vh auto 0; }
.login h1 { margin-bottom: 1rem; }
.login form { display: grid; gap: .6rem; }
.login label { color: var(--muted); }

@media (max-width: 640px) {
  main { padding: .75rem; }
  .filters input[type=search] { min-width: 0; flex: 1 1 100%; }
  .clip { max-width: 14rem; }
}

/* API tokens */
.card-highlight { border-color: var(--ok); background: var(--ok-bg); }
.token-value {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); font-size: .95rem;
}
input[type=text] {
  padding: .4rem .55rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
  min-width: 16rem;
}
button.danger { background: var(--error-bg); color: var(--error); padding: .25rem .6rem; }

/* Login with Authentik */
a.button {
  display: block; text-align: center; padding: .55rem .9rem; border-radius: 6px;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
a.button:hover { text-decoration: none; filter: brightness(1.05); }
.divider { text-align: center; margin: .75rem 0; }
