:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --border: #e3e3de;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --accent: #0f6e56;
  --accent-soft: #e1f2ec;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --add-bg: #e6f6ec;
  --add-fg: #116329;
  --del-bg: #fdebec;
  --del-fg: #a40e26;
  --code-bg: #fbfbfa;
  --tk-c: #6a737d;
  --tk-k: #8250df;
  --tk-s: #0a6b3d;
  --tk-f: #0550ae;
  --tk-v: #b35900;
  --tk-n: #953800;
  --tk-fn: #cf222e;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --surface: #1c1c1a; --surface-2: #252523; --border: #33332f; --text: #ecebe6; --muted: #9b9a93;
    --accent: #4fc7a0; --accent-soft: #173a30; --warn: #f0b45a; --warn-soft: #3a2c14; --danger: #ff8a7a; --danger-soft: #3d1c18;
    --add-bg: #12301d; --add-fg: #7ee2a0; --del-bg: #3a1619; --del-fg: #ff9ea6; --code-bg: #181816;
    --tk-c: #8b949e; --tk-k: #c9a3ff; --tk-s: #7ee2a0; --tk-f: #79c0ff; --tk-v: #ffa657; --tk-n: #ffb37a; --tk-fn: #ff7b72;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413; --surface: #1c1c1a; --surface-2: #252523; --border: #33332f; --text: #ecebe6; --muted: #9b9a93;
  --accent: #4fc7a0; --accent-soft: #173a30; --warn: #f0b45a; --warn-soft: #3a2c14; --danger: #ff8a7a; --danger-soft: #3d1c18;
  --add-bg: #12301d; --add-fg: #7ee2a0; --del-bg: #3a1619; --del-fg: #ff9ea6; --code-bg: #181816;
  --tk-c: #8b949e; --tk-k: #c9a3ff; --tk-s: #7ee2a0; --tk-f: #79c0ff; --tk-v: #ffa657; --tk-n: #ffb37a; --tk-fn: #ff7b72;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 2rem 0 .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; }
code, pre, .mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }

/* Layout */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 1.25rem .75rem; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: .25rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; padding: 0 .5rem 1rem; color: var(--text); }
.brand img { width: 24px; height: 24px; }
.nav a { display: block; padding: .45rem .6rem; border-radius: 6px; color: var(--text); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { float: right; color: var(--muted); font-size: 12px; font-weight: 400; }
.side-foot { margin-top: auto; padding: .5rem; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: .35rem; }
.side-foot button { align-self: flex-start; }
.main { padding: 2rem 2.5rem 4rem; max-width: 1200px; width: 100%; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: .5rem; }
.crumbs a { color: var(--muted); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .meta { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .35rem; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .6rem 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0 .5rem 0 0; }
  .nav { display: flex; flex-wrap: wrap; gap: .1rem; }
  .nav .count { display: none; }
  .side-foot { display: none; }
  .main { padding: 1.25rem 16px 3rem; }
}

/* Components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .9rem; }
.card-link { color: inherit; display: block; transition: border-color .15s; }
.card-link:hover { border-color: var(--accent); text-decoration: none; }
.card-link .title { font-weight: 600; margin-bottom: .2rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .9rem; margin: 1rem 0 0; }
.stat .num { font-size: 1.7rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--muted); font-size: 13px; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.deprecated { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.draft { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); padding: .05rem .4rem; border-radius: 5px; display: inline-block; margin: 0 .25rem .25rem 0; }

.btn, button { font: inherit; font-size: 13px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .35rem .7rem; border-radius: 6px; cursor: pointer; }
.btn:hover, button:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

.banner { border-radius: var(--radius); padding: .8rem 1rem; margin: 0 0 1rem; }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner.info { background: var(--accent-soft); color: var(--accent); }

input[type=search], input[type=password], input[type=text], select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .45rem .65rem;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar input[type=search] { flex: 1 1 240px; }

table.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.list th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: .6rem .8rem; border-bottom: 1px solid var(--border); background: var(--surface-2); }
table.list td { padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

dl.props { display: grid; grid-template-columns: 160px 1fr; gap: .5rem 1rem; margin: 0; }
dl.props dt { color: var(--muted); font-size: 13px; }
dl.props dd { margin: 0; min-width: 0; }
@media (max-width: 560px) { dl.props { grid-template-columns: 1fr; } dl.props dt { margin-top: .4rem; } }

.prose { max-width: 75ch; }
.prose p { margin: .4rem 0; }

/* Code */
.code { background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin: 0 0 1rem; }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .45rem .7rem; border-bottom: 1px solid var(--border); background: var(--surface-2); font-size: 13px; }
.code-head .name { font-family: var(--mono); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code pre { margin: 0; padding: .8rem 0; overflow-x: auto; line-height: 1.55; counter-reset: ln; }
.code pre .ln { display: block; padding: 0 1rem 0 0; }
.code pre .ln::before { counter-increment: ln; content: counter(ln); display: inline-block; width: 3.2em; padding-right: 1em; text-align: right; color: var(--muted); opacity: .55; user-select: none; }
.code.expr pre { padding: .8rem 1rem; white-space: pre-wrap; word-break: break-word; }
.tk-c { color: var(--tk-c); font-style: italic; }
.tk-k { color: var(--tk-k); font-weight: 600; }
.tk-s { color: var(--tk-s); }
.tk-f { color: var(--tk-f); }
.tk-v { color: var(--tk-v); }
.tk-n { color: var(--tk-n); }
.tk-fn { color: var(--tk-fn); }

.tabs-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.tabs-nav { position: sticky; top: 1rem; display: flex; flex-direction: column; gap: .1rem; font-size: 13px; }
.tabs-nav a { padding: .3rem .55rem; border-radius: 5px; color: var(--text); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs-nav a:hover { background: var(--surface-2); text-decoration: none; }
@media (max-width: 960px) { .tabs-layout { grid-template-columns: 1fr; } .tabs-nav { position: static; flex-direction: row; flex-wrap: wrap; } }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; margin-bottom: 1rem; }
.segmented a { padding: .35rem .8rem; color: var(--text); font-size: 13px; border-right: 1px solid var(--border); background: var(--surface); }
.segmented a:last-child { border-right: 0; }
.segmented a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.segmented a:hover { text-decoration: none; }

/* Diff */
.diff-file { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 1rem; background: var(--code-bg); }
.diff-file > summary { list-style: none; cursor: pointer; padding: .5rem .75rem; background: var(--surface-2); border-bottom: 1px solid var(--border); font-family: var(--mono); font-size: 13px; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.diff-file > summary::-webkit-details-marker { display: none; }
.diff-file:not([open]) > summary { border-bottom: 0; }
.diff-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; }
.diff-wrap { overflow-x: auto; }
.diff-table td { padding: 0 .5rem; white-space: pre; vertical-align: top; }
.diff-table td.n { width: 1%; min-width: 3em; text-align: right; color: var(--muted); opacity: .7; user-select: none; }
.diff-table tr.add td { background: var(--add-bg); }
.diff-table tr.add td.t { color: var(--add-fg); }
.diff-table tr.del td { background: var(--del-bg); }
.diff-table tr.del td.t { color: var(--del-fg); }
.diff-table tr.hunk td { background: var(--surface-2); color: var(--muted); padding: .2rem .5rem; }
.stat-add { color: var(--add-fg); font-weight: 600; }
.stat-del { color: var(--del-fg); font-weight: 600; }
.fstatus { font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 0 .35rem; border-radius: 4px; }
.fstatus.A, .fstatus.added { background: var(--add-bg); color: var(--add-fg); }
.fstatus.D, .fstatus.deleted { background: var(--del-bg); color: var(--del-fg); }
.fstatus.M, .fstatus.modified { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.fstatus.R, .fstatus.renamed { background: var(--warn-soft); color: var(--warn); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 1rem .9rem; }
.timeline li::before { content: ""; position: absolute; left: -1.42rem; top: .45rem; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline .v { font-family: var(--mono); font-weight: 600; }

.commit-row { display: flex; gap: .9rem; padding: .7rem .9rem; border-bottom: 1px solid var(--border); color: inherit; }
.commit-row:last-child { border-bottom: 0; }
.commit-row:hover { background: var(--surface-2); text-decoration: none; }
.commit-row .subj { font-weight: 550; }
.commit-row .sha { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-left: auto; white-space: nowrap; }
.commit-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.day-head { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin: 1.25rem 0 .4rem; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 340px; padding: 2rem 1.75rem; text-align: center; }
.login img { width: 40px; height: 40px; }
.login h1 { font-size: 1.25rem; margin: .75rem 0 .25rem; }
.login form { display: flex; flex-direction: column; gap: .75rem; margin-top: 1.25rem; }
.login input { text-align: center; font-size: 1.4rem; letter-spacing: .4em; padding: .6rem; font-family: var(--mono); }
.login .btn { padding: .6rem; font-size: 15px; }
.login .msg { min-height: 1.5em; font-size: 13px; }
.login .msg.err { color: var(--danger); }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .5rem 1rem; border-radius: 6px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

/* Utilities (CSP forbids inline styles) */
.mb { margin-bottom: 1.1rem; }
.m0 { margin: 0; }
.strong { font-weight: 550; }
.minw0 { min-width: 0; }
.commit-body { white-space: pre-wrap; font-family: var(--sans); font-size: 14px; }
.file-title { font-size: 1.2rem; word-break: break-all; }

/* Calculation */
.impl { margin-bottom: 1.1rem; }
.impl-head { font-weight: 600; margin-bottom: .4rem; }
.impl-req { margin: -.5rem 0 0; }
.lineage { list-style: none; counter-reset: step; margin: 0; padding: 0; }
.lineage > li { counter-increment: step; position: relative; padding: 0 0 1rem 2.2rem; border-left: 2px solid var(--border); margin-left: .7rem; }
.lineage > li:last-child { border-left-color: transparent; }
.lineage > li::before { content: counter(step); position: absolute; left: -.8rem; top: 0; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); color: var(--accent); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.lin-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .3rem; }
.lineage .code { margin-top: .5rem; }
.badge.layer-dbt { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.layer-qlik { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.layer-source { background: var(--surface-2); }
.expr-cell { white-space: pre-wrap; word-break: break-word; font-size: 12.5px; }
ul.plain { margin: 0; padding-left: 1.1rem; }
