/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--ctl-h);
  padding: 0 var(--sp-3);
  border: 1px solid transparent;
  border-radius: var(--r);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  touch-action: manipulation;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-sm { height: var(--ctl-h-sm); padding: 0 var(--sp-2); font-size: var(--fs-xs); }
.btn-block { width: 100%; height: 40px; font-size: var(--fs); }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--hover); }

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

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-danger-outline { background: var(--surface); color: var(--danger-text); border-color: var(--danger-border); }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger-text); }

.btn-danger-ghost { background: transparent; color: var(--danger-text); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }

.btn.is-done { color: var(--success-text); }
.btn-primary.is-done { color: var(--on-primary); }

.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--muted);
}
.btn-icon:hover { background: var(--hover); color: var(--text); }

/* Busy spinner (generic for every action button) */
.is-busy { position: relative; }
.btn.is-busy > svg { display: none; }
.btn.is-busy::before,
.switch.is-busy .switch-thumb::after {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}
.btn.is-busy:disabled { opacity: .75; cursor: progress; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------- inputs */
.input {
  width: 100%;
  min-width: 0;
  height: var(--ctl-h);
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder { color: var(--muted); opacity: .85; }
.input:hover:not(:disabled) { border-color: var(--muted); }
.input:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent);
}
.input:disabled { background: var(--surface-3); color: var(--muted); cursor: not-allowed; }
.input[readonly] { background: var(--surface-2); }
.input[aria-invalid="true"] { border-color: var(--danger-text); }
.input[aria-invalid="true"]:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger-text) 25%, transparent); }
textarea.input { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.45; }
select.input { padding-right: 28px; }
.input-sm { height: var(--ctl-h-sm); font-size: var(--fs-sm); }
.input.mono { font-family: var(--mono); font-size: var(--fs-sm); }

.input-icon { position: relative; }
.input-icon > svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > .input { padding-left: 32px; }

.input-group { position: relative; display: flex; }
.input-group .input { padding-right: 40px; }
.input-group .input-addon { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.field-label .req { color: var(--danger-text); }
.field-hint { font-size: var(--fs-xs); color: var(--muted); }
.field-error { font-size: var(--fs-xs); color: var(--danger-text); font-weight: 600; min-height: 0; }
.field-error:empty { display: none; }

.check { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; font-weight: 500; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); cursor: pointer; flex: none; }
.check-sm { font-size: var(--fs-sm); }
.check-sm input { width: 16px; height: 16px; }

.form { display: flex; flex-direction: column; gap: var(--sp-4); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3) var(--sp-4); }
.form-grid .span-2 { grid-column: 1 / -1; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.form-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.dirty-note { display: inline-flex; align-items: center; gap: 6px; color: var(--warning-text); font-size: var(--fs-sm); font-weight: 600; margin-left: var(--sp-2); }

.form-alert {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r);
  border: 1px solid var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger-text);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.form-alert.is-info { border-color: var(--info-border); background: var(--info-soft); color: var(--info-text); }

/* ----------------------------------------------------------------- badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--b-border, transparent);
  background: var(--b-bg);
  color: var(--b-fg);
  font-size: var(--fs-xs);
  font-weight: 650;
  white-space: nowrap;
  line-height: 1;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge-sm { height: 20px; padding: 0 7px; font-size: 11.5px; }
.tone-success { --b-bg: var(--success-soft); --b-fg: var(--success-text); --b-border: var(--success-border); }
.tone-danger { --b-bg: var(--danger-soft); --b-fg: var(--danger-text); --b-border: var(--danger-border); }
.tone-warning { --b-bg: var(--warning-soft); --b-fg: var(--warning-text); --b-border: var(--warning-border); }
.tone-info { --b-bg: var(--info-soft); --b-fg: var(--info-text); --b-border: var(--info-border); }
.tone-neutral { --b-bg: var(--neutral-soft); --b-fg: var(--neutral-text); --b-border: var(--neutral-border); }

.count-pill {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 650;
}
.more-pill {
  margin-left: 4px;
  padding: 1px 5px;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
}

/* Banners */
.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--b-border);
  border-radius: var(--r);
  background: var(--b-bg);
  color: var(--b-fg);
  font-size: var(--fs-sm);
  line-height: 1.45;
}
.banner > svg { margin-top: 2px; }
.banner a { color: inherit; font-weight: 600; }

/* ----------------------------------------------------------------- tables */
.table-scroll { overflow: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.table th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 650;
  text-align: left;
  white-space: nowrap;
}
.table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--hover); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.is-muted td { color: var(--muted); }
.table-compact td, .table-compact th { padding: 6px 10px; }
.table-compact th { position: static; }
.col-actions { width: 1%; text-align: right; white-space: nowrap; }
.cell-link { font-weight: 600; color: var(--text); text-decoration: none; }
.cell-link:hover { color: var(--primary-text); text-decoration: underline; }
.cell-sub { color: var(--muted); font-size: var(--fs-xs); }
.num-link { font-weight: 600; color: var(--text); text-decoration: none; }
.num-link:hover { text-decoration: underline; color: var(--primary-text); }
.num-link.text-danger { color: var(--danger-text); }
.clip { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

.time-cell { display: flex; flex-direction: column; line-height: 1.3; white-space: nowrap; }
.time-rel { font-weight: 600; }
.time-abs { color: var(--muted); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }

.empty-row td:hover, .empty-row:hover td { background: transparent !important; }

/* Pager */
.pager {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex: none;
  flex-wrap: wrap;
}
.pager-summary { color: var(--muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.pager-page { min-width: 64px; text-align: center; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.pager .input-sm { width: auto; }
.pager .btn-sm { width: 32px; padding: 0; }

/* ------------------------------------------------------------------- tabs */
.tabs {
  display: flex;
  gap: var(--sp-1);
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex: none;
}
.tab {
  position: relative;
  height: 42px;
  padding: 0 var(--sp-3);
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary-text); }
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: var(--sp-2);
  right: var(--sp-2);
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--primary);
}
.tab:focus-visible { outline-offset: -2px; }
.tab-panel { flex: 1 1 auto; min-height: 0; overflow: auto; }
.tab-panel:focus-visible { outline-offset: -2px; }

/* ----------------------------------------------------------------- switch */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 32px;
  padding: 0 var(--sp-2) 0 4px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
}
.switch:hover { background: var(--hover); }
.switch-track {
  position: relative;
  width: 36px;
  height: 20px;
  flex: none;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background var(--dur) var(--ease);
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  transition: transform var(--dur) var(--ease);
}
.switch[aria-checked="true"] .switch-track { background: var(--primary); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(16px); color: var(--primary); }
.switch.is-busy .switch-thumb::after { width: 10px; height: 10px; border-width: 2px; }
.switch:disabled { cursor: progress; }

/* -------------------------------------------------------------- segmented */
.seg {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--surface-2);
}
.seg-btn {
  height: 28px;
  padding: 0 var(--sp-3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1), 0 0 0 1px var(--border); }

/* ------------------------------------------------------------------ modal */
.modal {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal:not([open]) { display: none; }
.modal[open] { animation: modal-in var(--dur-slow) var(--ease); }
.modal::backdrop { background: var(--scrim); }
.modal-sm { width: min(460px, calc(100vw - 32px)); }
.modal-lg { width: min(720px, calc(100vw - 32px)); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5) var(--sp-2);
}
.modal-title { font-size: var(--fs-lg); font-weight: 650; }
.modal-body { padding: var(--sp-2) var(--sp-5) var(--sp-5); overflow: auto; display: flex; flex-direction: column; gap: var(--sp-3); }
.modal-footer { padding: var(--sp-3) var(--sp-5) var(--sp-4); border-top: 1px solid var(--border); }
.modal-actions { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-2); }
.modal-footer .modal-actions { margin-top: 0; }
.modal-body > p { color: var(--text-2); }

.confirm-form { display: flex; flex-direction: column; gap: var(--sp-3); }
.confirm-message { display: flex; flex-direction: column; gap: var(--sp-2); color: var(--text-2); }
.confirm-list { list-style: disc; padding-left: var(--sp-5); display: flex; flex-direction: column; gap: 4px; }
.confirm-form code, .confirm-message code { padding: 1px 5px; border-radius: var(--r-sm); background: var(--surface-3); }

/* ----------------------------------------------------------------- toasts */
.toasts {
  position: fixed;
  right: var(--sp-4);
  bottom: var(--sp-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sp-2);
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 400px;
  max-width: 100%;
  padding: var(--sp-3) var(--sp-2) var(--sp-3) var(--sp-3);
  border: 1px solid var(--border);
  border-left: 4px solid var(--b-fg);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  overflow: hidden;
  animation: toast-in var(--dur-slow) var(--ease);
}
.toast.is-leaving { opacity: 0; transform: translateY(4px); transition: opacity .18s ease-in, transform .18s ease-in; }
.toast-icon { color: var(--b-fg); }
.toast-msg { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-sm); line-height: 1.4; min-width: 0; overflow-wrap: anywhere; }
.toast-title { font-weight: 650; }
.toast-close { width: 28px; height: 28px; }
.toast-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: var(--b-fg);
  transform-origin: left;
  animation: toast-progress linear forwards;
  opacity: .6;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-progress { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .toast-progress { display: none; } }

/* ------------------------------------------------------------ empty/skeleton */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
  min-height: 220px;
  height: 100%;
}
.empty-compact { min-height: 160px; padding: var(--sp-6) var(--sp-4); }
.empty-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--muted);
}
.empty-title { font-weight: 650; font-size: var(--fs-md); }
.empty-text { color: var(--muted); font-size: var(--fs-sm); max-width: 420px; }
.empty .btn { margin-top: var(--sp-2); }

.skeleton {
  display: block;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-3) 0%, var(--hover) 50%, var(--surface-3) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
.skeleton-text { height: 12px; width: 70%; margin: 4px 0; }
.skeleton-num { height: 28px; width: 40%; margin-top: 10px; }
.skeleton-title { height: 20px; width: 40%; }
.skeleton-row { height: 30px; width: 100%; }
.skeleton-rows { display: flex; flex-direction: column; gap: 10px; padding: var(--sp-4); }
.skeleton-block { height: 100%; min-height: 160px; width: 100%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.progress-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  z-index: 20;
  overflow: hidden;
  background: color-mix(in srgb, var(--primary) 20%, transparent);
}
.progress-line::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30%;
  background: var(--primary);
  animation: progress 1s var(--ease) infinite;
}
@keyframes progress { from { left: -30%; } to { left: 100%; } }

/* ------------------------------------------------------------- code block */
.code {
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.55;
  overflow: auto;
  white-space: pre;
  tab-size: 4;
}

.kv { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: 6px var(--sp-4); font-size: var(--fs-sm); }
.kv dt { color: var(--muted); }
.kv dd { min-width: 0; overflow-wrap: anywhere; }

.link-sm { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-sm); font-weight: 600; }
.section-title { font-size: var(--fs-sm); font-weight: 650; color: var(--text-2); text-transform: none; }
