:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0d1011;
  color: #e7eeee;
  --bg: #0d1011;
  --surface: #151a1b;
  --surface-2: #101516;
  --surface-3: #1b2223;
  --line: #2a3536;
  --line-strong: #3b494b;
  --text: #e7eeee;
  --muted: #8b999a;
  --dim: #667476;
  --green: #28c69a;
  --red: #f06a76;
  --amber: #e6ae50;
  --blue: #70a8ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, .22);
}

body[data-theme="light"] {
  color-scheme: light;
  --bg: #f0eee8;
  --surface: #fbfaf7;
  --surface-2: #f5f3ee;
  --surface-3: #e9e6de;
  --line: #d5d0c4;
  --line-strong: #bdb6a8;
  --text: #242b2b;
  --muted: #6f706b;
  --dim: #92928b;
  --green: #087d61;
  --red: #b6374d;
  --amber: #97600b;
  --blue: #255fae;
  --shadow: 0 18px 50px rgba(61, 53, 38, .12);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
[hidden] { display: none !important; }

.topbar { min-height: 64px; padding: 10px 24px; display: flex; align-items: center; gap: 28px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, transparent); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; color: #08110f; background: linear-gradient(135deg, #54e0b0, #5ea7ff); font-weight: 900; letter-spacing: -.08em; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; letter-spacing: .02em; }
.brand small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.topnav { display: flex; align-self: stretch; gap: 2px; }
.nav-tab { border: 0; border-bottom: 2px solid transparent; color: var(--muted); background: transparent; padding: 0 13px; font-size: 13px; white-space: nowrap; }
.nav-tab:hover, .nav-tab.active { color: var(--text); border-bottom-color: var(--green); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.badge, .market-badge, .count-badge { border: 1px solid var(--line-strong); border-radius: 999px; color: var(--green); padding: 4px 9px; font-size: 11px; white-space: nowrap; }
.badge.muted { color: var(--muted); }
.compact-field { display: flex; align-items: center; gap: 5px; color: var(--dim); font-size: 10px; }
.compact-field input, .compact-field select { width: 108px; padding: 6px 8px; color: var(--text); border: 1px solid var(--line); border-radius: 6px; outline: none; background: var(--surface-2); }
.compact-field select { width: 86px; }

.workspace { max-width: 1680px; margin: 0 auto; padding: 24px; }
.view { min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.panel-view { min-height: calc(100vh - 112px); padding: 24px; }
.active-view { display: grid; grid-template-columns: minmax(280px, 330px) minmax(0, 1fr); gap: 18px; align-items: start; }
.control-panel { padding: 18px; position: sticky; top: 88px; }
.panel-heading, .chart-heading, .view-heading, .editor-heading, .section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
h1, h2, p { margin: 0; }
h1 { font-size: 22px; letter-spacing: -.03em; }
h2 { font-size: 14px; }
.panel-heading h1 { margin-top: 3px; }
.eyebrow { display: block; color: var(--dim); font-size: 9px; letter-spacing: .14em; font-weight: 700; }
.market-badge { color: var(--blue); border-color: color-mix(in srgb, var(--blue) 55%, var(--line)); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 11px; }
input, select, textarea { color: var(--text); background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 7px; outline: none; }
input, select { height: 34px; padding: 0 9px; }
textarea { padding: 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 2px color-mix(in srgb, var(--blue) 18%, transparent); }
.section-heading { align-items: center; margin: 24px 0 9px; }
.section-heading h2 { font-size: 12px; }
.text-button { border: 0; background: transparent; padding: 2px 0; color: var(--blue); font-size: 11px; }
.search-input { width: 100%; margin-bottom: 10px; }
.definition-picker { display: flex; flex-direction: column; gap: 7px; max-height: 315px; overflow: auto; }
.definition-option { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 9px; background: var(--surface-2); }
.definition-option:has(input:checked) { border-color: color-mix(in srgb, var(--green) 60%, var(--line)); background: color-mix(in srgb, var(--green) 7%, var(--surface-2)); }
.definition-option input { width: 15px; height: 15px; accent-color: var(--green); }
.definition-option strong, .definition-option small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.definition-option strong { color: var(--text); font-size: 12px; }
.definition-option small { color: var(--dim); font-size: 9px; margin-top: 3px; }
.kind-tag { border: 1px solid var(--line); border-radius: 4px; color: var(--amber); padding: 2px 4px; font-size: 9px; }
.control-actions, .editor-actions, .heading-actions, .chart-actions { display: flex; gap: 8px; align-items: center; }
.control-actions { flex-direction: column; margin-top: 17px; }
.control-actions button { width: 100%; }
button.primary-button, button.secondary-button, button.danger-button, .icon-text-button { border-radius: 7px; padding: 9px 12px; border: 1px solid var(--line-strong); color: var(--text); background: var(--surface-3); }
button.primary-button { background: var(--green); color: #071511; border-color: var(--green); font-weight: 700; }
button.secondary-button:hover, .icon-text-button:hover { border-color: var(--blue); color: var(--blue); }
button.danger-button { color: var(--red); border-color: color-mix(in srgb, var(--red) 55%, var(--line)); }
.status-line { min-height: 18px; margin-top: 10px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.status-line.ok { color: var(--green); }
.status-line.error { color: var(--red); }
.hint-box { display: flex; flex-direction: column; gap: 4px; margin-top: 18px; padding: 10px; border-left: 2px solid var(--blue); background: color-mix(in srgb, var(--blue) 6%, var(--surface-2)); color: var(--muted); font-size: 10px; line-height: 1.5; }
.hint-box strong { color: var(--blue); }

.board-main { min-width: 0; }
.metric-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.metric-card { min-height: 82px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.metric-card span, .metric-card small { display: block; color: var(--muted); font-size: 10px; }
.metric-card strong { display: block; margin: 7px 0 4px; font-size: 18px; letter-spacing: -.03em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metric-card small { color: var(--dim); }
.chart-panel { min-height: 650px; padding: 14px 14px 8px; position: relative; }
.chart-heading { align-items: center; padding: 0 4px 12px; }
.chart-heading h2 { margin-top: 3px; font-size: 15px; }
.chart-actions select { width: auto; height: 29px; font-size: 11px; }
.icon-text-button { padding: 6px 9px; font-size: 11px; }
.chart-container { height: 570px; min-height: 430px; position: relative; overflow: hidden; border-radius: 7px; background: var(--surface-2); }
.chart-container .empty-state { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 12px; }
.chart-legend { position: absolute; top: 60px; left: 28px; z-index: 2; max-width: calc(100% - 56px); color: var(--muted); font-size: 11px; pointer-events: none; }
.chart-legend .legend-group { display: inline-flex; gap: 10px; margin-right: 14px; }
.chart-legend .legend-item { margin-left: 7px; }
.chart-legend i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 3px; }
.chart-hud { position: absolute; right: 27px; bottom: 27px; z-index: 2; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: color-mix(in srgb, var(--surface) 92%, transparent); font-size: 10px; pointer-events: none; }
.chart-hud .hover-row { display: flex; gap: 6px; justify-content: space-between; min-width: 120px; }
.chart-hud .hover-name { color: #0c1212; border-radius: 3px; padding: 1px 4px; }
.chart-hud .hover-value { color: var(--text); font-variant-numeric: tabular-nums; }
.raw-panel { margin-top: 12px; }
.raw-panel summary { padding: 12px 14px; color: var(--muted); font-size: 11px; cursor: pointer; }
.raw-panel pre { max-height: 360px; overflow: auto; margin: 0; padding: 0 14px 14px; color: var(--muted); font-size: 10px; white-space: pre-wrap; word-break: break-word; }

.view-heading { align-items: center; margin-bottom: 20px; }
.view-heading h1 { margin-top: 4px; }
.view-heading p { max-width: 700px; margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.manager-layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 16px; align-items: start; }
.definition-list-panel, .definition-editor { padding: 16px; }
.count-badge { padding: 3px 7px; color: var(--muted); }
.manager-list { display: flex; flex-direction: column; gap: 7px; max-height: calc(100vh - 245px); overflow: auto; }
.manager-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); text-align: left; }
.manager-item.active { border-color: var(--blue); }
.manager-item strong, .manager-item small { display: block; }
.manager-item strong { color: var(--text); font-size: 12px; }
.manager-item small { color: var(--dim); margin-top: 3px; font-size: 9px; }
.pin-button { width: 25px; height: 25px; padding: 0; border: 0; border-radius: 5px; color: var(--dim); background: transparent; }
.pin-button.pinned { color: var(--amber); background: color-mix(in srgb, var(--amber) 12%, transparent); }
.editor-heading { align-items: center; margin-bottom: 18px; }
.editor-heading h2 { margin-top: 4px; font-size: 17px; }
.metadata-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; }
.wide-label, .source-label { margin-top: 12px; }
.source-label textarea { min-height: 420px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.5; font-size: 12px; tab-size: 2; }
.editor-actions { justify-content: flex-end; margin-top: 12px; }
.editor-actions button { width: auto; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 830px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; font-size: 11px; white-space: nowrap; }
th { color: var(--dim); font-size: 10px; font-weight: 600; }
td { color: var(--muted); }
td strong { color: var(--text); font-weight: 600; }
.table-empty { padding: 48px; text-align: center; color: var(--dim); }
.status-success { color: var(--green); }
.status-failed { color: var(--red); }
.status-cached { color: var(--blue); }
.scheduler-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 15px; overflow: hidden; }
.scheduler-summary > div { padding: 20px; border-right: 1px solid var(--line); }
.scheduler-summary > div:last-child { border-right: 0; }
.scheduler-summary span, .scheduler-summary strong { display: block; }
.scheduler-summary span { color: var(--muted); font-size: 11px; }
.scheduler-summary strong { margin-top: 8px; font-size: 20px; }
.scheduler-jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.scheduler-job { padding: 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.scheduler-job header { display: flex; justify-content: space-between; gap: 8px; }
.scheduler-job strong { font-size: 13px; }
.scheduler-job p { margin-top: 7px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.scheduler-job code { color: var(--blue); font-size: 10px; }

.pg-swal { background: var(--surface) !important; color: var(--text) !important; border: 1px solid var(--line) !important; border-radius: 10px !important; }
.pg-swal-title { color: var(--text) !important; font-size: 16px !important; }
.pg-swal-body { color: var(--muted) !important; font-size: 12px !important; }
.pg-swal-actions { gap: 8px !important; }
.pg-swal-confirm, .pg-swal-cancel { padding: 8px 14px; border: 1px solid var(--line-strong); border-radius: 6px; cursor: pointer; }
.pg-swal-confirm { color: #071511; background: var(--green); border-color: var(--green); }
.pg-swal-confirm.is-danger { color: #fff; background: var(--red); border-color: var(--red); }
.pg-swal-cancel { color: var(--text); background: var(--surface-3); }

@media (max-width: 1100px) {
  .topbar { gap: 14px; }
  .top-actions .compact-field { display: none; }
  .active-view { grid-template-columns: 280px minmax(0, 1fr); }
  .chart-container { height: 520px; }
}
@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; padding: 10px 14px; }
  .topnav { order: 3; width: 100%; overflow-x: auto; height: 34px; }
  .nav-tab { padding: 0 10px; }
  .top-actions { margin-left: auto; }
  .top-actions .compact-field:first-of-type { display: flex; }
  .workspace { padding: 12px; }
  .active-view, .manager-layout { grid-template-columns: 1fr; }
  .control-panel { position: static; }
  .metric-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-panel { min-height: 520px; }
  .chart-container { height: 430px; }
  .manager-list { max-height: 300px; }
  .metadata-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-view { padding: 16px; }
  .view-heading { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 480px) {
  .brand small, #connectionBadge { display: none; }
  .top-actions .compact-field:first-of-type span { display: none; }
  .top-actions .compact-field:first-of-type input { width: 92px; }
  .metric-cards { gap: 7px; }
  .metric-card { padding: 10px; }
  .metric-card strong { font-size: 15px; }
  .chart-heading { align-items: flex-start; flex-direction: column; }
  .chart-actions { width: 100%; }
  .chart-actions select { margin-left: auto; }
  .metadata-grid { grid-template-columns: 1fr; }
  .editor-actions { flex-wrap: wrap; }
}
