:root {
  --bg: #0d1016;
  --bg-2: #12161e;
  --panel: #161b24;
  --panel-2: #1b212c;
  --line: #27303d;
  --line-2: #344050;
  --text: #e7eaf0;
  --muted: #8d97aa;
  --amber: #f2b134;
  --amber-2: #ffcd66;
  --green: #3ddc97;
  --red: #ff5f6d;
  --blue: #63b3ff;
  --font-display: "Bricolage Grotesque", "IBM Plex Sans", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(242,177,52,.10), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, rgba(99,179,255,.07), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 39px, rgba(255,255,255,.025) 39px 40px),
    repeating-linear-gradient(90deg, transparent 0 39px, rgba(255,255,255,.025) 39px 40px),
    var(--bg);
  min-height: 100vh;
  line-height: 1.45;
}
h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: -.01em; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }

/* ---------- top bar */
.top {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 18px 28px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(22,27,36,.9), rgba(13,16,22,.6));
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 22px; font-weight: 700; }
.tag { font-family: var(--font-mono); font-size: 11px; color: var(--muted); border: 1px solid var(--line); padding: 1px 7px; border-radius: 99px; }
.beacon { width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(61,220,151,.6); animation: pulse 2.4s infinite; }
.beacon.busy { background: var(--blue); box-shadow: 0 0 0 0 rgba(99,179,255,.6); animation-duration: 1.1s; }
.beacon.bad { background: var(--red); box-shadow: 0 0 0 0 rgba(255,95,109,.6); }
.beacon.off { background: var(--muted); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 currentColor; } 70% { box-shadow: 0 0 0 10px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.clock { display: flex; align-items: baseline; gap: 10px; margin-left: auto; }
.clock .mono { font-size: 20px; font-weight: 500; }
.actions { display: flex; gap: 8px; }
.actions form.inline { display: contents; }

main { padding: 24px 28px 60px; max-width: 1500px; margin: 0 auto; }

/* ---------- banner */
.banner { border: 1px solid rgba(242,177,52,.5); background: rgba(242,177,52,.08); color: var(--amber-2); border-radius: 10px; padding: 10px 14px; margin-bottom: 18px; font-size: 13px; }
.banner b { font-family: var(--font-mono); font-weight: 500; }

/* ---------- stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)) auto; gap: 14px; align-items: end; margin-bottom: 24px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; inset: auto 0 0 0; height: 2px; background: linear-gradient(90deg, var(--amber), transparent); opacity: .5; }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 600; }
#stat-problems.hot .value { color: var(--red); }
#stat-problems.warm .value { color: var(--amber); }
.stat-note { font-size: 12px; padding-bottom: 6px; }

/* ---------- task cards */
.tasks { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; margin-bottom: 24px; }
.task {
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px;
  position: relative; overflow: hidden; transition: border-color .2s;
}
.task.running { border-color: rgba(99,179,255,.5); }
.task.problem { border-color: rgba(255,95,109,.45); }
.task.disabled { opacity: .7; }
.task-head { display: flex; align-items: flex-start; gap: 12px; }
.task-head h2 { font-size: 18px; font-weight: 700; }
.task-sub { font-family: var(--font-mono); font-size: 12px; color: var(--muted); word-break: break-all; }
.task-head .spacer { flex: 1; }
.chip { font-family: var(--font-mono); font-size: 11px; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.chip.success { color: var(--green); border-color: rgba(61,220,151,.4); }
.chip.partial, .chip.warn { color: var(--amber); border-color: rgba(242,177,52,.4); }
.chip.failed, .chip.error, .chip.interrupted { color: var(--red); border-color: rgba(255,95,109,.4); }
.chip.running { color: var(--blue); border-color: rgba(99,179,255,.4); }
.chip.cancelled { color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv .mono { font-size: 13px; }
.next-big { font-family: var(--font-mono); font-size: 15px; font-weight: 600; color: var(--amber-2); }
.upcoming { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.progress { display: flex; flex-direction: column; gap: 6px; background: rgba(99,179,255,.06); border: 1px solid rgba(99,179,255,.2); border-radius: 8px; padding: 10px 12px; }
.progress .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress .bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), #9ed3ff); transition: width .4s; }
.progress .bar.indeterminate > i { width: 30% !important; animation: slide 1.2s infinite linear; }
@keyframes slide { from { transform: translateX(-100%);} to { transform: translateX(400%);} }
.progress .line { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 12px; }
.progress .key { font-family: var(--font-mono); font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-actions { display: flex; gap: 8px; align-items: center; margin-top: auto; }
.task-actions .spacer { flex: 1; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 12px; color: var(--muted); user-select: none; }
.switch input { appearance: none; width: 34px; height: 18px; border-radius: 99px; background: var(--line-2); position: relative; transition: background .2s; margin: 0; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked { background: var(--green); }
.switch input:checked::after { transform: translateX(16px); }

/* ---------- buttons */
.btn { font: inherit; font-weight: 500; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { border-color: var(--amber); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #1b1200; font-weight: 600; }
.btn.primary:hover { background: var(--amber-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: rgba(255,95,109,.4); background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.select { font: inherit; background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2); border-radius: 8px; padding: 5px 8px; }

/* ---------- panels */
.columns { display: grid; grid-template-columns: minmax(320px, 2fr) minmax(0, 3fr); gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head h2 { font-size: 16px; }
.problems { display: flex; flex-direction: column; gap: 8px; max-height: 560px; overflow: auto; }
.problem { border-left: 3px solid var(--amber); background: var(--bg-2); border-radius: 0 8px 8px 0; padding: 8px 12px; font-size: 13px; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; cursor: pointer; }
.problem.error { border-left-color: var(--red); }
.problem .when { font-family: var(--font-mono); font-size: 11px; color: var(--muted); grid-column: 2; }
.problem .subject { font-family: var(--font-mono); font-size: 12px; word-break: break-all; }
.problem .msg { grid-column: 1 / -1; color: var(--muted); }
.problem .code { font-family: var(--font-mono); font-size: 11px; color: var(--amber); }
.problem.error .code { color: var(--red); }
.empty { color: var(--muted); font-size: 13px; padding: 20px 0; text-align: center; }

.table-wrap { overflow: auto; max-height: 560px; }
table.runs { width: 100%; border-collapse: collapse; font-size: 13px; }
table.runs th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
table.runs td { padding: 7px 8px; border-bottom: 1px solid rgba(39,48,61,.6); font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }
table.runs tr.row { cursor: pointer; }
table.runs tr.row:hover td { background: rgba(255,255,255,.03); }
table.runs .num, table.runs td.num { text-align: right; }
table.runs td.zero { color: var(--line-2); }
table.runs td.hot { color: var(--red); }
table.runs td.good { color: var(--green); }

/* ---------- dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 14px; padding: 22px 24px; width: min(680px, 94vw); box-shadow: 0 30px 80px rgba(0,0,0,.6); }
dialog::backdrop { background: rgba(5,7,10,.7); backdrop-filter: blur(3px); }
dialog h3 { font-size: 18px; margin-bottom: 14px; }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
dialog label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
dialog input, dialog textarea, dialog select { font: inherit; font-family: var(--font-mono); font-size: 13px; background: var(--bg-2); color: var(--text); border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 9px; }
dialog input[type=checkbox] { width: auto; }
dialog textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset legend { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); padding: 0 6px; }
fieldset label.check { grid-column: span 1; }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.dlg-actions .spacer { flex: 1; }
.error { color: var(--red); font-size: 13px; margin: 0; min-height: 1em; }
#connections, #pg-connections { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; }
.conn { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; font-family: var(--font-mono); font-size: 12px; }
.conn .res { color: var(--muted); }
.conn .res.ok { color: var(--green); }
.conn .res.bad { color: var(--red); }
.dlg-run-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
#run-detail .kv { margin-bottom: 14px; }
.events { display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow: auto; font-family: var(--font-mono); font-size: 12px; }
.event { display: grid; grid-template-columns: 62px 56px 1fr; gap: 10px; padding: 4px 6px; border-radius: 6px; background: var(--bg-2); }
.event.warn { color: var(--amber); }
.event.error { color: var(--red); }
.event .msg { color: var(--text); white-space: pre-wrap; word-break: break-word; }
.event details { grid-column: 1 / -1; color: var(--muted); }
.event pre { margin: 4px 0 0; white-space: pre-wrap; word-break: break-all; font-size: 11px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 20; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.toast.bad { border-color: var(--red); }

@media (max-width: 900px) {
  .top, main { padding-left: 16px; padding-right: 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .columns { grid-template-columns: 1fr; }
  .grid2, fieldset { grid-template-columns: 1fr; }
}
