/* Reusable components. Built from tokens only; the dashboard, landing and auth pages all use these. */

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); position: relative;
  height: 32px; padding: 0 var(--sp-3); border-radius: var(--r-md); border: 1px solid var(--sb-border-strong);
  background: var(--sb-surface-2); color: var(--sb-text); font-size: var(--fs-sm); font-weight: var(--fw-medium); line-height: 1;
  white-space: nowrap; text-decoration: none; transition: background .15s var(--ease), border-color .15s var(--ease);
}
.btn:hover { background: var(--sb-surface-3); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--sb-brand-fill); border-color: var(--sb-brand-fill); color: var(--sb-on-brand); box-shadow: inset 0 0 0 1px var(--sb-brand-ring); }
.btn-primary:hover { background: var(--sb-brand-fill-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--sb-text-muted); }
.btn-ghost:hover { background: var(--sb-surface-2); color: var(--sb-text); }
.btn-outline { background: transparent; }
.btn-danger { background: transparent; border-color: var(--sb-bad); color: var(--sb-bad); }
.btn-danger:hover, .btn.confirm { background: var(--sb-bad-soft); border-color: var(--sb-bad); color: var(--sb-bad); }
.btn-sm { height: 26px; padding: 0 10px; font-size: var(--fs-xs); border-radius: var(--r-md); }
.btn-lg { height: 38px; padding: 0 var(--sp-4); }
.btn-block { width: 100%; }
.btn-icon { width: 32px; padding: 0; }
.btn-icon.btn-sm { width: 26px; }
.btn svg { flex: none; }
.btn.armed { background: var(--sb-bad-soft); border-color: var(--sb-bad); color: var(--sb-bad); width: auto; padding: 0 10px; }
/* a spinner replaces the label's room while a request from this button is running */
.btn.loading { pointer-events: none; color: transparent; }
.btn.loading > * { opacity: 0; }
.btn.loading::after { content: ""; position: absolute; width: 14px; height: 14px; border: 2px solid var(--sb-text); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-primary.loading::after { border-color: var(--sb-on-brand); border-right-color: transparent; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.btn-row.end { justify-content: flex-end; }
.link-btn { background: none; border: 0; padding: 0; color: var(--sb-brand); font: inherit; cursor: pointer; }
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: var(--sp-4); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.field > .hint, .hint { font-weight: var(--fw-text); font-size: var(--fs-xs); color: var(--sb-text-muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.input {
  width: 100%; height: 32px; padding: 0 var(--sp-3); border-radius: var(--r-md); border: 1px solid var(--sb-border-strong);
  background: var(--sb-surface-1); color: var(--sb-text); font-size: var(--fs-sm); font-weight: var(--fw-text);
}
.input::placeholder { color: var(--sb-text-faint); }
.input:hover { border-color: var(--sb-text-faint); }
.input:focus-visible { outline: none; border-color: var(--sb-brand); box-shadow: 0 0 0 3px var(--sb-brand-ring); }
.input-lg { height: 38px; }
textarea.input { height: auto; padding: var(--sp-2) var(--sp-3); line-height: 1.5; resize: vertical; }
select.input { appearance: none; padding-right: 28px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23989a99' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.input-sm { height: 26px; font-size: var(--fs-xs); }
.input-search { padding-left: 32px; }
.search { position: relative; display: block; }
.search > svg { position: absolute; left: 10px; top: 50%; translate: 0 -50%; color: var(--sb-text-faint); pointer-events: none; }
.check { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); font-weight: var(--fw-text); margin-bottom: var(--sp-4); }
.check input { accent-color: var(--sb-brand-fill); width: 16px; height: 16px; margin: 0; }
.inline-field { display: inline-flex; flex: none; align-items: center; min-height: 32px; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--sb-text-muted); white-space: nowrap; }
.inline-field select.input { width: auto; }
.form-error { color: var(--sb-bad); min-height: 1.4em; font-size: var(--fs-sm); margin: 0 0 var(--sp-3); }
.form-error:empty { display: none; }

/* ---------- surfaces ---------- */
.card { background: var(--sb-surface-1); border: 1px solid var(--sb-border); border-radius: var(--r-lg); padding: var(--sp-5); }
.card-flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--sb-border); }
.card-head h3 { font-size: var(--fs-sm); }
.card-body { padding: var(--sp-5); }
.card-link { display: block; color: inherit; text-decoration: none; transition: border-color .15s var(--ease), background .15s var(--ease); }
.card-link:hover { border-color: var(--sb-border-strong); background: var(--sb-surface-2); text-decoration: none; }
.grid { display: grid; gap: var(--sp-4); }
.grid > *, .card > *, .card-body > * { min-width: 0; } /* long code lines scroll inside their block instead of widening the page */
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px) { .grid-4, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4, .grid-5, .field-row { grid-template-columns: minmax(0, 1fr); } }

.stat { display: grid; gap: 4px; align-content: start; padding: var(--sp-4) var(--sp-5); }
.stat-label { color: var(--sb-text-muted); font-size: var(--fs-xs); font-weight: var(--fw-medium); }
.stat-value { font-family: var(--font-display); font-size: 28px; line-height: 1.2; font-weight: var(--fw-semibold); letter-spacing: -.02em; }
.stat-sub { color: var(--sb-text-muted); font-size: var(--fs-xs); }
.meter { display: block; height: 4px; border-radius: var(--r-pill); background: var(--sb-surface-3); overflow: hidden; margin-top: var(--sp-2); }
.meter > i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--sb-brand); transition: width .3s var(--ease); }
.meter[data-tone="warn"] > i { background: var(--sb-warn); }
.meter[data-tone="bad"] > i { background: var(--sb-bad); }

.banner { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--sb-border); border-radius: var(--r-md); background: var(--sb-surface-1); color: var(--sb-text-muted); font-size: var(--fs-sm); }
.banner[data-tone="ok"] { border-color: var(--sb-ok); background: var(--sb-brand-soft); }
.banner[data-tone="warn"] { border-color: var(--sb-warn); background: var(--sb-warn-soft); }
.banner[data-tone="bad"] { border-color: var(--sb-bad); background: var(--sb-bad-soft); color: var(--sb-text); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 20px; padding: 0 8px; border-radius: var(--r-pill); border: 1px solid var(--sb-border-strong); background: var(--sb-surface-2); color: var(--sb-text-muted); font-size: var(--fs-xs); font-weight: var(--fw-medium); line-height: 1; white-space: nowrap; }
.badge[data-tone="ok"], .badge[data-tone="brand"] { background: var(--sb-brand-soft); border-color: transparent; color: var(--sb-ok); }
.badge[data-tone="warn"] { background: var(--sb-warn-soft); border-color: transparent; color: var(--sb-warn); }
.badge[data-tone="bad"] { background: var(--sb-bad-soft); border-color: transparent; color: var(--sb-bad); }
.badge[data-tone="info"] { background: var(--sb-info-soft); border-color: transparent; color: var(--sb-info); }
button.badge { cursor: pointer; }
button.badge:hover { border-color: var(--sb-text-faint); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.kbd { font-family: var(--font-mono); font-size: var(--fs-xs); padding: 1px 6px; border: 1px solid var(--sb-border-strong); border-radius: var(--r-sm); color: var(--sb-text-muted); background: var(--sb-surface-1); }
.avatar { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--sb-surface-3); color: var(--sb-text); font-size: var(--fs-xs); font-weight: var(--fw-semibold); flex: none; }
.avatar.known { background: var(--sb-brand-soft); color: var(--sb-ok); }

/* ---------- tabs and segmented control ---------- */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--sb-border); margin-bottom: var(--sp-4); overflow-x: auto; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: var(--sp-2) var(--sp-3); color: var(--sb-text-muted); font-size: var(--fs-sm); font-weight: var(--fw-medium); white-space: nowrap; border-radius: 0; }
.tab:hover { color: var(--sb-text); }
.tab[aria-selected="true"] { color: var(--sb-text); border-bottom-color: var(--sb-brand); }
.seg { display: inline-flex; padding: 2px; border: 1px solid var(--sb-border-strong); border-radius: var(--r-md); background: var(--sb-surface-1); }
.seg button { background: none; border: 0; border-radius: 6px; height: 26px; padding: 0 var(--sp-3); font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--sb-text-muted); }
.seg button[aria-selected="true"] { background: var(--sb-surface-3); color: var(--sb-text); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th { height: 40px; text-align: left; padding: 0 var(--sp-4); color: var(--sb-text); font-size: var(--fs-sm); font-weight: var(--fw-medium); border-bottom: 1px solid var(--sb-border-strong); border-right: 1px solid var(--sb-border); white-space: nowrap; background: var(--sb-surface-2); }
.table th .th-hint { margin-left: var(--sp-2); color: var(--sb-text-faint); font-weight: var(--fw-text); }
.table td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--sb-border); border-right: 1px solid var(--sb-border); vertical-align: middle; }
.table th:last-child, .table td:last-child { border-right: 0; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--sb-surface-2); }
.table .cell-name { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.table .cell-text { display: grid; min-width: 0; }
.table .cell-title { font-weight: var(--fw-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 64ch; }
.table .cell-sub { color: var(--sb-text-muted); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 64ch; }
.table .cell-actions { text-align: right; white-space: nowrap; }
.table .cell-actions > * + * { margin-left: var(--sp-1); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-toolbar { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; padding: var(--sp-2) var(--sp-4); min-height: 52px; border-bottom: 1px solid var(--sb-border-strong); background: var(--sb-surface-2); }
.table-toolbar .search { width: 240px; max-width: 100%; }
.table-toolbar select.input { width: auto; }
.table-toolbar .input, .table-toolbar .search .input { height: 32px; font-size: var(--fs-sm); } /* one height for everything in the bar */
.tile { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r-md); background: var(--sb-surface-3); color: var(--sb-text-muted); font-family: var(--font-mono); font-size: 10px; font-weight: var(--fw-semibold); flex: none; }
.life { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--sb-text-muted); white-space: nowrap; }
.life i { width: 6px; height: 6px; border-radius: 50%; background: var(--sb-ok); }
.life[data-tone="mid"] i { background: var(--sb-warn); }
.life[data-tone="late"] i { background: var(--sb-bad); }
.only-sm { display: none; }
.wrap-actions { display: flex; flex-wrap: wrap; gap: var(--sp-1); justify-content: flex-end; }
/* Column sizing: short fixed-content columns shrink to their content, the Access column keeps its full
   description on one line, and the first column (the name) takes whatever is left. */
.table th.col-narrow, .table td.col-narrow { width: 1%; white-space: nowrap; }
.table td.col-access { min-width: 12rem; }
.table th.col-narrow, .table td.col-narrow { padding-inline: var(--sp-3); }
.table td.col-access .cell-sub { max-width: none; overflow: visible; text-overflow: clip; white-space: nowrap; }
@media (min-width: 721px) { .wrap-actions { flex-wrap: nowrap; } }
@media (max-width: 720px) { .only-sm { display: inline; } .hide-sm { display: none; } .table th, .table td { padding: var(--sp-3) var(--sp-2); } .table .cell-title, .table .cell-sub { max-width: 22ch; } }

/* ---------- states ---------- */
.state { display: grid; justify-items: center; gap: var(--sp-2); padding: var(--sp-7) var(--sp-4); text-align: center; color: var(--sb-text-muted); font-size: var(--fs-sm); }
.state > svg { color: var(--sb-text-faint); margin-bottom: var(--sp-1); }
.state strong { color: var(--sb-text); font-family: var(--font-display); font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.state p { margin: 0; max-width: 46ch; }
.state .btn { margin-top: var(--sp-3); }
.state-loading { display: flex; align-items: center; justify-content: center; gap: var(--sp-3); padding: var(--sp-7) 0; color: var(--sb-text-muted); font-size: var(--fs-sm); }
.state-error { color: var(--sb-bad); }
.state-error strong { color: var(--sb-bad); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }
.spin { display: inline-block; width: 1em; height: 1em; flex: none; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -.15em; }
.spin.lg { width: 22px; height: 22px; border-width: 3px; }
#netbar { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 80; overflow: hidden; opacity: 0; transition: opacity .15s; pointer-events: none; }
#netbar.on { opacity: 1; }
#netbar i { display: block; width: 30%; height: 100%; background: var(--sb-brand); animation: slide 1.1s ease-in-out infinite; }
.boot { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; gap: var(--sp-3); background: var(--sb-bg); color: var(--sb-text-muted); font-size: var(--fs-sm); }

/* ---------- code ---------- */
.codeblock { position: relative; border: 1px solid var(--sb-border); border-radius: var(--r-md); background: var(--sb-surface-1); }
.codeblock pre { margin: 0; padding: var(--sp-3) var(--sp-4); padding-right: 64px; overflow-x: auto; font: 13px/1.6 var(--font-mono); color: var(--sb-text); white-space: pre; }
.codeblock .btn { position: absolute; top: var(--sp-2); right: var(--sp-2); }
.codeblock .c { color: var(--sb-text-faint); }
.codeblock .k, .cmd .v { color: var(--sb-brand); }
.codeblock .s { color: var(--sb-text-muted); }
.codeblock-label { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); margin: 0 0 6px; font-size: var(--fs-xs); color: var(--sb-text-muted); font-weight: var(--fw-medium); }

/* ---------- dialog, menu, toast ---------- */
dialog { border: 1px solid var(--sb-border-strong); border-radius: var(--r-lg); background: var(--sb-surface-1); color: var(--sb-text); padding: 0; width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 32px); font-size: var(--fs-sm); }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: var(--sb-overlay); }
dialog.wide { width: min(640px, calc(100vw - 32px)); }
.dlg-head { padding: var(--sp-5) var(--sp-5) var(--sp-3); }
.dlg-head h3 { font-size: var(--fs-lg); }
.dlg-head p { margin: 4px 0 0; color: var(--sb-text-muted); overflow-wrap: anywhere; }
.dlg-body { padding: var(--sp-2) var(--sp-5) var(--sp-4); overflow-y: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--sb-border); background: var(--sb-surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.menu { position: absolute; z-index: 40; min-width: 220px; padding: var(--sp-1); border: 1px solid var(--sb-border-strong); border-radius: var(--r-md); background: var(--sb-surface-1); box-shadow: 0 8px 24px rgb(0 0 0 / .25); }
.menu-head { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--sb-border); margin-bottom: var(--sp-1); }
.menu-head strong, .menu-head span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-head span { color: var(--sb-text-muted); font-size: var(--fs-xs); }
.menu-item { display: flex; align-items: center; gap: var(--sp-2); width: 100%; padding: 0 var(--sp-3); height: 30px; border: 0; border-radius: var(--r-sm); background: none; color: var(--sb-text); text-align: left; font-size: var(--fs-sm); text-decoration: none; }
.menu-item:hover { background: var(--sb-surface-3); text-decoration: none; }
/* snackbar: always a dark pill, so it reads the same on a light or dark page */
#snackbar { position: fixed; left: 50%; bottom: var(--sp-5); translate: -50% 0; z-index: 90; display: grid; justify-items: center; max-width: calc(100vw - 32px); pointer-events: none; }
.snack { display: inline-flex; align-items: center; gap: var(--sp-2); max-width: 100%; height: 36px; padding: 0 var(--sp-4) 0 var(--sp-3); border-radius: var(--r-pill); border: 1px solid rgb(255 255 255 / .1); background: #1f2321; color: #edefee; font-size: var(--fs-sm); font-weight: var(--fw-medium); box-shadow: 0 8px 24px rgb(0 0 0 / .35); animation: snack-in .18s var(--ease); }
.snack span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snack-dot { width: 8px; height: 8px; border-radius: 50%; background: #3ecf8e; flex: none; }
.snack.bad .snack-dot { background: #ff6369; }
.snack.out { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@keyframes snack-in { from { opacity: 0; transform: translateY(8px); } }
@media (max-width: 768px) { #snackbar { bottom: 72px; } } /* clears the Recent uploads pill */
@media (prefers-reduced-motion: reduce) { .snack, .snack.out { animation: none; transition: none; } }
.keybox { padding: var(--sp-3); border: 1px dashed var(--sb-border-strong); border-radius: var(--r-md); background: var(--sb-surface-2); overflow-wrap: anywhere; margin: var(--sp-3) 0; }
.keybox code { background: none; border: 0; padding: 0; font-size: 13px; user-select: all; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.checks li { display: flex; gap: var(--sp-2); align-items: center; color: var(--sb-text-muted); }
.checks svg { color: var(--sb-brand); flex: none; }
