/* TDS Lens */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1d232b;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --accent: #1f5fa8;
  --accent-soft: #e3eef9;
  --ok: #1e7a46;
  --ok-soft: #e1f3e8;
  --warn: #8a5a00;
  --warn-soft: #fbefd6;
  --error: #b42318;
  --error-soft: #fdecea;
  --code-bg: #eef1f4;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161b;
    --surface: #1a2027;
    --surface-2: #222a33;
    --text: #e6eaef;
    --muted: #9aa6b4;
    --border: #2e3843;
    --accent: #6aa7ea;
    --accent-soft: #1d3247;
    --ok: #6fd39b;
    --ok-soft: #173426;
    --warn: #f0c060;
    --warn-soft: #3a2e14;
    --error: #ff8a80;
    --error-soft: #3d1d1b;
    --code-bg: #242c35;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161b; --surface: #1a2027; --surface-2: #222a33; --text: #e6eaef; --muted: #9aa6b4;
  --border: #2e3843; --accent: #6aa7ea; --accent-soft: #1d3247; --ok: #6fd39b; --ok-soft: #173426;
  --warn: #f0c060; --warn-soft: #3a2e14; --error: #ff8a80; --error-soft: #3d1d1b; --code-bg: #242c35;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0; }
code { font-family: var(--mono); font-size: .86em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
pre { font-family: var(--mono); font-size: 12.5px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 16px; }
.filebar { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.filename { font-family: var(--mono); font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.privacy { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ok); background: var(--ok-soft); padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.filebar + .privacy { margin-left: 0; }

/* buttons */
.btn {
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; cursor: pointer; line-height: 1.3;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:focus-visible, .tname:focus-visible, .link:focus-visible, .canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.ghost { background: transparent; }
.btn.icon { width: 30px; padding: 5px 0; font-size: 16px; line-height: 1.1; }
.btn.link { border: 0; background: none; color: var(--accent); text-decoration: underline; padding: 0; font-size: 14px; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-align: left; }
.link:hover { text-decoration: underline; }

/* intro */
.intro { max-width: 860px; margin: 0 auto; padding: 48px 0 32px; }
.intro h1 { font-size: 34px; letter-spacing: -.02em; text-align: center; }
.lead { text-align: center; color: var(--muted); font-size: 17px; max-width: 640px; margin: 12px auto 28px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 2px dashed var(--border); border-radius: 14px; background: var(--surface);
  padding: 40px 16px; cursor: pointer; color: var(--muted); text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone svg { color: var(--accent); margin-bottom: 6px; }
.dropzone strong { color: var(--text); font-size: 17px; }
.dropzone:hover, body.dragging .dropzone { border-color: var(--accent); background: var(--accent-soft); }
.error { background: var(--error-soft); color: var(--error); border-radius: 8px; padding: 10px 14px; text-align: center; }
.features { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px 28px; margin-top: 40px; }
.features h2 { font-size: 15px; margin-bottom: 4px; }
.features p { margin: 0; color: var(--muted); font-size: 14px; }
.howto { margin-top: 32px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.howto summary { cursor: pointer; font-weight: 600; }
.howto ol { padding-left: 20px; }
body.dragging::after {
  content: "Drop to open"; position: fixed; inset: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent);
  font-size: 22px; font-weight: 700; pointer-events: none; z-index: 50;
}

/* result */
.result { padding: 20px 0 32px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { font: inherit; font-size: 13px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); padding: 5px 12px; border-radius: 999px; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.summary { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 14px; }
.summary h1 { font-size: 24px; overflow-wrap: anywhere; }
.summary p { margin: 4px 0 0; }
.stats { display: flex; gap: 8px; margin: 0; flex-wrap: wrap; }
.stats div { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; min-width: 88px; }
.stats dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stats dd { margin: 0; font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 10px; }
.seg { display: inline-flex; gap: 4px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; cursor: pointer; }
.spacer { flex: 1; }
.downloads { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.downloads .muted { margin-right: 2px; }

.stage { scroll-margin-top: 64px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; }
.stage.with-panel { grid-template-columns: minmax(0, 1fr) 360px; }
.canvas {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; max-height: 72vh; min-height: 60px; box-shadow: var(--shadow);
}
.canvas svg { display: block; }
.canvas g.tbl, .canvas g.rel { cursor: pointer; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; position: relative; max-height: 72vh; overflow: auto; box-shadow: var(--shadow);
}
.panel h3 { font-size: 17px; margin: 2px 32px 8px 0; overflow-wrap: anywhere; }
.panel h4 { margin: 16px 0 6px; }
.panel .close { position: absolute; top: 10px; right: 10px; }
.hint-line { margin: 6px 2px 0; }
.hint { background: var(--warn-soft); color: var(--text); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; }

/* report */
.report { margin-top: 24px; display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin-bottom: 10px; }
.card-head h3 { font-size: 18px; overflow-wrap: anywhere; }
.eyebrow { display: block; width: 100%; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.badge { font-size: 12px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 9px; font-weight: 600; }
.card h4, .panel h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
h4.group { text-transform: none; letter-spacing: 0; font-size: 13.5px; color: var(--text); margin: 10px 0 4px; }
.count { display: inline-block; min-width: 20px; text-align: center; background: var(--surface-2); color: var(--muted); border-radius: 999px; font-size: 11.5px; padding: 0 6px; margin-left: 4px; letter-spacing: 0; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13.5px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv pre, .sql { margin: 4px 0; background: var(--code-bg); padding: 8px 10px; border-radius: 6px; overflow: auto; white-space: pre-wrap; }
details summary { cursor: pointer; }
ul.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
ul.tables { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
ul.tables > li { padding: 4px 0; border-bottom: 1px solid var(--surface-2); overflow-wrap: anywhere; }
ul.tables > li:last-child { border-bottom: 0; }
.tname { font: inherit; font-weight: 600; color: var(--text); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; overflow-wrap: anywhere; }
.tname:hover { color: var(--accent); text-decoration: underline; }
.phys { margin: 4px 0 2px 2px; font-size: 13.5px; }
ul.tree { list-style: none; margin: 2px 0 2px 6px; padding-left: 14px; border-left: 2px solid var(--border); }
ul.tree li { margin: 3px 0; }
.kw { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.kw.join { color: var(--accent); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: bottom; }
td { padding: 6px 10px; border-bottom: 1px solid var(--surface-2); vertical-align: top; }
table.rels tr.first td { border-top: 1px solid var(--border); }
table.rels tbody tr { cursor: pointer; }
table.rels tbody tr:hover td { background: var(--accent-soft); }
table.cols td { padding: 3px 8px; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 0 8px; }
.pill.all { background: var(--ok-soft); color: var(--ok); }
.pill.some { background: var(--surface-2); color: var(--muted); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.notice { background: var(--warn-soft); border-radius: var(--radius); padding: 12px 16px; }

.footer { border-top: 1px solid var(--border); padding: 16px; text-align: center; color: var(--muted); font-size: 12.5px; }
.footer p { margin: 2px 0; }

@media (max-width: 900px) {
  .stage.with-panel { grid-template-columns: minmax(0, 1fr); }
  .panel { max-height: none; }
}
@media (max-width: 640px) {
  .intro { padding-top: 28px; }
  .intro h1 { font-size: 26px; }
  .features { grid-template-columns: 1fr; }
  .privacy { display: none; }
  .card { padding: 14px; }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .kv dt { margin-top: 6px; }
  .canvas { max-height: 60vh; }
  .stats { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .stats div { min-width: 0; padding: 5px 8px; }
  .stats dt { font-size: 9.5px; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .stats dd { font-size: 17px; }
  /* relationships: stacked rows instead of a squeezed table */
  table.rels thead { display: none; }
  table.rels, table.rels tbody { display: block; }
  table.rels tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--surface-2); }
  table.rels tr.first { border-top: 1px solid var(--border); }
  table.rels td { display: block; padding: 0; border: 0; }
  table.rels tr.first td { border-top: 0; }
  table.rels td:nth-child(1) { grid-column: 1 / -1; }
  table.rels td:nth-child(1):empty { display: none; }
  table.rels td:nth-child(2) { grid-column: 1 / -1; font-weight: 600; }
  table.rels td:nth-child(3) { grid-column: 1 / -1; }
  table.rels td:nth-child(4) { color: var(--muted); }
}

/* checks */
.checks { border-left: 4px solid var(--warn); }
.checklist { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 12px; }
.finding-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.finding-detail { margin: 4px 0; line-height: 1.8; }
.finding-detail code { white-space: pre-wrap; }
details.notes { margin-top: 14px; }
details.notes > summary { color: var(--muted); font-size: 13.5px; }
details.notes .checklist { margin-top: 10px; }

/* comparison */
.comparebar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; background: var(--accent-soft); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.pill.added { background: var(--ok-soft); color: var(--ok); }
.pill.removed { background: var(--error-soft); color: var(--error); }
.pill.changed { background: var(--warn-soft); color: var(--warn); }
.pill.a, .pill.b { background: var(--surface-2); color: var(--text); }
table.diff { table-layout: fixed; min-width: 640px; }
table.diff th:nth-child(1) { width: 100px; }
table.diff th:nth-child(2) { width: 28%; }
table.diff td { overflow-wrap: anywhere; }
table.diff tr[data-table], table.diff tr[data-rel] { cursor: pointer; }
table.diff tr[data-table]:hover td, table.diff tr[data-rel]:hover td { background: var(--accent-soft); }
#dsModel .pill { margin-right: 4px; }

/* Calc Lens */
.pill.sev-high { background: var(--error-soft); color: var(--error); }
.pill.sev-medium { background: var(--warn-soft); color: var(--warn); }
.pill.sev-low { background: var(--accent-soft); color: var(--accent); }
.pill.sev-none { background: var(--surface-2); color: var(--muted); }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.search { cursor: text; min-width: 220px; }
select.btn { padding-right: 6px; }
.stats .stat-high dd { color: var(--error); }
.stats .stat-medium dd { color: var(--warn); }
.card.calc { border-left: 4px solid var(--border); scroll-margin-top: 64px; }
.card.calc.prio-high { border-left-color: var(--error); }
.card.calc.prio-medium { border-left-color: var(--warn); }
.card.calc.prio-low { border-left-color: var(--accent); }
.card.calc .card-head h3 { margin-right: auto; }
.card.calc .checklist { gap: 8px; }
.card.calc .finding-head .kw { margin-left: 2px; }
.formula { max-height: 420px; }
.formula mark { background: var(--warn-soft); color: inherit; font-weight: 700; border-radius: 3px; padding: 0 1px; }
.card.calc.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 4px var(--accent); } to { box-shadow: var(--shadow); } }
table.rules-table td:first-child { font-weight: 600; white-space: nowrap; }
table.rules-table tr.first td { border-top: 1px solid var(--border); }
.howto .rules { margin-top: 10px; }
#rulesResult { margin-top: 16px; }
@media (max-width: 640px) {
  .btn.search { min-width: 0; flex: 1 1 100%; order: 1; }
  #wbStats { grid-template-columns: repeat(5, 1fr); }
  table.rules-table td:first-child { white-space: normal; }
}
