:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #1d4ed8;
  --accent-soft: #dbeafe;
  --pass: #15803d;
  --pass-soft: #dcfce7;
  --warn: #a16207;
  --warn-soft: #fef9c3;
  --fail: #b91c1c;
  --fail-soft: #fee2e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 4px 16px rgb(15 23 42 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --panel: #111827; --text: #e5e7eb; --muted: #94a3b8; --line: #1f2937;
    --accent: #60a5fa; --accent-soft: #1e3a8a; --pass: #4ade80; --pass-soft: #14532d;
    --warn: #facc15; --warn-soft: #422006; --fail: #f87171; --fail-soft: #450a0a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1 { font-size: 1.35rem; margin: 0 0 .5rem; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 .5rem; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); padding: .55rem .9rem; min-height: 40px; }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.secondary { background: var(--panel); }
button.link-button { border: 0; background: none; color: var(--muted); min-height: 0; padding: .3rem .5rem; }
button.icon-button { border: 0; background: none; font-size: 1.25rem; min-height: 0; padding: .25rem .5rem; }
select, input[type=text], input[type=number], input:not([type]), input[type=password], textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: .5rem .6rem; min-height: 40px;
}
textarea { resize: vertical; }
label { display: block; margin: .5rem 0; font-size: .9rem; }
label.check { display: flex; gap: .5rem; align-items: center; }
label.check input { width: auto; min-height: 0; }
.hint { color: var(--muted); font-size: .82rem; margin: .4rem 0; }
.error { color: var(--fail); background: var(--fail-soft); padding: .5rem .7rem; border-radius: 10px; white-space: pre-wrap; }
.chip { font-size: .78rem; padding: .15rem .55rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45vw; }
.chip.ready { background: var(--pass-soft); color: var(--pass); }

.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .6rem;
  padding: calc(.5rem + env(safe-area-inset-top)) .9rem .5rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.topbar .brand { margin-right: auto; }
.layout { display: grid; grid-template-columns: 300px 1fr; min-height: calc(100% - 56px); }
.sidebar { border-right: 1px solid var(--line); padding: 1rem; overflow-y: auto; background: var(--panel); }
.sidebar section { margin-bottom: 1.4rem; }
.only-mobile { display: none; }

.file-drop { display: grid; gap: .15rem; border: 1.5px dashed var(--line); border-radius: var(--radius); padding: .9rem; text-align: center; cursor: pointer; }
.file-drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file-drop span { font-weight: 600; color: var(--accent); }
.dataset-list { list-style: none; padding: 0; margin: .7rem 0 0; display: grid; gap: .5rem; }
.dataset-list li { border: 1px solid var(--line); border-radius: 10px; padding: .5rem .6rem; font-size: .85rem; }
.dataset-list .name { font-weight: 600; word-break: break-word; }
.dataset-list .meta { color: var(--muted); }
.dataset-list .actions { display: flex; gap: .3rem; margin-top: .3rem; flex-wrap: wrap; }
.dataset-list .actions button { min-height: 30px; padding: .2rem .5rem; font-size: .8rem; }

.main { display: flex; flex-direction: column; min-width: 0; }
.feed { flex: 1; padding: 1rem; display: grid; gap: 1rem; align-content: start; max-width: 1100px; width: 100%; margin: 0 auto; }
.welcome { background: var(--panel); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); }
.welcome ol { padding-left: 1.2rem; }
.composer {
  position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--line);
  padding: .7rem 1rem calc(.7rem + env(safe-area-inset-bottom)); max-width: 1100px; width: 100%; margin: 0 auto;
}
.composer-row { display: flex; gap: .5rem; margin-top: .5rem; }
.composer-row select { flex: 1; min-width: 0; }

.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; min-width: 0; }
.card.user { background: var(--accent-soft); box-shadow: none; }
.card h3 { margin: 0 0 .35rem; font-size: 1rem; }
.card .sub { color: var(--muted); font-size: .82rem; }
.card .desc { margin: .35rem 0 .6rem; }
.card-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .7rem; }
.plan-steps { margin: .5rem 0 0; padding-left: 1.1rem; }
.plan-steps li { margin-bottom: .45rem; }
.plan-steps .details { list-style: none; padding-left: .3rem; margin: .2rem 0; color: var(--muted); font-size: .85rem; }
.assumptions { font-size: .85rem; color: var(--muted); }
.spinner { display: inline-block; width: .9rem; height: .9rem; border: 2px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -2px; margin-right: .35rem; }
@keyframes spin { to { transform: rotate(360deg); } }

.checks { display: flex; flex-wrap: wrap; gap: .35rem; margin: .4rem 0; }
.badge { font-size: .76rem; padding: .12rem .5rem; border-radius: 999px; border: 1px solid transparent; }
.badge.PASS { background: var(--pass-soft); color: var(--pass); }
.badge.WARN { background: var(--warn-soft); color: var(--warn); }
.badge.FAIL { background: var(--fail-soft); color: var(--fail); }
.badge.INFO { background: var(--accent-soft); color: var(--accent); }
details.check-list { font-size: .85rem; margin: .3rem 0; }
details.check-list li { margin: .2rem 0; }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; margin: .5rem 0; }
.metric { border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; }
.metric .label { font-size: .78rem; color: var(--muted); }
.metric .value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.output-title { font-weight: 600; margin: .8rem 0 .3rem; font-size: .9rem; }
.table-wrap { overflow: auto; max-height: 60vh; border: 1px solid var(--line); border-radius: 10px; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; min-width: 100%; }
th, td { padding: .35rem .6rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel); font-weight: 600; z-index: 1; }
td.num { text-align: right; }
tr.total td { font-weight: 700; }
.chart { max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
pre.text { white-space: pre-wrap; background: var(--bg); border-radius: 10px; padding: .6rem; font-size: .85rem; }
a.download { display: inline-flex; align-items: center; gap: .4rem; padding: .55rem .9rem; border-radius: 10px; background: var(--accent); color: #fff; text-decoration: none; font-weight: 600; margin: .3rem .3rem 0 0; }
.code { font-size: .78rem; }

.builder { width: min(760px, 100vw); max-height: 92vh; border: 0; border-radius: var(--radius); padding: 0; background: var(--panel); color: var(--text); }
.builder::backdrop { background: rgb(15 23 42 / 45%); }
.builder form { display: flex; flex-direction: column; max-height: 92vh; }
.builder header, .builder footer { display: flex; justify-content: space-between; align-items: center; padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.builder footer { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
.builder header h2 { margin: 0; }
.builder-body { overflow-y: auto; padding: .8rem 1rem; }
.step-editor { border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .9rem; margin: .8rem 0; }
.draft-steps { display: grid; gap: .4rem; }
.draft-step { display: flex; gap: .5rem; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: .45rem .6rem; font-size: .85rem; }
.draft-step .text { flex: 1; min-width: 0; word-break: break-word; }
.draft-step button { min-height: 30px; padding: .15rem .5rem; font-size: .8rem; }
.param { border-top: 1px dashed var(--line); padding-top: .4rem; margin-top: .4rem; }
.param > .param-doc { color: var(--muted); font-size: .78rem; margin: .1rem 0 .3rem; }
.repeat-row { display: grid; grid-template-columns: 1.3fr 1fr 1.3fr auto auto; gap: .3rem; align-items: center; margin: .3rem 0; }
.repeat-group { border: 1px solid var(--line); border-radius: 10px; padding: .4rem .6rem; margin: .4rem 0; }
.multi { display: flex; flex-wrap: wrap; gap: .25rem .8rem; max-height: 180px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: .4rem .6rem; }
.multi label { margin: 0; display: flex; gap: .3rem; align-items: center; font-size: .85rem; }
.multi input { width: auto; min-height: 0; }
.row-end { display: flex; justify-content: flex-end; gap: .5rem; }

.login-page { display: grid; place-items: center; min-height: 100%; padding: 1rem; }
.login-card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; width: min(380px, 100%); }
.login-card .brand { margin-bottom: 1rem; font-size: 1.1rem; }
.login-card button { width: 100%; margin-top: .6rem; }

@media (max-width: 820px) {
  .only-mobile { display: inline-block; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 56px 0 0 0; z-index: 15; transform: translateX(-100%); transition: transform .2s ease; border-right: 0; padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }
  .sidebar.open { transform: none; }
  .feed { padding: .7rem; }
  .composer { padding-left: .7rem; padding-right: .7rem; }
  .composer-row { flex-wrap: wrap; }
  .composer-row select { flex-basis: 100%; }
  .composer-row button { flex: 1; }
  .repeat-row { grid-template-columns: 1fr 1fr; }
  .builder { max-height: 100vh; height: 100vh; border-radius: 0; }
  .builder form { max-height: 100vh; }
  input, select, textarea { font-size: 16px; } /* stops iOS zooming into fields */
}
