:root {
  --bg: #0f1216;
  --bg-panel: #161b22;
  --bg-side: #12161c;
  --bg-hover: #1d242e;
  --border: #262e39;
  --text: #d7dee8;
  --text-dim: #8894a5;
  --accent: #4c8dff;
  --accent-soft: #1e2b45;
  --warn: #d9a441;
  --error: #e05561;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --bg-panel: #ffffff;
    --bg-side: #f0f2f5;
    --bg-hover: #e8ecf1;
    --border: #d9dee5;
    --text: #1c2430;
    --text-dim: #6b7683;
    --accent: #1f6feb;
    --accent-soft: #dce8fc;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted, .dim { color: var(--text-dim); }
.spacer { flex: 1; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 280px;
  flex: 0 0 280px;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.content { flex: 1; padding: 28px 32px 60px; min-width: 0; }

/* ---------- brand ---------- */
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px; letter-spacing: .5px;
}
.brand-name { font-weight: 600; font-size: 13.5px; }
.brand-sub { color: var(--text-dim); font-size: 11.5px; }

/* ---------- sidebar nav ---------- */
.nav-main { display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; }
.nav-main a {
  padding: 7px 10px; border-radius: 6px;
  color: var(--text); font-size: 13px;
}
.nav-main a:hover { background: var(--bg-hover); text-decoration: none; }
.nav-main a.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }

.side-label {
  padding: 12px 16px 6px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .8px;
  text-transform: uppercase; color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
}

.side-search {
  margin: 0 12px 8px; padding: 6px 9px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 12.5px; width: calc(100% - 24px);
}
.side-search:focus { outline: none; border-color: var(--accent); }

.side-toggle {
  display: flex; align-items: center; gap: 7px;
  margin: 0 12px 8px; padding: 2px 0;
  font-size: 12px; color: var(--text-dim); cursor: pointer;
  user-select: none;
}
.side-toggle:hover { color: var(--text); }
.side-toggle input { accent-color: var(--accent); margin: 0; cursor: pointer; }

.db-list { padding: 0 8px; max-height: 190px; overflow-y: auto; flex: 0 0 auto; }
.db-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 6px;
  color: var(--text); font-size: 12.5px;
}
.db-item:hover { background: var(--bg-hover); text-decoration: none; }
.db-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.db-item.system .db-name { color: var(--text-dim); }
.db-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-size { color: var(--text-dim); font-size: 11px; flex-shrink: 0; }

.obj-list { padding: 0 8px 16px; overflow-y: auto; flex: 1; }
.obj-item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 5px 10px; border-radius: 6px;
  color: var(--text); font-size: 12.5px;
}
.obj-item:hover { background: var(--bg-hover); text-decoration: none; }
.obj-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.obj-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.obj-count { color: var(--text-dim); font-size: 11px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.obj-item.is-view .obj-count { font-style: italic; }

/* ---------- page head ---------- */
.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 4px 0 6px; font-size: 23px; font-weight: 600; letter-spacing: -.2px; }
.crumb { font-size: 12px; color: var(--text-dim); display: flex; gap: 6px; }
.collation { margin: -8px 0 22px; font-size: 12px; }

.tabs { display: flex; gap: 4px; margin-top: 12px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 7px 14px; font-size: 13px; color: var(--text-dim);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }

/* ---------- stats ---------- */
.stat-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin-bottom: 22px;
}
.stat {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
}
.stat-value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-label {
  font-size: 11px; color: var(--text-dim); margin-top: 2px;
  text-transform: uppercase; letter-spacing: .6px;
}

/* ---------- panels ---------- */
.panel {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px 20px; margin-bottom: 20px;
}
.panel h2 {
  margin: 0 0 14px; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.panel h3.sub {
  margin: 16px 0 8px; font-size: 12px; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: .6px;
}

.pill {
  background: var(--bg-hover); color: var(--text-dim);
  border-radius: 20px; padding: 2px 8px;
  font-size: 11px; font-weight: 500;
}
.pill.warn { background: rgba(217,164,65,.16); color: var(--warn); }

/* ---------- bars ---------- */
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row {
  display: grid; grid-template-columns: minmax(140px, 260px) 1fr auto;
  gap: 12px; align-items: center;
  padding: 5px 8px; border-radius: 6px; color: var(--text); font-size: 12.5px;
}
.bar-row:hover { background: var(--bg-hover); text-decoration: none; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--bg-hover); border-radius: 4px; height: 8px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar-value { color: var(--text-dim); font-variant-numeric: tabular-nums; font-size: 12px; }

/* ---------- grids ---------- */
.grid-wrap { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.grid-wrap.scroll { overflow: auto; max-height: 68vh; }

.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; }
.grid th, .grid td {
  text-align: left; padding: 7px 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.grid thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-side);
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr:hover td { background: var(--bg-hover); }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .rownum {
  color: var(--text-dim); text-align: right;
  font-variant-numeric: tabular-nums; width: 1%;
  background: var(--bg-panel); position: sticky; left: 0; z-index: 1;
}
.grid thead .rownum { z-index: 3; background: var(--bg-side); }
.grid td.null { color: var(--text-dim); font-style: italic; }
.grid td.empty { text-align: center; color: var(--text-dim); padding: 26px; }

.data-grid td { max-width: 340px; overflow: hidden; text-overflow: ellipsis; }

.col-head { display: flex; flex-direction: column; gap: 1px; color: inherit; }
.col-head:hover { text-decoration: none; color: var(--text); }
.col-head.sorted { color: var(--accent); }
.col-name { font-size: 11.5px; }
.col-type { font-size: 10px; font-weight: 400; text-transform: none; letter-spacing: 0; opacity: .7; }
.arrow { font-size: 8px; }

.key {
  background: var(--accent-soft); color: var(--accent);
  border-radius: 3px; padding: 0 4px; margin-left: 5px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .3px;
}

.mini-link { font-size: 11.5px; color: var(--text-dim); }
.mini-link:hover { color: var(--accent); }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px; font-size: 12px; color: var(--text);
}
.chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.rel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.rel-list li { font-size: 12.5px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.arrow-r { color: var(--text-dim); }

/* ---------- toolbar & controls ---------- */
.toolbar {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.search, .toolbar select, .jump input {
  background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; font-size: 12.5px; font-family: inherit;
}
.search { min-width: 260px; }
.search:focus, .toolbar select:focus, .jump input:focus { outline: none; border-color: var(--accent); }

.btn {
  display: inline-block; cursor: pointer;
  background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 13px; font-size: 12.5px; font-family: inherit;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.disabled { opacity: .38; pointer-events: none; }

.pager { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.page-info { font-size: 12.5px; color: var(--text-dim); margin: 0 6px; }
.jump { display: flex; gap: 6px; margin-left: auto; }
.jump input { width: 90px; }

/* ---------- query console ---------- */
.query-form { margin-bottom: 18px; }
#sql {
  width: 100%; min-height: 160px; resize: vertical;
  background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 13px 15px; font-family: var(--mono); font-size: 13px; line-height: 1.6;
  tab-size: 2;
}
#sql:focus { outline: none; border-color: var(--accent); }
.query-actions { display: flex; align-items: center; gap: 12px; margin-top: 10px; font-size: 12px; }

.sql-block {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; overflow-x: auto; font-family: var(--mono);
  font-size: 12.5px; line-height: 1.55; margin: 0; white-space: pre-wrap;
}

/* ---------- alerts ---------- */
.alert {
  border: 1px solid var(--border); border-left-width: 3px;
  border-radius: 8px; padding: 14px 16px; margin-bottom: 20px;
  background: var(--bg-panel); font-size: 13px;
}
.alert p { margin: 6px 0 0; color: var(--text-dim); }
.alert-error { border-left-color: var(--error); }
.alert-warn { border-left-color: var(--warn); }
.alert details { margin-top: 12px; }
.alert summary { cursor: pointer; font-size: 12.5px; color: var(--accent); }
.alert pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 12px; overflow-x: auto; font-family: var(--mono);
  font-size: 12px; line-height: 1.55; margin: 10px 0;
}

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .obj-list { max-height: 240px; }
  .content { padding: 20px 16px 40px; }
}

/* ---------- reports: SAIBA look-alike form (always light, like the real page) ---------- */
.saiba-panel {
  background: #ffffff; color: #1c2430;
  border: 1px solid #d5dbe3; border-radius: 10px;
  padding: 16px 22px 20px; margin-bottom: 20px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
.saiba-title {
  margin: 0 0 16px; padding-bottom: 10px;
  color: #2c6cb5; font-size: 17px; font-weight: 600;
  border-bottom: 1px solid #e3e8ee;
}
.saiba-row-top { display: flex; align-items: flex-end; gap: 40px; flex-wrap: wrap; }
.saiba-note { color: #d8433a; font-size: 12.5px; font-weight: 600; padding-bottom: 9px; }
.saiba-or { color: #d8433a; font-weight: 700; font-size: 12.5px; margin: 14px 0 6px; }
.saiba-grid {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px 18px;
}
.saiba-field label {
  display: block; font-size: 12px; color: #3d4753; margin-bottom: 4px;
}
.saiba-field.narrow { width: 190px; }
.saiba-field input, .saiba-field select {
  width: 100%; padding: 7px 9px;
  border: 1px solid #c6cfd9; border-radius: 4px;
  font-size: 13px; font-family: inherit; background: #fff; color: #1c2430;
}
.saiba-field input:focus, .saiba-field select:focus { outline: none; border-color: #2c6cb5; }
.saiba-with-help { display: flex; }
.saiba-with-help input { border-radius: 4px 0 0 4px; border-right: none; }
.saiba-help {
  display: grid; place-items: center; width: 34px; flex: 0 0 34px;
  background: #2c6cb5; color: #fff; border-radius: 0 4px 4px 0;
  font-weight: 700; font-size: 14px;
}
.saiba-help:hover { background: #245b9a; text-decoration: none; color: #fff; }
.saiba-engine {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  margin-top: 18px; padding: 10px 14px;
  background: #f3f6fa; border: 1px solid #dfe5ec; border-radius: 6px; font-size: 12.5px;
}
.saiba-engine-label { font-weight: 600; color: #3d4753; text-transform: uppercase; font-size: 11px; letter-spacing: .6px; }
.saiba-engine label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.saiba-engine input { accent-color: #2c6cb5; margin: 0; }
.saiba-actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.saiba-hint { font-size: 12px; color: #5b6673; }
.default-submit { position: absolute; left: -9999px; width: 1px; height: 1px; padding: 0; border: 0; overflow: hidden; }
.definition {
  margin: -4px 0 12px; padding: 10px 14px; font-size: 13px;
  background: var(--accent-soft); color: var(--text); border-radius: 6px;
}
.saiba-btn {
  display: inline-block; cursor: pointer;
  background: #2c6cb5; color: #fff; border: 1px solid #2c6cb5; border-radius: 4px;
  padding: 8px 18px; font-size: 13px; font-family: inherit; font-weight: 500;
}
.saiba-btn:hover { background: #245b9a; text-decoration: none; color: #fff; }
.saiba-btn.secondary { background: #fff; color: #2c6cb5; }
.saiba-btn.secondary:hover { background: #eef3fa; }
.saiba-btn.proposed { background: #2e8b57; border-color: #2e8b57; }
.saiba-btn.proposed:hover { background: #26744a; }

.pill.ok { background: rgba(46,139,87,.16); color: #3fae6e; }
.sql-details { margin: 0 0 12px; font-size: 12.5px; }
.sql-details summary { cursor: pointer; color: var(--accent); }
.sql-details .sql-block { margin-top: 8px; }
.report-grid tr.row-deleted td { background: rgba(224, 85, 97, .14); }
.report-grid tr.row-restored td { background: rgba(46, 139, 87, .16); }
.report-grid tr.row-deleted:hover td, .report-grid tr.row-restored:hover td { filter: brightness(1.08); }
/* ---------- audit trail ---------- */
.about { margin: -6px 0 18px; font-size: 13px; }
.about summary { cursor: pointer; color: var(--accent); }
.about-body { margin-top: 8px; padding: 12px 16px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px; }
.about-body p { margin: 0 0 8px; color: var(--text); }
.about-body p:last-child { margin-bottom: 0; }
.audit-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 760px; }
.stat-warn .stat-value { color: var(--warn); }
.audit-grid-table td.val { max-width: 220px; }
.audit-grid-table td.changes { white-space: normal; min-width: 320px; max-width: 520px; vertical-align: top; }
.change-list { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.change-list li { font-size: 12px; line-height: 1.4; }
.change-list .fld { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); margin-right: 6px; }
.change-list .oldv { text-decoration: line-through; color: var(--text-dim); }
.change-list .arr { color: var(--text-dim); margin: 0 5px; }
.change-list .newv { font-weight: 600; }
.audit-grid-table td.changes .summary { font-size: 12px; color: var(--text-dim); white-space: normal; }
.audit-grid-table td { vertical-align: top; }
.audit-grid-table td.nowrap { white-space: nowrap; }
.audit-grid-table .time { font-size: 11px; }
.report-grid tr.k-insert td { background: rgba(46, 139, 87, .12); }
.report-grid tr.k-delete td { background: rgba(224, 85, 97, .14); }
.report-grid tr.k-unrecorded td { background: rgba(217, 164, 65, .16); }
.report-grid tr.k-system td { color: var(--text-dim); }
.report-grid tr.k-screen td { color: var(--text-dim); font-style: italic; }
.swatch.insert { background: rgba(46, 139, 87, .35); }
.swatch.unrec { background: rgba(217, 164, 65, .45); }
.swatch.screen { background: var(--bg-hover); }
.legend { font-size: 12px; margin: 0 0 10px; display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; border: 1px solid var(--border); }
.swatch.restored { background: rgba(46, 139, 87, .35); }
.swatch.deleted { background: rgba(224, 85, 97, .35); }

@media (max-width: 1250px) { .saiba-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px)  { .saiba-grid { grid-template-columns: 1fr; } .saiba-field.narrow { width: 100%; } }

/* ---------- signed-in user ---------- */
.user-box { margin: 4px 12px 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); font-size: 12px; }
.user-name { font-weight: 600; color: var(--text); }
.user-role { color: var(--text-dim); margin-top: 1px; }
.user-logout { display: inline-block; margin-top: 6px; color: var(--accent); font-size: 12px; }

.nav-main a.nav-guide { color: var(--text-dim); }
.nav-main a.nav-guide::before { content: "?"; display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--text-dim); font-size: 10px; margin-right: 8px; }
.nav-main a.nav-guide.active, .nav-main a.nav-guide:hover { color: var(--accent); }
.nav-main a.nav-guide.active::before { border-color: var(--accent); }
