/* components.css — buttons, inputs, cards, sliders, tables, badges, progress bars */

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform var(--transition) var(--ease-spring),
    box-shadow var(--transition), border-color var(--transition);
}

/* Soft top-edge highlight — the light-catching rim that sells the glass. */
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: linear-gradient(90deg, transparent, var(--glass-top-highlight), transparent);
  pointer-events: none;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg),
    0 0 0 1px color-mix(in srgb, var(--card-accent) 22%, transparent),
    0 14px 40px -18px color-mix(in srgb, var(--card-accent) 45%, transparent);
  border-color: color-mix(in srgb, var(--card-accent) 28%, var(--surface-border));
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: var(--space-4);
  color: var(--text-0);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  color: var(--text-2);
  transition: color var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
}

.icon-btn:hover {
  color: var(--text-0);
  background: var(--surface-hover);
}

.icon-btn:active {
  transform: scale(0.93);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius);
  font-weight: 600;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.3);
}

.btn.primary:hover {
  box-shadow: 0 6px 20px rgba(56, 189, 248, 0.4);
}

.btn.secondary {
  background: var(--bg-3);
  color: var(--text-0);
}

.btn.danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
}

.btn.ghost {
  color: var(--text-2);
}

.btn.ghost:hover {
  background: var(--surface-hover);
  color: var(--text-0);
}

.btn.block {
  width: 100%;
}

.btn-sm {
  padding: var(--space-2) var(--space-3);
  font-size: 0.875rem;
}

/* Segmented control — a single track holding mutually-exclusive options.
   Reads as one control instead of a row of loose buttons. */
.segmented {
  display: inline-flex;
  align-self: flex-start;   /* hug buttons even inside a stretch flex column */
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 1px solid var(--surface-border);
}

.segmented > button {
  padding: var(--space-2) var(--space-3);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: calc(var(--radius) - 3px);
  color: var(--text-2);
  transition: color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

.segmented > button:hover {
  color: var(--text-0);
}

.segmented > button.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 2px 8px -2px rgba(56, 189, 248, 0.5);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-1);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
input[type="date"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--surface-border);
  background: var(--bg-2);
  color: var(--text-0);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

/* Strip the native search-field chrome (rounded WebKit box + clear "×") so a
   search input matches every other text field instead of showing OS styling. */
input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

/* Chrome paints autofilled inputs with an opaque tan/olive background that ignores
   our `background` and clashes badly with the dark theme. The only reliable override
   is an inset box-shadow the size of the field; the long transition keeps it from
   flashing back to the OS colour. Applied to every field so none can slip through. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-text-fill-color: var(--text-0);
  -webkit-box-shadow: 0 0 0 100px var(--bg-2) inset;
  box-shadow: 0 0 0 100px var(--bg-2) inset;
  caret-color: var(--text-0);
  transition: background-color 100000s ease-in-out 0s;
}
input:-webkit-autofill:focus,
textarea:-webkit-autofill:focus,
select:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 100px var(--bg-2) inset, var(--focus-ring);
  box-shadow: 0 0 0 100px var(--bg-2) inset, var(--focus-ring);
}

/* ── Checkboxes ──────────────────────────────────────────────────────────────
   A styled box that matches the app's surfaces and accent. Real checkboxes
   (selection semantics — e.g. the Records multi-select) use this; on/off setting
   toggles opt into the pill switch below with `.switch-cb`. */
input[type="checkbox"]:not(.switch-cb) {
  -webkit-appearance: none;
  appearance: none;
  flex-shrink: 0;
  position: relative;
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--surface-border);
  background: var(--bg-2);
  cursor: pointer;
  vertical-align: middle;
  transition: background var(--transition-fast), border-color var(--transition-fast),
    box-shadow var(--transition-fast), transform var(--transition-fast);
}
input[type="checkbox"]:not(.switch-cb):hover {
  border-color: var(--accent);
}
input[type="checkbox"]:not(.switch-cb):active {
  transform: scale(0.88);
}
input[type="checkbox"]:not(.switch-cb):checked {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}
/* The tick — drawn as a rotated border, popped in when checked. */
input[type="checkbox"]:not(.switch-cb):checked::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 46%;
  width: 0.3rem;
  height: 0.55rem;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -50%) rotate(45deg);
}
input[type="checkbox"]:not(.switch-cb):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
@media (prefers-reduced-motion: no-preference) {
  input[type="checkbox"]:not(.switch-cb):checked::after {
    animation: cb-tick var(--transition) var(--ease-spring);
  }
}
:root[data-reduce-motion="1"] input[type="checkbox"]:not(.switch-cb):checked::after {
  animation: none;
}
@keyframes cb-tick {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(45deg) scale(0.2);
  }
}

/* ── Switch-style checkbox ────────────────────────────────────────────────────
   For on/off setting toggles (chart "Smooth", "Show archived"). Keeps a real
   <input type="checkbox"> so existing change handlers work, but paints it as the
   same pill switch used in Settings. */
input.switch-cb {
  -webkit-appearance: none;
  appearance: none;
  flex-shrink: 0;
  position: relative;
  width: 2.6rem;
  height: 1.45rem;
  margin: 0;
  border-radius: 999px;
  border: 1px solid var(--surface-border);
  background: var(--bg-3);
  cursor: pointer;
  vertical-align: middle;
  transition: background var(--transition-fast), border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}
input.switch-cb::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 3px;
  width: 1.05rem;
  height: 1.05rem;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--text-0);
  box-shadow: var(--shadow-sm);
  transition: left var(--transition) var(--ease-spring), background var(--transition-fast);
}
input.switch-cb:checked {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}
input.switch-cb:checked::before {
  left: calc(100% - 1.05rem - 3px);
  background: #fff;
}
input.switch-cb:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
:root[data-reduce-motion="1"] input.switch-cb::before {
  transition: none;
}

/* Unit combo box: a select of known units + a "+" to add a new one (kept in
   localStorage, not the database). Buttons stretch to the control height. */
.unit-picker {
  display: flex;
  gap: var(--space-2);
  align-items: stretch;
}
.unit-picker .unit-select,
.unit-picker .unit-new {
  flex: 1 1 auto;
  min-width: 0;
}
.unit-picker .btn {
  flex: 0 0 auto;
  width: 2.75rem;
  padding: 0;
  font-size: 1.125rem;
  line-height: 1;
}

/* Color picker: a clean full-width swatch bar at the same height as the other
   controls, showing the selected color. */
input[type="color"] {
  width: 100%;
  height: 3rem;
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--surface-border);
  background: var(--bg-2);
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
input[type="color"]:hover {
  border-color: var(--accent);
}
input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--color-swatch-border);
  border-radius: calc(var(--radius) - 4px);
}
input[type="color"]::-moz-color-swatch {
  border: 1px solid var(--color-swatch-border);
  border-radius: calc(var(--radius) - 4px);
}

/* Substance rows are click-to-select for the quick-dose form (buttons excepted). */
.substance-row {
  cursor: pointer;
  transition: transform var(--transition-fast) var(--ease-spring),
    box-shadow var(--transition-fast), filter var(--transition-fast);
}
.substance-row:hover {
  transform: translateX(3px);
  filter: brightness(1.08);
}
.substance-row:active {
  transform: translateX(3px) scale(0.995);
}
.substance-row.selected {
  transform: translateX(3px);
  box-shadow: inset 0 0 0 1px var(--accent),
    0 0 0 2px color-mix(in srgb, var(--accent) 26%, transparent),
    0 10px 26px -16px color-mix(in srgb, var(--accent) 65%, transparent);
}

/* Assign-existing prompt — styled radio cards (no default radio chrome) */
.assign-existing {
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--warning, #facc15) 9%, transparent);
}
.assign-existing-head {
  font-weight: 600;
  font-size: 0.9375rem;
  margin-bottom: 2px;
}
.assign-existing-hint {
  color: var(--text-3);
  font-size: 0.8125rem;
  margin-bottom: var(--space-3);
}
.assign-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.assign-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  background: var(--bg-2);
  cursor: pointer;
  user-select: none;
  transition: border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}
.assign-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.assign-option::before {
  content: "";
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 2px solid var(--surface-border);
  flex-shrink: 0;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.assign-option:hover {
  border-color: var(--accent);
}
.assign-option:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}
.assign-option:has(input:checked)::before {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 3px var(--accent);
}
.assign-option:has(input:focus-visible) {
  border-color: var(--accent);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-3);
}

select option {
  background: var(--bg-2);
  color: var(--text-0);
}

.form-error {
  color: var(--danger);
  font-size: 0.875rem;
  min-height: 1.25rem;
}

/* Slider */
.slider-wrap {
  position: relative;
  padding-top: var(--space-6);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--bg-3);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--text-0);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow);
  transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--text-0);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow);
}

.slider-bubble {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.slider-wrap:hover .slider-bubble,
input[type="range"]:active ~ .slider-bubble,
input[type="range"]:focus ~ .slider-bubble {
  opacity: 1;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--surface-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

th, td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--surface-border);
}

th {
  font-weight: 600;
  color: var(--text-2);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-2);
}

tr:hover td {
  background: var(--surface-hover);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-sm {
  padding: 0.125rem var(--space-2);
}

/* Progress bar */
.progress-bar {
  height: 0.5rem;
  border-radius: 999px;
  background: var(--bg-3);
  overflow: hidden;
}

.progress-bar > div {
  height: 100%;
  border-radius: 999px;
  transition: width var(--transition-slow);
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--text-2);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
  opacity: 0.7;
}

.empty-state h3 {
  color: var(--text-1);
  margin-bottom: var(--space-2);
}

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
  margin-bottom: var(--space-5);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
}

.filter-bar .form-group {
  margin-bottom: 0;
  flex: 1 1 10rem;
  min-width: 8rem;
}

/* Toolbar control alignment — every interactive control in a filter/chart bar
   (inputs, selects, buttons, and segmented toggles) shares one height so a row of
   them sits on a common baseline instead of stair-stepping. */
.filter-bar :is(input:not([type="checkbox"]), select, .btn),
.chart-controls :is(input:not([type="checkbox"]), select, .btn) {
  min-height: var(--control-h);
}
.filter-bar .segmented,
.chart-controls .segmented {
  min-height: var(--control-h);
  align-items: stretch;
}
.filter-bar .segmented > button,
.chart-controls .segmented > button {
  display: inline-flex;
  align-items: center;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

.pagination button {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  color: var(--text-1);
  background: var(--surface);
  border: 1px solid var(--surface-border);
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Settings — labelled rows pairing a description with its control. */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  flex-wrap: wrap;
}
.setting-row + .setting-row {
  border-top: 1px solid var(--surface-border);
}
.setting-label {
  min-width: 0;
  flex: 1 1 12rem;
}
.setting-name {
  font-weight: 600;
  color: var(--text-0);
}
.setting-hint {
  font-size: 0.8125rem;
  color: var(--text-3);
  margin-top: 2px;
}

/* Accent color picker — round swatches plus a custom-color slot. */
.accent-picker {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.accent-swatch {
  position: relative;
  width: 2rem;
  height: 2rem;
  padding: 3px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: transform var(--transition-fast) var(--ease-spring), border-color var(--transition-fast);
}
.accent-swatch > span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}
.accent-swatch:hover {
  transform: scale(1.12);
}
.accent-swatch.selected {
  border-color: var(--text-0);
}
.accent-custom {
  overflow: hidden;
  cursor: pointer;
}
/* The color input fills the swatch invisibly so the whole circle is the hit target. */
.accent-custom input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  opacity: 0;
  cursor: pointer;
}

/* Toggle switch */
.switch {
  position: relative;
  width: 2.75rem;
  height: 1.5rem;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--surface-border);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.switch-knob {
  position: absolute;
  top: 50%;
  left: 3px;
  width: 1.1rem;
  height: 1.1rem;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--text-0);
  box-shadow: var(--shadow-sm);
  transition: left var(--transition) var(--ease-spring), background var(--transition-fast);
}
.switch.on {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}
.switch.on .switch-knob {
  left: calc(100% - 1.1rem - 3px);
  background: #fff;
}

/* Management console — section tabs, list rows, drag-to-reorder. */
.manage-tabs {
  display: inline-flex;
  margin-top: var(--space-2);
}
.manage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}
.muted-count {
  color: var(--text-3);
  font-weight: 500;
  font-size: 0.875rem;
}
.show-archived {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.875rem;
  color: var(--text-2);
  cursor: pointer;
}
.manage-hint {
  color: var(--text-3);
  font-size: 0.8125rem;
  margin-bottom: var(--space-3);
}
.manage-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.manage-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--surface-border);
}
.manage-row.dragging {
  opacity: 0.5;
}
.manage-row[draggable="true"] {
  cursor: grab;
}
.drag-grip {
  color: var(--text-3);
  cursor: grab;
  user-select: none;
  letter-spacing: -2px;
  flex-shrink: 0;
}
.row-dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}
.row-main {
  flex: 1 1 auto;
  min-width: 0;
}
.row-name {
  font-weight: 600;
  color: var(--text-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-meta {
  font-size: 0.8125rem;
  color: var(--text-3);
}
.row-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}
.btn.ghost.danger-text {
  color: var(--danger);
}
.method-name-input {
  flex: 1 1 auto;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  color: var(--text-0);
  font: inherit;
  font-weight: 600;
}
.method-name-input:hover {
  border-color: var(--surface-border);
}
.method-name-input:focus {
  border-color: var(--accent);
  background: var(--bg-2);
  outline: none;
}
.add-method-row {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.add-method-row input {
  flex: 1 1 auto;
  min-width: 0;
}
.add-method-row button {
  flex-shrink: 0;
  white-space: nowrap;
}

/* Records table (Manage → Records) */
.rec-table {
  min-width: 44rem;
}
.rec-table td {
  vertical-align: middle;
}
.rec-sub {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 500;
}
.rec-note {
  max-width: 18rem;
  color: var(--text-2);
}
.rec-unspec {
  color: var(--text-3, var(--text-2));
  font-style: italic;
}
/* Inline-edit row: compact, full-width controls so fields fit the cells. */
.rec-editing td {
  background: var(--surface-hover);
}
.rec-editing select,
.rec-editing input {
  width: 100%;
  min-width: 0;
  height: 2.25rem;
  padding: 0 var(--space-2);
  font-size: 0.9375rem;
}
.rec-editing .rec-edit-amount {
  width: 6rem;
}
.rec-table .row-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: nowrap;
}
/* Multi-select column + selected-row highlight. */
.rec-table .rec-check {
  width: 2.5rem;
  text-align: center;
  padding-right: 0;
}
.rec-table .rec-check input {
  cursor: pointer;
}
.rec-table tr.rec-selected td {
  background: var(--accent-soft, var(--surface-hover));
}
/* Bulk action bar above the table when records are checked. */
.rec-bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.rec-bulk-count {
  font-weight: 600;
  font-size: 0.9375rem;
}
.rec-bulk-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* Access codes panel */
.ac-form {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
}
.ac-form > .input {
  flex: 1 1 12rem;
  min-width: 0;
}
.ac-len {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8125rem;
  color: var(--text-2);
}
.ac-len .input {
  width: 5rem;
}
.ac-list {
  gap: var(--space-2);
}
.ac-item {
  align-items: center;
}
.ac-item-off {
  opacity: 0.62;
}
.ac-item-main {
  flex: 1 1 auto;
  min-width: 0;
}
.ac-code-line {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.ac-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text-0);
  background: var(--surface-hover);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm, 6px);
  padding: 2px 8px;
  user-select: all;
}
.ac-item-off .ac-code {
  text-decoration: line-through;
  color: var(--text-3);
}
.ac-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
}
.ac-badge-on {
  color: var(--success, #3ba776);
  background: color-mix(in srgb, var(--success, #3ba776) 16%, transparent);
}
.ac-badge-off {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 16%, transparent);
}
.ac-tag {
  font-size: 0.8rem;
  color: var(--text-2);
}
.ac-item-meta {
  font-size: 0.8125rem;
  color: var(--text-3);
  margin-top: 3px;
}

/* Icon action buttons (Manage console row actions) */
.icon-btn svg {
  width: 1.15rem;
  height: 1.15rem;
}
.icon-btn.icon-sm {
  width: 2rem;
  height: 2rem;
}
.icon-btn.icon-sm svg {
  width: 1.05rem;
  height: 1.05rem;
}
.icon-btn.danger:hover {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}
.icon-btn.accent {
  color: var(--accent);
}
.icon-btn.accent:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
/* Buttons pairing a leading icon with a text label (bulk action bar) */
.btn.has-icon {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
}
.btn.has-icon svg {
  width: 1.05em;
  height: 1.05em;
  flex-shrink: 0;
}

/* Offline banner (PWA) — a thin bar pinned to the top while connectivity is lost. */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  padding: 0.4rem 1rem;
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #1e130a;
  background: color-mix(in srgb, var(--warning, #e0a94a) 88%, #fff);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.offline-banner[hidden] {
  display: none;
}

/* Toasts */
.toast-root {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  z-index: 110;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
}
.toast {
  padding: var(--space-3) var(--space-5);
  margin-top: var(--space-3);
  border-radius: var(--radius);
  background: var(--bg-3);
  color: var(--text-0);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--accent);
  animation: toast-in 250ms ease;
  pointer-events: auto;
  max-width: min(22rem, calc(100vw - var(--space-8)));
}
.toast-success {
  border-left-color: var(--success);
}
.toast-error {
  border-left-color: var(--danger);
}

/* Modals */
.modal-wrapper {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--space-4);
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: modal-backdrop-in 200ms ease;
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 28rem;
  max-height: 90vh;
  overflow: auto;
  animation: modal-content-in 250ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Button loading state */
.btn.loading {
  opacity: 0.8;
  pointer-events: none;
  position: relative;
}
.btn.loading::after {
  content: "";
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 0.5em;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
