/* ==========================================================================
   Messaging Platform SDK — Shared UI components
   Requires design-tokens.css. Used by the landing page, developer portal
   and admin console.
   ========================================================================== */

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: var(--lh-body);
    color: var(--text-body);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    margin: 0;
    color: var(--text);
    line-height: var(--lh-tight);
    font-weight: 700;
    letter-spacing: -0.015em;
}

p { margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .mono { font-family: var(--font-mono); }

img, svg { max-width: 100%; }

/* --- Focus -------------------------------------------------------------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: var(--focus-ring);
    border-radius: var(--r-sm);
}

/* --- Utilities ---------------------------------------------------------- */
/* Components below set explicit `display`, which would otherwise beat the
   user-agent rule for [hidden]. */
[hidden] { display: none !important; }

/* Two names for one thing: the landing pages have always written .sr-only and
   sdk-app.css already keys a rule off it, so an app page that loads ui.css but
   not landing.css was rendering its screen-reader text on screen. */
.visually-hidden,
.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: var(--sp-4);
    top: -100px;
    z-index: 200;
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: var(--sp-4); text-decoration: none; }

.num, .tabular { font-variant-numeric: tabular-nums; }

/* --- Icons -------------------------------------------------------------- */
.icon {
    width: 1.25em;
    height: 1.25em;
    flex: none;
    vertical-align: -0.2em;
}
.icon--sm { width: 1em; height: 1em; }
.icon--lg { width: 1.5em; height: 1.5em; }

/* --- Buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 0.625rem 1rem;
    min-height: 40px;
    font-family: inherit;
    font-size: var(--fs-md);
    font-weight: 600;
    line-height: 1;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--dur-fast) var(--ease),
                border-color var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface-3); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
    background: var(--brand);
    border-color: transparent;
    color: #fff;
}
.btn--primary:hover:not(:disabled) { background: var(--brand-hover); }

.btn--gradient {
    background: var(--gradient-brand);
    border-color: transparent;
    color: #fff;
}
.btn--gradient:hover:not(:disabled) { filter: brightness(1.08); }

.btn--ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text-body);
}
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

/* Destructive buttons are outline at rest; solid only inside a confirm modal. */
.btn--danger {
    background: transparent;
    border-color: rgba(248, 113, 113, 0.45);
    color: var(--danger);
}
.btn--danger:hover:not(:disabled) { background: var(--danger-bg); }

.btn--danger-solid {
    background: var(--danger-strong);
    border-color: transparent;
    color: #fff;
}
.btn--danger-solid:hover:not(:disabled) { filter: brightness(1.1); }

.btn--sm { min-height: 32px; padding: 0.375rem 0.625rem; font-size: var(--fs-sm); }
.btn--lg { min-height: 48px; padding: 0.875rem 1.5rem; font-size: var(--fs-base); }

.btn--icon {
    min-height: 32px;
    width: 32px;
    padding: 0;
    border-radius: var(--r-sm);
}
.btn--block { width: 100%; }

/* In-flight state: keeps width, swaps label for a spinner. */
.btn[data-busy="true"] { position: relative; color: transparent !important; pointer-events: none; }
.btn[data-busy="true"]::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 16px; height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: ui-spin 0.7s linear infinite;
}
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* --- Badges ------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding: 0.1875rem 0.5rem;
    font-size: var(--fs-xs);
    font-weight: 600;
    line-height: 1.4;
    border-radius: var(--r-sm);
    border: 1px solid var(--border-strong);
    color: var(--text-body);
    background: var(--surface-2);
    white-space: nowrap;
}
.badge--brand   { background: var(--brand-subtle);  border-color: rgba(99,102,241,.35);  color: var(--brand-ink); }
.badge--success { background: var(--success-bg);    border-color: rgba(52,211,153,.35);  color: var(--success); }
.badge--warning { background: var(--warning-bg);    border-color: rgba(251,191,36,.35);  color: var(--warning); }
.badge--danger  { background: var(--danger-bg);     border-color: rgba(248,113,113,.35); color: var(--danger); }
.badge--info    { background: var(--info-bg);       border-color: rgba(34,211,238,.35);  color: var(--accent-ink); }
.badge--pill    { border-radius: var(--r-pill); padding-inline: 0.625rem; }

/* --- Cards -------------------------------------------------------------- */
.card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-6);
}
.card--interactive { transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.card--interactive:hover { background: var(--surface-2); border-color: var(--border-strong); }

/* --- Forms -------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-4); }

.field__label {
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--text);
}
.field__label .req { color: var(--danger); }
.field__label .opt { color: var(--text-muted); font-weight: 400; }

.field__input,
.field__select,
.field__textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    min-height: 40px;
    font-family: inherit;
    font-size: var(--fs-md);
    color: var(--text);
    background: var(--code-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    transition: border-color var(--dur-fast) var(--ease);
}
.field__textarea { min-height: 88px; resize: vertical; line-height: var(--lh-snug); }
.field__input::placeholder, .field__textarea::placeholder { color: var(--text-faint); }
.field__input:hover, .field__select:hover, .field__textarea:hover { border-color: var(--border-strong); }
.field__input:disabled { opacity: 0.6; cursor: not-allowed; }

.field__hint  { font-size: var(--fs-sm); color: var(--text-muted); }
.field__error { font-size: var(--fs-sm); color: var(--danger); display: none; }

.field[data-state="invalid"] .field__input,
.field[data-state="invalid"] .field__select,
.field[data-state="invalid"] .field__textarea { border-color: var(--danger); }
.field[data-state="invalid"] .field__error { display: block; }

.field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
    gap: var(--sp-4);
}

/* --- Alerts ------------------------------------------------------------- */
.alert {
    display: flex;
    gap: var(--sp-3);
    align-items: flex-start;
    padding: var(--sp-3) var(--sp-4);
    border: 1px solid var(--border-strong);
    border-left-width: 3px;
    border-radius: var(--r-md);
    background: var(--surface-2);
    font-size: var(--fs-md);
    color: var(--text-body);
}
.alert .icon { color: var(--text-muted); margin-top: 0.15em; }
.alert--info    { border-left-color: var(--info);    background: var(--info-bg); }
.alert--info .icon { color: var(--accent-ink); }
.alert--success { border-left-color: var(--success); background: var(--success-bg); }
.alert--success .icon { color: var(--success); }
.alert--warning { border-left-color: var(--warning); background: var(--warning-bg); }
.alert--warning .icon { color: var(--warning); }
.alert--danger  { border-left-color: var(--danger);  background: var(--danger-bg); }
.alert--danger .icon { color: var(--danger); }

/* --- Tables ------------------------------------------------------------- */
.table-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
}
/* Horizontal scroll lives here so wide tables never clip. */
.table-card__scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }

.table th {
    position: sticky;
    top: 0;
    z-index: 1;
    text-align: left;
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--surface-3);
    padding: var(--sp-3) var(--sp-4);
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}
.table td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    color: var(--text-body);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }

/* Dense variant — admin tables. */
.table--dense { font-size: var(--fs-sm); }
.table--dense th { padding: var(--sp-2) var(--sp-3); }
.table--dense td { padding: var(--sp-2) var(--sp-3); line-height: 1.35; }

.table__sort {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    cursor: pointer;
}
.table__sort:hover { color: var(--text); }
.table__sort .icon { opacity: 0; transition: opacity var(--dur-fast); }
.table__sort:hover .icon { opacity: 0.5; }
[aria-sort] .table__sort .icon { opacity: 1; color: var(--brand-ink); }
[aria-sort="ascending"] .table__sort .icon { transform: rotate(180deg); }

.table .cell-actions { display: flex; gap: var(--sp-1); justify-content: flex-end; }
.table .cell-num { text-align: right; font-variant-numeric: tabular-nums; }

.state-cell { padding: var(--sp-12) var(--sp-4) !important; text-align: center; }
.state-cell .state-title { color: var(--text); font-weight: 600; margin-bottom: var(--sp-1); }
.state-cell .state-body  { color: var(--text-muted); font-size: var(--fs-md); margin-bottom: var(--sp-4); }
.state-cell .icon        { color: var(--text-faint); width: 28px; height: 28px; margin-bottom: var(--sp-3); }
.state-cell--error .icon { color: var(--danger); }

.table-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--border);
    background: var(--surface-1);
    font-size: var(--fs-sm);
    color: var(--text-muted);
}
.pager { display: flex; align-items: center; gap: var(--sp-3); }

/* --- Skeletons ---------------------------------------------------------- */
.skeleton {
    display: block;
    height: 0.85em;
    min-width: 2.5rem;
    border-radius: var(--r-sm);
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
    background-size: 400% 100%;
    animation: ui-shimmer 1.4s ease infinite;
}
@keyframes ui-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; background: var(--surface-2); } }

/* --- Toasts ------------------------------------------------------------- */
.toast-region {
    position: fixed;
    right: var(--sp-4);
    bottom: var(--sp-4);
    z-index: 1200;
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    width: min(380px, calc(100vw - 2 * var(--sp-4)));
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    border-left: 3px solid var(--text-muted);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-2);
    color: var(--text);
    font-size: var(--fs-md);
    pointer-events: auto;
    animation: ui-toast-in var(--dur) var(--ease);
}
@keyframes ui-toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast__msg { flex: 1; margin: 0; line-height: var(--lh-snug); overflow-wrap: anywhere; }
.toast__close {
    flex: none;
    background: none;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.toast__close:hover { color: var(--text); }
.toast--success { border-left-color: var(--success); }
.toast--success .toast__icon { color: var(--success); }
.toast--error   { border-left-color: var(--danger); }
.toast--error .toast__icon { color: var(--danger); }
.toast--warning { border-left-color: var(--warning); }
.toast--warning .toast__icon { color: var(--warning); }
.toast--info    { border-left-color: var(--info); }
.toast--info .toast__icon { color: var(--accent-ink); }

/* --- Modals ------------------------------------------------------------- */
.modal[hidden] { display: none !important; }
.modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
}
.modal__scrim { position: absolute; inset: 0; background: var(--overlay); }
.modal__card {
    position: relative;
    width: min(520px, 100%);
    max-height: calc(100vh - 2 * var(--sp-8));
    display: flex;
    flex-direction: column;
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-3);
    animation: ui-modal-in var(--dur) var(--ease);
}
@keyframes ui-modal-in { from { opacity: 0; transform: translateY(10px) scale(0.99); } }
.modal__card--wide   { width: min(760px, 100%); }
.modal__card--danger { border-color: rgba(248, 113, 113, 0.4); }

.modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 1px solid var(--border);
}
.modal__title { font-size: var(--fs-xl); }
.modal__close {
    flex: none;
    background: none;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--sp-1);
    line-height: 1;
}
.modal__close:hover { color: var(--text); }
.modal__body { padding: var(--sp-5) var(--sp-6); overflow-y: auto; }
.modal__body > p { color: var(--text-body); }
.modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-6);
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
body.modal-open { overflow: hidden; }

/* --- Secret / credential display ---------------------------------------- */
.secret-box {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-3);
    background: var(--code-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    margin-bottom: var(--sp-3);
}
.secret-box code {
    flex: 1;
    font-size: var(--fs-sm);
    color: var(--text);
    overflow-wrap: anywhere;
    user-select: all;
}
.secret-box code[data-masked="true"] { color: var(--text-faint); letter-spacing: 0.1em; }

/* --- Meters ------------------------------------------------------------- */
.meter { display: flex; flex-direction: column; gap: var(--sp-2); }
.meter__track {
    height: 8px;
    background: var(--surface-3);
    border-radius: var(--r-pill);
    overflow: hidden;
}
.meter__fill {
    height: 100%;
    width: 0;
    background: var(--brand);
    border-radius: inherit;
    transition: width var(--dur) var(--ease);
}
.meter[data-level="warning"] .meter__fill { background: var(--warning); }
.meter[data-level="danger"]  .meter__fill { background: var(--danger); }
.meter[data-level="unknown"] .meter__fill { background: repeating-linear-gradient(45deg, var(--surface-3), var(--surface-3) 6px, var(--border-strong) 6px, var(--border-strong) 12px); width: 100%; }
.meter__text { font-size: var(--fs-sm); color: var(--text-muted); }
.meter__text strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* --- Bar chart ---------------------------------------------------------- */
.chart { margin: 0; }
.chart__bars {
    display: flex;
    align-items: flex-end;
    gap: var(--sp-2);
    height: 160px;
    padding-top: var(--sp-4);
}
.chart__col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-2);
    height: 100%;
    position: relative;
    cursor: default;
}
.chart__track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.chart__bar {
    width: 100%;
    max-width: 56px;
    height: var(--h, 0%);
    min-height: 2px;
    background: var(--brand);
    border-radius: var(--r-sm) var(--r-sm) 0 0;
    transition: background var(--dur-fast) var(--ease);
}
.chart__col:hover .chart__bar,
.chart__col:focus-visible .chart__bar { background: var(--brand-hover); }
.chart__label { font-size: var(--fs-xs); color: var(--text-muted); }
.chart__tip {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    padding: var(--sp-1) var(--sp-2);
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    font-size: var(--fs-xs);
    color: var(--text);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-fast) var(--ease);
}
.chart__col:hover .chart__tip,
.chart__col:focus-visible .chart__tip { opacity: 1; }

/* --- Console app shell (developer portal + admin) ------------------------ */
.shell { display: flex; min-height: 100vh; }

.shell__sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    width: 248px;
    flex: none;
    display: flex;
    flex-direction: column;
    background: var(--surface-1);
    border-right: 1px solid var(--border);
}
.shell__brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-5) var(--sp-5);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-weight: 700;
}
.shell__brand:hover { text-decoration: none; }
.shell__brand .logo-mark { width: 28px; height: 28px; flex: none; }

.shell__nav { flex: 1; overflow-y: auto; padding: var(--sp-3); display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3);
    border-radius: var(--r-md);
    color: var(--text-body);
    font-size: var(--fs-md);
    font-weight: 500;
    text-decoration: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item .icon { color: var(--text-muted); }
.nav-item[aria-current="page"] {
    background: var(--brand-subtle);
    color: var(--text);
    font-weight: 600;
    box-shadow: inset 2px 0 0 var(--brand);
}
.nav-item[aria-current="page"] .icon { color: var(--brand-ink); }
.nav-item__badge { margin-left: auto; }

.shell__sidebar-footer { padding: var(--sp-3); border-top: 1px solid var(--border); }
.shell__identity { padding: var(--sp-3); font-size: var(--fs-sm); }
.shell__identity .email { display: block; color: var(--text); font-weight: 600; overflow-wrap: anywhere; }
.shell__identity .meta  { color: var(--text-muted); }

.shell__main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.shell__header {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-4) var(--sp-6);
    background: rgba(11, 17, 32, 0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
.shell__header h1 { font-size: var(--fs-xl); }
.shell__header-actions { display: flex; align-items: center; gap: var(--sp-3); }
.shell__content { padding: var(--sp-6); flex: 1; }

.shell__menu-btn { display: none; }

.section[hidden] { display: none !important; }
.section > * + * { margin-top: var(--sp-6); }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
}
.section-header h2 { font-size: var(--fs-xl); }
/* Keeps the toolbar right-aligned even when the heading is visually hidden
   because the shell header already shows the section title. */
.section-header .toolbar { margin-left: auto; }
.toolbar { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.toolbar .field { margin: 0; }
.search-input { min-width: 220px; }

/* --- Stat cards --------------------------------------------------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(232px, 100%), 1fr));
    gap: var(--sp-4);
}
.stat-card {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-5);
}
.stat-card__icon {
    display: grid;
    place-items: center;
    width: 40px; height: 40px;
    flex: none;
    border-radius: var(--r-md);
    background: var(--surface-2);
    color: var(--brand-ink);
}
.stat-card__value {
    font-size: var(--fs-2xl);
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.stat-card__label { font-size: var(--fs-sm); color: var(--text-muted); }
.stat-card[data-state="loading"] .stat-card__value { color: transparent; }
.stat-card[data-state="error"]   .stat-card__value { color: var(--text-faint); }
.stat-card--alert { border-color: rgba(251, 191, 36, 0.4); }
.stat-card--alert .stat-card__icon { color: var(--warning); background: var(--warning-bg); }

/* --- Responsive shell --------------------------------------------------- */
@media (max-width: 1023px) {
    .shell__sidebar {
        position: fixed;
        z-index: 60;
        left: 0; top: 0;
        transform: translateX(-100%);
        transition: transform var(--dur) var(--ease);
        box-shadow: var(--shadow-3);
    }
    .shell[data-nav-open="true"] .shell__sidebar { transform: none; }
    .shell__scrim {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 55;
        background: var(--overlay);
    }
    .shell[data-nav-open="true"] .shell__scrim { display: block; }
    .shell__menu-btn { display: inline-flex; }
    .shell__content { padding: var(--sp-4); }
    .shell__header { padding: var(--sp-3) var(--sp-4); }
}

@media (max-width: 640px) {
    .modal { padding: 0; align-items: flex-end; }
    .modal__card { width: 100%; max-height: 92vh; border-radius: var(--r-xl) var(--r-xl) 0 0; }
    /* Top, not bottom: the bottom of a phone screen is where the message box
       and the send button are, and a toast landing on them intercepts the tap.
       Clear of the header for the same reason — a notice that covers the
       controls it is telling you about is worse than no notice. */
    .toast-region { left: var(--sp-3); right: var(--sp-3); width: auto; top: 72px; bottom: auto; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); }
    .search-input { min-width: 0; width: 100%; }
    .toolbar { width: 100%; }
}

/* --- Bulk selection bar -------------------------------------------------- */
.bulk-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
    padding: var(--sp-3) var(--sp-4);
    background: var(--brand-subtle);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--text);
}
.bulk-bar__actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

.table .cell-check { width: 40px; padding-right: 0; }
.table .cell-check input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--brand); }
.table tr[data-selected="true"] { background: var(--brand-subtle); }

/* Compact meter used inside a table cell. */
.quota-cell { display: flex; align-items: center; gap: var(--sp-3); min-width: 12rem; }
/* The bar needs a floor or the nowrap label squeezes it out of existence. */
.quota-cell .meter { min-width: 3.5rem; }
.quota-cell .meter__track { height: 6px; }
.quota-cell .quota-value {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}


/* --------------------------------------------------------------------------
   Touch targets.

   A finger is not a pointer. On a coarse pointer every real control gets at
   least 44px in the direction it is short — which mostly means the icon-only
   buttons, since text buttons already clear it from their padding.

   Deliberately NOT applied to inline text links inside prose or cards: the
   card itself is the tap target (a full-size .entry-hit sits over it), and
   stretching "Open demo" to 44px would make the card look broken to fix a
   target that is already 300px wide.
   -------------------------------------------------------------------------- */
@media (pointer: coarse) {
    .btn--icon,
    .nav-toggle,
    .modal__close {
        min-width: 44px;
        min-height: 44px;
    }

    .btn { min-height: 44px; }

    /* The wordmark is also the way home from every page. */
    .brand { min-height: 44px; display: inline-flex; align-items: center; }

    /* The account chip is an <a>, not a .btn, so every rule above missed it
       and it stayed a ~24px target -- the height of the initial circle inside
       it. It is the only way to reach the platform account from most pages. */
    .mp-chip { min-height: 44px; }
}

/* Save indicator — used by the apps with durable boards.
   Bottom-left so it never lands under a toast (bottom-centre) or a share
   dialog, and quiet enough to ignore until it says something is wrong. */
.save-indicator {
    position: fixed;
    inset-block-end: var(--sp-4, 1rem);
    inset-inline-start: var(--sp-4, 1rem);
    z-index: 50;
    padding: var(--sp-1, .25rem) var(--sp-3, .75rem);
    border-radius: var(--r-pill, 999px);
    background: var(--surface-2, #16203a);
    color: var(--text-muted, #8a97ab);
    font-size: var(--fs-xs, .75rem);
    border: 1px solid var(--border, rgba(148, 163, 184, .14));
    pointer-events: none;
}

.save-indicator--saved { color: var(--success, #34d399); }
.save-indicator--saving { color: var(--text-body, #c4cede); }
.save-indicator--failed {
    color: var(--danger, #f87171);
    border-color: var(--danger, #f87171);
    pointer-events: auto;
}


/* A code block is the one element whose content cannot wrap, so it scrolls
   inside itself. Without this a long line widens the whole document and the
   page scrolls sideways on a phone. */
pre {
    max-width: 100%;
    overflow-x: auto;
}
