:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d7dde5;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #0f8f63;
  --red: #c2413b;
  --orange: #b76e00;
  --purple: #6d28d9;
  --radius: 8px;
  --shadow: 0 18px 55px rgba(24, 36, 58, 0.12);
  --sidebar: #111827;
  --sidebar-active: #243145;
  --control: #ffffff;
  --button-soft: #eef2f7;
  --button-soft-ink: #243145;
  --table-head: #fafbfc;
  --table-line: #edf0f4;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #111827;
  --ink: #e5e7eb;
  --muted: #9ca3af;
  --line: #334155;
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.42);
  --sidebar: #020617;
  --sidebar-active: #1e293b;
  --control: #0b1220;
  --button-soft: #1f2937;
  --button-soft-ink: #e5e7eb;
  --table-head: #0b1220;
  --table-line: #1f2937;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

a {
  color: inherit;
}

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

.sidebar {
  background: var(--sidebar);
  color: #e5e7eb;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  margin-bottom: 26px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2f80ed, #0f8f63 55%, #f59e0b);
  color: white;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #9ca3af;
  margin-top: 2px;
}

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

.nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  padding: 9px 10px;
  border-radius: 8px;
  color: #cbd5e1;
  text-decoration: none;
}

.nav a.active,
.nav a:hover {
  background: var(--sidebar-active);
  color: #ffffff;
}

.theme-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 20;
  width: calc(260px - 32px);
  padding: 10px;
  border: 1px solid rgba(148, 163, 184, 0.26);
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.94);
  box-shadow: 0 14px 35px rgba(2, 6, 23, 0.28);
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 750;
}

.theme-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  width: 44px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 3px;
  background: #334155;
  border: 1px solid #475569;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.switch-thumb {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.36);
  transition: transform 0.18s ease;
}

.theme-switch input:checked + .switch-track {
  background: var(--green);
  border-color: var(--green);
}

.theme-switch input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
}

.theme-switch:focus-within .switch-track {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.main {
  min-width: 0;
  padding: 24px 28px 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 20px;
  margin-bottom: 12px;
}

h3 {
  font-size: 15px;
  margin-bottom: 8px;
}

.view {
  display: grid;
  gap: 18px;
}

.grid {
  display: grid;
  gap: 14px;
}

.metrics {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card,
.table-panel,
.form-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card {
  padding: 16px;
}

.metric strong {
  display: block;
  font-size: 28px;
  line-height: 1.1;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.inset-toolbar {
  padding: 12px 16px 0;
}

.toolbar .spacer {
  flex: 1;
}

.toolbar .input,
.toolbar select {
  width: auto;
  min-width: 170px;
}

.toolbar .field {
  min-width: 170px;
}

.short-input {
  max-width: 110px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--control);
  color: var(--ink);
  padding: 8px 10px;
}

textarea {
  min-height: 78px;
  resize: vertical;
}

.form-panel {
  padding: 16px;
}

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

.form-grid .wide {
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

td .actions {
  margin-top: 0;
}

.workflow-actions {
  display: grid;
  grid-template-columns: 104px 76px 56px 64px;
  gap: 8px;
  align-items: center;
  width: max-content;
}

.workflow-actions .ghost {
  width: 100%;
}

.button,
.ghost,
.danger,
.icon-button {
  min-height: 36px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  font-weight: 750;
}

.button {
  background: var(--blue);
  color: white;
}

.button:hover {
  background: var(--blue-dark);
}

.ghost {
  background: var(--button-soft);
  color: var(--button-soft-ink);
}

.danger {
  background: #fee2e2;
  color: #991b1b;
}

.icon-button {
  width: 38px;
  padding: 0;
  background: var(--button-soft);
  color: var(--button-soft-ink);
  font-size: 19px;
}

.table-panel {
  overflow: hidden;
}

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

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: var(--table-head);
}

td {
  font-size: 14px;
  line-height: 1.35;
}

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

.table-panel td > .button,
.table-panel td > .ghost,
.table-panel td > .danger,
.table-panel td > .pill {
  vertical-align: middle;
}

.table-panel td > .ghost,
.table-panel td > .button,
.table-panel td > .danger,
.table-panel td .actions {
  align-items: center;
}

.table-panel td select,
.table-panel td input {
  margin: 0;
}

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

.detail-stack {
  display: grid;
  gap: 4px;
  min-width: 190px;
}

.detail-stack span {
  overflow-wrap: anywhere;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 750;
  background: #eef2f7;
  color: #344054;
  white-space: nowrap;
}

.pill.ok {
  background: #dcfce7;
  color: #166534;
}

.pill.warn {
  background: #fef3c7;
  color: #92400e;
}

.pill.bad {
  background: #fee2e2;
  color: #991b1b;
}

.pill.info {
  background: #dbeafe;
  color: #1e40af;
}

.pill.purple {
  background: #ede9fe;
  color: #5b21b6;
}

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

.notice {
  border-radius: var(--radius);
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.notice.error {
  border-color: #fecaca;
  background: #fff1f2;
  color: #991b1b;
}

.modal {
  width: min(920px, calc(100vw - 28px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  background: var(--panel);
  color: var(--ink);
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.38);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
}

pre {
  overflow: auto;
  max-height: 420px;
  padding: 12px;
  background: #111827;
  color: #e5e7eb;
  border-radius: 8px;
}

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

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
}

.backup-schedule {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(110px, 0.8fr) 92px minmax(170px, 1.2fr);
  gap: 8px;
  align-items: center;
  min-width: 520px;
}

.backup-time {
  min-width: 92px;
}

.backup-timezone {
  min-width: 170px;
}

.hidden {
  display: none !important;
}

.diff-view {
  max-height: 62vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.diff-line {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  min-height: 22px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}

.diff-line code {
  white-space: pre;
  padding: 2px 10px;
  overflow-x: auto;
}

.diff-sign {
  padding: 2px 8px;
  text-align: center;
  user-select: none;
  color: var(--muted);
  border-right: 1px solid rgba(148, 163, 184, 0.22);
}

.diff-line.add {
  background: #dcfce7;
  color: #14532d;
}

.diff-line.add .diff-sign {
  background: #bbf7d0;
  color: #166534;
}

.diff-line.remove {
  background: #fee2e2;
  color: #7f1d1d;
}

.diff-line.remove .diff-sign {
  background: #fecaca;
  color: #991b1b;
}

body[data-theme="dark"] .diff-line.add {
  background: rgba(22, 101, 52, 0.34);
  color: #dcfce7;
}

body[data-theme="dark"] .diff-line.add .diff-sign {
  background: rgba(22, 101, 52, 0.5);
  color: #bbf7d0;
}

body[data-theme="dark"] .diff-line.remove {
  background: rgba(127, 29, 29, 0.36);
  color: #fee2e2;
}

body[data-theme="dark"] .diff-line.remove .diff-sign {
  background: rgba(127, 29, 29, 0.56);
  color: #fecaca;
}

@media (max-width: 1040px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 12px;
    display: block;
  }

  .brand {
    margin-bottom: 10px;
  }

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

  .theme-switch {
    left: 12px;
    bottom: 12px;
    width: auto;
  }

  .nav a {
    white-space: nowrap;
  }

  .metrics,
  .two-col,
  .three-col,
  .form-grid,
  .split-json {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 18px 14px 36px;
  }
}
