/* ==========================================================================
   eDelivery UI — custom layer on top of Pico.css
   Sections: tokens, base, header/nav, cards, forms, dropzone, badges,
   tables, empty states, detail, toast, footer, responsive.
   ========================================================================== */

/* --- Design tokens -------------------------------------------------------- */
:root {
  --ed-brand: #2456e6;
  --ed-brand-strong: #1d47c4;
  --ed-brand-weak: rgba(36, 86, 230, 0.10);
  --ed-surface: #ffffff;
  --ed-surface-2: #f6f8fb;
  --ed-border: #e3e8f0;
  --ed-text: #182135;
  --ed-muted: #64748b;
  --ed-ok: #067a53;
  --ed-ok-bg: #d9f3e7;
  --ed-err: #b42332;
  --ed-err-bg: #fce8ea;
  --ed-info: #21569c;
  --ed-info-bg: #e0ecfb;
  --ed-warn: #8a5300;
  --ed-warn-bg: #fdf0d5;
  --ed-neutral: #52607a;
  --ed-neutral-bg: #e9edf4;
  --ed-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px -12px rgba(15, 23, 42, 0.12);
}

/* Pico defines its palette under selectors like :root:not([data-theme=dark])
   (specificity 0,2,0): overrides need at least the same specificity. */
:root:not([data-theme="dark"]),
[data-theme="light"] {
  --pico-primary: var(--ed-brand);
  --pico-primary-background: var(--ed-brand);
  --pico-primary-border: var(--ed-brand);
  --pico-primary-hover: var(--ed-brand-strong);
  --pico-primary-hover-background: var(--ed-brand-strong);
  --pico-primary-hover-border: var(--ed-brand-strong);
  --pico-primary-underline: color-mix(in srgb, var(--ed-brand) 50%, transparent);
  --pico-primary-focus: color-mix(in srgb, var(--ed-brand) 30%, transparent);
}

:root {
  --pico-border-radius: 0.5rem;
  --pico-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

html { background: var(--ed-surface-2); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --pico-primary: var(--ed-brand);
    --pico-primary-background: var(--ed-brand);
    --pico-primary-border: var(--ed-brand);
    --pico-primary-hover: var(--ed-brand-strong);
    --pico-primary-hover-background: var(--ed-brand-strong);
    --pico-primary-hover-border: var(--ed-brand-strong);
    --pico-primary-underline: color-mix(in srgb, var(--ed-brand) 50%, transparent);
    --pico-primary-focus: color-mix(in srgb, var(--ed-brand) 35%, transparent);
    --ed-brand: #6d8dff;
    --ed-brand-strong: #8aa4ff;
    --ed-brand-weak: rgba(109, 141, 255, 0.16);
    --ed-surface: #171d2b;
    --ed-surface-2: #10151f;
    --ed-border: #2a3347;
    --ed-text: #e6eaf2;
    --ed-muted: #94a0b8;
    --ed-ok: #4cd6a2;
    --ed-ok-bg: rgba(76, 214, 162, 0.14);
    --ed-err: #ff8b96;
    --ed-err-bg: rgba(255, 139, 150, 0.14);
    --ed-info: #86b7ff;
    --ed-info-bg: rgba(134, 183, 255, 0.14);
    --ed-warn: #f0b649;
    --ed-warn-bg: rgba(240, 182, 73, 0.14);
    --ed-neutral: #aab5c9;
    --ed-neutral-bg: rgba(170, 181, 201, 0.14);
    --ed-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  }
}

/* --- Base ----------------------------------------------------------------- */
body {
  background: var(--ed-surface-2);
  /* did:com addresses, hashes and uuids are long unbreakable tokens. Without
     this they widen the whole document on a phone, which pushes every card
     and the header off screen — not just the element that contains them. */
  overflow-wrap: break-word;
}

/* Visually hidden but still announced: used for labels that would be noise on
   screen but are needed to name a control or a column. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

main.container { padding-block: 1.75rem 3rem; max-width: 1080px; }
/* Pico scales the root font with the viewport (16 px up to 21 px at 1536+),
   so a container fixed at 1080 px holds fewer characters the wider the
   screen: the queue's six columns did not fit at 1920 px. Let it grow a
   little on wide screens instead. The header follows below. */
@media (min-width: 1280px) { main.container { max-width: 1200px; } }
@media (min-width: 1536px) { main.container { max-width: 1280px; } }

h1 { font-size: 1.45rem; margin-bottom: 0.2rem; }
hgroup > p { color: var(--ed-muted); }

.muted { color: var(--ed-muted); }
.error-text { color: var(--ed-err); }
.notice { color: #9a6b00; }

/* --- Header / nav ---------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--ed-surface);
  border-bottom: 1px solid var(--ed-border);
}

.site-header nav {
  max-width: 1080px; /* widened together with main.container below */
  margin-inline: auto;
  padding: 0.45rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.site-header ul { margin: 0; padding: 0; }
@media (min-width: 1280px) { .site-header nav { max-width: 1200px; } }
@media (min-width: 1536px) { .site-header nav { max-width: 1280px; } }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ed-text);
  text-decoration: none;
}
.brand:hover { color: var(--ed-brand); }
.brand svg { width: 26px; height: 26px; flex: none; }

.nav-links {
  display: flex;
  gap: 0.15rem;
  list-style: none;
  margin-inline: auto;
}
.nav-links a {
  display: inline-block;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  color: var(--ed-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
}
.nav-links a:hover { color: var(--ed-text); background: var(--ed-neutral-bg); }
.nav-links a[aria-current="page"] {
  color: var(--ed-brand);
  background: var(--ed-brand-weak);
  font-weight: 600;
}

.nav-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  list-style: none;
  margin-left: auto;
}
.nav-meta li { list-style: none; padding: 0; }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--ed-muted);
}
.user-chip .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ed-brand);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Segmented language switcher */
.lang-form {
  display: inline-flex;
  margin: 0;
  border: 1px solid var(--ed-border);
  border-radius: 999px;
  overflow: hidden;
}
.lang-btn {
  margin: 0;
  padding: 0.18rem 0.65rem;
  width: auto;
  font-size: 0.72rem;
  font-weight: 600;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--ed-muted);
  box-shadow: none;
}
.lang-btn:hover { background: var(--ed-neutral-bg); color: var(--ed-text); }
.lang-btn.active,
.lang-btn.active:disabled {
  background: var(--ed-brand);
  color: #fff;
  opacity: 1;
}

.logout-form { margin: 0; display: inline-flex; }
.btn-ghost {
  margin: 0;
  width: auto;
  padding: 0.3rem 0.85rem;
  font-size: 0.82rem;
  background: transparent;
  border: 1px solid var(--ed-border);
  color: var(--ed-muted);
  box-shadow: none;
}
.btn-ghost:hover { border-color: var(--ed-muted); color: var(--ed-text); background: transparent; }

/* --- Cards ----------------------------------------------------------------- */
.card {
  background: var(--ed-surface);
  border: 1px solid var(--ed-border);
  border-radius: 14px;
  box-shadow: var(--ed-shadow);
  padding: 1.4rem 1.5rem;
  margin-bottom: 1.5rem;
}
.card > h2, .card > h3 {
  font-size: 1.02rem;
  margin-bottom: 1rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.card-head h2, .card-head h3 { margin: 0; font-size: 1.02rem; }

.page-head {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.count-pill {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ed-neutral);
  background: var(--ed-neutral-bg);
  border-radius: 999px;
  padding: 0.12rem 0.65rem;
}
.page-head .lead { width: 100%; margin: 0.15rem 0 0; color: var(--ed-muted); }

/* Wallet / info side card */
.wallet-card dl { margin: 0; }
.wallet-card dt {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ed-muted);
  margin-top: 0.9rem;
}
.wallet-card dt:first-child { margin-top: 0; }
.wallet-card dd { margin: 0.15rem 0 0; }
.balance-value { font-size: 1.35rem; font-weight: 700; color: var(--ed-text); }
.cost-note {
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 1px dashed var(--ed-border);
  font-size: 0.8rem;
  color: var(--ed-muted);
}

.notarize-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1.5rem;
  align-items: start;
}
.notarize-grid .card { margin-bottom: 0; }
.queue-card { margin-top: 1.5rem; }

/* --- Forms ----------------------------------------------------------------- */
.form-row {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 1rem;
}
/* Form controls carry an intrinsic width (a select sizes to its widest
   option, a textarea defaults to 20 columns) that survives width:100%. */
input, select, textarea { max-width: 100%; }
form button[type="submit"].btn-primary {
  width: auto;
  padding: 0.55rem 2.2rem;
  font-weight: 600;
}
.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.25rem;
}
/* Optional metadata disclosure: closed by default (progressive disclosure),
   so the summary must read as a control — bordered row, chevron that
   rotates when open, hover feedback, ≥44px tap target. */
.metadata-details {
  margin-bottom: 1rem;
  border: 1px solid var(--ed-border);
  border-radius: 10px;
  background: var(--ed-surface);
}
.metadata-details summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ed-text);
  cursor: pointer;
  border-radius: 10px;
  list-style: none; /* the chevron below replaces the native marker */
}
.metadata-details summary::-webkit-details-marker { display: none; }
.metadata-details summary::marker { content: ""; }
/* Pico draws its own accordion chevron via ::after: ours replaces it. */
.metadata-details summary::after { display: none; }
.metadata-details summary:hover { background: var(--ed-surface-2); }
.metadata-details summary svg {
  flex: none;
  margin-left: auto;
  color: var(--ed-muted);
  transition: transform 0.2s ease;
}
.metadata-details[open] summary svg { transform: rotate(180deg); }
.metadata-details[open] summary {
  border-bottom: 1px solid var(--ed-border);
  border-radius: 10px 10px 0 0;
}
.metadata-summary-hint {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--ed-muted);
}
.metadata-body { padding: 0.9rem 0.9rem 0.1rem; }
.metadata-details .alert { margin-bottom: 0.9rem; }
.metadata-hint {
  font-size: 0.8rem;
  color: var(--ed-muted);
  margin-bottom: 0.9rem;
}
#upload-error:not(:empty) { margin-bottom: 0.9rem; }
.alert {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  font-size: 0.88rem;
  border: 1px solid transparent;
  margin-bottom: 0;
}
.alert-error {
  background: var(--ed-err-bg);
  color: var(--ed-err);
  border-color: color-mix(in srgb, var(--ed-err) 25%, transparent);
}
.alert-info {
  background: var(--ed-info-bg);
  color: var(--ed-info);
  border-color: color-mix(in srgb, var(--ed-info) 25%, transparent);
}
.alert-warn {
  background: var(--ed-warn-bg);
  color: var(--ed-warn);
  border-color: color-mix(in srgb, var(--ed-warn) 30%, transparent);
  margin-bottom: 0.9rem;
}
.alert svg { flex: none; margin-top: 0.1rem; }

/* Password field with a show/hide eye button overlaid on the input.
   The wrapper carries the bottom spacing so the button can stretch to the
   full height of the input itself. */
.password-field {
  position: relative;
  margin-bottom: var(--pico-spacing, 1rem);
}
.password-field > input {
  margin-bottom: 0;
  padding-inline-end: 3rem;
}
.password-toggle {
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  width: 3rem;
  margin: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0 var(--pico-border-radius) var(--pico-border-radius) 0;
  background: transparent;
  box-shadow: none;
  color: var(--ed-muted);
  cursor: pointer;
}
.password-toggle:hover,
.password-toggle:focus {
  background: transparent;
  color: var(--ed-brand);
}
.password-toggle svg { width: 20px; height: 20px; }
.password-toggle .icon-eye-off { display: none; }
.password-toggle[aria-pressed="true"] .icon-eye { display: none; }
.password-toggle[aria-pressed="true"] .icon-eye-off { display: block; }

/* --- Dropzone --------------------------------------------------------------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 2px dashed var(--ed-border);
  border-radius: 12px;
  background: var(--ed-surface-2);
  padding: 2.1rem 1rem;
  text-align: center;
  cursor: pointer;
  margin-bottom: 1.1rem;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.dropzone:hover { border-color: var(--ed-brand); }
.dropzone.dragover {
  border-color: var(--ed-brand);
  background: var(--ed-brand-weak);
}
.dropzone svg {
  width: 34px;
  height: 34px;
  color: var(--ed-brand);
  margin-bottom: 0.25rem;
}
.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}
#dropzone-text { font-weight: 600; color: var(--ed-text); }
.dropzone-hint { font-size: 0.8rem; color: var(--ed-muted); }
.dropzone-file {
  display: none;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ed-ok);
}
.dropzone.has-file { border-style: solid; border-color: var(--ed-ok); }
.dropzone.has-file .dropzone-file { display: block; }

#upload-progress {
  width: 100%;
  height: 6px;
  margin-bottom: 0.9rem;
}

/* --- Badges ----------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.16rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.badge-enqueued   { background: var(--ed-neutral-bg); color: var(--ed-neutral); }
.badge-processing { background: var(--ed-info-bg); color: var(--ed-info); }
.badge-processing::before { animation: ed-pulse 1.2s ease-in-out infinite; }
.badge-success    { background: var(--ed-ok-bg); color: var(--ed-ok); }
.badge-failure    { background: var(--ed-err-bg); color: var(--ed-err); }

@keyframes ed-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* --- Tables ----------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }

/* Fixed layout: the row always fits the card, whatever the viewport. Every
   value is already shortened (shortHash, shortAddr) or truncated with the
   full text in its title attribute, so nothing legitimately needs a
   horizontal scrollbar -- which is what the auto layout produced between
   720 and ~1000 px and, in Italian, even at 1280 px. In a fixed layout the
   first row sizes the columns, hence the widths on the header cells; the
   file column has none and takes what is left. A header hidden with
   display:none removes its column outright (compact band below). */
.table-wrap table { margin-bottom: 0; font-size: 0.88rem; table-layout: fixed; width: 100%; }
.table-wrap th.col-hash { width: 8.25rem; }
.table-wrap th.col-recipients { width: 8.25rem; }
.table-wrap th.col-status { width: 9.25rem; } /* "In elaborazione" is the widest badge */
.table-wrap th.col-tx { width: 8rem; }
.table-wrap th.col-date { width: 8rem; }
.table-wrap th.col-action { width: 5rem; }
/* The queue's action is an icon button; the document lists' is a text link. */
.queue-scroll th.col-action { width: 2.6rem; }
/* Tighter gutters than Pico's default 1rem: five or six columns of hashes,
   addresses and dates have to share roughly a thousand pixels. */
.table-wrap th,
.table-wrap td { padding-inline: 0.6rem; }
.table-wrap th:first-child,
.table-wrap td:first-child { padding-inline-start: 0; }
.table-wrap th:last-child,
.table-wrap td:last-child { padding-inline-end: 0; }
/* Hash and transaction are already shortened (shortHash): keep them on one
   line so the columns stay narrow and predictable. */
.table-wrap td.cell-hash,
.table-wrap td.cell-tx,
.table-wrap td.col-recipients { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* The hash algorithm, tucked under the hash it qualifies. */
.algo {
  display: block;
  margin-top: 0.05rem;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  color: var(--ed-muted);
}
.table-wrap thead th {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ed-muted);
  border-bottom-width: 2px;
}
.table-wrap tbody tr:hover { background: var(--ed-surface-2); }
.table-wrap td { vertical-align: middle; }
.table-wrap td.date-cell { white-space: nowrap; font-size: 0.8rem; color: var(--ed-muted); }

/* Monospace values inside tables: quiet, no boxed background */
.table-wrap .mono,
.detail-list .mono {
  background: transparent;
  padding: 0;
  color: inherit;
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78em;
  /* Inherits overflow-wrap:break-word from body, which breaks a token only
     when it would overflow. Deliberately NOT `anywhere`: that also lets the
     token contribute a one-character min-content width, which makes the
     browser starve the hash column on the desktop table. */
}
.mono.wrap { word-break: break-all; white-space: normal; }
[data-copy] { cursor: copy; }
[data-copy]:hover { color: var(--ed-brand); }

.fname {
  /* Takes whatever the fixed columns leave and truncates; the full name
     stays in the cell's title attribute. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.err-detail {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 0.3rem;
  max-width: 16rem;
  font-size: 0.75rem;
  line-height: 1.35;
}

.row-link { font-weight: 600; font-size: 0.82rem; text-decoration: none; white-space: nowrap; }
.row-link svg { vertical-align: -0.15em; margin-right: 0.15rem; }
/* Certificate download in the last queue column: icon button on desktop,
   the label appears in card mode only (title/aria-label carry it here). */
.cert-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  color: var(--ed-brand);
  background: var(--ed-brand-weak);
}
.cert-btn:hover { background: var(--ed-brand); color: #fff; }
.cert-btn svg { margin: 0; width: 16px; height: 16px; }
.cert-btn .cert-label { display: none; }
.queue-scroll td.cell-action { text-align: right; }

/* Queue: a twelve-month window can be long, so the table scrolls inside the
   card with its header pinned instead of stretching the page. */
.queue-head { margin: 0; }
.queue-head h3 { display: flex; align-items: center; gap: 0.5rem; }
.queue-head p { margin: 0.15rem 0 0; font-size: 0.8rem; }
.card-head .queue-head + small { flex: none; text-align: right; max-width: 18rem; }
.queue-truncated { font-size: 0.8rem; margin: -0.35rem 0 0.8rem; }
.queue-scroll { max-height: 32rem; overflow-y: auto; }
.queue-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--ed-surface);
}

/* --- Empty states ------------------------------------------------------------ */
.empty {
  text-align: center;
  padding: 2.75rem 1rem;
  color: var(--ed-muted);
}
.empty svg {
  width: 44px;
  height: 44px;
  color: var(--ed-border);
  margin-bottom: 0.6rem;
}
.empty .empty-title {
  font-weight: 600;
  color: var(--ed-text);
  margin-bottom: 0.2rem;
}
.empty p { margin: 0; font-size: 0.88rem; }

/* --- Detail pages ------------------------------------------------------------ */
.detail-list {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.55rem 1.75rem;
  margin: 0;
}
.detail-list dt {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ed-muted);
  align-self: center;
  margin: 0;
}
.detail-list dd { margin: 0; min-width: 0; }

.btn-row { display: flex; gap: 0.75rem; margin-top: 1.25rem; flex-wrap: wrap; }
.btn-row [role="button"], .btn-row a[role="button"] {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1.1rem;
  font-size: 0.88rem;
}
.back-link {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--ed-muted);
  text-decoration: none;
  font-size: 0.9rem;
}
.back-link:hover { color: var(--ed-brand); }

/* --- Login ------------------------------------------------------------------- */
.login-wrap {
  max-width: 25rem;
  margin: 8vh auto 0;
}
.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--ed-text);
}
.login-brand svg { width: 34px; height: 34px; }
.login-card { padding: 1.75rem; margin: 0; }
.login-card h1 { font-size: 1.15rem; margin-bottom: 0.1rem; }
.login-card form button[type="submit"] { width: 100%; font-weight: 600; }
.login-foot {
  text-align: center;
  margin-top: 1.1rem;
  font-size: 0.78rem;
  color: var(--ed-muted);
}

/* --- Toast ------------------------------------------------------------------- */
#toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--ed-surface);
  color: var(--ed-ok);
  border: 1px solid color-mix(in srgb, var(--ed-ok) 35%, transparent);
  border-radius: 10px;
  box-shadow: var(--ed-shadow);
  padding: 0.7rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#toast.show { opacity: 1; transform: translateY(0); }

/* --- Footer ------------------------------------------------------------------ */
.site-footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  font-size: 0.78rem;
  color: var(--ed-muted);
}

/* --- Responsive --------------------------------------------------------------- */
@media (max-width: 900px) {
  /* minmax(0, 1fr), not 1fr: a grid item defaults to min-width:auto, so the
     widest unbreakable content inside the card (the did:com address in the
     recipients hint) would stretch the column past the viewport. */
  .notarize-grid { grid-template-columns: minmax(0, 1fr); }
}

/* The header runs out of room before the main content does: brand, nav links,
   account, language switch and log-out do not fit on one line much below
   900 px. */
@media (max-width: 900px) {
  .nav-meta { flex-wrap: wrap; justify-content: flex-end; }
  .nav-links { margin-inline: auto 0.5rem; }
}
@media (max-width: 860px) {
  .site-header nav { flex-wrap: wrap; gap: 0.5rem; }
  .nav-links { order: 3; width: 100%; justify-content: center; margin-inline: 0; }
}

/* Compact tables: tablet portrait, split screens, narrow laptop windows. The
   fixed columns are trimmed and the recipients column is dropped -- the least
   consulted one (most notarizations go to the sender's own wallet), still
   listed on the detail page -- so the file name keeps a readable width. The
   status badge may wrap here: "In elaborazione" alone needs two lines. Up to
   1099 px because a 1024 px viewport with every column left the file name
   about a hundred pixels. */
@media (min-width: 721px) and (max-width: 1099px) {
  .table-wrap table { font-size: 0.84rem; }
  .table-wrap th.col-hash { width: 8rem; }
  .table-wrap th.col-status { width: 8.25rem; }
  .table-wrap th.col-tx { width: 7.5rem; }
  .table-wrap th.col-date { width: 7.75rem; }
  .table-wrap th.col-action { width: 4.5rem; }
  .queue-scroll th.col-action { width: 2.2rem; }
  .table-wrap .col-recipients { display: none; }
  .table-wrap .badge { white-space: normal; text-align: left; }
  .table-wrap th,
  .table-wrap td { padding-inline: 0.45rem; }
}
/* Below 900 px the transaction column goes too: with the certificate action
   in the last column, five columns of tokens would leave the file name a
   handful of characters. The transaction hash stays on the certificate and
   on the detail page. */
@media (min-width: 721px) and (max-width: 899px) {
  .table-wrap th.col-tx,
  .table-wrap td.cell-tx { display: none; }
}

/* Phones and small tablets. The tables become cards here: six columns of
   hashes and addresses cannot be read on a 390 px screen, and a horizontally
   scrolling table hides most of every row behind a gesture people do not
   discover. */
@media (max-width: 720px) {
  main.container { padding-block: 1.1rem 2.25rem; }

  /* --- Header ---------------------------------------------------------- */
  .site-header nav { padding: 0.4rem 0.75rem; }
  .nav-links a { padding: 0.5rem 0.9rem; }
  .user-chip .user-email { display: none; }
  /* Comfortable touch targets: the desktop sizes are around 22 px tall. */
  .lang-btn { padding: 0.45rem 0.8rem; font-size: 0.78rem; }
  .btn-ghost { padding: 0.45rem 0.9rem; }

  /* --- Layout ---------------------------------------------------------- */
  .card { padding: 1.1rem 1rem; border-radius: 12px; }
  .page-head h1 { font-size: 1.25rem; }
  /* minmax(0, …) again: a select or textarea in a 1fr column keeps its
     intrinsic width and pushes the card past a narrow viewport. */
  .form-row { grid-template-columns: minmax(0, 1fr); }
  .dropzone { padding: 1.5rem 0.85rem; }
  .form-actions { display: block; }
  form button[type="submit"].btn-primary { width: 100%; padding-block: 0.7rem; }
  /* Keep the disclosure row to two elements on a phone: the subtitle would
     wrap awkwardly between the title and the chevron. */
  .metadata-summary-hint { display: none; }

  /* --- Detail lists ---------------------------------------------------- */
  .detail-list { grid-template-columns: 1fr; gap: 0.1rem 0; }
  .detail-list dt { margin-top: 0.7rem; }
  /* Values are uuids, addresses and hashes: they must break, not overflow. */
  .detail-list dd .mono { word-break: break-all; }
  .btn-row { flex-direction: column; align-items: stretch; }
  .btn-row [role="button"], .btn-row a[role="button"] { justify-content: center; }

  /* --- Tables as cards -------------------------------------------------- */
  /* The header row is hidden and each cell carries its own label through
     data-label. The explicit roles in the markup keep the table semantics
     that changing `display` would otherwise drop. */
  .table-wrap,
  .queue-scroll { overflow: visible; max-height: none; }
  .table-wrap table { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tbody { display: block; }

  .table-wrap tr {
    display: block;
    background: var(--ed-surface);
    border: 1px solid var(--ed-border);
    border-radius: 12px;
    padding: 0.85rem 0.9rem;
    margin-bottom: 0.7rem;
  }
  .table-wrap tr:last-child { margin-bottom: 0; }
  .table-wrap tbody tr:hover { background: var(--ed-surface); }

  .table-wrap td,
  .queue-scroll td {
    display: block;
    border: 0;
    padding: 0.28rem 0;
  }
  /* An inline-block label acts as a narrow first column, so single-line
     values line up without needing a wrapper element around each value.
     The hanging indent keeps wrapped lines (a second recipient, a long error)
     aligned under the value instead of falling back to the card edge. */
  .table-wrap td[data-label] {
    padding-left: 6.5rem;
    text-indent: -6.5rem;
  }
  .table-wrap td[data-label] > * { text-indent: 0; }
  .table-wrap td[data-label]::before {
    content: attr(data-label);
    display: inline-block;
    min-width: 6.5rem;
    text-indent: 0;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ed-muted);
    vertical-align: baseline;
  }

  /* First cell: the card title (file name or sender). */
  .table-wrap td.cell-primary {
    max-width: none;
    white-space: normal;
    overflow: visible;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0 0 0.5rem;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--ed-border);
  }
  .table-wrap td.date-cell { font-size: 0.8rem; }
  .table-wrap td.cell-status .badge { vertical-align: baseline; }
  .table-wrap td.cell-hash,
  .table-wrap td.cell-tx,
  .table-wrap td.col-recipients { white-space: normal; overflow: visible; }
  .algo { display: inline; margin-left: 0.4rem; }

  /* Room for the whole message: a card is not as tight as a table row. */
  .err-detail {
    -webkit-line-clamp: 4;
    line-clamp: 4;
    max-width: none;
    margin-top: 0.35rem;
  }

  /* Row action: a full-width target at the foot of the card. Rows without
     one (a notarization not yet on the chain) render no cell at all. */
  .table-wrap td.cell-action:empty { display: none; }
  .table-wrap td.cell-action {
    padding: 0.6rem 0 0;
    margin-top: 0.5rem;
    border-top: 1px solid var(--ed-border);
    text-align: center;
  }
  .table-wrap td.cell-action .row-link {
    display: block;
    padding: 0.4rem;
    border-radius: 8px;
    background: var(--ed-brand-weak);
    color: var(--ed-brand);
  }
  /* The certificate button becomes that same full-width action, label shown. */
  .table-wrap td.cell-action .cert-btn {
    display: flex;
    gap: 0.4rem;
    width: auto;
    height: auto;
    padding: 0.5rem;
    text-align: center;
  }
  .table-wrap td.cell-action .cert-btn .cert-label { display: inline; }

  .queue-truncated { margin-bottom: 1rem; }
  .card-head { flex-direction: column; align-items: flex-start; gap: 0.4rem; }
  .card-head .queue-head + small { text-align: left; max-width: none; }

  /* --- Login ------------------------------------------------------------ */
  .login-wrap { margin-top: 3vh; }
  .login-card { padding: 1.25rem 1.1rem; }

  /* --- Toast ------------------------------------------------------------ */
  #toast { left: 1rem; right: 1rem; bottom: 1rem; }
}

/* Very narrow phones only (an iPhone SE is 375 px): below this the label
   column costs more room than the alignment is worth, so it moves above the
   value. Common phones (390–430 px) keep the compact two-column reading. */
@media (max-width: 360px) {
  .table-wrap td[data-label] { padding-left: 0; text-indent: 0; }
  .table-wrap td[data-label]::before { display: block; min-width: 0; }
  .table-wrap td { padding: 0.35rem 0; }
}
