/* The shell every application page shares: the header, the offline banner and
   the viewport readout (Platform §3.2, FS §12.4, §17.4). Each page's own
   stylesheet comes after this one. */

/* A page that scrolls as a whole — the hub, Réglages. The board is a fixed-height
   column instead (.app in board.css), so its lanes can scroll on their own. */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ----------------------------------------------------------------- header */

/* It takes the lamp's light on every page (FS §12.6): brightest at the mark, a little
   shade at its far end, and a shadow cast on the page below it. Above what follows
   it, so that the shadow is not painted over. */
.app-header {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  border-bottom: 1px solid transparent;
  background:
    radial-gradient(circle var(--lamp-reach) at var(--lx) var(--ly), var(--lamp-header-l0) 0%, transparent 40%),
    radial-gradient(circle var(--lamp-reach) at var(--lx) var(--ly), transparent 30%, var(--lamp-header-s100) 100%),
    var(--surface);
  box-shadow: 0 1px 0 var(--lamp-edge), 0 6px 18px -10px var(--lamp-shadow);
  padding-top: env(safe-area-inset-top);
}

/* The row wraps rather than overflow. With a page's own controls and a larger text
   size (FS §12.5), a narrow screen cannot hold everything on one line, and a header
   wider than the screen would scroll the page sideways and push the shared controls,
   Réglages among them, off it. */
.header-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  min-height: var(--header-height);
  padding: var(--sp-2) var(--sp-4);
}

/* The logo goes back to the hub. Step 4 holds it for the PIN pad (Platform §9.3),
   which nothing on screen may announce, so neither a press nor a hold may answer:
   no tap highlight, callout or selection, no hover or press state in any
   stylesheet, and no cursor change, as the mark's spec sheet asks. Dragging is
   turned off in the pages, by the link's `draggable="false"`, the one switch every
   engine honours. The callout rule is Safari's alone; Chrome on Android still
   offers its link menu on a long press, which step 4's handler cancels through
   `contextmenu`. The keyboard keeps its focus ring (base.css). The drawing takes
   the header's text colour through currentColor, so it follows the theme; the
   icons' ochre never appears in the interface, where red belongs to the urgency
   scale. The minimum height keeps the target as large as the old 32 px icon. */
.app-logo {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 2rem;
  border-radius: var(--radius-md);
  color: var(--text);
  cursor: default;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Sized by its height, its width following the mark's own proportions (the
   viewBox): about 33 px wide at the default text size, never under the 28 px the
   mark needs to read, since every text size is larger (Platform §3.2). The press
   lands on the link, never on the drawing. */
.app-logo svg {
  display: block;
  height: 1.375rem;
  width: auto;
  aspect-ratio: 143 / 93.98;
  pointer-events: none;
}

.app-title {
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: -0.01em;
}

/* Text size, theme and Réglages: the same three on every page, at the end. */
.header-shared {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin-left: auto;
}

.header-shared a.btn { text-decoration: none; }

/* The base text size cycles through its steps (FS §12.5). The glyph grows with
   the setting, so the button says what it is currently doing without a label. */
.text-size-toggle {
  font-weight: 700;
  line-height: 1;
}

.text-size-toggle[data-scale="100"] { font-size: 0.75rem; }
.text-size-toggle[data-scale="115"] { font-size: 0.9rem; }
.text-size-toggle[data-scale="132"] { font-size: 1.05rem; }
.text-size-toggle[data-scale="150"] { font-size: 1.2rem; }

/* --------------------------------------------------------------- the lamp

   FS §12.6, ARCHITECTURE.md §22.5. One still light at the mark, which shell/lamp.js
   places: `--lx` and `--ly` are the lamp in each lit surface's own box, so every
   gradient is an ordinary scrolling background (iOS Safari ignores fixed ones), and
   on the board and the hub `--sx`, `--sy`, `--sb` and `--ck` are the shadow a lane,
   card or tile casts and the strength of its rim. Registered so that none of them is
   inherited — a card must never draw its lane's shadow — with values for the moment
   before the script has run. */

@property --lx { syntax: "<length>"; inherits: false; initial-value: 36px; }
@property --ly { syntax: "<length>"; inherits: false; initial-value: 28px; }
@property --sx { syntax: "<length>"; inherits: false; initial-value: 1px; }
@property --sy { syntax: "<length>"; inherits: false; initial-value: 4px; }
@property --sb { syntax: "<length>"; inherits: false; initial-value: 10px; }
@property --ck { syntax: "<number>"; inherits: false; initial-value: 0.5; }

/* The lamp in the viewport, for the relief's fixed layer; lamp.js overrides it. */
:root {
  --lamp-vx: 36px;
  --lamp-vy: 28px;
}

/* The wall's grain, on every page with the header. */
body {
  background: var(--lamp-grain), var(--bg);
}

/* The board and the hub are rooms: the page is lit from the mark and falls into
   shade away from it. Elsewhere text sits on the page, where the shade would take
   secondary text below 4.5:1. */
body[data-lamp="room"] {
  background:
    radial-gradient(circle var(--lamp-reach) at var(--lx) var(--ly),
      var(--lamp-page-l0) 0%, var(--lamp-page-l24) 24%, transparent 56%),
    radial-gradient(circle var(--lamp-reach) at var(--lx) var(--ly),
      transparent 12%, var(--lamp-page-s52) 52%, var(--lamp-page-s100) 100%),
    var(--lamp-grain),
    var(--bg);
}

/* The rock's relief where the lamp reaches: a fixed layer behind the page, masked by
   a gradient around the lamp in the viewport. */
body[data-lamp="room"]::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--lamp-relief) 0 0 / 560px 560px;
  -webkit-mask-image: radial-gradient(circle calc(var(--lamp-reach) * 0.62) at var(--lamp-vx) var(--lamp-vy),
    var(--lamp-mask-full) 0%, var(--lamp-mask-half) 45%, transparent 100%);
  mask-image: radial-gradient(circle calc(var(--lamp-reach) * 0.62) at var(--lamp-vx) var(--lamp-vy),
    var(--lamp-mask-full) 0%, var(--lamp-mask-half) 45%, transparent 100%);
}

/* A high-contrast mode keeps no lamp, no grain and no relief. */
@media (forced-colors: active) {
  body,
  body[data-lamp="room"],
  .app-header {
    background-image: none;
  }

  body[data-lamp="room"]::before { display: none; }
}

/* --------------------------------------------------------- offline banner */

/* Like the row above, it wraps rather than overflow. The button keeps its words on
   one line, so at the two largest text sizes (FS §12.5) a phone cannot hold it
   beside the sentence: it goes under it, still at the right. */
.offline-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-top: 1px solid var(--attention);
  background: color-mix(in srgb, var(--attention) 14%, var(--surface));
  color: var(--text);
  font-size: var(--fs-sm);
}

.offline-dot {
  flex: 0 0 auto;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--attention);
}

/* The sentence takes what the line has left. Its basis is what it must find
   beside the button to stay there: less than that, and the button wraps. */
#offline-banner-text { flex: 1 1 6rem; }

.offline-banner button { margin-left: auto; }

/* --------------------------------------------------------- viewport readout */

/* A 100dvh element measured live by debugpanel.js (FS §12.4). */
.debug-probe {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 100dvh;
  visibility: hidden;
  pointer-events: none;
}

/* In pixels on purpose: the readout must not grow with the text size it is
   helping to diagnose. Pinned to the top of the visual viewport. */
#debug-panel {
  position: fixed;
  top: var(--vv-top, 0px);
  left: var(--vv-left, 0px);
  z-index: 9999;
  max-width: 100%;
  margin: 0;
  padding: 6px 8px;
  background: rgb(0 0 0 / 86%);
  color: #8f8;
  font: 11px/1.35 ui-monospace, monospace;
  white-space: pre;
  pointer-events: none;
}

/* ---------------------------------------------------------------- responsive */

/* ---------------------------------------------- links and the object picker
   Platform §6.5, §8.3: an object as a link or a result shows it — in a dialog, a
   panel, or Réglages' list of public links. */

.object-entry {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

.object-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.object-status {
  flex: none;
  padding: 0 var(--sp-1);
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  font-size: var(--fs-xs);
}

.object-due { flex: none; font-size: var(--fs-xs); font-weight: 650; font-variant-numeric: tabular-nums; }
.object-due[data-urgency="overdue"]     { color: var(--u-overdue); }
.object-due[data-urgency="today"]       { color: var(--u-today); }
.object-due[data-urgency="second-half"] { color: var(--u-second-half); }

.link-groups,
.link-group { display: flex; flex-direction: column; gap: var(--sp-2); }

.link-list,
.picker-results {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.link-row { display: flex; align-items: center; gap: var(--sp-2); }

.link-open,
.picker-result {
  flex: 1 1 auto;
  display: flex;
  min-width: 0;
  min-height: 2.25rem;
  align-items: center;
  padding: 0 var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.link-open:hover,
.picker-result:hover { border-color: var(--border-strong); }

/* ------------------------------------------------------------ public links
   Platform §10.5: a link in the file's panel and in Réglages, with its actions,
   and the form that creates one. */

.public-links {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.public-link {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.public-link .link-open { align-self: flex-start; max-width: 100%; }

.public-link-label { font-weight: 600; overflow-wrap: anywhere; }
.public-link-unlabelled { color: var(--text-faint); font-weight: 400; font-style: italic; }

.public-link-address {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-family: ui-monospace, monospace;
}

.public-link-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--sp-3);
}

.public-link-actions,
.public-link-password {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.public-link-password[hidden] { display: none; }
.public-link-password .input { flex: 1 1 10rem; min-width: 0; }

/* Expiration… — Prolonger… once expired —: the choice and Enregistrer on one row; the
   expiry itself in red once past (Platform §10.5). */
.public-link-expiry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.public-link-fact.public-link-expired { color: var(--danger); }

/* The expiry's choice: a select, and beside it a date for Jusqu'au… (ARCHITECTURE.md §41.6). */
.expiry-control {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.expiry-control .input { flex: 1 1 9rem; min-width: 0; }

.public-link-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
  padding: var(--sp-3);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.public-link-form[hidden] { display: none; }

.public-link-form .label {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin: 0;
}

.public-link-form .btn { align-self: flex-start; }

@media (max-width: 767px) {
  .header-main { gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); }
  .app-title { font-size: var(--fs-lg); }
}

/* ---------------------------------------------------------------- PIN pad
   Platform §9.3. An overlay with dots, a keypad and nothing that names it. */

.hide-revealed { flex: none; }

.pinpad {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: var(--overlay);
}

.pinpad-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
  width: 100%;
  max-width: 18rem;
  padding: var(--sp-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.pinpad-dots { display: flex; gap: var(--sp-2); min-height: 0.75rem; }

.pinpad-dot {
  width: 0.75rem;
  height: 0.75rem;
  border: 1px solid var(--text-muted);
  border-radius: 50%;
}

.pinpad-dot-on { background: var(--text); border-color: var(--text); }

.pinpad-keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
  width: 100%;
}

.pinpad-key {
  min-height: 3rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-xl);
}

.pinpad-key:hover { background: var(--surface-3); }

.pinpad-forgotten {
  border: 0;
  background: none;
  color: var(--text-faint);
  font-size: var(--fs-xs);
}

.pinpad-form { display: flex; flex-direction: column; gap: var(--sp-2); width: 100%; }
.pinpad-form-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-2); }

/* Revealed mode is ending (Platform §9.6): nothing stays on screen while the page
   sends its last saves and reloads. */
:root[data-concealed] body { visibility: hidden; }
