:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f9fbfd;
  --text: #1c2430;
  --muted: #65758b;
  --line: #d8e0ea;
  --accent: #136f63;
  --accent-strong: #0e554c;
  --danger: #b42318;
  --warning: #946200;
  --success: #157347;
  --code-bg: #101828;
  --code-text: #e6edf3;
  --shadow: 0 8px 24px rgba(22, 34, 51, 0.08);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111827;
  --panel: #182231;
  --panel-soft: #202c3d;
  --text: #eef4ff;
  --muted: #a8b3c4;
  --line: #314056;
  --accent: #2aa893;
  --accent-strong: #38bca6;
  --danger: #ef7167;
  --warning: #e4ad35;
  --success: #44c37d;
  --code-bg: #0b1220;
  --code-text: #e6edf3;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    color-scheme: dark;
    --bg: #111827;
    --panel: #182231;
    --panel-soft: #202c3d;
    --text: #eef4ff;
    --muted: #a8b3c4;
    --line: #314056;
    --accent: #2aa893;
    --accent-strong: #38bca6;
    --danger: #ef7167;
    --warning: #e4ad35;
    --success: #44c37d;
    --code-bg: #0b1220;
    --code-text: #e6edf3;
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }

button {
  border: 0;
  border-radius: 6px;
  padding: 9px 13px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  min-height: 38px;
}

button:hover { background: var(--accent-strong); }
button.secondary { background: var(--panel-soft); color: var(--text); border: 1px solid var(--line); }
button.secondary:hover { background: var(--line); }
button.danger { background: var(--danger); }
button.compact { padding: 6px 9px; min-height: 30px; }

input, select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--panel);
  color: var(--text);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

a { color: inherit; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; line-height: 1.1; }
h2 { font-size: 20px; }
h3 { font-size: 18px; }
p, td { color: var(--muted); }

.shell { min-height: 100vh; }
.hidden { display: none !important; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  display: grid;
  gap: 18px;
  width: min(420px, 100%);
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.brand-icon.large {
  width: 64px;
  height: 64px;
}

.form-message {
  min-height: 20px;
  color: var(--danger);
}

.console-page {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 6px 18px;
  text-decoration: none;
  font-weight: 700;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav a {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}

.nav a:hover,
.nav a.active {
  background: var(--panel-soft);
  color: var(--text);
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar, .section-head, .topbar-actions, .filters, menu {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar, .section-head {
  justify-content: space-between;
}

.page-content {
  display: grid;
  gap: 16px;
  margin-top: 22px;
}

.panel, .metric, dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  padding: 14px 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
}

.wide { grid-column: span 2; }
.search { max-width: 320px; }

.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  color: var(--text);
  background: var(--panel-soft);
  font-size: 12px;
  text-transform: uppercase;
}

td.actions {
  white-space: nowrap;
  text-align: right;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  color: var(--text);
  background: var(--panel-soft);
}

.badge.queued { color: var(--warning); background: color-mix(in srgb, var(--warning) 18%, transparent); }
.badge.running { color: #1786bd; background: color-mix(in srgb, #1786bd 18%, transparent); }
.badge.succeeded { color: var(--success); background: color-mix(in srgb, var(--success) 18%, transparent); }
.badge.failed { color: var(--danger); background: color-mix(in srgb, var(--danger) 18%, transparent); }

.json-view {
  margin: 0;
  min-height: 420px;
  overflow: auto;
  padding: 16px;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 8px;
}

dialog {
  width: min(560px, calc(100% - 24px));
  padding: 0;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
}

.dialog-body {
  display: grid;
  gap: 14px;
  padding: 18px;
}

menu {
  justify-content: flex-end;
  padding: 0;
  margin: 4px 0 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
  box-shadow: var(--shadow);
}

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.link { color: var(--accent); overflow-wrap: anywhere; }

@media (max-width: 980px) {
  .console-page { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
  }
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .wide { grid-column: span 2; }
}

@media (max-width: 640px) {
  .workspace { padding: 16px 10px; }
  .topbar, .section-head { align-items: flex-start; flex-direction: column; }
  .topbar-actions, .filters { width: 100%; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-form { grid-template-columns: 1fr; }
  .wide { grid-column: span 1; }
  h1 { font-size: 24px; }
}
