:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2024;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --ok-bg: #ecfdf3;
  --ok: #067647;
  --code-bg: #f2f4f7;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
.card h2:first-child { margin-top: 0; }
code, .mono { font-family: var(--mono); font-size: .88em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.no-margin { margin: 0; }
.spacer { flex: 1; }
.error { color: var(--danger); background: var(--danger-bg); border-radius: var(--radius); padding: .5rem .75rem; }
[hidden] { display: none !important; }

/* Kept in the page but invisible, unfocusable and hidden from assistive technology. */
.offscreen { position: absolute !important; left: -10000px !important; top: auto !important;
             width: 1px !important; height: 1px !important; overflow: hidden !important; }

button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem .9rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text);
}
button:hover, .button:hover { border-color: #c7ccd3; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.05); }
input, select, textarea {
  padding: .45rem .6rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; align-items: center; gap: .6rem; margin: .5rem 0; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: .6rem; }
.label { font-weight: 600; font-size: .9rem; }
.check { display: flex; gap: .5rem; align-items: flex-start; }
.check input { margin-top: .3rem; }

/* ---- centered cards (consent, messages, login) ---- */
body.centered { display: flex; justify-content: center; padding: 2rem 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem; }
.card.narrow { max-width: 680px; width: 100%; align-self: flex-start; }
.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: .75rem; color: var(--muted); margin: 0 0 .5rem; }
.consent-form { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 1rem; align-items: flex-start;
                border-top: 1px solid var(--border); padding-top: 1.25rem; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: 0 1rem; height: 52px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 650; white-space: nowrap; }
.brand a { text-decoration: none; }
.tabs { display: flex; gap: .25rem; flex: 1; justify-content: center; }
.tabs button { border: none; background: transparent; padding: .5rem .9rem; border-radius: var(--radius); color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--code-bg); color: var(--text); font-weight: 600; }

/* ---- workspace ---- */
body.workspace { display: flex; flex-direction: column; }
body.workspace main { flex: 1; min-height: 0; }
.panel { height: calc(100vh - 52px); overflow: auto; padding: 1.25rem; }
#tab-instructions { display: flex; justify-content: center; }
.prose { max-width: 820px; width: 100%; background: var(--surface); border: 1px solid var(--border);
         border-radius: 12px; padding: 1.75rem 2rem; align-self: flex-start; }
.prose h1 { font-size: 1.6rem; }
.prose h2 { border-top: 1px solid var(--border); padding-top: 1.25rem; margin-top: 1.75rem; }
.prose table { border-collapse: collapse; width: 100%; font-size: .92rem; }
.prose th, .prose td { border: 1px solid var(--border); padding: .45rem .6rem; text-align: left; vertical-align: top; }
.prose pre { background: var(--code-bg); padding: .75rem 1rem; border-radius: var(--radius); overflow-x: auto; }
.prose pre code { font-size: .82rem; }
.prose :not(pre) > code { background: var(--code-bg); padding: .1rem .3rem; border-radius: 4px; }
.prose blockquote { margin: 0; padding: .75rem 1rem; border-left: 3px solid var(--border); background: #fafbfc; }

#tab-database:not([hidden]) { display: grid; grid-template-columns: 240px 1fr; gap: 1rem; }
.schema { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; align-self: start; }
.schema h2 { margin-top: 0; }
.schema details { margin: .35rem 0; }
.schema summary { cursor: pointer; font-family: var(--mono); font-size: .88rem; font-weight: 600; }
.schema ul { list-style: none; padding-left: .9rem; margin: .3rem 0; font-family: var(--mono); font-size: .8rem; }
.console { min-width: 0; }
#sql { width: 100%; min-height: 150px; resize: vertical; font-family: var(--mono); font-size: .88rem; margin-top: .35rem; }
.results { margin-top: .75rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { padding: .4rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #fafbfc; font-weight: 600; position: sticky; top: 0; }
.results td { font-family: var(--mono); font-size: .8rem; white-space: nowrap; }

.log-controls select { max-width: 240px; }
.log-controls input { flex: 1; min-width: 200px; font-family: var(--mono); font-size: .85rem; }
.log-lines { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
             font-family: var(--mono); font-size: .78rem; overflow-x: auto; }
.log-line { display: flex; gap: .75rem; padding: .15rem .6rem; white-space: pre; border-bottom: 1px solid #f1f3f5; }
.log-line .ln { color: var(--muted); min-width: 3.5rem; text-align: right; user-select: none; }

#tab-report:not([hidden]) { display: flex; flex-direction: column; }
#report { flex: 1; width: 100%; min-height: 360px; resize: none; line-height: 1.6; padding: 1rem; }

/* ---- admin ---- */
.admin-main { max-width: 1200px; margin: 0 auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.admin-main input[name="name"], .admin-main input[name="email"] { min-width: 240px; }
#invite { width: 100%; margin: .35rem 0 1rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .75rem 1.5rem; margin: 0; }
.facts dt { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; background: var(--code-bg); color: var(--muted); white-space: nowrap; }
.pill-submitted { background: var(--ok-bg); color: var(--ok); }
.pill-in-progress { background: #eff4ff; color: var(--accent); }
.pill-revoked { background: var(--danger-bg); color: var(--danger); }
.pill-flag { background: var(--danger-bg); color: var(--danger); }
.flags { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; }
.flag { border-left: 4px solid var(--border); padding: .5rem .75rem; background: #fafbfc; border-radius: 0 var(--radius) var(--radius) 0; }
.flag .row { margin: 0 0 .2rem; }
.flag-strong { border-color: var(--danger); background: var(--danger-bg); }
.flag-moderate { border-color: var(--warn); background: var(--warn-bg); }
.report { white-space: pre-wrap; font-family: inherit; background: #fafbfc; border: 1px solid var(--border);
          border-radius: var(--radius); padding: 1rem; max-height: 560px; overflow: auto; }
table.compact td, table.compact th { padding: .3rem .5rem; }
code.sql { white-space: pre-wrap; word-break: break-word; }
tr.flagged td { background: var(--danger-bg); }
tr.jump td { background: var(--warn-bg); }
.details .kv { display: inline-block; margin-right: .6rem; overflow-wrap: anywhere; }
.details b { font-weight: 600; }

@media (max-width: 800px) {
  .topbar { height: auto; flex-wrap: wrap; padding: .5rem 1rem; }
  .tabs { order: 3; width: 100%; justify-content: flex-start; overflow-x: auto; }
  .panel { height: auto; min-height: calc(100vh - 100px); }
  #tab-database:not([hidden]) { grid-template-columns: 1fr; }
  .prose { padding: 1.25rem; }
}
button.danger { color: var(--danger); border-color: #f4c7c3; }
button.danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.log-lines.wrap .log-line .lt { white-space: pre-wrap; overflow-wrap: anywhere; }
.log-line mark { background: #fff1a8; color: inherit; border-radius: 2px; padding: 0 1px; }
