/* Admin styling. Plain CSS, no build step, no framework: the backend is a few
   dense data screens, and a dependency here would outlive its usefulness. */

:root {
  --ink: #16202b;
  --ink-soft: #5a6878;
  --accent: #0f4c5c;
  --accent-soft: #2a7f93;
  --bg: #f6f8fa;
  --surface: #ffffff;
  --rule: #dde4ec;
  --ok: #1f7a4d;
  --warn: #9a6b00;
  --error: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 32 43 / 6%), 0 4px 16px rgb(16 32 43 / 6%);

  /* Lets the browser draw its own controls — checkboxes, file pickers,
     scrollbars — in the scheme the page is actually using. Without it they
     stay light-on-light inside a dark page. */
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --ink: #e7edf3;
    --ink-soft: #9fb0c0;
    --accent: #7fd1e3;
    --accent-soft: #a7e0ed;
    --bg: #11181f;
    --surface: #18222c;
    --rule: #2a3845;
    --ok: #5fcf96;
    --warn: #e0b64e;
    --error: #ff8a80;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
  }
}

:root[data-theme='dark'] {
  --ink: #e7edf3;
  --ink-soft: #9fb0c0;
  --accent: #7fd1e3;
  --accent-soft: #a7e0ed;
  --bg: #11181f;
  --surface: #18222c;
  --rule: #2a3845;
  --ok: #5fcf96;
  --warn: #e0b64e;
  --error: #ff8a80;
}

* {
  box-sizing: border-box;
}

/* Links in the content area. Without an explicit colour the browser uses its
   default (#0000EE, visited #551A8B), which is unreadable on the dark surface.
   :visited is set as well, or every link a user has already opened drifts to
   purple. Declared early so the topbar and notice rules still win. */
a {
  color: var(--accent);
}

a:visited {
  color: var(--accent);
}

a:hover {
  color: var(--accent-soft);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, 'Segoe UI', sans-serif;
}

body.centered {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 16px;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}

.brand {
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.2px;
}

.topbar nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
}

.topbar nav a {
  padding: 6px 10px;
  border-radius: 7px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 14px;
}

.topbar nav a:hover {
  background: var(--bg);
  color: var(--ink);
}

.topbar nav a.active {
  background: var(--accent);
  color: var(--surface);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .topbar nav a.active {
    color: #11181f;
  }
}

.topbar .user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--ink-soft);
}

.badge {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--surface);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

button.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent-soft);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

/* ---------- page ---------- */

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1 {
  font-size: 24px;
  margin: 8px 0 20px;
  letter-spacing: -0.3px;
}

h2 {
  font-size: 15px;
  margin: 0 0 8px;
  color: var(--ink-soft);
  font-weight: 600;
}

.lead {
  color: var(--ink-soft);
  max-width: 70ch;
}

.muted {
  color: var(--ink-soft);
  font-size: 13px;
  margin: 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 1px 5px;
}

/* ---------- cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric {
  font-size: 30px;
  font-weight: 700;
  margin: 4px 0;
  letter-spacing: -0.5px;
}

/* ---------- forms ---------- */

.login {
  width: min(360px, 100%);
  display: grid;
  gap: 14px;
}

.login h1 {
  margin: 0;
  font-size: 20px;
  color: var(--accent);
}

/* Block, not grid: in a grid every child is its own row, so the hint after the
   label text dropped onto a line of its own and the fields in a row ended up on
   different heights. As a block the text and its hint stay on one line. */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

label > input,
label > select,
label > textarea {
  margin-top: 5px;
}

input,
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
}

button[type='submit']:not(.link) {
  font: inherit;
  font-weight: 600;
  background: var(--accent);
  color: var(--surface);
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) button[type='submit']:not(.link) {
    color: #11181f;
  }
}

button[type='submit']:not(.link):hover {
  background: var(--accent-soft);
}

/* ---------- messages ---------- */

.error,
.notice {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid;
}

.error {
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 40%, transparent);
  background: color-mix(in srgb, var(--error) 8%, transparent);
}

.notice {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
  background: color-mix(in srgb, var(--warn) 8%, transparent);
}

.notice a {
  color: inherit;
}

/* ---------- broker surface ---------- */

/* Same stylesheet, different accent: support should see at a glance whether a
   screenshot comes from the cockpit or from a broker's account (/F-140/). */
body[data-surface='broker'] {
  --accent: #7a4b16;
  --accent-soft: #a9711f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) body[data-surface='broker'] {
    --accent: #e8b06a;
    --accent-soft: #f3c98f;
  }
}

body[data-surface='broker'] .topbar {
  border-bottom: 2px solid var(--accent);
}

/* ---------- tables ---------- */

table.grid {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

table.grid th,
table.grid td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

table.grid thead th {
  background: var(--bg);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--ink-soft);
}

table.grid tbody tr:last-child td {
  border-bottom: 0;
}

table.grid .num {
  text-align: right;
}

/* ---------- panels and forms ---------- */

.panel {
  margin-top: 22px;
}

.panel > h2 {
  margin-bottom: 12px;
}

.row-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.row-form > label {
  flex: 1 1 200px;
  min-width: 0;
}

.row-form > button[type='submit'] {
  flex: 0 0 auto;
}

.stack {
  display: grid;
  gap: 10px;
  justify-items: start;
  margin: 8px 0;
}

.stack > label {
  width: min(520px, 100%);
}

form.inline {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  margin: 0;
}

form.inline select {
  width: auto;
}

label.check {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  flex: 1 1 100%;
}

label.check input {
  width: auto;
}

.hint {
  font-weight: 400;
  color: var(--ink-soft);
  font-size: 12px;
}

button.link.danger {
  color: var(--error);
}

/* ---------- lead detail ---------- */

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
  margin-top: 22px;
}

.split > .panel {
  margin-top: 0;
}

dl.facts {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  gap: 6px 14px;
  margin: 0;
}

dl.facts dt {
  color: var(--ink-soft);
  font-size: 13px;
}

dl.facts dd {
  margin: 0;
}

.valuation + .valuation {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}

.valuation .metric {
  margin: 2px 0;
}

.chip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--bg);
  font-size: 11px;
  color: var(--ink-soft);
}

ul.plain {
  margin: 0;
  padding: 0;
  list-style: none;
}

.pager {
  display: flex;
  gap: 14px;
  align-items: center;
  margin: 14px 0;
}

details > summary {
  cursor: pointer;
  color: var(--accent-soft);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- settings ---------- */

label.wide {
  margin-top: 12px;
}

fieldset.scopes {
  flex: 1 1 260px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 8px 12px 10px;
  margin: 0;
  min-width: 0;
}

fieldset.scopes legend {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 0 4px;
}

.secret-once {
  border-color: var(--warn);
  box-shadow: none;
}

.secret-once code {
  font-size: 14px;
  user-select: all;
  word-break: break-all;
}

tr.revoked td {
  opacity: 0.55;
}

form + form {
  margin-top: 0;
}

/* Breadcrumbs. The separator is drawn by CSS rather than written into the
   markup: as a literal "·" at the end of a line it loses its trailing space
   when the template is collapsed, and the next link sticks to it. */
p.crumbs {
  margin: 0 0 16px;
  font-size: 14px;
}

/* Between any two items, not only between two links: a breadcrumb often ends
   in a plain label such as the tenant name. */
p.crumbs > * + *::before {
  content: '·';
  margin: 0 9px;
  color: var(--ink-soft);
}

/* A filter bar is not a form to fill in — its fields should not stretch to
   whatever width is left over. */
.row-form.filter > label,
.filters .row-form > label {
  flex: 0 1 240px;
}

/* ---------- lead detail ---------- */

/* Raw JSON for support (/F-440/). Scrolls rather than stretching the page. */
pre.raw {
  margin: 10px 0 0;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  max-height: 420px;
  overflow: auto;
}

/* Source URLs and user agents are long and have no spaces to break at. */
.break {
  overflow-wrap: anywhere;
}

.chip.warn {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: baseline;
}

.filters .row-form + .row-form {
  margin-top: 12px;
}

/* Deleting a lead is irreversible, so it does not look like the other panels. */
.danger-zone {
  border-color: color-mix(in srgb, var(--error) 45%, var(--rule));
}

.danger-zone > h2 {
  color: var(--error);
}

button.danger-button {
  font: inherit;
  font-weight: 600;
  background: var(--error);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
}

button.danger-button:hover {
  background: color-mix(in srgb, var(--error) 85%, black);
}

details > summary {
  margin-top: 8px;
}

/* ---------- form builder ---------- */

details.step {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
  background: var(--bg);
}

details.step > summary {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
}

details.step[open] > summary {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}

details.step fieldset.scopes {
  margin-top: 14px;
  flex-basis: 100%;
}

.step-actions {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  gap: 18px;
}

button[disabled] {
  opacity: 0.45;
  cursor: default;
}

/* ---------- analytics ---------- */

/* A plain CSS sparkline: one bar per day, the darker part is the completed
   share. No chart library for six numbers. */
.spark {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 120px;
  padding: 0 2px;
  border-bottom: 1px solid var(--rule);
}

.spark-bar {
  flex: 1 1 0;
  min-width: 2px;
  min-height: 2px;
  background: color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 2px 2px 0 0;
  display: flex;
  align-items: flex-end;
}

.spark-bar > i {
  display: block;
  width: 100%;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

span.bar {
  display: block;
  height: 10px;
  width: var(--w, 0%);
  min-width: 2px;
  background: var(--accent);
  border-radius: 999px;
}
