/* The app's styles. Every colour, face and
   size comes from tokens.css; no colour value is written here. */

*, *::before, *::after { box-sizing: border-box; }

/* The ground is painted on <html> first, so no page flashes white. */
html { background: var(--g0); }

body {
  margin: 0;
  background: var(--g0);
  color: var(--ink);
  font: 400 var(--fs-body)/1.45 var(--font-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 var(--space-16);
}
h1 { font-size: var(--fs-title-l); line-height: 1.12; letter-spacing: -0.02em; }
h2 { font-size: var(--fs-title-s); line-height: 1.15; letter-spacing: -0.015em; }

/* A third-level heading is a label: mono capitals. */
h3 {
  font: 500 var(--fs-label)/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
  margin: var(--space-32) 0 var(--space-12);
}

p { margin: 0 0 var(--space-14); }
p:last-child { margin-bottom: 0; }
strong { font-weight: 600; }

a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--ink4);
  text-underline-offset: 3px;
  transition: text-decoration-color var(--dur-140) var(--ease);
}
a:hover { text-decoration-color: var(--ink); }

:focus-visible { outline: 2px solid var(--live); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--live) 35%, transparent); }
* { scrollbar-width: thin; scrollbar-color: var(--hair2) transparent; }

/* ─── App shell: the rail, then the top bar and the page ─────────────────── */

.db-app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.db-rail {
  width: var(--rail-w);
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--g0);
  border-right: 1px solid var(--hair);
}

.db-rail-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--rail-w);
  height: var(--top);
  flex: none;
  border-bottom: 1px solid var(--hair);
}
/* The DrawBridge emblem (static/brand/drawbridge-emblem.svg), inked in the
   theme's live colour with a soft glow. The
   artwork declares no fill, so it is a mask over the ink, never an <img>. */
.db-rail-emblem {
  display: block;
  width: 36px;
  height: 24px;
  background: var(--live);
  -webkit-mask: url("/static/brand/drawbridge-emblem.svg") no-repeat center / contain;
  mask: url("/static/brand/drawbridge-emblem.svg") no-repeat center / contain;
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--live) 45%, transparent));
}
.db-rail-logo:hover .db-rail-emblem { filter: drop-shadow(0 0 9px color-mix(in srgb, var(--live) 70%, transparent)); }

/* The htmx target: a full-height column so the footer sits at the bottom. */
.db-rail-nav {
  flex: 1;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
}

.db-rail-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-12) 0;
}

.db-rail-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: var(--radius-8);
  color: var(--ink3);
  text-decoration: none;
  transition: color var(--dur-140) var(--ease), background var(--dur-140) var(--ease);
}
.db-rail-btn svg { width: 18px; height: 18px; }
.db-rail-btn:hover { color: var(--ink); background: var(--g1); }

.db-rail-signout { display: contents; }

button.db-rail-btn {
  padding: 0;
  border: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
}
button.db-rail-btn:hover { background: var(--g1); }

.db-rail-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-top: var(--space-6);
  flex: none;
  border-radius: var(--radius-pill);
  box-shadow: var(--ring);
  color: var(--ink2);
  font: 500 var(--fs-label)/1 var(--font-mono);
  text-decoration: none;
  transition: color var(--dur-140) var(--ease), box-shadow var(--dur-140) var(--ease);
}
.db-rail-avatar:hover { color: var(--ink); box-shadow: var(--ring-hover); }

.db-canvas {
  flex: 1;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* The top bar: the app's name as its wordmark. */
.db-top {
  position: sticky;
  top: 0;
  z-index: 10;
  flex: none;
  height: var(--top);
  display: flex;
  align-items: center;
  padding: 0 var(--space-40);
  background: var(--g0);
  border-bottom: 1px solid var(--hair);
}

.db-wordmark {
  font: 700 var(--fs-wordmark)/1 var(--font-display);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink);
  white-space: nowrap;
}

.db-page {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: calc(var(--page-w) + 2 * var(--space-40));
  padding: var(--space-32) var(--space-40) var(--space-40);
}

/* ─── Sections ────────────────────────────────────────────────────────────── */

.db-card {
  background: var(--g1);
  box-shadow: var(--ring-soft);
  border-radius: var(--radius-12);
  padding: var(--space-24);
  margin-bottom: var(--space-16);
}
.db-card > form:not(:last-child),
#export-panel > form:not(:last-child) { margin-bottom: var(--space-14); }

/* ─── Sign-in pages (no app shell) ────────────────────────────────────────── */

body.db-login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-32);
}

.db-login-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  width: min(880px, 100%);
  min-height: 500px;
  background: var(--g1);
  box-shadow: var(--ring-soft), var(--shadow);
  border-radius: var(--radius-16);
  overflow: hidden;
}

.db-login-brand {
  padding: var(--space-32);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-32);
  border-right: 1px solid var(--hair);
}

/* DrawBridge's wide combination mark (static/brand/), masked over the
   panel's ink; its aspect ratio is the artwork's own viewBox. */
.db-login-wordmark {
  display: block;
  width: 176px;
  max-width: 100%;
  aspect-ratio: 6230 / 826;
  background-color: var(--ink);
  -webkit-mask: url("/static/brand/drawbridge-combination-mark-wide.svg") no-repeat center / contain;
  mask: url("/static/brand/drawbridge-combination-mark-wide.svg") no-repeat center / contain;
}
.db-login-app {
  display: block;
  margin-top: var(--space-12);
  font: 500 var(--fs-label)/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
}

/* The giant emblem under the whole sign-in door, faint. */
.db-login-emblem {
  position: fixed;
  inset: 10vh 6vw;
  z-index: 0;
  pointer-events: none;
  background: var(--live);
  opacity: 0.06;
  -webkit-mask: url("/static/brand/drawbridge-emblem.svg") no-repeat center / contain;
  mask: url("/static/brand/drawbridge-emblem.svg") no-repeat center / contain;
}
body.db-login-page .db-login-card { position: relative; z-index: 1; }

.db-login-headline {
  font-size: var(--fs-title-l);
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-12);
}

.db-login-brand-sub {
  color: var(--ink2);
  font-size: var(--fs-lead);
  line-height: 1.55;
  margin: 0;
}

.db-login-powered {
  font: 500 var(--fs-label)/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
}

.db-login-form-panel {
  padding: var(--space-32);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-22);
}

.db-login-form-title {
  font-size: var(--fs-title-s);
  margin: 0 0 var(--space-8);
}

.db-login-form-sub {
  color: var(--ink2);
  margin: 0;
}

.db-login-footnote {
  margin: 0;
  text-align: center;
}

/* ─── Forms ───────────────────────────────────────────────────────────────── */

.db-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-14);
}

/* A form's own buttons sit at its left edge, and its fields keep a
   readable width. */
.db-form > .db-btn { align-self: flex-start; }
.db-form > label:not(.db-check) { max-width: 440px; }

/* A field's name is a label: mono capitals above the field. */
.db-form label {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  font: 500 var(--fs-label)/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
}

.db-form input,
.db-form select,
.db-form textarea,
.db-table select {
  height: var(--h-34);
  padding: 0 var(--space-12);
  border: 0;
  border-radius: var(--radius-8);
  background: var(--g2);
  box-shadow: var(--ring);
  font: 400 var(--fs-body)/1 var(--font-text);
  letter-spacing: normal;
  text-transform: none;
  color: var(--ink);
  outline: none;
  transition: box-shadow var(--dur-140) var(--ease);
}
.db-form input::placeholder { color: var(--ink3); }
.db-form input:hover,
.db-form select:hover,
.db-table select:hover { box-shadow: var(--ring-hover); }
.db-form input:focus,
.db-form select:focus,
.db-form textarea:focus,
.db-table select:focus { box-shadow: var(--ring-field); }

/* A select is a pill with a drawn caret. */
.db-form select,
.db-table select {
  appearance: none;
  -webkit-appearance: none;
  border-radius: var(--radius-pill);
  padding: 0 var(--space-32) 0 var(--space-14);
  background-color: transparent;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink3) 50%),
    linear-gradient(135deg, var(--ink3) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.db-form select option,
.db-table select option { background: var(--g2); color: var(--ink); }
.db-table select { height: var(--h-28); min-width: 116px; }

.db-form input[type="date"] { font-family: var(--font-mono); font-size: var(--fs-label); letter-spacing: 0.03em; }

/* A checkbox with its words beside it, on the settings form: a sentence. */
.db-form label.db-check {
  flex-direction: row;
  align-items: center;
  gap: var(--space-10);
  font: 400 var(--fs-body)/1.4 var(--font-text);
  letter-spacing: normal;
  text-transform: none;
  color: var(--ink);
  cursor: pointer;
}
.db-form label.db-check input {
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  box-shadow: none;
  accent-color: var(--solid);
  cursor: pointer;
}

/* ─── Buttons: mono capital pills ─────────────────────────────────────────── */

.db-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  height: var(--h-32);
  padding: 0 var(--space-16);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--solid);
  color: var(--onsolid);
  font: 500 var(--fs-label)/1 var(--font-mono);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: box-shadow var(--dur-140) var(--ease), background var(--dur-140) var(--ease), color var(--dur-140) var(--ease);
}
.db-btn:hover { box-shadow: 0 0 0 2px color-mix(in srgb, var(--solid) 25%, transparent); }
.db-btn:active { transform: translateY(1px); }

/* The quieter buttons: a ring, not a fill. */
.db-btn--ghost,
.db-btn-sm {
  background: transparent;
  color: var(--ink);
  box-shadow: var(--ring);
}
.db-btn--ghost:hover,
.db-btn-sm:hover { box-shadow: var(--ring-hover); }

.db-btn-sm {
  height: var(--h-28);
  padding: 0 var(--space-12);
  letter-spacing: 0.06em;
}

.db-btn--full {
  width: 100%;
  align-self: stretch;
}

/* A form button that reads as a link (sign out, start again). */
.db-link-btn {
  padding: 0;
  border: 0;
  background: none;
  font: 500 var(--fs-label)/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
  cursor: pointer;
  transition: color var(--dur-140) var(--ease);
}
.db-link-btn:hover { color: var(--ink); }

/* ─── Words and states ────────────────────────────────────────────────────── */

.db-muted { color: var(--ink3); }

/* A small capital label in the mono face, over a title or a value. */
.db-label {
  margin: 0 0 var(--space-8);
  font: 500 var(--fs-label)/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
}

/* Something the person should know, but nothing went wrong: a reset of their
   password or two-step sign-in by someone else. */
.db-notice {
  color: var(--ink);
  background: color-mix(in srgb, var(--wait) 9%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--wait) 45%, transparent);
  padding: var(--space-10) var(--space-14);
  border-radius: var(--radius-8);
}

/* The error page: one card, the status over its title. */
.db-error-page { max-width: 640px; }
.db-error-page h1 { margin-top: 0; }
.db-error-page p:last-child { margin-bottom: 0; }

.db-error {
  color: var(--bad-text);
  background: var(--bad-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bad) 45%, transparent);
  padding: var(--space-10) var(--space-14);
  border-radius: var(--radius-8);
}

/* ─── Tables: hairline rows ───────────────────────────────────────────────── */

.db-table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-8) 0 var(--space-4);
}

.db-table th {
  text-align: left;
  height: var(--h-34);
  padding: 0 var(--space-12);
  border-bottom: 1px solid var(--hair2);
  font: 500 var(--fs-label)/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
  white-space: nowrap;
}

.db-table td {
  height: var(--row);
  padding: var(--space-8) var(--space-12);
  border-bottom: 1px solid var(--hair);
  vertical-align: middle;
}
.db-table th:first-child,
.db-table td:first-child { padding-left: 0; }
.db-table tr:last-child td { border-bottom: 0; }
.db-table tbody tr:hover td { background: color-mix(in srgb, var(--ink) 3%, transparent); }

/* Times, ids and addresses: mono data, tabular figures. */
.db-data {
  font: 400 var(--fs-label)/1.3 var(--font-mono);
  letter-spacing: 0.03em;
  color: var(--ink2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.db-table .db-inline { gap: var(--space-8); flex-wrap: nowrap; }
.db-table td > .db-inline { margin-top: var(--space-4); }
.db-table td > .db-inline:first-child { margin-top: 0; }

/* ─── Layout utilities ────────────────────────────────────────────────────── */

.db-inline { display: flex; gap: var(--space-12); align-items: center; flex-wrap: wrap; }
/* A row of fields with its button: the button sits on the fields' line. */
.db-form .db-inline { align-items: flex-end; }
.db-form .db-inline > .db-btn-sm { margin-bottom: 3px; }

/* Text kept on one line. */
.db-nowrap { white-space: nowrap; }

/* ─── Export progress ─────────────────────────────────────────────────────── */

progress {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: min(420px, 100%);
  height: 4px;
  margin: var(--space-8) 0 var(--space-16);
  border: 0;
  border-radius: 2px;
  background: var(--hair2);
  color: var(--ink);
  overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--hair2); border-radius: 2px; }
progress::-webkit-progress-value { background: var(--ink); border-radius: 2px; }
progress::-moz-progress-bar { background: var(--ink); border-radius: 2px; }

/* ─── Two-step sign-in (/account, /login/two-step) ────────────────────────── */

.db-twostep { display: flex; flex-direction: column; gap: var(--space-14); }
.db-twostep-steps { margin: 0; padding-left: var(--space-22); color: var(--ink2); }
.db-twostep-steps li + li { margin-top: var(--space-4); }
.db-twostep-qr { align-self: flex-start; padding: var(--space-8); border-radius: var(--radius-8); background: var(--qr-ground); }
.db-twostep-qr svg { display: block; }
.db-twostep-secret-label {
  margin: 0;
  font: 500 var(--fs-label)/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
}
.db-twostep .db-twostep-secret { margin: 0; }
.db-twostep-secret code,
.db-twostep-codes code {
  font: 400 var(--fs-code)/1.55 var(--font-mono);
  color: var(--ink);
  letter-spacing: 0.06em;
  user-select: all;
}
.db-twostep-codes code { font-size: var(--fs-label); letter-spacing: 0.03em; }
.db-twostep-codes {
  list-style: none;
  margin: 0;
  padding: var(--space-12) var(--space-14);
  border-radius: var(--radius-8);
  background: var(--g2);
  box-shadow: var(--ring-soft);
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: var(--space-6) var(--space-16);
}
/* A code box sized to its code: six digits (with room for a space), or a
   recovery code on the sign-in step. */
.db-form input.db-code-input {
  width: calc(10ch + 2 * var(--space-12));
  max-width: 100%;
  font: 400 var(--fs-body)/1 var(--font-mono);
  letter-spacing: 0.08em;
}
.db-form input.db-code-input--recovery { width: calc(20ch + 2 * var(--space-12)); }
/* On the sign-in card the fields and the button span the card. */
.db-login-form-panel .db-form > label { max-width: none; }
.db-form > .db-btn--full { align-self: stretch; }
