:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #20242a;
  --muted: #68707d;
  --line: #dfe5ee;
  --blue: #1f6feb;
  --green: #1a7f37;
  --amber: #9a6700;
  --red: #cf222e;
  --cyan: #087990;
  --shadow: 0 10px 28px rgba(25, 35, 52, .08);
}

* { box-sizing: border-box; }

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

button, input, select, textarea {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

button {
  min-height: 38px;
  padding: 8px 12px;
  cursor: pointer;
}

button.primary {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

button.danger {
  color: var(--red);
  border-color: #efb5bc;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

input, select {
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

textarea {
  min-height: 220px;
  padding: 10px;
  width: 100%;
  resize: vertical;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }

main {
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px;
}

summary {
  cursor: pointer;
  font-weight: 800;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.danger-text { color: var(--red); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.actions.wrap { flex-wrap: wrap; }

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

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

.section-head.compact {
  align-items: center;
  margin-bottom: 10px;
}

.details-body {
  margin-top: 14px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(8, minmax(120px, 1fr));
  gap: 10px;
}

.metric {
  min-height: 78px;
  padding: 12px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric .value {
  font-size: 25px;
  font-weight: 850;
  line-height: 1.1;
}

.metric .label {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(120px, .7fr) minmax(110px, .6fr) minmax(220px, auto);
  gap: 10px;
  align-items: end;
}

.control-grid label,
.form-grid label,
.json-grid label,
.single-domain {
  display: grid;
  gap: 6px;
}

.control-grid label span,
.form-grid label span,
.json-grid label span,
.single-domain span,
.label {
  color: var(--muted);
  font-size: 12px;
}

.button-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(95px, 1fr));
  gap: 8px;
}

.allocation {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.allocation-item,
.node-card,
.batch-node {
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.allocation-item.selected,
.node-card.selected {
  border-color: #8bb7f0;
  box-shadow: inset 0 0 0 1px #8bb7f0;
}

.node-grid,
.batch-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(280px, 1fr));
  gap: 12px;
}

.card-head,
.split-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.node-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.node-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-title input,
.check-row input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
  flex: 0 0 auto;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.tone-online,
.tone-completed {
  color: var(--green);
  border-color: #9bd3ad;
}

.tone-running,
.tone-dispatching {
  color: var(--blue);
  border-color: #9dc0f4;
}

.tone-warning,
.tone-completed_with_warnings,
.tone-stopped,
.tone-pending {
  color: var(--amber);
  border-color: #e7c45e;
}

.tone-degraded,
.tone-stale {
  color: #a15c00;
  border-color: #efc27d;
}

.tone-failed,
.tone-offline {
  color: var(--red);
  border-color: #efb5bc;
}

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

.bar {
  height: 9px;
  margin: 10px 0;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1f7;
}

.bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--blue);
}

.bar.good span { background: var(--green); }
.bar.warn span { background: var(--amber); }
.bar.bad span { background: var(--red); }
.bar.degraded span { background: #c56a00; }

.mini-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(54px, 1fr));
  gap: 8px;
}

.mini-stats div {
  min-width: 0;
  padding: 7px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.mini-stats strong {
  display: block;
  font-size: 16px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.mini-stats span {
  color: var(--muted);
  font-size: 11px;
}

.status-line {
  min-height: 21px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 13px;
}

.error-line {
  margin-top: 8px;
  color: var(--red);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.provider-line {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.table-wrap {
  margin-top: 12px;
  overflow-x: auto;
}

.mail-profile-row {
  cursor: pointer;
}

.mail-profile-row:hover { background: #f8fbff; }

.mail-profile-row.selected {
  background: #eef5ff;
  box-shadow: inset 3px 0 0 var(--blue);
}

.form-grid,
.json-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.profile-form {
  grid-template-columns: repeat(2, minmax(260px, 1fr));
}

.check-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  align-self: end;
  min-height: 38px;
}

.mode-box {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented button {
  border: 0;
  border-radius: 0;
  background: #fbfcfe;
}

.segmented button.active {
  color: #fff;
  background: var(--blue);
}

.domain-panel,
.advanced-json,
.single-domain {
  margin-top: 14px;
}

.domain-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 8px;
}

.domain-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.domain-option input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
}

.domain-option.selected {
  background: #eef5ff;
  border-color: #8bb7f0;
}

.form-message {
  min-height: 22px;
  margin-top: 10px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.secret-box,
.log-box {
  margin: 0;
  padding: 12px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  white-space: pre-wrap;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.secret-box {
  margin-top: 12px;
}

.log-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 12px;
}

.log-box {
  max-height: 300px;
  margin-top: 8px;
}

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

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

.login-card p {
  margin: 8px 0 18px;
  color: var(--muted);
}

.login-card button {
  width: 100%;
  margin-top: 10px;
}

@media (max-width: 1180px) {
  .metrics { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
  .node-grid, .batch-grid, .allocation { grid-template-columns: repeat(2, minmax(240px, 1fr)); }
  .control-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
}

@media (max-width: 760px) {
  main { padding: 12px; }
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 14px;
  }
  .actions { width: 100%; }
  .actions button { flex: 1; }
  .section { padding: 13px; }
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }
  .metrics,
  .node-grid,
  .batch-grid,
  .allocation,
  .control-grid,
  .form-grid,
  .json-grid,
  .domain-grid,
  .log-grid {
    grid-template-columns: 1fr;
  }
  .button-pair {
    grid-template-columns: 1fr;
  }
  .mini-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .card-head {
    align-items: flex-start;
  }
  .profile-form {
    grid-template-columns: 1fr;
  }
  textarea {
    min-height: 180px;
  }
}
