:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --text: #18212f;
  --muted: #647084;
  --line: #dfe5ec;
  --blue: #2563eb;
  --green: #16835a;
  --amber: #b7791f;
  --red: #b42318;
  --shadow: 0 8px 24px rgba(24, 33, 47, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, "Segoe UI", Arial, sans-serif;
}

.sidebar {
  background: #111827;
  color: white;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #38bdf8;
  color: #082f49;
  display: grid;
  place-items: center;
  font-weight: 800;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 18px; }
.brand p, .field span { color: #aeb8c8; }
.field { display: grid; gap: 8px; }
input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
}
nav { display: grid; gap: 8px; }
.nav {
  text-align: left;
  background: transparent;
  color: #d7dee9;
  border: 1px solid transparent;
}
.nav.active { background: #1f2937; border-color: #334155; color: white; }

main { min-width: 0; }
.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
}
.topbar p { color: var(--muted); }
.actions { display: flex; gap: 10px; }
.batch-hint {
  align-self: center;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.account-tabs {
  display: flex;
  gap: 8px;
  min-height: 58px;
  padding: 10px 28px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
  background: #eef3f7;
}
.account-tab {
  position: relative;
  flex: 0 0 190px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  padding: 8px 11px;
  border-color: #cfd8e3;
  background: #ffffff;
  text-align: left;
}
.account-tab.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}
.account-tab strong,
.account-tab span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-tab strong {
  grid-column: 1;
  font-size: 13px;
}
.account-tab span {
  grid-column: 1;
  color: var(--muted);
  font-size: 12px;
}
.account-tab i {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.account-tab i.on { background: var(--green); }
.account-tab i.off { background: var(--red); }
.account-tabs-empty {
  align-self: center;
  color: var(--muted);
}
.status-bar {
  display: none;
  padding: 8px 28px;
  border-bottom: 1px solid var(--line);
  background: #fff8e5;
  color: #7a4d08;
  font-size: 13px;
}
.status-bar.active {
  display: block;
}

.toast-root {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 60;
  display: grid;
  gap: 10px;
  width: min(420px, calc(100vw - 28px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 12px 12px 12px 14px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}
.toast.info { border-left-color: var(--blue); }
.toast.ok { border-left-color: var(--green); }
.toast.danger { border-left-color: var(--red); }
.toast strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
}
.toast p {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.toast button {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
}
button:hover { border-color: #9aa8b8; }
button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}
button.small {
  padding: 5px 8px;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}
.primary { background: var(--blue); border-color: var(--blue); color: white; }
.danger { color: var(--red); }
.icon-button {
  width: 30px;
  height: 30px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}

.view { display: none; padding: 24px 28px; }
.view.active { display: block; }
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-grid article, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.kpi-grid article { padding: 16px; }
.kpi-grid span { display: block; color: var(--muted); margin-bottom: 8px; }
.kpi-grid strong { font-size: 24px; }
.panel { margin-bottom: 18px; overflow: hidden; }
.panel-head {
  min-height: 52px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel-note {
  color: var(--muted);
  font-size: 13px;
}
.panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.checks, .jobs, #runtimeState { padding: 14px 16px; }
#ledgerState {
  display: grid;
  gap: 16px;
  padding: 14px 16px;
}
#ledgerState h4 {
  margin: 2px 0 -6px;
  font-size: 15px;
}
.ledger-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
}
.ledger-note a {
  color: var(--blue);
  white-space: nowrap;
}
.ledger-kpis {
  margin-bottom: 0;
}
.ledger-kpis.secondary strong {
  font-size: 20px;
}
#runtimeState h4 {
  margin: 18px 0 10px;
  font-size: 15px;
}
#runtimeState h4:first-child {
  margin-top: 0;
}
#runtimeState p {
  color: var(--muted);
  padding: 4px 0 12px;
}
.table-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}
.runtime-refresh-note {
  margin: -6px 0 10px;
  padding: 0 !important;
  color: var(--muted);
  font-size: 12px;
}
.runtime-top-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.72fr);
  gap: 14px;
  align-items: start;
  margin-bottom: 18px;
}
.runtime-mini-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  background: #fff;
}
.runtime-mini-panel h4 {
  margin: 0;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.runtime-mini-panel p {
  padding: 12px 14px !important;
  margin: 0;
}
.runtime-mini-panel table {
  border: 0;
  min-width: 560px;
}
.runtime-mini-panel th,
.runtime-mini-panel td {
  padding: 9px 10px;
}
.runtime-lock-panel {
  overflow: visible;
}
.lock-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
}
.lock-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  max-width: 100%;
  min-height: 34px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}
.lock-main {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
}
.lock-chip strong,
.lock-chip em,
.lock-chip small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lock-chip strong {
  color: var(--text);
  font-weight: 700;
}
.lock-chip em {
  font-style: normal;
}
.lock-chip small {
  display: block;
  max-width: 100%;
  color: var(--muted);
  font-size: 11px;
}
.lock-chip.ok {
  border-color: #b8ead2;
  background: #ecfdf5;
  color: var(--green);
}
.lock-chip.warn {
  border-color: #f1d497;
  background: #fffbeb;
  color: var(--amber);
}
.lock-chip.muted {
  border-color: var(--line);
  background: #f8fafc;
  color: var(--muted);
}
.runtime-table-scroll {
  max-height: 560px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.runtime-table-scroll.compact {
  max-height: 356px;
}
.runtime-table-scroll table {
  border: 0;
}
.runtime-table-scroll th {
  top: 0;
}
.check, .job {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #edf1f5;
}
.check:last-child, .job:last-child { border-bottom: 0; }
.badge {
  display: inline-flex;
  width: max-content;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
}
.ok { color: var(--green); background: #e9f8f1; }
.warn { color: var(--amber); background: #fff6df; }
.danger-badge { color: var(--red); background: #fff0ef; }
.split { display: grid; grid-template-columns: minmax(320px, 0.8fr) minmax(520px, 1.2fr); gap: 18px; }
pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  font: 12px/1.55 "Cascadia Code", Consolas, monospace;
}
.log {
  min-height: 560px;
  max-height: 70vh;
  background: #0f172a;
  color: #dbeafe;
}
.table-wrap { overflow: auto; max-height: calc(100vh - 180px); }
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th, td {
  border-bottom: 1px solid #edf1f5;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
th { position: sticky; top: 0; background: #f8fafc; z-index: 1; }
td.wrap { white-space: normal; min-width: 260px; }
.strategy-editors {
  display: grid;
  gap: 18px;
  padding: 16px;
}
.strategy-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fbfdff;
}
.strategy-editor-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.strategy-editor-head h4 {
  margin: 0;
  font-size: 16px;
}
.strategy-editor-head p {
  color: var(--muted);
  font-size: 13px;
}
.editor-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
.strategy-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 14px;
  padding: 14px;
}
.strategy-field {
  display: grid;
  align-content: start;
  gap: 7px;
}
.strategy-field label {
  font-weight: 700;
}
.strategy-field input,
.strategy-field select,
.strategy-field textarea {
  min-height: 38px;
  background: white;
}
.strategy-field input[readonly] {
  color: var(--muted);
  background: #eef3f7;
}
.strategy-field textarea {
  resize: vertical;
}
.strategy-field p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.modal {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  font-size: 16px;
}

.modal-body {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.modal-summary {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.modal-summary span {
  color: var(--muted);
  font-size: 13px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .kpi-grid, .split, .runtime-top-grid { grid-template-columns: 1fr; }
  .topbar { height: auto; padding: 16px; align-items: flex-start; gap: 14px; flex-direction: column; }
  .account-tabs { padding: 10px 16px; }
  .strategy-fields { grid-template-columns: 1fr; }
}
