/* Switchboard components (classes prefixed sb-). Colors, radii and spacing come from tokens.css.
   Shared by admin, desk and phone. Pages add layout; this file never positions the page. */

/* Buttons */
.sb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface-3);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition:
    background var(--ease),
    border-color var(--ease),
    color var(--ease),
    box-shadow var(--ease);
}
.sb-btn:hover {
  background: var(--surface-2);
  border-color: var(--text-3);
}
.sb-btn:active {
  transform: translateY(0.5px);
}
.sb-btn:disabled,
.sb-btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}
.sb-btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.sb-btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.sb-btn-primary:active {
  background: var(--primary-active);
}
.sb-btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.sb-btn-ghost:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: transparent;
}
.sb-btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.sb-btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
}
.sb-btn-sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
  gap: 6px;
}
.sb-btn-icon {
  width: 36px;
  min-width: 36px;
  padding: 0;
}
.sb-btn-sm.sb-btn-icon {
  width: 30px;
  min-width: 30px;
}
.sb-btn svg {
  flex: none;
}
.sb-btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.sb-btn.is-loading::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: sb-spin 0.7s linear infinite;
}
.sb-btn:not(.sb-btn-primary):not(.sb-btn-danger).is-loading::after {
  border-color: var(--border-strong);
  border-top-color: var(--primary);
}
@keyframes sb-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Focus ring (shared) */
.sb-btn:focus-visible,
.sb-input:focus-visible,
.sb-select:focus-visible,
.sb-textarea:focus-visible,
.sb-tab:focus-visible,
.sb-menu-item:focus-visible,
.sb-switch input:focus-visible + .sb-switch-track,
.sb-segmented > button:focus-visible,
.sb-link:focus-visible,
.sb-checkbox input:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* Inputs */
.sb-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.sb-label,
.sb-field > span:first-child {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.sb-input,
.sb-select,
.sb-textarea {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface-3);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  transition:
    border-color var(--ease),
    background var(--ease);
}
.sb-input::placeholder,
.sb-textarea::placeholder {
  color: var(--text-3);
}
.sb-input:hover,
.sb-select:hover,
.sb-textarea:hover {
  border-color: var(--text-3);
}
.sb-input:disabled,
.sb-select:disabled,
.sb-textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.sb-input[aria-invalid="true"],
.sb-textarea[aria-invalid="true"],
.sb-select[aria-invalid="true"] {
  border-color: var(--danger);
}
.sb-textarea {
  min-height: 84px;
  resize: vertical;
}
.sb-select {
  appearance: none;
  padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%),
    linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) 50%,
    calc(100% - 11px) 50%;
  background-size:
    5px 5px,
    5px 5px;
  background-repeat: no-repeat;
}
.sb-help {
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.45;
}
.sb-error {
  font-size: 13px;
  color: var(--danger);
  line-height: 1.45;
}
.sb-error:empty {
  display: none;
}
.sb-alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  background: var(--surface-3);
  font-size: 13px;
  line-height: 1.45;
}
.sb-alert-danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--text);
}
.sb-alert-warning {
  background: var(--warning-soft);
  border-color: transparent;
}
.sb-alert-info {
  background: var(--info-soft);
  border-color: transparent;
}
.sb-alert-success {
  background: var(--success-soft);
  border-color: transparent;
}

/* Checkbox + switch */
.sb-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}
.sb-checkbox input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
  border-radius: 4px;
}
.sb-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}
.sb-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.sb-switch-track {
  position: relative;
  width: 36px;
  height: 20px;
  flex: none;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  transition: background var(--ease);
}
.sb-switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-1);
  transition: transform var(--ease);
}
.sb-switch input:checked + .sb-switch-track {
  background: var(--primary);
}
.sb-switch input:checked + .sb-switch-track::after {
  transform: translateX(16px);
}
.sb-switch input:disabled + .sb-switch-track {
  opacity: 0.5;
}

/* Segmented control */
.sb-segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius-control);
  background: var(--surface-3);
  border: 1px solid var(--border);
}
.sb-segmented > button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 5px 12px;
  min-height: 28px;
  border-radius: 6px;
  cursor: pointer;
  transition:
    background var(--ease),
    color var(--ease);
}
.sb-segmented > button:hover {
  color: var(--text);
}
.sb-segmented > button[aria-pressed="true"],
.sb-segmented > button[aria-selected="true"] {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

/* Badges and pills */
.sb-badge,
.sb-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.sb-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.sb-badge-success,
.sb-pill-success {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}
.sb-badge-warning,
.sb-pill-warning {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: transparent;
}
.sb-badge-danger,
.sb-pill-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}
.sb-badge-info,
.sb-pill-info {
  background: var(--info-soft);
  color: var(--info);
  border-color: transparent;
}
.sb-badge-primary,
.sb-pill-primary {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: transparent;
}
.sb-badge-accent,
.sb-pill-accent {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}
.sb-badge-away {
  background: var(--away-soft);
  color: var(--away);
  border-color: transparent;
}
[data-theme="light"] .sb-badge-success,
[data-theme="light"] .sb-pill-success {
  color: #15803d;
}
[data-theme="light"] .sb-badge-warning,
[data-theme="light"] .sb-pill-warning {
  color: #b45309;
}
[data-theme="light"] .sb-badge-danger,
[data-theme="light"] .sb-pill-danger {
  color: #b91c1c;
}
[data-theme="light"] .sb-badge-info,
[data-theme="light"] .sb-pill-info {
  color: #0369a1;
}
[data-theme="light"] .sb-badge-primary,
[data-theme="light"] .sb-pill-primary {
  color: #1d4ed8;
}
[data-theme="light"] .sb-badge-accent,
[data-theme="light"] .sb-pill-accent {
  color: #6d28d9;
}
[data-theme="light"] .sb-badge-away {
  color: #c2410c;
}

/* Presence dot and timer chip */
.sb-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex: none;
}
.sb-dot.is-available {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}
.sb-dot.is-on-call,
.sb-dot.is-on-call-inbound {
  background: var(--primary);
}
.sb-dot.is-on-call-outbound {
  background: var(--accent);
}
.sb-dot.is-ringing {
  background: var(--info);
  animation: sb-pulse 1.2s ease-in-out infinite;
}
.sb-dot.is-wrap-up {
  background: var(--warning);
}
.sb-dot.is-away {
  background: var(--away);
}
.sb-dot.is-offline {
  background: var(--text-3);
}
@keyframes sb-pulse {
  50% {
    opacity: 0.4;
  }
}
.sb-timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
}

/* Cards and stat tiles */
.sb-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  min-width: 0;
  box-shadow: var(--shadow-1);
}
.sb-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.sb-card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sb-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.sb-card-body {
  padding: 16px;
}
.sb-card-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12px;
}
.sb-stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  min-width: 0;
}
.sb-stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sb-stat-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.sb-stat-delta {
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.sb-stat-delta.is-up {
  color: var(--success);
}
.sb-stat-delta.is-down {
  color: var(--danger);
}

/* Tables */
.sb-table-wrap {
  overflow: auto;
  max-width: 100%;
  border-radius: inherit;
}
.sb-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  text-align: left;
}
.sb-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  height: 36px;
}
.sb-table td {
  padding: 7px 16px;
  height: 36px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  overflow-wrap: anywhere;
}
.sb-table tbody tr:last-child td {
  border-bottom: 0;
}
.sb-table tbody tr:hover td {
  background: var(--surface-3);
}
.sb-table .num,
.sb-table td.num,
.sb-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.sb-table .sb-row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  opacity: 0.85;
}
.sb-table tbody tr:hover .sb-row-actions {
  opacity: 1;
}
.sb-table-empty td {
  text-align: center;
  color: var(--text-2);
  padding: 28px 16px;
}

/* Tabs */
.sb-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.sb-tab {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 12px;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 6px 6px 0 0;
  transition: color var(--ease);
}
.sb-tab:hover {
  color: var(--text);
}
.sb-tab[aria-selected="true"],
.sb-tab.is-active {
  color: var(--text);
}
.sb-tab[aria-selected="true"]::after,
.sb-tab.is-active::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

/* Dialog */
.sb-dialog {
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-card);
  background: var(--surface-2);
  color: var(--text);
  box-shadow: var(--shadow-2);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
}
.sb-dialog::backdrop {
  background: var(--scrim);
}
.sb-dialog-head,
.sb-dialog-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
}
.sb-dialog-head {
  border-bottom: 1px solid var(--border);
}
.sb-dialog-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.sb-dialog-head p {
  margin: 4px 0 0;
  color: var(--text-2);
  font-size: 13px;
}
.sb-dialog-body {
  padding: 20px;
  overflow: auto;
  overscroll-behavior: contain;
}
.sb-dialog-foot {
  justify-content: flex-end;
  align-items: center;
  border-top: 1px solid var(--border);
  background: var(--surface);
  border-radius: 0 0 var(--radius-card) var(--radius-card);
  padding: 12px 20px;
}

/* Toasts */
.sb-toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 40px));
  pointer-events: none;
}
.sb-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border-strong);
  background: var(--surface-3);
  color: var(--text);
  box-shadow: var(--shadow-2);
  font-size: 13px;
  pointer-events: auto;
  animation: sb-toast-in var(--ease-panel);
}
.sb-toast > svg:first-child {
  color: var(--success);
}
.sb-toast-danger > svg:first-child {
  color: var(--danger);
}
.sb-toast-warning > svg:first-child {
  color: var(--warning);
}
@keyframes sb-toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* Dropdown menu */
.sb-menu {
  position: relative;
}
.sb-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  min-width: 220px;
  padding: 6px;
  margin: 0;
  list-style: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-card);
  background: var(--surface-2);
  box-shadow: var(--shadow-2);
}
.sb-menu-list[hidden] {
  display: none;
}
.sb-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
}
.sb-menu-item:hover {
  background: var(--surface-3);
}
.sb-menu-item.is-danger {
  color: var(--danger);
}
.sb-menu-item svg {
  color: var(--text-2);
  flex: none;
}
.sb-menu-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--border);
}
.sb-menu-head {
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.sb-menu-head strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
}
.sb-menu-head small {
  display: block;
  color: var(--text-2);
  font-size: 12px;
  margin-top: 2px;
}

/* Skeleton */
.sb-skeleton {
  display: block;
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--border-strong) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: sb-shimmer 1.4s linear infinite;
}
@keyframes sb-shimmer {
  to {
    background-position: -200% 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .sb-skeleton,
  .sb-dot.is-ringing,
  .sb-toast,
  .sb-btn.is-loading::after {
    animation: none;
  }
}

/* Empty state */
.sb-empty {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 36px 20px;
  text-align: center;
}
.sb-empty-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 6px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
}
.sb-empty strong {
  font-size: 15px;
  font-weight: 600;
}
.sb-empty p {
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
  max-width: 46ch;
}
.sb-empty .sb-btn {
  margin-top: 10px;
}

/* Page header and links */
.sb-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.sb-page-head h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.sb-page-head p {
  margin: 4px 0 0;
  color: var(--text-2);
  font-size: 14px;
}
.sb-link {
  color: var(--primary);
  text-decoration: none;
  border-radius: 4px;
}
.sb-link:hover {
  text-decoration: underline;
}
.sb-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.sb-brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--brand-gradient);
  color: #fff;
  flex: none;
}

/* Theme toggle button (icons injected by /ui/theme.js) */
[data-theme-toggle] svg.theme-sun {
  display: none;
}
[data-theme="light"] [data-theme-toggle] svg.theme-sun {
  display: block;
}
[data-theme="light"] [data-theme-toggle] svg.theme-moon {
  display: none;
}
