:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-subtle: #f9fafb;
  --line: #dde3ea;
  --text: #182233;
  --muted: #687385;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --ok: #12814a;
  --warn: #b7791f;
  --danger: #b54708;
  --nav: #151a24;
  --nav-text: #cbd5e1;
  --code-bg: #0b1020;
  --code-text: #dbeafe;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1420;
  --panel: #151d2b;
  --panel-subtle: #101827;
  --line: #2c394d;
  --text: #e6edf7;
  --muted: #9aa8bc;
  --accent: #5b8cff;
  --accent-strong: #7aa2ff;
  --ok: #52c47f;
  --warn: #e0a947;
  --danger: #ff8a5b;
  --nav: #0a101b;
  --nav-text: #b9c6d8;
  --code-bg: #080d17;
  --code-text: #d9e7ff;
  --shadow: 0 8px 28px rgba(0, 0, 0, .28);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1420;
    --panel: #151d2b;
    --panel-subtle: #101827;
    --line: #2c394d;
    --text: #e6edf7;
    --muted: #9aa8bc;
    --accent: #5b8cff;
    --accent-strong: #7aa2ff;
    --ok: #52c47f;
    --warn: #e0a947;
    --danger: #ff8a5b;
    --nav: #0a101b;
    --nav-text: #b9c6d8;
    --code-bg: #080d17;
    --code-text: #d9e7ff;
    --shadow: 0 8px 28px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(37, 99, 235, .45);
  outline-offset: 2px;
}
.app-page { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.public-page { min-height: 100vh; }
.side-nav { position: sticky; top: 0; height: 100vh; background: var(--nav); color: var(--nav-text); padding: 22px 14px; border-right: 1px solid rgba(255, 255, 255, .06); }
.brand { color: #fff; font-size: 15px; font-weight: 750; margin: 0 8px 24px; }
.side-nav a, .link-button {
  display: block;
  width: 100%;
  color: var(--nav-text);
  text-decoration: none;
  background: transparent;
  border: 0;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.side-nav a.active, .side-nav a:hover, .link-button:hover { background: #1d2939; color: #fff; }
.theme-toggle { margin-top: 10px; }
.content { padding: 30px 34px; max-width: 1280px; width: 100%; margin: 0 auto; }
.toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 18px; margin-bottom: 22px; }
.toolbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.inline-form { margin: 0; }
.refresh-meta { color: var(--muted); font-size: 13px; }
h1 { margin: 0; font-size: 28px; line-height: 1.18; letter-spacing: 0; }
h2 { margin: 0 0 14px; font-size: 17px; line-height: 1.3; letter-spacing: 0; }
p { color: var(--muted); margin: 6px 0 0; line-height: 1.5; }
.grid { display: grid; gap: 18px; margin-bottom: 18px; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.targets-overview { margin-bottom: 18px; }
.targets-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr);
  gap: 18px;
  align-items: start;
}
.primary-column,
.side-column {
  display: grid;
  gap: 18px;
  min-width: 0;
}
.diagnostic-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 14px;
  margin: 0 0 18px;
}
.summary-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
  display: grid;
  gap: 10px;
}
.summary-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}
.summary-card span,
.current-target span,
.review-rows span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}
.summary-card strong {
  display: block;
  font-size: 24px;
  line-height: 1.1;
  text-align: right;
  overflow-wrap: anywhere;
}
.summary-card small {
  display: block;
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-primary { border-color: #b9c7da; }
.compact-panel { padding: 16px; }
.command summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  cursor: pointer;
  font-weight: 700;
}
.command summary::marker { color: var(--muted); }
.form-disclosure summary,
details.danger-panel summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-weight: 750;
}
.form-disclosure summary small,
details.danger-panel summary small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.form-disclosure form,
details.danger-panel form { margin-top: 16px; }
.advanced-fields {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel-subtle);
}
.advanced-fields summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.advanced-fields .form-grid { margin-top: 12px; }
.command pre, .alert {
  white-space: pre-wrap;
  overflow: auto;
  max-height: 560px;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 8px;
  padding: 14px;
  font-size: 13px;
  line-height: 1.45;
}
.command pre span { display: block; min-height: 1.45em; }
.line-ok { color: #71e09c; }
.line-warn { color: #ffd166; }
.line-error { color: #ff9b85; }
.command.error pre, .alert.error { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
:root[data-theme="dark"] .command.error pre,
:root[data-theme="dark"] .alert.error { background: #31180d; color: #ffb28f; border-color: #7c2d12; }
.alert.ok { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
:root[data-theme="dark"] .alert.ok { background: #0c2a1a; color: #86efac; border-color: #14532d; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 680px; }
.table-scroll th, .table-scroll td { overflow-wrap: anywhere; }
.status {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  min-width: 54px;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 8px;
  background: #ecfdf3;
  color: var(--ok);
  font-size: 12px;
  font-weight: 700;
}
:root[data-theme="dark"] .status { background: #10331f; }
.stack { display: grid; gap: 12px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.stepper {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}
.stepper li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-subtle);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.stepper span {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  flex: 0 0 auto;
}
.current-target {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-subtle);
}
.current-target strong {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.actions-row, .inline-form { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.actions-row select { flex: 1 1 180px; }
.actions-row button { flex: 0 0 auto; }
label { display: grid; gap: 6px; color: var(--text); font-size: 13px; font-weight: 600; }
input, select, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cfd8e3;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  color: #172033;
}
input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 0;
  padding: 0;
  accent-color: var(--accent);
}
label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 8px;
}
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
  background: #0f1724;
  border-color: #3a4961;
  color: var(--text);
}
textarea { min-height: 560px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.45; }
.editor-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.json-status { color: var(--muted); font-size: 13px; }
.json-status.ok { color: var(--ok); }
.json-status.error { color: var(--danger); }
button {
  border: 1px solid #cfd8e3;
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 13px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
button:hover { border-color: #94a3b8; }
button:disabled { cursor: wait; opacity: .62; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-strong); }
button.danger { background: #fff7ed; border-color: #fdba74; color: var(--danger); }
:root[data-theme="dark"] button.danger { background: #31180d; border-color: #7c2d12; }
.copy-button { padding: 6px 9px; font-size: 12px; }
.danger-panel { border-color: #fdba74; }
:root[data-theme="dark"] .danger-panel { border-color: #7c2d12; }
.danger-zone { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 16px; }
.review-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, .45);
}
.review-backdrop[hidden] { display: none; }
.review-dialog {
  width: min(680px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 72px rgba(15, 23, 42, .32);
  padding: 20px;
}
.review-dialog h2 { font-size: 18px; }
.review-rows {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}
.review-rows div {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.review-rows strong {
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.review-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; box-shadow: var(--shadow); }
code { background: #eef2ff; color: #3730a3; padding: 2px 5px; border-radius: 5px; }
:root[data-theme="dark"] code { background: #1e2a44; color: #b9ccff; }
[data-refresh-url].is-refreshing { outline: 1px solid rgba(17, 109, 255, .18); }

@media (max-width: 900px) {
  .app-page { grid-template-columns: 1fr; }
  .side-nav { position: static; height: auto; display: flex; flex-wrap: wrap; gap: 6px; padding: 12px; }
  .brand { width: 100%; margin: 0 8px 6px; }
  .side-nav a, .link-button { width: auto; min-width: 112px; text-align: center; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two,
  .targets-workspace,
  .diagnostic-grid { grid-template-columns: 1fr; }
  .current-target { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { grid-template-columns: 1fr; align-items: stretch; }
  .toolbar-actions { justify-content: flex-start; }
  .toolbar-actions, .inline-form { width: 100%; }
  .content { padding: 16px; }
}

@media (max-width: 520px) {
  .content { padding: 14px; }
  h1 { font-size: 24px; }
  .panel { padding: 16px; }
  .summary-grid,
  .form-grid,
  .stepper,
  .current-target { grid-template-columns: 1fr; }
  .side-nav a, .link-button { flex: 1 1 44%; min-width: 0; }
  .actions-row button, .inline-form button, .toolbar-actions button { flex: 1 1 auto; }
  button { min-height: 42px; }
  .table-scroll { overflow: visible; }
  .table-scroll table,
  .table-scroll thead,
  .table-scroll tbody,
  .table-scroll tr,
  .table-scroll th,
  .table-scroll td { display: block; min-width: 0; width: 100%; }
  .table-scroll thead { display: none; }
  .table-scroll tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    background: var(--panel-subtle);
  }
  .table-scroll td {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 10px;
    border-bottom: 0;
    padding: 6px 0;
  }
  .table-scroll td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }
  .review-rows div { grid-template-columns: 1fr; gap: 4px; }
  .review-actions { flex-direction: column-reverse; }
}
