/*
 * Base styles of every server web page (/v/, login, the pages the app opens, and what the dashboard shares
 * with them). Colours, radii, spacing and fonts come only from tokens.css (decisions 95 and 97): no hex or
 * rgba values here (spec/requests/ui_tokens_spec.rb).
 * Every corner is rounded; nothing may overflow sideways at 375 px.
 */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: var(--font-body); line-height: var(--line-body); font-family: var(--sans);
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

/* Type */
h1, h2, h3 { font-weight: 600; line-height: 1.15; margin: 0 0 var(--space-3); text-wrap: balance; }
h1 { font-size: var(--font-h1); letter-spacing: -.03em; }
h2 { font-size: var(--font-h2); letter-spacing: -.015em; }
p { margin: 0 0 var(--space-3); }
p:last-child { margin-bottom: 0; }
small { color: var(--muted); }
/* Links are never underlined (decision 98.2). --link is the text's own ink, so what tells a link apart without colour
   (WCAG 1.4.1) is its weight: 500 in the interface (tables, cards), 600 inside running text (p, li, dd, small), where
   400 surrounds it. Under the pointer the ink turns --link-hover; the focus ring stays the usual one. In :where() (no
   specificity): any component class (.btn, .nav-item, .seg-item) keeps its own colour, weight and hover. */
:where(a) { color: var(--link); font-weight: 500; text-decoration: none; overflow-wrap: anywhere; }
:where(p, li, dd, small, figcaption) :where(a) { font-weight: 600; }
:where(a:hover) { color: var(--link-hover); }
code {
  font-family: var(--mono); font-size: .9em;
  background: var(--code-bg); color: var(--text);
  padding: 2px 7px; border-radius: var(--radius-xs);
  overflow-wrap: anywhere;
}
:focus-visible { outline: var(--focus-ring) solid var(--focus); outline-offset: var(--focus-offset); }

/* Top bar: a floating rounded card */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: var(--space-3);
  max-width: var(--shell-width); margin: var(--space-3) auto 0; padding: var(--space-2) var(--space-2) var(--space-2) var(--space-5);
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
@media (max-width: 64rem) { .topbar { margin-left: var(--space-4); margin-right: var(--space-4); } }
.topbar > a { font-weight: 600; text-decoration: none; letter-spacing: -.01em; }
.brand { display: inline-flex; align-items: center; gap: 9px; min-height: var(--tap); }
.brand svg { flex: none; }
.brand-seal { fill: var(--verified); stroke: var(--surface); }
.brand-tick { stroke: var(--surface); }
.topbar form { display: inline; margin: 0; }

/* Page column; each section is a rounded card */
.shell { max-width: var(--shell-width); margin: 0 auto; padding: var(--space-6) var(--space-4) var(--space-7); }
.shell > h1 { margin-bottom: var(--space-4); }
.shell-narrow { max-width: var(--shell-narrow); }
.card-grid { display: grid; gap: 0 var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }
:where(.shell > section, .card-grid > section) {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: clamp(var(--space-4), 4vw, var(--space-5)); margin: 0 0 var(--space-4);
  min-width: 0;
}
.shell > section > h2 { margin-bottom: var(--space-4); }
.lede { color: var(--text-2); font-size: 17px; }
.muted { color: var(--muted); }

/* Forms. Element defaults go inside :where() (no specificity), so a component class (.btn, .input) always wins. */
form { margin: 0 0 var(--space-3); }
label { font-weight: 500; font-size: 15px; }
:where(input[type="email"], input[type="password"], input[type="text"], input[type="number"], select) {
  font: var(--font-body)/1.3 var(--sans); color: var(--text); background: var(--surface);
  border: 1px solid var(--control-border); border-radius: var(--radius-sm);
  padding: 10px 14px; min-height: var(--tap); max-width: 100%;
}
:where(select) { padding-right: 36px; }
::placeholder { color: var(--muted); opacity: 1; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); vertical-align: -3px; margin: 0 6px 0 0; }
/* A label that wraps a checkbox is the touch target: 44 px tall, whole label clickable. */
label:has(> input[type="checkbox"]) { display: inline-flex; align-items: center; min-height: var(--tap); cursor: pointer; }
:where(input[type="submit"], button) {
  display: inline-flex; align-items: center; justify-content: center;
  font: 500 15px/1.2 var(--sans); cursor: pointer;
  min-height: var(--tap); padding: 10px 20px; border-radius: var(--radius-sm);
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  transition: background-color .15s, border-color .15s;
}
:where(input[type="submit"], button):hover { background: var(--accent-hover); border-color: var(--accent-hover); }
/* Copy a password with one tap (application.js, [data-copy]); the code is selected whole on a tap too */
.copyable { user-select: all; -webkit-user-select: all; }
.stack { display: grid; gap: var(--space-2); max-width: 24rem; }
.stack input[type="submit"] { margin-top: var(--space-3); justify-self: start; }
.stack label:not(:first-child) { margin-top: var(--space-2); }
/* The public pages' fields (locked /v/): the component .field (components.css) in a narrow column. */
.shell .field { max-width: 24rem; margin: 0 0 var(--space-4); }
:where(.field input:not([type="submit"], [type="checkbox"], [type="radio"]), .field select) { width: 100%; } /* a submit keeps its width (P8) */
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
:where(.inline-form input[type="password"], .inline-form input[type="text"]) { flex: 1 1 12rem; min-width: 0; }

/* The login «E · Icono» (decision 108, sessions/new): a white page as tall as the screen, the app's icon (app_icon)
   and the name centred in the free space, the form at the bottom: labels above filled fields without an edge and a
   full-width «Entrar» (--accent), all at the phone's reading size. From 900 px it splits in two: the same block,
   left-aligned and centred in height, on the left; the landing's motto on the mist on the right (.login-panel). */
body:has(> .login) { background: var(--surface); }
.login { min-height: 100vh; min-height: 100dvh; }
.login-main {
  display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh;
  max-width: var(--shell-narrow); margin: 0 auto;
  padding: max(var(--space-5), env(safe-area-inset-top)) var(--space-4) max(40px, env(safe-area-inset-bottom));
}
.login-mark { flex: 1 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: var(--space-6) 0; }
.login-mark h1 { font-size: var(--font-hero); font-weight: 700; letter-spacing: -.02em; margin: 0; }
.login-title { display: none; }
.login-main > .login-form { background: none; box-shadow: none; padding: 0; margin: 0; }
.login-form .stack { max-width: none; gap: 6px; margin: 0; }
.login-form label { font-size: var(--font-small); color: var(--muted); }
.login-form .stack label:not(:first-child) { margin-top: 6px; }
.login-form :is(input[type="email"], input[type="password"]) {
  width: 100%; min-height: var(--control-h-lg); padding: 0 var(--space-4); border: 0; border-radius: var(--radius-tile);
  background: var(--bg); font-size: var(--font-lg);
}
.login-form .stack input[type="submit"] {
  justify-self: stretch; margin-top: 20px; min-height: var(--btn-h-lg); border-radius: var(--radius-tile);
  font-size: var(--font-lg); font-weight: 600;
}
.login-form .alert { margin-bottom: var(--space-4); }
.login-panel { display: none; }

/* The split page: the form's column (26 rem of block) and the panel, inset by 16 px so its rounded corners show. */
@media (min-width: 900px) {
  .login { display: grid; grid-template-columns: minmax(26rem, 5fr) 7fr; }
  .login-main { max-width: none; width: 100%; margin: 0; padding: var(--space-7) clamp(var(--space-6), 6vw, 96px); justify-content: center; }
  .login-main > * { width: 100%; max-width: 24rem; }
  .login-mark { flex: none; flex-direction: row; justify-content: flex-start; gap: var(--space-3); padding: 0; margin-bottom: var(--space-7); }
  .login-mark .app-icon { width: 44px; height: 44px; border-radius: calc(var(--radius-icon) * 44 / 128); box-shadow: none; }
  .login-mark .app-icon svg { width: 29px; height: 29px; }
  .login-mark h1 { font-size: var(--font-h2); }
  .login-title { display: block; font-size: var(--font-hero); font-weight: 700; letter-spacing: -.02em; line-height: 1.15; margin: 0 0 var(--space-5); }

  .login-panel {
    display: flex; align-items: flex-end; margin: var(--space-4) var(--space-4) var(--space-4) 0;
    padding: clamp(var(--space-6), 5vw, 72px); border-radius: var(--radius-hero); background: var(--bg);
  }
}

/* The motto (the landing's h1: its tracking, its round dots in the seal's green). Each line keeps its room while
   hidden, so nothing moves as the lines come in (application.js: .is-writing on the motto, .is-shown on each line written). */
.login-motto {
  margin: 0; display: grid; font-size: clamp(44px, 5.4vw, 84px); font-weight: 700; line-height: 1.02;
  letter-spacing: -.045em; color: var(--text);
}
.login-motto-line { display: block; }
.login-motto-dot {
  display: inline-block; width: .16em; height: .16em; margin-left: .05em; border-radius: 50%;
  background: var(--verified); color: transparent; overflow: hidden; vertical-align: baseline;
}
.login-motto.is-writing .login-motto-line {
  opacity: 0; transform: translateY(.3em); transition: opacity .6s ease, transform .6s cubic-bezier(.2, .7, .2, 1);
}
.login-motto.is-writing .login-motto-line.is-shown { opacity: 1; transform: none; }
.login-motto.is-clearing .login-motto-line { transition-duration: .4s; }
@media (prefers-reduced-motion: reduce) {
  .login-motto.is-writing .login-motto-line { opacity: 1; transform: none; transition: none; }
}

/* In dark mode the login takes the darkest navy (--bg, like the app's icon) and the fields the lighter one (108.9);
   the panel, the lighter one too. */
@media (prefers-color-scheme: dark) {
  body:has(> .login) { background: var(--bg); }
  .login-form :is(input[type="email"], input[type="password"]) { background: var(--surface); }
  .login-panel { background: var(--surface); }
}

/* The app's screen (decision 111, app_home/show): the login's page (white; the icon's navy in dark mode), the app's
   icon and the name at the top, the organization's certifications to record as the compact list of 108.3 on a filled
   tile (the login's fields), and «Cerrar sesión» at the bottom. No bar, no menu, no KPIs. */
body:has(> .app-home) { background: var(--surface); }
.app-home {
  display: flex; flex-direction: column; gap: var(--space-5); min-height: 100vh; min-height: 100dvh;
  max-width: var(--shell-narrow); margin: 0 auto;
  padding: max(var(--space-5), env(safe-area-inset-top)) var(--space-4) max(40px, env(safe-area-inset-bottom));
}
.app-home-head { display: flex; align-items: center; gap: var(--space-3); }
.app-home-head .app-icon { width: 48px; height: 48px; border-radius: calc(var(--radius-icon) * 48 / 128); box-shadow: none; }
.app-home-head .app-icon svg { width: 32px; height: 32px; }
.app-home-head h1 { font-size: var(--font-h2); font-weight: 700; letter-spacing: -.01em; margin: 0; }
.app-home-org { margin: 0; color: var(--muted); font-size: var(--font-small); }
.app-home-section > h2 { font-size: var(--font-small); font-weight: 600; color: var(--muted); margin: 0 0 var(--space-2) var(--space-1); }
.app-home-section .cert-list, .app-home-empty { background: var(--bg); border-radius: var(--radius-tile); overflow: hidden; }
.app-home-section .cert-list > li + li { border-top-color: var(--surface); }
.app-home-empty { margin: 0; padding: var(--space-4); color: var(--muted); }
.app-home-pager { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  margin-top: var(--space-2); padding: 0 var(--space-1); color: var(--muted); font-size: var(--font-small); }
.app-home-pager a { color: var(--link); font-weight: 600; text-decoration: none; }
.app-home-login { text-align: center; color: var(--muted); font-size: var(--font-small); margin: auto 0 0; }
.app-home-login a { color: var(--link); font-weight: 600; text-decoration: none; }
.app-home-logout-form { margin: auto 0 0; }
.app-home .app-home-logout {
  width: 100%; min-height: var(--btn-h-lg); border-radius: var(--radius-tile); border: 0;
  background: var(--bg); color: var(--text); font-size: var(--font-lg); font-weight: 600;
}
.app-home .app-home-logout:hover { background: var(--row-hover); }
@media (prefers-color-scheme: dark) {
  body:has(> .app-home) { background: var(--bg); }
  .app-home-section .cert-list, .app-home-empty, .app-home .app-home-logout { background: var(--surface); }
  .app-home-section .cert-list > li + li { border-top-color: var(--bg); }
}

/* 119 (mockup «C3»): one list with filter tabs and a sheet per row (app_home/_certifications, _sheet).
   The tabs: the segmented control of 100.1 in one row that scrolls sideways (never 98.13's columns): no scrollbar,
   snap, a fade at the edge where more follow (.fade-l/.fade-r, application.js), sticky under the status bar. */
#app-list { display: block; min-width: 0; }
.app-tabs {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; margin: 0 calc(-1 * var(--space-4)) var(--space-1);
  padding: var(--space-2) var(--space-4) var(--space-3); background: var(--surface);
  overflow-x: auto; scroll-snap-type: x proximity; scroll-padding-inline: var(--space-4); scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.app-tabs::-webkit-scrollbar { display: none; }
.app-tabs.fade-r { -webkit-mask-image: linear-gradient(to right, currentColor calc(100% - 56px), transparent); mask-image: linear-gradient(to right, currentColor calc(100% - 56px), transparent); }
.app-tabs.fade-l { -webkit-mask-image: linear-gradient(to left, currentColor calc(100% - 56px), transparent); mask-image: linear-gradient(to left, currentColor calc(100% - 56px), transparent); }
.app-tabs.fade-l.fade-r { -webkit-mask-image: linear-gradient(to right, transparent, currentColor 56px, currentColor calc(100% - 56px), transparent); mask-image: linear-gradient(to right, transparent, currentColor 56px, currentColor calc(100% - 56px), transparent); }
.app-tabs .seg { display: inline-flex; flex-wrap: nowrap; width: max-content; max-width: none; }
.app-tabs .seg-item { justify-content: flex-start; min-height: var(--btn-h); padding: 0 10px; scroll-snap-align: start; }
.app-tabs .seg-item:last-child { scroll-snap-align: end; }
/* A row: the retry icon (a denied one this viewer can retry) or a chevron at its end */
.cert-row-trail { width: 28px; height: 28px; flex: none; display: grid; place-items: center; margin-right: -4px; color: var(--muted); }
.cert-row-trail.is-retry { border-radius: 50%; background: var(--accent); color: var(--accent-ink); }
/* The sheet: a <dialog> from the bottom over the scrim (modal with JavaScript; without it, open in the page's flow) */
.sheet {
  position: fixed; inset: auto 0 0; margin: 0 auto; padding: 0; border: 0; width: 100%; max-width: var(--shell-narrow);
  max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain; background: var(--surface); color: var(--text);
  border-radius: var(--radius-hero) var(--radius-hero) 0 0; box-shadow: var(--shadow-sheet);
}
.sheet::backdrop { background: var(--scrim); }
.sheet[open] { animation: sheet-up .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes sheet-up { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } }
.sheet[open]:not(:modal) { position: static; max-height: none; border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: none; animation: none; }
.sheet-in { padding: var(--space-2) 20px max(40px, env(safe-area-inset-bottom)); }
.sheet-grab { width: 36px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto var(--space-4); }
.sheet-head { display: flex; align-items: center; gap: var(--space-3); }
.sheet-mark { width: 56px; height: 56px; flex: none; border-radius: 50%; display: grid; place-items: center; }
.sheet-mark-denied { background: var(--denied-bg); color: var(--denied); }
.sheet-mark-verified { background: var(--verified-bg); color: var(--verified); }
.sheet-mark-pending { background: var(--pending-bg); color: var(--pending); }
.sheet-close {
  margin-left: auto; width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text-2);
}
.sheet-status { margin-top: 20px; }
.sheet-h { margin: 10px 0 4px; font-size: var(--font-page-title); line-height: 1.25; letter-spacing: -.01em; }
.sheet-p { margin: 0; font-size: var(--font-body); line-height: 1.5; color: var(--text-2); }
.sheet-card { display: flex; gap: var(--space-3); align-items: flex-start; margin-top: var(--space-4); padding: 14px; border-radius: var(--radius-lg); background: var(--bg); }
.sheet-card .icon { flex: none; margin-top: 1px; color: var(--text-2); }
.sheet-card.is-stop .icon { color: var(--denied); }
.sheet-card p { margin: 0; font-size: var(--font-card-title); line-height: 1.45; color: var(--text-2); }
.sheet-card strong { display: block; color: var(--text); font-weight: 600; }
.sheet-actions { display: grid; gap: var(--space-2); margin-top: 20px; }
.sheet-actions:empty { display: none; }
.sheet-form { margin: 0; }
.sheet .sheet-big { width: 100%; min-height: var(--btn-h-lg); font-size: var(--font-lg); font-weight: 600; }
.sheet .sheet-big .icon { width: 20px; height: 20px; }
.sheet-textbtn { display: flex; align-items: center; justify-content: center; min-height: var(--btn-h-lg); font-weight: 600; font-size: var(--font-card-title); color: var(--link); text-decoration: none; }
.sheet-textbtn:hover { color: var(--link-hover); }
.sheet-prev { margin: var(--space-3) 0 0; font-size: var(--font-sm); color: var(--muted); }
.sheet-prev a { font-weight: 600; color: var(--link); text-decoration: none; }
@media (prefers-color-scheme: dark) {
  .app-tabs { background: var(--bg); }
  .app-tabs .seg { background: var(--surface); }
  .sheet-close { background: var(--bg); }
}

/* The landing of the server (home/show): the app's icon before the name (108), smaller than on the login */
.home-mark { display: flex; align-items: center; gap: var(--space-4); margin-bottom: var(--space-4); }
.home-mark h1 { margin: 0; }
.home-mark .app-icon { width: 72px; height: 72px; border-radius: calc(var(--radius-icon) * 72 / 128); }
.home-mark .app-icon svg { width: 48px; height: 48px; }

/* Messages */
.alert, .notice, .pending {
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-weight: 500;
}
.alert { background: var(--denied-bg); color: var(--denied); }
.notice { background: var(--verified-bg); color: var(--verified); }
.pending { background: var(--pending-bg); color: var(--pending); }

/* Page status mark before the title of /v/: a ring with a tick, a cross or a lock, in the state's colour.
   Decorative (the title says it in words); drawn with a mask so the colour stays a token. */
.status-mark { display: flex; align-items: center; gap: var(--space-3); }
.status-mark::before {
  content: ""; flex: none; width: 40px; height: 40px; background: var(--muted);
  -webkit-mask: var(--mark) center / contain no-repeat; mask: var(--mark) center / contain no-repeat;
}
.status-verified .status-mark::before {
  background: var(--verified);
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10.5'/%3E%3Cpath d='M7.5 12.4l3 3 6-6.3'/%3E%3C/svg%3E");
}
.status-denied .status-mark::before {
  background: var(--denied);
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10.5'/%3E%3Cpath d='M8.8 8.8l6.4 6.4M15.2 8.8l-6.4 6.4'/%3E%3C/svg%3E");
}
.status-locked .status-mark::before {
  background: var(--text-2);
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10.5'/%3E%3Crect x='8.3' y='11' width='7.4' height='5.8' rx='1.4'/%3E%3Cpath d='M9.9 11V9.4a2.1 2.1 0 0 1 4.2 0V11'/%3E%3C/svg%3E");
}

/* Lists of rows inside a card */
.list { list-style: none; padding: 0; margin: 0; }
.list > li { padding: var(--space-3) 0; border-top: 1px solid var(--border); min-width: 0; }
.list > li:first-child { border-top: 0; padding-top: 0; }
.list > li:last-child { padding-bottom: 0; }
.list form { margin: var(--space-2) 0 0; }
.list .button-inline, .list li > form.button_to { display: inline; margin: 0; }
.row-meta { color: var(--muted); font-size: var(--font-small); }
.list > li > p { margin-bottom: var(--space-2); }
.public-id { font-family: var(--mono); letter-spacing: .02em; margin-right: var(--space-2); }

/* Video, frames, QR */
video { display: block; width: 100%; max-width: 40rem; height: auto; border-radius: var(--radius-md); background: var(--text); margin-bottom: var(--space-3); }
.carousel {
  display: flex; gap: var(--space-3); overflow-x: auto; scroll-snap-type: x mandatory;
  padding: 2px 2px var(--space-3); margin-bottom: var(--space-3);
}
.candidate { flex: 0 0 auto; margin: 0; scroll-snap-align: start; text-align: center; }
.candidate img { display: block; width: 160px; height: auto; border-radius: var(--radius-md); background: var(--code-bg); }
.candidate figcaption { font-size: 13px; margin-top: var(--space-2); color: var(--text-2); max-width: 160px; }
.qr-box { margin: var(--space-4) 0; }
.qr-box svg.qr { display: block; width: min(100%, 20rem); height: auto; background: var(--qr-bg); padding: var(--space-3); border-radius: var(--radius-md); }
.qr-box figcaption { margin-top: var(--space-3); }
.qr-box code { font-size: 1.15rem; letter-spacing: .05em; }
.back { margin-top: var(--space-5); }
