/*
 * databasis app.
 *
 * Design notes, so the next change does not undo a deliberate choice:
 *
 * COLOUR. Three brand values, and only one of them may carry text: slate #425A91 is
 * 6.6:1 on white, azure #3E88D4 is 3.3:1 (chrome and large type only), teal #00D2C3 is
 * 1.9:1 and is a fill, never text on a light ground. The neutrals are biased a few
 * degrees toward slate rather than pure grey, so the page reads as one palette instead
 * of brand colour dropped onto a default.
 *
 * Semantic colour is separate from the accent, because this is a tool where state has
 * to read at a glance: amber means "not trustworthy yet", not "warning in general".
 *
 * TYPE. A data tool is scanned, not read. Numbers are tabular everywhere so columns
 * align; values are set slightly tighter than prose; provenance is set small but never
 * below 12px, because it is the evidence and evidence you cannot read is decoration.
 *
 * DENSITY. Rows are 34px. Tighter loses the hit target for the provenance popover,
 * looser and fewer than a dozen companies fit on a laptop screen.
 */

:root {
  --slate: #425a91;
  --azure: #3e88d4;
  --teal: #00d2c3;

  /* Neutrals, hue-biased toward slate. */
  --ink: #16202f;
  --ink-2: #3c4859;
  --ink-3: #6b7688;
  /* Was #97a0ae, 2.7:1 on white, and it carries "not checked", the column age and the
     stale marker: exactly the distinctions the table must not collapse. #6b7482 is
     4.6:1, which passes AA at the 11px these are set in. */
  --ink-4: #6b7482;
  --line: #dfe3ea;
  --line-2: #eceff4;
  --ground: #ffffff;
  --ground-2: #f7f8fb;
  --ground-3: #eef1f6;

  /* Semantic, deliberately not the accent. */
  --warn: #9a6700;
  --warn-bg: #fff8e6;
  --bad: #a4343a;
  --bad-bg: #fdf1f1;
  --good: #1a7f5a;
  --good-bg: #edf7f2;

  --radius: 6px;
  --pad: 12px;
  --row: 34px;

  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
}

:root:not([data-theme='light']) {
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--ground);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ shell -- */

.app {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  height: 100%;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--ground-2);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 14px var(--pad);
  border-bottom: 1px solid var(--line);
}
.brand svg { display: block; }
a.brand { text-decoration: none; color: inherit; }
a.brand:hover .brand-name { color: var(--azure); }
/* The signed-out screens show the mark without the sidebar's padding and rule. */
.brand.brand-plain { padding: 0; border-bottom: 0; }
.brand-name {
  font-weight: 640;
  letter-spacing: -0.01em;
  color: var(--slate);
}

.sidebar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px var(--pad) 6px;
}
.sidebar-head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.base-list { list-style: none; margin: 0; padding: 0 6px 6px; overflow-y: auto; flex: 1; min-height: 0; }
.base-list li { margin-bottom: 1px; }

.base-link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: var(--radius);
  padding: 7px 8px;
  cursor: pointer;
  color: var(--ink);
}
.base-link:hover { background: var(--ground-3); }
.base-link[aria-current='page'] {
  background: var(--ground);
  box-shadow: inset 0 0 0 1px var(--line);
  font-weight: 560;
}
.base-link .name { display: block; }
.base-link .meta {
  display: block;
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 1px;
}

/* The signed-in address is a way to the account screen, not a field. It borrowed
   `.base-link`, whose current-page treatment is a bordered inset box — which read as a
   text input sitting in the sidebar. */
.account-link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-link:hover { color: var(--azure); text-decoration: underline; }
.account-link[aria-current='page'] { color: var(--slate); font-weight: 560; }

/* One column of panels, at a width prose can be read at. */
.account { max-width: 680px; }

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 10px var(--pad);
  font-size: 12px;
  color: var(--ink-3);
}

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: var(--pad);
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  min-height: 56px;
}
.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 620;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .spacer { flex: 1; }
.topbar .request {
  font-size: 12px;
  color: var(--ink-3);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40ch;
}

/* One strip across the top of the work, not a modal over it: what it interrupts is the
   thing the trial exists to demonstrate. Amber only when something is actually running
   out, so the colour still means something when it appears. */
.trial-bar {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px var(--pad);
  border-bottom: 1px solid var(--line);
  background: var(--ground-2);
  font-size: 13px;
  flex-wrap: wrap;
}
.trial-bar strong { font-weight: 600; color: var(--ink); }
.trial-bar .detail { color: var(--ink-3); }
.trial-bar .spacer { flex: 1; }
.trial-bar .btn { align-self: center; }
.trial-bar-urgent {
  background: var(--warn-bg);
  border-bottom-color: #f0e0b6;
}
.trial-bar-urgent strong { color: var(--warn); }
.trial-bar-urgent .detail { color: #6b4a00; }

.screen { flex: 1; overflow: auto; min-height: 0; }

/* --------------------------------------------------------- signed-out gate -- */

/* Signed out there is no sidebar to fill the first grid track, so the shell stops
   being two columns. Without this the sign-in card renders inside the 244px sidebar
   column and every line of it wraps. */
.app-solo { grid-template-columns: minmax(0, 1fr); }

.gate {
  width: min(420px, 100%);
  margin: 12vh auto 0;
  padding: 0 18px 48px;
}
.gate-banner { margin-bottom: 0; padding-bottom: 0; }
.gate .brand { margin-bottom: 20px; }
.gate .brand-name { font-size: 19px; }
.gate h2 {
  margin: 0 0 6px;
  font-size: 21px;
  line-height: 1.25;
  letter-spacing: -0.02em;
  font-weight: 640;
}
.gate p.lede { margin: 0; color: var(--ink-3); }
.gate .field-label { margin-top: 16px; }
.gate .btn-primary { width: 100%; margin-top: 18px; padding: 8px 11px; }
.gate p.note { margin: 6px 0 0; font-size: 12px; color: var(--ink-3); }
.gate p.sub { margin: 10px 0 0; min-height: 20px; font-size: 13px; color: var(--ink-2); }
/* Same idea on the sign-up screen, which has no alternate-door block: the link to the
   other screen is held apart from the form. */
.gate p.sub + p.note {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line-2);
}
.gate .gate-alt + p.note { margin-top: 14px; }
/* The other door. A rule above it, because it is a different way in rather than one
   more thing to fill in on the way through this one. */
.gate .gate-alt {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line-2);
}
.gate .gate-alt .btn { width: 100%; }
.gate .gate-alt p.note { margin-top: 8px; }
.gate a { color: var(--slate); }
.gate a:hover { color: var(--azure); }
.pad { padding: 18px; }

/* ---------------------------------------------------------------- controls -- */

.btn {
  border: 1px solid var(--line);
  background: var(--ground);
  border-radius: var(--radius);
  padding: 6px 11px;
  cursor: pointer;
  color: var(--ink-2);
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-4); color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--slate);
  border-color: var(--slate);
  color: #fff;
  font-weight: 560;
}
.btn-primary:hover { background: #35496f; border-color: #35496f; color: #fff; }
.btn-danger:hover { border-color: var(--bad); color: var(--bad); }
.btn-small { padding: 3px 8px; font-size: 12px; }

:where(button, input, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--azure);
  outline-offset: 1px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 4px;
}

input[type='text'], input[type='password'], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 9px;
  background: var(--ground);
}
textarea { resize: vertical; }

/* ------------------------------------------------------------ query screen -- */

.ask {
  max-width: 760px;
  margin: 8vh auto 0;
  padding: 0 18px 40px;
}
.ask h2 {
  margin: 0 0 6px;
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 640;
  text-wrap: balance;
}
.ask p.lede { margin: 0 0 20px; color: var(--ink-3); max-width: 58ch; }

/* The single dominant input. It is the product's one instruction, so it gets the
   visual weight rather than sharing it with a toolbar. */
.ask-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  background: var(--ground);
  box-shadow: 0 1px 2px rgb(22 32 47 / 6%);
}
.ask-box:focus-within { border-color: var(--azure); box-shadow: 0 0 0 3px rgb(62 136 212 / 14%); }
.ask-box textarea {
  border: 0;
  min-height: 84px;
  font-size: 16px;
  line-height: 1.45;
  padding: 10px 11px 4px;
}
.ask-box textarea:focus-visible { outline: none; }
.ask-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 6px;
}
.ask-actions .hint { font-size: 12px; color: var(--ink-4); flex: 1; }

.examples { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.example {
  border: 1px solid var(--line);
  background: var(--ground-2);
  border-radius: 20px;
  padding: 5px 11px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
}
.example:hover { border-color: var(--azure); color: var(--slate); }

/* --------------------------------------------------------------- criteria -- */

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ground);
  overflow: hidden;
}
.panel + .panel { margin-top: 14px; }
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-2);
  background: var(--ground-2);
}
.panel-head h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.panel-head .spacer { flex: 1; }
.panel-body { padding: 12px; }

.criteria { list-style: none; margin: 0; padding: 0; }
.criterion {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-2);
}
.criterion:last-child { border-bottom: 0; }
.criterion .body { flex: 1; min-width: 0; }
.criterion .expr { font-family: var(--mono); font-size: 13px; }
.criterion .note { font-size: 12px; color: var(--ink-3); margin-top: 3px; }

/* A substitution has to look like one. */
.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  padding: 1px 6px;
  vertical-align: 1px;
}
.tag-proxy { background: var(--ground-3); color: var(--slate); }
.tag-bound { background: var(--ground-3); color: var(--ink-2); }
.tag-thin { background: var(--warn-bg); color: var(--warn); }
.tag-metered { background: var(--warn-bg); color: var(--warn); }
.tag-ai { background: var(--ground-3); color: var(--ink-2); }

.dropped {
  border-left: 3px solid var(--bad);
  background: var(--bad-bg);
  padding: 9px 11px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 8px;
}
.dropped .what { font-weight: 600; }
.dropped .why { font-size: 13px; color: var(--ink-2); }

.summary {
  font-size: 15px;
  line-height: 1.5;
  padding: 11px 13px;
  border-radius: var(--radius);
  background: var(--ground-2);
  border: 1px solid var(--line);
}
.summary.partial { background: var(--warn-bg); border-color: #f0e0b6; color: #6b4a00; }

.numbers { display: flex; gap: 22px; flex-wrap: wrap; margin: 0 0 12px; }
.number .n {
  font-size: 24px;
  font-weight: 640;
  letter-spacing: -0.02em;
  display: block;
  line-height: 1.1;
}
.number .k {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}
.number.approx .n::before { content: '≥ '; color: var(--ink-4); font-weight: 500; }

/* ------------------------------------------------------------------ table -- */

.table-wrap { overflow: auto; }
table.rows {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 13px;
}
table.rows th, table.rows td {
  text-align: left;
  padding: 0 10px;
  height: var(--row);
  border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.rows thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--ground-2);
  border-bottom: 1px solid var(--line);
  font-weight: 620;
  font-size: 12px;
  color: var(--ink-2);
}
table.rows thead th .col {
  display: flex;
  align-items: center;
  gap: 6px;
}
table.rows tbody tr:hover { background: var(--ground-2); }
table.rows td.num { text-align: right; font-family: var(--mono); }

/* A cell is a button because it opens provenance. It must not look like a link, or
   the table turns into noise, so the affordance appears on hover. */
.cell {
  display: block;
  width: 100%;
  text-align: inherit;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td:hover .cell { text-decoration: underline dotted var(--ink-4); text-underline-offset: 3px; }

/* Never checked and checked-but-empty must not look the same. */
.unchecked { color: var(--ink-4); font-style: italic; }
.empty-value { color: var(--ink-3); }

/* Freshness is a stripe, not a colour on the text: the value stays readable. */
.stale-mark {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--warn);
  margin-left: 5px;
  vertical-align: 1px;
}
.col-age { font-size: 11px; font-weight: 500; color: var(--ink-4); }
.col-age.stale { color: var(--warn); }

/* ---------------------------------------------------------------- popover -- */

.pop {
  position: absolute;
  z-index: 40;
  width: 340px;
  max-width: calc(100vw - 24px);
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgb(22 32 47 / 16%);
  overflow: hidden;
}
.pop-head {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line-2);
  background: var(--ground-2);
  display: flex;
  align-items: center;
  gap: 8px;
}
.pop-head .what { font-weight: 620; font-size: 13px; }
.pop-body { padding: 11px; max-height: 320px; overflow: auto; }
.obs { padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid var(--line-2); }
.obs:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.obs .v { font-family: var(--mono); font-size: 13px; }
.obs .who { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.obs .when { font-size: 12px; color: var(--ink-3); }
.obs .ev {
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 4px;
  padding-left: 8px;
  border-left: 2px solid var(--line);
}
.obs.superseded { opacity: 0.62; }
.obs.superseded .v { text-decoration: line-through; }

/* ------------------------------------------------------------------ feed -- */

.feed { list-style: none; margin: 0; padding: 0; }
.feed li {
  display: flex;
  gap: 11px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-2);
}
.feed .kind {
  flex: none;
  width: 74px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding-top: 2px;
}
.kind-entered { color: var(--good); }
.kind-exited { color: var(--bad); }
.kind-changed { color: var(--slate); }
.feed .what { flex: 1; min-width: 0; }
.feed .when { flex: none; font-size: 12px; color: var(--ink-3); }
.diff { font-family: var(--mono); font-size: 12px; }
.diff .from { color: var(--ink-3); text-decoration: line-through; }
.diff .to { color: var(--ink); }

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

.empty {
  max-width: 46ch;
  margin: 12vh auto;
  text-align: center;
  color: var(--ink-3);
}
.empty h3 { margin: 0 0 6px; color: var(--ink); font-size: 16px; }
.empty p { margin: 0 0 14px; }

.banner {
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1px solid;
}
.banner-error { background: var(--bad-bg); border-color: #eccccd; color: #7d2226; }
.banner-warn { background: var(--warn-bg); border-color: #f0e0b6; color: #6b4a00; }
.banner-info { background: var(--ground-2); border-color: var(--line); color: var(--ink-2); }
.banner strong { display: block; margin-bottom: 2px; }

.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid var(--line);
  border-top-color: var(--azure);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

.skeleton {
  height: 11px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--ground-3), var(--line-2), var(--ground-3));
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--ground-3);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--teal);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.cost { font-family: var(--mono); }

dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  box-shadow: 0 16px 48px rgb(22 32 47 / 22%);
}
dialog::backdrop { background: rgb(22 32 47 / 34%); }
.dialog-body { padding: 16px; }
.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line-2);
  background: var(--ground-2);
}
.dialog-body h3 { margin: 0 0 4px; font-size: 16px; }
.dialog-body p.sub { margin: 0 0 14px; color: var(--ink-3); font-size: 13px; }
.dialog-body label + label { margin-top: 12px; display: block; }

@media (max-width: 820px) {
  /* Hiding the sidebar took the base list, "+ New", billing and sign-out with it, so a
     phone could reach only whatever hash was already loaded. It becomes a strip across
     the top instead: everything stays reachable, nothing needs a toggle to remember. */
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 45vh; overflow-y: auto; }
  .sidebar-head { position: sticky; top: 0; background: var(--ground); z-index: 1; }
  .base-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 var(--pad) 10px; }
  .base-list li { flex: 1 1 auto; min-width: 45%; }
  .base-link { border: 1px solid var(--line); border-radius: 8px; }
  .sidebar-foot { position: static; }
  .screen { padding-left: 12px; padding-right: 12px; }
  .table-wrap { overflow-x: auto; }
}
