/* ======================================================================
   Admin screens design system (Links, Allowed domains, Tokens, Users).
   Builds on the tokens and components in app.css.
   ====================================================================== */
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.i.sm { width: 15px; height: 15px; }

/* Page header: title + one-line explanation, actions on the right. */
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.section-head h1 { margin: 0; font-size: 1.5rem; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }
.section-head .actions { display: flex; gap: 8px; align-items: center; }

/* Small counters under the header, e.g. "3 admins · 1 viewer". */
.stat-strip { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 16px; }
.stat { display: inline-flex; align-items: baseline; gap: 6px; padding: 5px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .85rem; color: var(--muted); }
.stat strong { font-size: .95rem; font-variant-numeric: tabular-nums; color: var(--text); }

/* A form panel with an icon heading. */
.panel-title { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.panel-title h2 { margin: 0; font-size: 1.05rem; }
.panel-title p { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }
.icon-bubble {
    --tone: var(--accent);
    display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
    color: var(--tone); background: color-mix(in srgb, var(--tone) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--tone) 28%, transparent);
}
.icon-bubble.sm { width: 32px; height: 32px; border-radius: 9px; }
.icon-bubble.muted { --tone: var(--muted); }
.icon-bubble.good { --tone: var(--success); }
.icon-bubble.bad { --tone: var(--danger); }

.field-row { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: end; }
.field { display: grid; gap: 6px; font-size: .85rem; font-weight: 600; min-width: 0; }
.field.grow { flex: 1 1 240px; }
.field .muted { font-weight: 400; }
.input-icon { position: relative; }
.input-icon > .i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > input { padding-left: 38px !important; }
.input-with-button { display: flex; gap: 6px; }
.input-with-button input { flex: 1; min-width: 0; }
.form-note { margin: 12px 0 0; color: var(--muted); font-size: .85rem; line-height: 1.5; }

/* Toggle switch: a checkbox styled as a switch. */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; font-size: .9rem; user-select: none; }
.switch input { appearance: none; -webkit-appearance: none; width: 38px; height: 22px; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; transition: background-color .2s; margin: 0; flex-shrink: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s cubic-bezier(.3, 1.4, .5, 1); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled { opacity: .5; cursor: default; }
.switch .sub { font-weight: 400; }

/* Segmented control: radio buttons as one pill group. */
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.segmented label { position: relative; display: block; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; width: 100%; height: 100%; }
.segmented span { display: block; padding: 8px 14px; border-radius: 7px; font-size: .875rem; font-weight: 600; color: var(--muted); transition: background-color .15s, color .15s; white-space: nowrap; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.segmented input:disabled { cursor: default; }
.segmented input:disabled + span { opacity: .45; }
.segmented.sm span { padding: 4px 10px; font-size: .8rem; }

/* Status pill with a coloured dot. */
.status { --tone: var(--muted); display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; color: var(--tone); background: color-mix(in srgb, var(--tone) 13%, transparent); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.good { --tone: var(--success); }
.status.bad { --tone: var(--danger); }
.status.warn { --tone: var(--accent); }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; font-size: .76rem; font-weight: 600; background: var(--bg); border: 1px solid var(--border); white-space: nowrap; color: var(--muted); }
.tag.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); background: var(--accent-soft); }
.tag.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: var(--danger-soft); }
.tag.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 500; }

/* Ghost icon buttons for row actions. */
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; transition: background-color .15s, color .15s, border-color .15s; flex-shrink: 0; text-decoration: none; }
.icon-btn:hover:not(:disabled) { background: var(--bg); border-color: var(--border); color: var(--text); }
.icon-btn.danger:hover:not(:disabled) { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: var(--danger-soft); }
.icon-btn.good:hover:not(:disabled) { color: var(--success); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn.sm { width: 28px; height: 28px; border-radius: 7px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; align-items: center; }

/* Roomy list rows: icon | main (title + meta) | side (status, actions). */
.list-card { padding: 6px 20px; }
.item-list { list-style: none; margin: 0; padding: 0; }
.item { display: grid; grid-template-columns: auto 1fr auto; gap: 8px 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent); }
.item:last-child { border-bottom: 0; }
.item.dim > .avatar, .item.dim > .icon-bubble, .item.dim > .item-main { opacity: .55; }
.item-main { min-width: 0; display: grid; gap: 5px; }
.item-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-weight: 700; overflow-wrap: anywhere; }
.item-title .mono { font-weight: 600; }
.item-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: .82rem; }
.item-meta > span { display: inline-flex; align-items: center; gap: 5px; }
.item-side { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
.list-foot { margin: 0; padding: 12px 0 10px; border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; line-height: 1.5; }

/* Inline expansion under a row (edit form, confirmation). */
.inline-panel { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 12px 14px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); animation: bulk-in .2s ease-out; }
.inline-panel.danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); background: color-mix(in srgb, var(--danger-soft) 70%, var(--bg)); }
.inline-panel.warn { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: color-mix(in srgb, var(--accent-soft) 60%, var(--bg)); }
.inline-panel .spacer { flex: 1; }
.inline-panel .grow { flex: 1 1 220px; min-width: 0; }
.inline-panel input[type=text], .inline-panel input[type=password] { padding: 8px 12px; }

/* Avatar with initials, coloured per name (--h set inline). */
.avatar { --h: 20; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; font-weight: 700; font-size: .85rem; letter-spacing: .02em; color: hsl(var(--h) 65% 34%); background: hsl(var(--h) 80% 90%); }
@media (prefers-color-scheme: dark) { .avatar { color: hsl(var(--h) 80% 80%); background: hsl(var(--h) 40% 26%); } }
.avatar.sm { width: 22px; height: 22px; font-size: .58rem; }

.empty-state { display: grid; justify-items: center; gap: 6px; padding: 36px 16px 28px; text-align: center; }
.empty-state .icon-bubble { width: 48px; height: 48px; border-radius: 14px; margin-bottom: 6px; }
.empty-state .i { width: 22px; height: 22px; }

.callout { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; margin: 0 0 16px; font-size: .9rem; line-height: 1.5; border: 1px solid var(--border); background: var(--surface); }
.callout.danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); background: var(--danger-soft); }
.callout.danger > .i { color: var(--danger); margin-top: 2px; }

details.help { margin: 0 0 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
details.help summary { cursor: pointer; padding: 10px 14px; font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: 8px; list-style: none; }
details.help summary::-webkit-details-marker { display: none; }
details.help summary::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform .2s; }
details.help[open] summary::after { transform: rotate(180deg); }
details.help > div { padding: 0 14px 12px 40px; color: var(--muted); font-size: .875rem; line-height: 1.55; }
details.help > div p { margin: 0 0 6px; }

/* Links table. */
.code-pill { display: inline-flex; align-items: center; gap: 2px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 600; }
.code-pill a { padding: 3px 8px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.code-pill a:hover { text-decoration: underline; }
.dest { display: grid; min-width: 0; max-width: 340px; }
.dest strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dest span { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { display: block; color: var(--muted); font-size: .78rem; font-weight: 400; }
.num { font-variant-numeric: tabular-nums; font-weight: 700; }
.links-table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.links-table td { padding-top: 12px; padding-bottom: 12px; }
.links-table tbody tr:not(.confirm-row):hover td { background: color-mix(in srgb, var(--bg) 55%, transparent); }
.links-table tr.confirm-row td { padding-top: 0; }
.links-table tr.has-confirm td { border-bottom: 0; }

/* The one-time token secret. */
.secret-card { display: grid; gap: 10px; padding: 16px; margin-top: 16px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--success) 45%, var(--border)); background: color-mix(in srgb, var(--success) 9%, var(--surface)); }
.secret-card header { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.secret-value { display: flex; gap: 8px; align-items: center; }
.secret-value code { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px dashed var(--border); font-size: .9rem; overflow-wrap: anywhere; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ---------- Settings ---------- */
.account-card { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 18px 24px; }
.account-main { flex: 1 1 200px; min-width: 0; display: grid; gap: 3px; }
.account-main strong { font-size: 1.1rem; overflow-wrap: anywhere; }
.account-main .chips { margin-top: 3px; }
.avatar.lg { width: 52px; height: 52px; font-size: 1.05rem; }
.panel-title h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-title h2 .tag { font-size: .7rem; }

/* A number with its unit attached: [ 30 | days ]. */
.unit-input { display: inline-flex; align-items: stretch; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.unit-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.unit-input input[type=number] { border: 0; border-radius: 0; background: transparent; width: 92px; padding: 8px 10px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.unit-input input[type=number]:focus { outline: none; }
.unit-input > span { display: grid; place-items: center; padding: 0 10px; min-width: 88px; font-size: .8rem; font-weight: 600; color: var(--muted); background: var(--surface); border-left: 1px solid var(--border); white-space: nowrap; }
.unit-input.lg input[type=number] { width: 120px; font-size: 1.6rem; padding: 8px 12px; }
.unit-input.lg > span { font-size: .9rem; }
.unit-input:has(input:disabled) { opacity: .6; }

.lifetime-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 14px; margin-bottom: 16px; }
.lifetime-tile { display: grid; gap: 12px; align-content: start; padding: 16px; border-radius: 12px; border: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 45%, var(--surface)); }
.lifetime-tile .unit-input { justify-self: start; }
.lifetime-head { display: flex; gap: 10px; align-items: center; }
.lifetime-head strong { display: block; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.preset { padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer; transition: background-color .15s, color .15s, border-color .15s; }
.preset:hover:not(:disabled) { color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.preset.on { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.preset:disabled { opacity: .5; cursor: default; }
.preset:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Label + explanation on the left, control on the right. */
.setting-list { display: grid; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; padding: 14px 16px; border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent); transition: background-color .15s; position: relative; }
.setting-row:last-child { border-bottom: 0; }
.setting-row.clickable { cursor: pointer; }
.setting-row.clickable:hover { background: color-mix(in srgb, var(--bg) 55%, transparent); }
.setting-row.edited { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.setting-row.edited::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.setting-text { display: grid; gap: 3px; min-width: 0; flex: 1 1 240px; }
.setting-text strong { font-size: .92rem; }
.setting-text .sub { font-size: .8rem; line-height: 1.45; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.setting-text .tag { font-size: .7rem; padding: 0 6px; }
.setting-control { display: inline-flex; align-items: center; gap: 6px; }

.system-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 18px; }
.system-group h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

/* Hint on the left, buttons on the right. The System card's bar sticks to the bottom while it has unsaved edits. */
.form-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.form-actions > .hint { margin-right: auto; display: inline-flex; align-items: center; gap: 6px; }
.save-bar.dirty { position: sticky; bottom: 12px; z-index: 5; padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border)); border-radius: 12px; background: var(--surface); box-shadow: 0 10px 30px rgba(0,0,0,.18); animation: bulk-in .2s ease-out; }
.save-bar.dirty > .hint { color: var(--text); font-weight: 600; }
.dirty-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); animation: dirty-pulse 1.8s ease-out infinite; }
@keyframes dirty-pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .dirty-dot { animation: none; } }
details.help + .form-actions, .notes + .error, .notes + .form-actions { margin-top: 16px; }

@media (max-width: 640px) {
    .item { grid-template-columns: auto 1fr; }
    .item-side { grid-column: 1 / -1; justify-content: flex-start; flex-wrap: wrap; }
    .system-groups { grid-template-columns: 1fr; }
    .setting-row { flex-wrap: wrap; }
    .account-card .btn { width: 100%; justify-content: center; }
}
