/* Retail SQL Analytics — same editorial dark palette as the portfolio site */
:root {
  color-scheme: dark;
  --bg: #0f0f0d;
  --surface: #171714;
  --surface-2: #1e1e1b;
  --surface-3: #262622;
  --ink: #f2efe8;
  --ink-soft: #c6c0b4;
  --ink-mute: #8f8a7e;
  --line: #2a2823;
  --line-strong: #46433b;
  --accent: #f05423;
  --accent-soft: rgba(240, 84, 35, 0.14);
  --blue: #3987e5;
  --blue-soft: rgba(57, 135, 229, 0.14);
  --good: #0ca30c;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter Tight", -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --radius: 14px;
  --gutter: clamp(16px, 4vw, 40px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: 130px; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: inherit; }
button, select { font: inherit; color: inherit; }
code, kbd { font-family: var(--mono); font-size: 0.86em; }
kbd { padding: 1px 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); }
.wrap { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 var(--gutter); }
.mono { font-family: var(--mono); }
.muted { color: var(--ink-mute); }

/* ---------- Loader ---------- */
.loader {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(240,84,35,0.10), transparent 60%), var(--bg);
  transition: opacity .5s ease, visibility .5s ease;
}
.loader.is-done { opacity: 0; visibility: hidden; }
.loader-card { width: min(440px, 100%); }
.loader-mark { display: flex; gap: 6px; align-items: flex-end; height: 40px; margin-bottom: 22px; }
.loader-mark span { width: 10px; border-radius: 3px; background: var(--ink); animation: grow 1.1s ease-in-out infinite; }
.loader-mark span:nth-child(1) { height: 40%; animation-delay: 0s; }
.loader-mark span:nth-child(2) { height: 70%; animation-delay: .15s; }
.loader-mark span:nth-child(3) { height: 100%; animation-delay: .3s; background: var(--accent); }
@keyframes grow { 0%, 100% { transform: scaleY(.55); } 50% { transform: scaleY(1); } }
.loader-mark span { transform-origin: bottom; }
.loader h2 { font-family: var(--serif); font-weight: 400; font-size: 26px; letter-spacing: -0.01em; margin-bottom: 18px; }
.loader-steps { list-style: none; display: grid; gap: 10px; margin-bottom: 22px; }
.loader-steps li { position: relative; padding-left: 28px; color: var(--ink-mute); font-size: 15px; transition: color .3s; }
.loader-steps li::before {
  content: ""; position: absolute; left: 0; top: 4px; width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--line-strong);
}
.loader-steps li.is-active { color: var(--ink); }
.loader-steps li.is-active::before { border-color: var(--accent); border-top-color: transparent; animation: spin .8s linear infinite; }
.loader-steps li.is-done { color: var(--ink-soft); }
.loader-steps li.is-done::before { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--bg); }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-mb { font-family: var(--mono); font-size: 12px; color: var(--ink-mute); margin-left: 6px; }
.loader-bar { height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.loader-fill { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }
.loader-error { margin-top: 16px; color: #ff8f6b; font-size: 14px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(15,15,13,0.82); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 19px; font-weight: 500; text-decoration: none; letter-spacing: -0.01em; white-space: nowrap; }
.brand-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.topnav { display: flex; gap: 22px; margin-left: auto; font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; }
.topnav a { text-decoration: none; color: var(--ink-mute); transition: color .2s; }
.topnav a:hover, .topnav a.is-current { color: var(--ink); }
.gh-link { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border: 1px solid var(--line-strong); border-radius: 999px; text-decoration: none; font-size: 13px; font-weight: 500; transition: border-color .2s, background .2s; }
.gh-link:hover { border-color: var(--ink-mute); background: var(--surface-2); }

/* ---------- Hero ---------- */
.hero { padding-top: clamp(48px, 9vw, 104px); padding-bottom: 36px; }
.eyebrow, .section-num { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.18em; color: var(--accent); margin-bottom: 18px; }
.hero h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(40px, 6.6vw, 82px); line-height: 1.0; letter-spacing: -0.03em; margin-bottom: 26px; }
.hero h1 em { font-style: italic; color: var(--accent); }
.deck { font-family: var(--serif); font-size: clamp(17px, 2vw, 20px); line-height: 1.5; color: var(--ink-soft); max-width: 760px; }
.deck em { color: var(--ink); }
.engine-pill { display: inline-flex; align-items: center; gap: 10px; margin-top: 28px; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-family: var(--mono); font-size: 12px; color: var(--ink-soft); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-mute); }
.engine-pill.is-ready .pulse { background: var(--good); box-shadow: 0 0 0 0 rgba(12,163,12,.6); animation: ping 2.2s infinite; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(12,163,12,.55); } 80%, 100% { box-shadow: 0 0 0 9px rgba(12,163,12,0); } }

/* ---------- Pipeline & funnel ---------- */
.pipeline-band { padding-bottom: 44px; }
.pipeline { list-style: none; display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 18px; }
.pipeline li { position: relative; padding: 16px 18px; background: var(--surface); display: grid; gap: 2px; }
.pipeline li + li { border-left: 1px solid var(--line); }
.pipeline li + li::before { content: "→"; position: absolute; left: -9px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; display: grid; place-items: center; font-size: 11px; background: var(--bg); color: var(--ink-mute); border-radius: 50%; }
.pl-num { font-family: var(--mono); font-size: 10px; color: var(--accent); letter-spacing: 0.1em; }
.pipeline strong { font-weight: 600; font-size: 15px; }
.pipeline small { color: var(--ink-mute); font-size: 12.5px; }

.funnel { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.fn-step { padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.fn-step .fn-val { font-family: var(--serif); font-size: 24px; letter-spacing: -0.01em; }
.fn-step .fn-lbl { font-size: 12.5px; color: var(--ink-mute); line-height: 1.35; margin-top: 2px; }
.fn-step.is-minus .fn-val { color: var(--ink-soft); }
.fn-step.is-total { background: var(--accent-soft); border-color: rgba(240,84,35,0.4); }
.fn-step.is-total .fn-val { color: var(--ink); }

/* ---------- Filters ---------- */
.filters-wrap { position: sticky; top: 58px; z-index: 20; background: rgba(15,15,13,0.9); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); border-top: 1px solid var(--line); }
.filters { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px 16px; padding-top: 12px; padding-bottom: 12px; }
.ctl { display: grid; gap: 4px; }
.ctl-label { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-mute); }
.ctl select {
  appearance: none; min-width: 140px; padding: 8px 32px 8px 12px; border-radius: 9px;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238f8a7e' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--line-strong); font-size: 14px; cursor: pointer; transition: border-color .2s;
}
.ctl select:hover:not(:disabled), .ctl select:focus-visible { border-color: var(--ink-mute); outline: none; }
.ctl select:disabled { opacity: .5; cursor: wait; }
.presets { display: flex; gap: 6px; }
.chip {
  padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line-strong); background: transparent;
  font-size: 13px; font-weight: 500; color: var(--ink-soft); cursor: pointer; transition: all .2s;
}
.chip:hover { border-color: var(--ink-mute); color: var(--ink); }
.chip.is-on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.view-sql-btn { padding: 7px 12px; border-radius: 9px; border: 1px dashed var(--line-strong); background: transparent; font-size: 13px; color: var(--ink-soft); cursor: pointer; }
.view-sql-btn:hover, .view-sql-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--ink); }
.run-stats { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--ink-mute); align-self: center; }
.run-stats b { color: var(--good); font-weight: 500; }
.view-sql { padding-bottom: 14px; }
.view-sql p { font-size: 13px; color: var(--ink-mute); margin-bottom: 8px; }

/* ---------- Sections ---------- */
.section { padding-top: 64px; }
.section-head { margin-bottom: 26px; max-width: 780px; }
.section-head h2 { font-family: var(--serif); font-weight: 400; font-size: clamp(30px, 4vw, 44px); line-height: 1.08; letter-spacing: -0.02em; }
.section-note { margin-top: 12px; color: var(--ink-mute); font-size: 14.5px; }
.grid { display: grid; gap: 20px; margin-bottom: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { padding: 18px 18px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); position: relative; overflow: hidden; }
.kpi::after { content: ""; position: absolute; left: 0; top: 0; height: 2px; width: 34px; background: var(--accent); }
.kpi-label { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-mute); }
.kpi-value { font-family: var(--serif); font-size: clamp(24px, 2.4vw, 32px); letter-spacing: -0.02em; margin-top: 8px; line-height: 1.1; white-space: nowrap; }
.kpi-sub { font-size: 12.5px; color: var(--ink-mute); margin-top: 4px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 22px 18px; display: flex; flex-direction: column; min-width: 0; transition: border-color .25s; }
.card:hover { border-color: var(--line-strong); }
.card-top { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; margin-bottom: 6px; }
.card-id { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.14em; color: var(--accent); text-transform: uppercase; margin-bottom: 6px; }
.card h3 { font-family: var(--serif); font-weight: 500; font-size: 22px; letter-spacing: -0.01em; line-height: 1.2; }
.card-q { font-family: var(--serif); font-style: italic; color: var(--ink-soft); font-size: 15.5px; margin-top: 4px; }
.tabs { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); flex-shrink: 0; }
.tab { padding: 5px 11px; border: 0; border-radius: 7px; background: transparent; font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-mute); cursor: pointer; transition: all .2s; }
.tab:hover { color: var(--ink); }
.tab.is-on { background: var(--surface-3); color: var(--ink); }
.card-controls { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.card-controls .chip { padding: 4px 11px; font-size: 12px; }
.skills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.skill { font-family: var(--mono); font-size: 10.5px; padding: 3px 8px; border-radius: 6px; background: var(--blue-soft); color: #9ec5f4; }
.pane { margin-top: 12px; min-height: 0; }
.pane[hidden] { display: none; }
.chart { width: 100%; height: 360px; }
.chart.tall { height: 470px; }
.insight { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border-left: 2px solid var(--accent); font-size: 14.5px; color: var(--ink-soft); line-height: 1.5; }
.insight strong { color: var(--ink); font-weight: 600; }
.card-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; font-family: var(--mono); font-size: 11px; color: var(--ink-mute); }
.empty { display: grid; place-items: center; height: 100%; min-height: 200px; color: var(--ink-mute); font-size: 14px; }
.card.is-busy .pane { opacity: .45; transition: opacity .2s; }
.skeleton {
  height: 100%; min-height: 300px; border-radius: 10px;
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%) 0 0 / 300% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* SQL view inside a card */
.code {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6; color: #d9d4c9;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; overflow: auto; max-height: 440px; white-space: pre; tab-size: 4;
}
.code .k { color: #ff8a5c; }
.code .f { color: #8fc0f7; }
.code .s { color: #9fd49f; }
.code .n { color: #e0a44c; }
.code .c { color: #7d786d; font-style: italic; }
.sql-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-ghost { padding: 7px 12px; border-radius: 9px; border: 1px solid var(--line-strong); background: transparent; font-size: 13px; color: var(--ink-soft); cursor: pointer; text-decoration: none; transition: all .2s; }
.btn-ghost:hover { border-color: var(--ink-mute); color: var(--ink); }

/* Data tables */
.table-wrap { overflow: auto; max-height: 420px; border: 1px solid var(--line); border-radius: 10px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-family: var(--mono); font-weight: 500; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-mute); padding: 9px 12px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
table.data td { padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
table.data td.num, table.data th.num { text-align: right; }
table.data tr:hover td { background: var(--surface-2); }

/* Market-basket pair list */
.pairs { list-style: none; display: grid; gap: 8px; max-height: 470px; overflow: auto; padding-right: 4px; }
.pair { display: grid; grid-template-columns: 26px 1fr 112px; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid transparent; transition: border-color .2s; }
.pair:hover { border-color: var(--line-strong); }
.pair-rank { font-family: var(--mono); font-size: 11px; color: var(--ink-mute); }
.pair-names { min-width: 0; font-size: 13px; line-height: 1.35; }
.pair-names span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pair-names .plus { color: var(--accent); font-family: var(--mono); font-size: 11px; display: inline; margin-right: 4px; }
.pair-meta { font-family: var(--mono); font-size: 10.5px; color: var(--ink-mute); margin-top: 3px; }
.pair-lift { text-align: right; }
.pair-lift b { font-family: var(--serif); font-weight: 500; font-size: 20px; }
.pair-lift small { display: block; font-family: var(--mono); font-size: 10px; color: var(--ink-mute); }
.lift-bar { height: 3px; border-radius: 2px; background: var(--line); margin-top: 5px; overflow: hidden; }
.lift-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* ---------- Playground ---------- */
.pg { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; margin-bottom: 40px; }
.pg-schema { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; font-size: 13px; align-self: start; max-height: 640px; overflow: auto; }
.pg-schema h4 { font-family: var(--mono); font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink); margin: 14px 0 6px; display: flex; justify-content: space-between; }
.pg-schema h4:first-child { margin-top: 0; }
.pg-schema h4 small { color: var(--ink-mute); text-transform: none; letter-spacing: 0; }
.pg-schema button { display: flex; justify-content: space-between; width: 100%; padding: 3px 6px; border: 0; border-radius: 5px; background: transparent; cursor: pointer; font-family: var(--mono); font-size: 12px; color: var(--ink-soft); text-align: left; }
.pg-schema button:hover { background: var(--surface-2); color: var(--ink); }
.pg-schema button i { font-style: normal; color: var(--ink-mute); font-size: 10.5px; }
.pg-main { min-width: 0; }
.pg-samples { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.pg-samples .chip { font-size: 12px; padding: 5px 11px; }
.pg-editor { border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.pg-editor .CodeMirror { height: 230px; background: var(--bg); color: #d9d4c9; font-family: var(--mono); font-size: 13px; line-height: 1.6; }
.pg-editor .CodeMirror-gutters { background: var(--bg); border-right: 1px solid var(--line); }
.pg-editor .CodeMirror-linenumber { color: #555149; }
.pg-editor .CodeMirror-cursor { border-left: 2px solid var(--accent); }
.pg-editor .CodeMirror-selected, .pg-editor .CodeMirror-focused .CodeMirror-selected { background: rgba(57,135,229,0.25); }
.pg-editor .cm-keyword { color: #ff8a5c; }
.pg-editor .cm-builtin, .pg-editor .cm-variable-2 { color: #8fc0f7; }
.pg-editor .cm-string { color: #9fd49f; }
.pg-editor .cm-number, .pg-editor .cm-atom { color: #e0a44c; }
.pg-editor .cm-type, .pg-editor .cm-def { color: #8fc0f7; }
.pg-editor .cm-comment { color: #7d786d; font-style: italic; }
.pg-editor .cm-operator { color: var(--ink-soft); }
.pg-actions { display: flex; align-items: center; gap: 14px; margin: 12px 0; }
.btn-run { padding: 10px 18px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer; transition: transform .1s, filter .2s; }
.btn-run:hover:not(:disabled) { filter: brightness(1.1); }
.btn-run:active:not(:disabled) { transform: translateY(1px); }
.btn-run:disabled { opacity: .5; cursor: wait; }
.pg-meta { font-family: var(--mono); font-size: 12px; color: var(--ink-mute); }
.pg-meta.is-error { color: #ff8f6b; }
.pg-error { padding: 14px 16px; border-radius: 10px; background: rgba(208,59,59,0.12); border: 1px solid rgba(208,59,59,0.4); color: #ffb4a0; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; }

/* ---------- Footer & toast ---------- */
.footer { border-top: 1px solid var(--line); margin-top: 40px; padding: 28px 0 40px; font-size: 13.5px; color: var(--ink-soft); }
.footer-inner { display: grid; gap: 6px; }
.footer a { color: var(--ink); text-underline-offset: 3px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: all .3s; z-index: 50; }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* Reveal on scroll */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity .6s ease, transform .6s ease; }
.reveal.is-in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .topnav { display: none; }
  .gh-link { margin-left: auto; }
}
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .pipeline { grid-template-columns: 1fr; }
  .pipeline li + li { border-left: 0; border-top: 1px solid var(--line); }
  .pipeline li + li::before { left: 18px; top: -9px; transform: rotate(90deg); }
  .funnel { grid-template-columns: repeat(2, 1fr); }
  .funnel .fn-step.is-total { grid-column: 1 / -1; }
  .pg { grid-template-columns: minmax(0, 1fr); }
  .pg-schema { max-height: 220px; }
  .run-stats { margin-left: 0; width: 100%; }
  /* on small screens the filter bar would cover a third of the page, so let it scroll away */
  .filters-wrap { position: static; }
  html { scroll-padding-top: 70px; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 18px 16px 14px; }
  .card-top { flex-direction: column; }
  .chart { height: 320px; }
  .chart.tall { height: 420px; }
  .filters { gap: 10px; }
  .ctl select { min-width: 0; width: 100%; }
  .ctl { flex: 1 1 40%; }
  .pair { grid-template-columns: 22px 1fr; }
  .pair-lift { grid-column: 2; text-align: left; }
  .gh-link span { display: none; }
}
