/* Reusable components: cards, buttons, fields, badges, tables, menus, alerts… */

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  min-width: 0;
}
.card-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px 0; }
.card-head > .icon { width: 24px; height: 24px; color: var(--text-2); margin-top: 1px; }
.card-head h2 { font-size: 17px; font-weight: 600; white-space: nowrap; }
.card-head p { margin-top: 2px; color: var(--text-2); font-size: 13.5px; }
.card-head .spacer { flex: 1; }
.card-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.card-body { padding: 14px 18px 18px; }
.card-foot {
  padding: 12px 18px; border-top: 1px solid var(--line); color: var(--text-2); font-size: 13px;
}
.card.danger { background: var(--red-soft); border-color: var(--red-line); }
.card.danger .card-head > .icon { color: var(--red); }
.card.danger h2 { color: var(--red-text); }
.card.danger p { color: var(--red-muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 7px 14px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--card-2); color: var(--text);
  font: 500 13.5px/1.2 var(--font-sans); text-decoration: none; white-space: nowrap;
  cursor: pointer; transition: background-color .15s, border-color .15s, color .15s, filter .15s;
}
.btn:hover { text-decoration: none; }
.btn .icon { width: 18px; height: 18px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary-bg); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--primary-bg-hover); }
.btn-success { background: var(--success-bg); color: var(--on-accent); }
.btn-success:hover:not(:disabled) { background: var(--success-bg-hover); }
.btn-danger { background: var(--red-2); color: var(--on-accent); letter-spacing: .02em; }
.btn-danger:hover:not(:disabled) { filter: brightness(.92); }
.btn-outline { background: var(--sunken); border-color: var(--line-2); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--hover); border-color: var(--line-3); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.btn-muted { background: var(--card-2); border-color: var(--line-2); color: var(--text-2); }
.btn-muted:hover:not(:disabled) { border-color: var(--blue-line); color: var(--text); }
.btn-link {
  min-height: 0; padding: 0; border: 0; background: none; color: var(--blue-text);
}
.btn-link:hover { text-decoration: underline; }
.btn-sm { min-height: 30px; padding: 4px 11px; font-size: 13px; }
.btn-lg { min-height: 46px; padding: 11px 18px; font-size: 15px; font-weight: 600; }
.btn-block { width: 100%; }
.btn-icon { width: 32px; min-height: 32px; padding: 0; background: transparent; color: var(--text-2); }
.btn-icon:hover { background: var(--hover); color: var(--text); }
.btn-icon .icon { width: 20px; height: 20px; }

/* ---------- form fields ---------- */
.stack { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label, .field > label { color: var(--text); font-size: 13.5px; font-weight: 500; }
.field-hint { color: var(--text-3); font-size: 12.5px; }
.field-error { color: var(--red-text); font-size: 12.5px; }
.input {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--input-line); border-radius: var(--radius-sm);
  background: var(--input-bg); color: var(--input-text); font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--blue); box-shadow: var(--focus-ring); }
.input[readonly] { background: var(--sunken); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap > .icon {
  position: absolute; left: 13px; width: 18px; height: 18px; color: var(--text-3);
  pointer-events: none;
}
.input-wrap > .icon ~ .input { padding-left: 40px; }
.input-action {
  position: absolute; right: 6px; display: grid; place-items: center;
  width: 32px; height: 32px; border: 0; border-radius: 6px; background: none; color: var(--text-3);
}
.input-action:hover { color: var(--text); background: var(--hover); }
.input-action .icon { width: 19px; height: 19px; }
.input-wrap:has(.input-action) .input { padding-right: 44px; }
/* password visibility toggle: [data-toggle-password] carries both icons */
[data-toggle-password] .icon-hide { display: none; }
[data-toggle-password][aria-pressed="true"] .icon-show { display: none; }
[data-toggle-password][aria-pressed="true"] .icon-hide { display: inline-block; }

/* ---------- OTP boxes ---------- */
.otp { display: flex; gap: 8px; }
.otp-box {
  width: 42px; height: 46px; min-height: 0; padding: 0; text-align: center;
  border: 1px solid var(--input-line); border-radius: var(--radius-sm);
  background: var(--input-bg); color: var(--input-text); font: 500 18px var(--font-mono);
}
.otp-box:focus { border-color: var(--blue); box-shadow: var(--focus-ring); }
.otp.compact { gap: 6px; }
.otp.compact .otp-box { width: 32px; height: 38px; border-radius: 7px; font-size: 17px; }
.otp.large { gap: 12px; }
.otp.large .otp-box { width: 48px; height: 54px; font-size: 20px; }
.otp-fallback { max-width: 220px; font-family: var(--font-mono); letter-spacing: .2em; }

/* ---------- badges ---------- */
.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}
.dot.ok { background: var(--green); }
.dot.warn { background: var(--amber); }
.dot.off { background: var(--red); }
.dot.info { background: var(--blue); }
.dot.muted { background: var(--text-3); }

.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 3px 13px;
  border-radius: var(--radius-pill); border: 1px solid var(--line-2);
  background: var(--sunken); color: var(--text-2); font-size: 14px; font-weight: 500;
  white-space: nowrap;
}
.pill.live { background: var(--green-soft); border-color: var(--green-line); color: var(--green-text); }
.pill.paper { background: var(--blue-soft); border-color: var(--blue-line); color: var(--blue-text); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 13px; font-weight: 500; line-height: 1.5; white-space: nowrap;
}
.chip.ok { background: var(--green-soft); border-color: var(--green-line); color: var(--green-text); }
.chip.warn { background: var(--amber-soft); border-color: var(--amber-line); color: var(--amber-text); }
.chip.danger { background: var(--red-soft); border-color: var(--red-line); color: var(--red-text); }
.chip.info { background: var(--blue-soft); border-color: var(--blue-line); color: var(--blue-text); }
.chip.muted { background: var(--card-2); border-color: var(--line-2); color: var(--text-2); }

.mode-badge {
  display: inline-block; padding: 2px 9px; border-radius: 6px; border: 1px solid;
  font-size: 12px; font-weight: 600; letter-spacing: .04em;
}
.mode-badge.live { background: var(--green-soft); border-color: var(--green-line); color: var(--green-text); }
.mode-badge.paper { background: var(--blue-soft); border-color: var(--blue-line); color: var(--blue-text); }

/* live status: worker ([data-worker-status]) and WebSocket ([data-state]) */
.status-indicator { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.status-indicator .dot { background: var(--text-3); }
[data-worker-status="active"] .dot, [data-state="ok"] .dot { background: var(--green); }
[data-worker-status="standby"] .dot, [data-state="warn"] .dot { background: var(--amber); }
[data-worker-status="down"] .dot, [data-state="off"] .dot { background: var(--red); }
.status-indicator.tinted[data-worker-status="active"], .status-indicator.tinted[data-state="ok"] { color: var(--green-text); }
.status-indicator.tinted[data-worker-status="standby"], .status-indicator.tinted[data-state="warn"] { color: var(--amber-text); }
.status-indicator.tinted[data-worker-status="down"], .status-indicator.tinted[data-state="off"] { color: var(--red-text); }

.chip[data-worker-status] { background: var(--card-2); border-color: var(--line-2); color: var(--text-2); }
.chip[data-worker-status="active"] { background: var(--green-soft); border-color: var(--green-line); color: var(--green-text); }
.chip[data-worker-status="standby"] { background: var(--amber-soft); border-color: var(--amber-line); color: var(--amber-text); }
.chip[data-worker-status="down"] { background: var(--red-soft); border-color: var(--red-line); color: var(--red-text); }
.status-indicator.unverified { color: var(--text-2); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.card > .table-wrap, .card > .table { margin-top: 14px; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 9px 18px; background: var(--sunken); color: var(--text-2);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: 13px; font-weight: 500; text-align: left; white-space: nowrap;
}
.table td { padding: 10px 18px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--hover); }
.table .num { text-align: right; }
.table .actions-cell { text-align: right; white-space: nowrap; }
.table .chev-cell { width: 48px; padding-left: 4px; text-align: right; color: var(--text-2); }
.table td.chev-cell .icon { width: 20px; height: 20px; }
.table .chev-cell .icon { transition: transform .15s; }
.table tr[data-expand] { cursor: pointer; }
.chev-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; vertical-align: middle;
  border: 0; border-radius: 6px; background: none; color: inherit;
}
.chev-btn:hover { color: var(--text); }
.chev-btn[aria-expanded="true"] .icon { transform: rotate(90deg); }
.table tr.is-open td { background: var(--hover); }
.row-details td { padding: 12px 18px 14px 18px; background: var(--sunken); color: var(--text-2); }
.row-details ul { list-style: none; padding: 0; display: grid; gap: 6px; }
.table .empty-row td { padding: 22px 18px; color: var(--text-2); text-align: center; }
.cell-icon { display: inline-flex; align-items: center; gap: 12px; }

/* ---------- KPI cards ---------- */
.kpi { position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 6px; padding: 16px 18px; }
.kpi-head { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; }
.kpi-head h2 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-head .icon { width: 20px; height: 20px; color: var(--text-2); }
.kpi-head .chev { margin-left: auto; pointer-events: none; }  /* decoration, not a link */
.kpi-value { margin-top: 6px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.kpi-value.green { color: var(--green-text); }
.kpi-sub { color: var(--text-2); font-size: 13px; }
.kpi-sub.green { color: var(--green-text); }
/* value row: the value on the left, the (empty) sparkline filling the rest */
.kpi-main { display: flex; align-items: flex-end; gap: 16px; min-height: 48px; margin-top: 6px; }
.kpi-main .kpi-value { margin-top: 0; }
/* empty sparkline: a flat, faded line until real data exists */
.spark-empty {
  flex: 1; height: 34px; margin-bottom: 8px;
  border-bottom: 2px solid var(--line-3);
  background: linear-gradient(to top, rgb(54 66 90 / 38%), transparent);
  mask-image: linear-gradient(to right, transparent, #000 35%);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 35%);
}

/* ---------- key / value list ---------- */
.kv { display: grid; grid-template-columns: 118px minmax(0, 1fr); row-gap: 6px; column-gap: 12px; font-size: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; min-width: 0; }

/* ---------- timeline (audit) ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item { position: relative; display: flex; gap: 14px; padding: 7px 0; font-size: 13px; }
.timeline-item::after {
  content: ""; position: absolute; left: 5px; top: 24px; bottom: -8px; width: 1px; background: var(--line-2);
}
.timeline-item:last-child::after { display: none; }
.timeline-item > .dot { width: 11px; height: 11px; margin-top: 4px; border: 2px solid var(--card); box-sizing: content-box; margin-left: -2px; }
.timeline-body { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; }

/* ---------- dropdown menu ([data-menu], positioned by ui.js) ---------- */
[data-menu] { position: relative; display: inline-flex; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  min-width: 210px; padding: 6px; display: flex; flex-direction: column; gap: 2px;
  background: var(--card-2); border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: 0 14px 34px rgb(0 0 0 / 45%);
}
.menu.is-fixed { position: fixed; right: auto; }
.menu form { margin: 0; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px;
  border: 0; border-radius: 6px; background: none; color: var(--text);
  font-size: 13.5px; text-align: left; text-decoration: none; white-space: nowrap;
}
.menu-item .icon { width: 18px; height: 18px; color: var(--text-2); }
.menu-item:hover { background: var(--hover); text-decoration: none; }
.menu-item:focus-visible {
  background: var(--hover); text-decoration: none; outline-offset: -2px;
  box-shadow: inset 0 0 0 2px var(--blue);
}
.menu-item.danger, .menu-item.danger .icon { color: var(--red-text); }
.menu-sep { height: 1px; margin: 4px 2px; background: var(--line); }

/* ---------- alerts ---------- */
.alert {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--card-2); color: var(--text); font-size: 13.5px;
}
.alert > .icon { width: 18px; height: 18px; margin-top: 1px; }
.alert.info { background: var(--blue-soft); border-color: var(--blue-line); }
.alert.info > .icon { color: var(--blue-text); }
.alert.error { background: var(--red-soft); border-color: var(--red-line); }
.alert.error > .icon { color: var(--red-text); }
.alert.success { background: var(--green-soft); border-color: var(--green-line); }
.alert.success > .icon { color: var(--green-text); }
.alert.warn { background: var(--amber-soft); border-color: var(--amber-line); }
.alert.warn > .icon { color: var(--amber-text); }

/* ---------- empty state ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 30px 18px; text-align: center; color: var(--text-2);
}
.empty-state > .icon { width: 30px; height: 30px; color: var(--text-3); }
.empty-state h3 { color: var(--text); font-size: 15px; }
.empty-state .btn { margin-top: 6px; }

/* ---------- copy field ---------- */
.copy-field {
  display: flex; align-items: center; gap: 8px; padding: 5px 5px 5px 12px;
  border: 1px solid var(--blue-line); border-radius: var(--radius-sm); background: var(--sunken);
}
.copy-field input, .copy-field code {
  flex: 1; min-width: 0; min-height: 30px; padding: 0; border: 0; background: transparent;
  color: var(--blue-text); font: 400 13px var(--font-mono); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.copy-field input:focus { box-shadow: none; }
@media (max-width: 639.98px) {
  .copy-field input { font-size: 16px; }  /* no iOS zoom on focus */
}

/* ---------- backup codes grid ---------- */
.codes-grid {
  list-style: none; margin: 0; padding: 14px 20px; counter-reset: code;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(5, auto);
  grid-auto-flow: column; gap: 6px 28px;
  background: var(--sunken); border-radius: var(--radius-sm); font: 400 14px var(--font-mono);
}
.codes-grid li { counter-increment: code; display: flex; gap: 14px; }
.codes-grid li::before { content: counter(code) "."; min-width: 3ch; color: var(--text-3); text-align: right; }

/* ---------- numbered steps ---------- */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; display: grid; gap: 18px; }
.steps > li { position: relative; counter-increment: step; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; }
.steps > li::before {
  content: counter(step); display: grid; place-items: center; width: 28px; height: 28px;
  border-radius: 50%; background: var(--blue-soft); color: var(--blue); font-size: 13px; font-weight: 600;
}
.steps > li:not(:last-child)::after {
  content: ""; position: absolute; left: 13.5px; top: 34px; bottom: -14px; width: 1px; background: var(--line-2);
}
.steps h3 { font-size: 14px; font-weight: 600; }
.steps p { color: var(--text-2); font-size: 12.5px; }

/* ---------- switches ---------- */
.toggle {
  position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0;
  border-radius: 13px; background: var(--violet);
}
.toggle::after {
  content: ""; position: absolute; top: 3px; right: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff;
}
.toggle.off { background: #2a3448; }
.toggle.off::after { right: auto; left: 3px; background: #c8d1e0; }
.admin-switch {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px; border-radius: var(--radius); border: 1px solid var(--violet-line);
  background: var(--violet-soft); color: var(--violet-text); font-weight: 500; text-decoration: none;
}
.admin-switch:hover { text-decoration: none; border-color: var(--violet); }
.admin-switch .left { display: flex; align-items: center; gap: 10px; }
.admin-switch .left .icon { width: 20px; height: 20px; color: var(--violet); }
