:root {
  color-scheme: light dark;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --text: #202326;
  --muted: #68717a;
  --line: #d8dde3;
  --accent: #2368a2;
  --accent-strong: #174d79;
  --success: #137333;
  --warning: #8a5a00;
  --error: #b3261e;
  --critical: #7d1b1b;
  --focus: #1a73e8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191b;
    --panel: #22262a;
    --text: #eef1f4;
    --muted: #aab2bb;
    --line: #3a4148;
    --accent: #7bb7ea;
    --accent-strong: #a9d3f5;
  }
}

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
}

button:hover { background: var(--accent-strong); }
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto 1fr minmax(180px, 260px) auto;
  gap: 18px;
  align-items: center;
  min-height: 64px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.nav a {
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
}

.nav a.active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--text);
}

.token-field {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  color: var(--muted);
}

.logout-form {
  margin: 0;
}

.token-field input,
input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  padding: 7px 9px;
}

textarea { resize: vertical; }

.shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.status-strip {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) repeat(3, minmax(90px, auto));
  gap: 10px;
  margin-bottom: 18px;
}

.status-strip > div,
.panel,
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.status-strip > div {
  min-width: 0;
  padding: 10px 12px;
}

.status-strip strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grid {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.grid.two { grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr); }
.grid.cards { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }

.panel {
  padding: 14px;
}

.stack {
  display: grid;
  gap: 12px;
  align-content: start;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.section-head h1 {
  margin: 0;
  font-size: 18px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.table-wrap {
  overflow-x: auto;
  padding: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

tr:last-child td { border-bottom: 0; }

.mono,
.code,
.output {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.code,
.output {
  overflow: auto;
  margin: 0;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
}

.code {
  background: color-mix(in srgb, var(--muted) 10%, transparent);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.output {
  max-height: 180px;
  font-size: 13px;
}

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

.pill,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 13px;
  font-weight: 600;
}

.pill { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.badge { background: color-mix(in srgb, var(--muted) 14%, transparent); }
.badge.success, .badge.sent { color: var(--success); }
.badge.warning, .badge.skipped { color: var(--warning); }
.badge.error, .badge.failed, .badge.timeout { color: var(--error); }
.badge.critical { color: var(--critical); }
.badge.running, .badge.info { color: var(--accent); }

.body-preview {
  margin: 4px 0 0;
  color: var(--muted);
  max-width: 620px;
  white-space: pre-wrap;
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.kv span { color: var(--muted); }
.kv strong {
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

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

.error-text {
  color: var(--error);
  max-width: 360px;
  word-break: break-word;
}

.action-cell {
  width: 90px;
}

.flash {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 12px;
}

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

.login-panel {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.login-panel h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.form-error {
  color: var(--error);
  border: 1px solid color-mix(in srgb, var(--error) 35%, var(--line));
  border-radius: 6px;
  padding: 8px 10px;
}

.switch-body {
  min-height: 100vh;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--panel) 94%, var(--accent) 6%), var(--bg));
}

.switch-shell {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 28px 16px 36px;
}

.switch-hero {
  display: grid;
  gap: 10px;
  padding: 12px 0 20px;
}

.switch-kicker {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 13px;
}

.switch-hero h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: 0;
}

.switch-subtitle {
  margin: 0;
  max-width: 560px;
  color: var(--muted);
  font-size: 17px;
}

.switch-current {
  display: grid;
  gap: 2px;
  width: min(100%, 560px);
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

.switch-current span,
.switch-details dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.switch-current strong,
.switch-details dd {
  overflow-wrap: anywhere;
}

.switch-flash {
  margin: 0 0 14px;
}

.switch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.switch-card {
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 14px;
  min-height: 250px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.switch-card h2 {
  margin: 0 0 6px;
  font-size: 24px;
  line-height: 1.15;
}

.switch-card p {
  margin: 0;
  color: var(--muted);
}

.switch-details {
  display: grid;
  gap: 8px;
  margin: 0;
}

.switch-details div {
  display: grid;
  gap: 2px;
}

.switch-details dd {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.switch-button {
  width: 100%;
  min-height: 44px;
}

.switch-empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 22px;
  color: var(--muted);
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .status-strip,
  .grid.two,
  .field-row {
    grid-template-columns: 1fr;
  }

  .shell { padding: 12px; }
  th, td { padding: 9px; }

  .switch-shell { padding: 22px 14px 30px; }
  .switch-hero h1 { font-size: 30px; }
  .switch-grid { grid-template-columns: 1fr; }
  .switch-card { min-height: 0; }
}
