/* Component library. One family of controls shared by every screen,
   dialog and public page. States: default, hover, focus, pressed,
   selected, disabled, busy, success and error. */

/* ------------------------------------------------------------- buttons */

.btn {
  --btn-bg: var(--hz-pool);
  --btn-fg: var(--ink);
  --btn-line: transparent;
  --btn-hover: var(--hz-reed);
  --btn-press: var(--hz-reed);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: var(--control);
  padding: 0 var(--s4);
  border: var(--border) solid var(--btn-line);
  border-radius: var(--r-pill);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  user-select: none;
}
.btn:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--btn-hover); color: var(--btn-fg); }
.btn:not(:disabled):active { background: var(--btn-press); }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: default; }
.btn .icon { width: 18px; height: 18px; }

.btn-primary {
  --btn-bg: var(--mode);
  --btn-fg: var(--on-mode);
  --btn-line: transparent;
  --btn-hover: var(--mode-hover);
  --btn-press: var(--mode-press);
}
/* Coral is only for sending: one per screen. */
.btn-send {
  --btn-bg: var(--send);
  font-size: 19px;
  font-weight: var(--fw-bold);
  --btn-fg: var(--on-send);
  --btn-line: transparent;
  --btn-hover: var(--send-hover);
  --btn-press: var(--send-hover);
  font-weight: var(--fw-semibold);
}
.btn-send:disabled, .btn-send[aria-disabled="true"] { --btn-bg: var(--hz-mist); --btn-fg: var(--hz-hint); opacity: 1; }
.btn-quiet {
  --btn-bg: transparent;
  --btn-line: transparent;
  --btn-fg: var(--ink-2);
  --btn-hover: var(--surface-hover);
}
.btn-quiet:hover:not(:disabled) { --btn-fg: var(--ink); }
/* Tertiary actions with a text label read as actions, not as body copy: they
   take the workspace colour and underline on hover. Icon-only buttons stay
   quiet. */
.btn-quiet:not(.btn-icon) { --btn-fg: var(--mode); }
.btn-quiet:not(.btn-icon):hover:not(:disabled) { --btn-fg: var(--mode-hover); text-decoration: underline; text-underline-offset: 3px; }
.btn-danger {
  --btn-bg: var(--surface);
  --btn-fg: var(--danger);
  --btn-line: var(--line-strong);
  --btn-hover: var(--danger-tint);
  --btn-press: var(--danger-tint);
}
.btn-danger-solid {
  --btn-bg: var(--danger);
  --btn-fg: var(--hz-on-ink);
  --btn-line: transparent;
  --btn-hover: var(--danger-hover);
  --btn-press: var(--danger-hover);
}
.btn-link {
  min-height: auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--mode);
  font-weight: var(--fw-semibold);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}
.btn-link:hover:not(:disabled) { background: none; color: var(--mode-hover); text-decoration-thickness: 2px; }

.btn-sm { min-height: var(--control-sm); padding: 0 var(--s3); font-size: var(--fs-meta); }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-lg { min-height: var(--control-lg); padding: 0 var(--s6); font-size: var(--fs-md); }
.btn-block { display: flex; width: 100%; }
.btn-icon { width: var(--control); padding: 0; flex: none; }
.btn-icon.btn-sm { width: var(--control-sm); }

.btn[aria-busy="true"] { color: transparent !important; pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border: 2px solid var(--btn-fg);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.btn[aria-busy="true"] > * { visibility: hidden; }

/* ------------------------------------------------------------- fields */

.field { display: grid; gap: var(--s2); min-width: 0; }
.field-label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--ink); }
.field-hint { font-size: var(--fs-meta); color: var(--ink-3); line-height: var(--lh-snug); }
.field-error, .form-error {
  display: flex;
  gap: var(--s2);
  align-items: flex-start;
  font-size: var(--fs-sm);
  color: var(--danger);
  font-weight: var(--fw-medium);
}
.form-message { font-size: var(--fs-sm); color: var(--ok); font-weight: var(--fw-medium); }

.field-control {
  width: 100%;
  min-height: var(--control);
  padding: 0 var(--s3);
  border: var(--border) solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-md);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
textarea.field-control { padding: var(--s3); min-height: 120px; line-height: var(--lh); }
select.field-control {
  appearance: none;
  padding-right: var(--s8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23626a65' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}
.field-control::placeholder { color: var(--ink-3); opacity: 1; }
.field-control:hover { border-color: var(--ink-3); }
.field-control:focus, .field-control:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--focus-halo);
}
.field-control[aria-invalid="true"] { border-color: var(--danger); }
.field-control:disabled, .field-control[readonly] { background: var(--surface-sunken); color: var(--ink-2); }
.field-inline { display: flex; gap: var(--s2); align-items: stretch; }
.field-inline > .field-control { flex: 1; min-width: 0; }

.code-input {
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  letter-spacing: 0.32em;
  text-align: center;
  min-height: 56px;
}

/* ------------------------------------------------------- segmented, tabs */

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  border: var(--border) solid var(--line);
  max-width: 100%;
}
.segmented { flex-wrap: wrap; }
.segmented-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-width: 0;
  min-height: calc(var(--control) - 8px);
  padding: 0 var(--s3);
  border: 0;
  border-radius: calc(var(--r-md) - 3px);
  background: transparent;
  color: var(--ink-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.segmented-btn:hover:not(:disabled) { color: var(--ink); }
.segmented-btn.has-new { position: relative; }
.segmented-btn.has-new::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 2px var(--surface-sunken, var(--surface));
}
.segmented-btn[data-nav="team"].has-new::after { background: var(--team); }
.segmented-btn[aria-pressed="true"], .segmented-btn[aria-selected="true"], .segmented-btn[aria-current="page"],
.segmented input:checked + .segmented-btn {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-raise), 0 0 0 1px var(--line);
}
.segmented label { display: contents; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented input:focus-visible + .segmented-btn { outline: 2px solid var(--focus); outline-offset: 1px; }
.segmented-btn .icon { width: 17px; height: 17px; }
.segmented-fill { display: flex; width: 100%; }
.segmented-fill .segmented-btn { flex: 1; }

.tabs {
  display: flex;
  gap: var(--s1);
  border-bottom: var(--border) solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  flex: none;
  min-height: var(--control);
  padding: 0 var(--s3);
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); }
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: var(--s3);
  right: var(--s3);
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--mode);
}
/* On phones every tab stays visible: the tabs become wrapping chips instead
   of hiding behind a horizontal scroll. */
@media (max-width: 640px) {
  .tabs { flex-wrap: wrap; overflow: visible; gap: var(--s2); padding-bottom: var(--s3); }
  .tab { min-height: var(--control-sm); padding: 0 var(--s3); border: var(--border) solid var(--line); border-radius: var(--r-pill); background: var(--surface); }
  .tab[aria-selected="true"] { border-color: var(--mode); background: var(--mode-tint); color: var(--mode); }
  .tab[aria-selected="true"]::after { display: none; }
}

/* ------------------------------------------------- switches & choices */

.switch {
  position: relative;
  display: inline-flex;
  flex: none;
  width: 42px;
  height: 24px;
}
.switch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch-track {
  width: 100%;
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  transition: background-color var(--t-fast) var(--ease);
  pointer-events: none;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: transform var(--t-med) var(--ease);
}
.switch input:checked + .switch-track { background: var(--mode); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.5; }

.check {
  display: flex;
  gap: var(--s3);
  align-items: flex-start;
  font-size: var(--fs-sm);
  color: var(--ink-2);
  cursor: pointer;
}
.check input { flex: none; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--mode); }

.choice {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--s1) var(--s3);
  align-items: center;
  padding: var(--s3) var(--s4);
  border: var(--border) solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.choice:hover { border-color: var(--ink-3); }
.choice input { width: 18px; height: 18px; margin: 0; accent-color: var(--mode); }
.choice-title { font-weight: var(--fw-semibold); color: var(--ink); }
.choice-meta { grid-column: 2 / -1; font-size: var(--fs-meta); color: var(--ink-3); }
.choice-value { font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; }
.choice:has(input:checked) { border-color: var(--mode); background: var(--mode-tint); box-shadow: 0 0 0 1px var(--mode); }
.choice:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.choice:has(input:disabled) { opacity: 0.55; cursor: not-allowed; }

/* ------------------------------------------------------ badges & status */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 0 var(--s2);
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  color: var(--ink-2);
  font-size: var(--fs-meta);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
  max-width: 100%;
}
.badge .icon { width: 13px; height: 13px; stroke-width: 2; }
.badge-brand { background: var(--mode-tint); color: var(--mode); }
.badge-ok { background: var(--ok-tint); color: var(--ok); }
.badge-warn { background: var(--warn-tint); color: var(--warn); }
.badge-danger { background: var(--danger-tint); color: var(--danger); }
.badge-team { background: var(--team-tint); color: var(--team); }
.badge-outline { background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); }

.dot {
  display: inline-block;
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-disabled);
}
.dot-online { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-tint); }
.dot-warn { background: var(--warn); }
.dot-off { background: var(--danger); }

.spinner {
  display: inline-block;
  flex: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--mode);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  position: relative;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  overflow: hidden;
}
.progress > span {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: inherit;
  background: var(--mode);
  transition: width var(--t-med) var(--ease);
}
.progress.is-waiting > span { background: var(--warn); }
.progress.is-error > span { background: var(--danger); }
.progress.is-indeterminate > span { width: 35% !important; animation: indeterminate 1.2s var(--ease) infinite; }
@keyframes indeterminate { from { left: -35%; } to { left: 100%; } }

/* ------------------------------------------------------- surfaces */

.panel {
  border: var(--border) solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.panel-pad { padding: var(--s5); }
.panel-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 52px;
  padding: var(--s3) var(--s5);
  border-bottom: var(--border) solid var(--line);
}
.panel-title { font-size: var(--fs-md); font-weight: var(--fw-bold); letter-spacing: var(--tracking-tight); }
.panel-head .spacer, .spacer { flex: 1; }

.section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-meta);
  font-weight: var(--fw-bold);
  color: var(--ink-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.notice {
  display: flex;
  gap: var(--s3);
  align-items: flex-start;
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  color: var(--ink-2);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
}
.notice .icon { margin-top: 1px; }
.notice strong { color: var(--ink); }
.notice-brand { background: var(--mode-tint); color: var(--ink); }
.notice-brand .icon { color: var(--mode); }
.notice-team { background: var(--team-tint); color: var(--ink); }
.notice-team .icon { color: var(--team); }
.notice-warn { background: var(--warn-tint); color: var(--ink); }
.notice-warn .icon { color: var(--warn); }
.notice-danger { background: var(--danger-tint); color: var(--ink); }
.notice-danger .icon { color: var(--danger); }
/* Standing policy or plan facts: plain text with an icon, not a box. Boxes
   are kept for things that need attention now (warn, danger, a result). */
.notice-plain { padding: 0; background: transparent; font-size: var(--fs-meta); color: var(--ink-3); }
.notice-plain .icon { color: var(--ink-3); }
.notice-plain.notice-team .icon { color: var(--team); }
.notice-body { display: grid; gap: var(--s2); flex: 1; min-width: 0; }
.notice-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }

.empty {
  display: grid;
  justify-items: center;
  gap: var(--s2);
  padding: var(--s10) var(--s6);
  text-align: center;
  color: var(--ink-3);
}
.empty-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: var(--s2);
  border-radius: var(--r-lg);
  background: var(--surface-sunken);
  color: var(--ink-3);
}
.empty-title { color: var(--ink); font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.empty p { max-width: 32ch; font-size: var(--fs-sm); }

/* Grouped rows (settings, members, devices). */
.rows { display: grid; border: var(--border) solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.rows > * + * { border-top: var(--border) solid var(--line); }
.row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 56px;
  padding: var(--s3) var(--s4);
}
.row-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  color: var(--ink-2);
}
.row-main { display: grid; gap: 2px; flex: 1; min-width: 0; }
.row-title { font-weight: var(--fw-semibold); color: var(--ink); }
.row-meta { font-size: var(--fs-meta); color: var(--ink-3); line-height: var(--lh-snug); }
.row-end { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s2); align-items: center; }
button.row {
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  color: inherit;
}
button.row:hover { background: var(--surface-hover); }
button.row:focus-visible { outline-offset: -2px; border-radius: 0; }

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--mode-tint);
  color: var(--mode);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
}

.meter { display: grid; gap: var(--s2); }
.meter-track { height: 6px; border-radius: var(--r-pill); background: var(--surface-sunken); overflow: hidden; }
.meter-track > span { display: block; height: 100%; border-radius: inherit; background: var(--mode); }
.meter-label { display: flex; justify-content: space-between; gap: var(--s3); font-size: var(--fs-meta); color: var(--ink-3); }

.code-display {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
  line-height: 1;
  color: var(--ink);
}
.code-chip {
  display: inline-block;
  padding: var(--s2) var(--s3);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  font-family: var(--font-mono);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.08em;
  user-select: all;
}

/* ------------------------------------------------------------- menus */

.menu {
  position: fixed;
  z-index: 60;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 24px));
  max-height: min(calc(70vh * var(--vz)), 520px);
  overflow: auto;
  padding: var(--s1);
  border: var(--border) solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  animation: pop-in var(--t-fast) var(--ease);
}
.menu-label {
  padding: var(--s2) var(--s3) var(--s1);
  font-size: var(--fs-meta);
  font-weight: var(--fw-semibold);
  color: var(--ink-3);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 40px;
  padding: var(--s2) var(--s3);
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  text-align: left;
  text-decoration: none;
}
.menu-item .icon { color: var(--ink-3); width: 18px; height: 18px; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-hover); color: var(--ink); outline: none; }
.menu-item[aria-checked="true"] { color: var(--mode); }
.menu-item[aria-checked="true"] .icon { color: var(--mode); }
.menu-item-danger { color: var(--danger); }
.menu-item-danger .icon { color: var(--danger); }
.menu-item:disabled { opacity: 0.5; }
.menu-item-main { display: grid; flex: 1; min-width: 0; }
.menu-item-hint { font-size: var(--fs-meta); color: var(--ink-3); font-weight: var(--fw-regular); }
.menu-sep { height: 1px; margin: var(--s1) 0; background: var(--line); }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }

/* ---------------------------------------------------- dialogs & sheets */

.dialog {
  width: min(520px, calc(100vw - 32px));
  max-width: none;
  max-height: min(calc(88dvh * var(--vz)), 860px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: var(--r-xl);
  background: transparent;
  color: var(--ink);
  overflow: visible;
}
.dialog::backdrop { background: var(--scrim); animation: fade-in var(--t-med) var(--ease); }
/* A dialog covered by one opened from it waits out of sight (never two sheets
   on top of each other); only the top dialog dims the page. */
.dialog-covered { visibility: hidden; }
.dialog-covered::backdrop { background: transparent; }
.dialog[open] { animation: dialog-in var(--t-med) var(--ease); }
.dialog-sm { width: min(420px, calc(100vw - 32px)); }
.dialog-lg { width: min(720px, calc(100vw - 32px)); }
.dialog-xl { width: min(960px, calc(100vw - 32px)); }
.dialog-surface {
  display: flex;
  flex-direction: column;
  max-height: inherit;
  border-radius: inherit;
  background: var(--surface);
  box-shadow: var(--shadow-dialog);
  overflow: hidden;
}
.dialog-head {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: var(--s5) var(--s5) var(--s2) var(--s6);
}
.dialog-title { flex: 1; font-size: var(--fs-lg); font-weight: var(--fw-bold); padding-top: 6px; }
.dialog-close { margin: 0 calc(var(--s2) * -1) 0 0; }
.dialog-body {
  display: grid;
  gap: var(--s4);
  padding: var(--s2) var(--s6) var(--s5);
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
}
.dialog-body > p { color: var(--ink-2); }
.dialog-foot {
  display: flex;
  flex-wrap: wrap-reverse;
  justify-content: flex-end;
  gap: var(--s2);
  padding: var(--s4) var(--s6) calc(var(--s5) + var(--safe-bottom));
  border-top: var(--border) solid var(--line);
  background: var(--surface);
}
.dialog-foot .spacer { flex: 1; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
@keyframes fade-in { from { opacity: 0; } }

/* On phones every dialog becomes a bottom sheet with a sticky footer. */
@media (max-width: 640px) {
  .dialog, .dialog-sm, .dialog-lg, .dialog-xl {
    width: 100%;
    max-height: calc(calc(100dvh * var(--vz)) - var(--safe-top) - 24px);
    margin: auto 0 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
  .dialog[open] { animation: sheet-in var(--t-slow) var(--ease); }
  .dialog-surface { border-radius: var(--r-xl) var(--r-xl) 0 0; }
  .dialog-surface::before {
    content: "";
    flex: none;
    width: 36px;
    height: 4px;
    margin: var(--s2) auto 0;
    border-radius: var(--r-pill);
    background: var(--line-strong);
  }
  .dialog-head { padding: var(--s3) var(--s4) var(--s2) var(--s5); }
  .dialog-body { padding: var(--s2) var(--s5) var(--s4); }
  .dialog-foot { padding: var(--s3) var(--s5) calc(var(--s3) + var(--safe-bottom)); }
  .dialog-foot .btn { flex: 1 1 auto; }
  @keyframes sheet-in { from { transform: translateY(100%); } }
}

/* -------------------------------------------------------------- toasts */

.toast-region {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(var(--s5) + var(--safe-bottom));
  display: grid;
  gap: var(--s2);
  width: min(440px, calc(100vw - 24px));
  transform: translateX(-50%);
  pointer-events: none;
}
/* Never over the composer or the newest items right above it: while a
   Transfer or Team composer is docked at the bottom, toasts drop in from the
   top, under the header. */
body:has(.chat-dock) .toast-region { top: calc(var(--app-header-h, var(--header)) + var(--s2)); bottom: auto; }
.toast {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 48px;
  padding: var(--s2) var(--s2) var(--s2) var(--s4);
  border-radius: var(--r-lg);
  background: var(--ink);
  color: var(--canvas);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  pointer-events: auto;
  animation: toast-in var(--t-med) var(--ease);
}
.toast-passive { pointer-events: none; }
.toast-text { flex: 1; min-width: 0; padding: var(--s1) 0; }
.toast .icon { width: 18px; height: 18px; }
.toast-error .icon { color: #ff9b92; }
.toast-ok .icon { color: #7fe0ae; }
.toast-action {
  flex: none;
  min-height: 36px;
  padding: 0 var(--s3);
  border: 0;
  border-radius: var(--r-md);
  background: rgb(255 255 255 / 0.12);
  color: inherit;
  font-weight: var(--fw-bold);
}
:root[data-theme="dark"] .toast-action { background: rgb(0 0 0 / 0.1); }
.toast-close { color: inherit; opacity: 0.7; }
.toast-leave { animation: toast-out var(--t-med) var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* --------------------------------------------------------- file visuals */

.thumb {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  color: var(--ink-2);
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-ext {
  position: absolute;
  inset: auto 3px 3px;
  font-size: 9px;
  font-weight: var(--fw-bold);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  line-height: 1;
}
.thumb-ext + .icon { margin-top: -10px; }
.thumb-pdf { color: #b4302a; background: #fbeceb; }
.thumb-image { color: var(--mode); background: var(--mode-tint); }
.thumb-text { color: var(--ink-2); }
.thumb-link { color: var(--mode); background: var(--mode-tint); }
.thumb-doc { color: #2d5fb8; background: #e8effb; }
:root[data-theme="dark"] .thumb-pdf { color: #ff9b92; background: rgb(255 155 146 / 0.12); }
:root[data-theme="dark"] .thumb-doc { color: #9ab8f5; background: rgb(154 184 245 / 0.12); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .thumb-pdf { color: #ff9b92; background: rgb(255 155 146 / 0.12); }
  :root:not([data-theme="light"]) .thumb-doc { color: #9ab8f5; background: rgb(154 184 245 / 0.12); }
}

.pro-tag {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  border-radius: var(--r-xs);
  background: var(--ink);
  color: var(--canvas);
  font-size: 11px;
  font-weight: var(--fw-bold);
  letter-spacing: 0.03em;
}

.stack { display: grid; gap: var(--s4); }
.stack-sm { display: grid; gap: var(--s2); }
.stack-lg { display: grid; gap: var(--s6); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.cluster-end { justify-content: flex-end; }
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-meta); }
.meta { font-size: var(--fs-meta); color: var(--ink-3); }
.lead { color: var(--ink-2); }

/* "How to fix this" next to an error: opens the matching Help topic. */
.help-link { font-size: var(--fs-meta); font-weight: var(--fw-semibold); white-space: nowrap; }

/* Touch: every control takes a tap of at least 44 px. Small buttons keep their
   look; an invisible margin around them catches the finger. */
@media (pointer: coarse) {
  .segmented-btn { min-height: 44px; }
  .plan-chip, .brand { position: relative; }
  .btn-sm::before, .plan-chip::before, .brand::before { content: ''; position: absolute; }
  .btn-sm::before { inset: -4px; }
  .plan-chip::before { inset: -7px -2px; }
  .brand::before { inset: -8px -4px; }
  .app-footer-inner, .app-footer-links { row-gap: 0; column-gap: var(--s2); }
  .app-footer-links a { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; }
}
