/* components.css — reusable UI primitives: card, table, badge, empty state,
 * modal, toast, placeholder, unauthorized. */

/* ===================== Card ===================== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card__header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.card__title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
}
.card__subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.card__actions {
  margin-left: auto;
  display: flex;
  gap: var(--sp-2);
}
.card__body {
  padding: var(--sp-5);
}
.card__body--flush {
  padding: 0;
}

/* Stat cards grid used by placeholder dashboards. */
.card-grid {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.stat {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.stat__label {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.stat__value {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  color: var(--text-strong);
  line-height: var(--lh-tight);
}

/* ===================== Table ===================== */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-md);
}
.table th,
.table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table thead th {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-surface-2);
  position: sticky;
  top: 0;
}
.table tbody tr:hover {
  background: var(--bg-hover);
}
.table tbody tr:last-child td {
  border-bottom: none;
}
.table td.is-numeric,
.table th.is-numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ===================== Badge ===================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1.4;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge--neutral {
  background: var(--bg-surface-2);
  color: var(--text);
  border-color: var(--border);
}
.badge--brand {
  background: var(--brand-soft);
  color: var(--brand);
}
.badge--success {
  background: var(--success-bg);
  color: var(--success);
}
.badge--warning {
  background: var(--warning-bg);
  color: var(--warning);
}
.badge--danger {
  background: var(--danger-bg);
  color: var(--danger);
}
.badge--info {
  background: var(--info-bg);
  color: var(--info);
}
.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ===================== Empty state ===================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-3);
  padding: var(--sp-12) var(--sp-6);
  color: var(--text-muted);
}
.empty-state__icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--bg-surface-2);
  color: var(--brand);
}
.empty-state__title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
}
.empty-state__desc {
  max-width: 42ch;
}

/* ===================== Modal ===================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  display: grid;
  place-items: center;
  padding: var(--sp-4);
  z-index: var(--z-modal);
  animation: fade-in var(--dur-fast) var(--ease);
}
.modal {
  width: 100%;
  max-width: 440px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: pop-in var(--dur-med) var(--ease);
}
.modal__header {
  padding: var(--sp-5) var(--sp-5) 0;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
}
.modal__title {
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
}
.modal__body {
  padding: var(--sp-3) var(--sp-5) var(--sp-5);
  color: var(--text);
}
.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--bg-surface-2);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}
.modal__icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.modal__icon--danger {
  background: var(--danger-bg);
  color: var(--danger);
}
.modal__icon--warning {
  background: var(--warning-bg);
  color: var(--warning);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

/* ===================== Toasts ===================== */
.toast-region {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: var(--z-toast);
  max-width: min(380px, calc(100vw - 2 * var(--sp-4)));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  animation: toast-in var(--dur-med) var(--ease);
}
.toast[data-leaving="true"] {
  animation: toast-out var(--dur-med) var(--ease) forwards;
}
.toast--success {
  border-left-color: var(--success);
}
.toast--error {
  border-left-color: var(--danger);
}
.toast--warning {
  border-left-color: var(--warning);
}
.toast--info {
  border-left-color: var(--info);
}
.toast__icon {
  flex: 0 0 auto;
  margin-top: 1px;
}
.toast--success .toast__icon {
  color: var(--success);
}
.toast--error .toast__icon {
  color: var(--danger);
}
.toast--warning .toast__icon {
  color: var(--warning);
}
.toast--info .toast__icon {
  color: var(--info);
}
.toast__body {
  flex: 1 1 auto;
  min-width: 0;
}
.toast__title {
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
}
.toast__message {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  word-break: break-word;
}
.toast__close {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 2px;
  border-radius: var(--radius-sm);
}
.toast__close:hover {
  color: var(--text-strong);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(12px);
  }
}

/* ===================== Placeholder / unauthorized ===================== */
.placeholder {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--sp-10);
  text-align: center;
  color: var(--text-muted);
  background: var(--bg-surface-2);
}
.placeholder__badge {
  margin-bottom: var(--sp-3);
}

.center-screen {
  min-height: 60vh;
  display: grid;
  place-items: center;
  text-align: center;
}
.access-denied {
  max-width: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
}
.access-denied__code {
  font-size: 3.5rem;
  font-weight: var(--fw-bold);
  color: var(--brand);
  line-height: 1;
}

/* ---- Forms (login and beyond) ---- */
.form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  text-align: left;
}
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.field__label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-strong);
}
.input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text);
  font-size: var(--fs-md);
  line-height: 1.4;
  transition: border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}
.input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}
.input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.form__actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.form__actions .btn {
  width: 100%;
}

/* Inline error surface for the shared error envelope. */
.form-error {
  border: 1px solid var(--danger);
  background: var(--danger-bg);
  color: var(--text-strong);
  border-radius: var(--radius-md);
  padding: var(--sp-3);
  font-size: var(--fs-sm);
}
.form-error__message {
  margin: 0;
  font-weight: var(--fw-medium);
}
.form-error__details {
  margin: var(--sp-2) 0 0;
  padding-left: var(--sp-4);
}
.form-error__meta {
  margin: var(--sp-2) 0 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

/* Login card sizing within the centered viewport. */
.login-card {
  width: 100%;
  max-width: 380px;
  text-align: left;
}

/* Theme toggle button icon swap. */
.theme-toggle .icon-sun {
  display: none;
}
[data-theme="dark"] .theme-toggle .icon-sun {
  display: inline;
}
[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

/* ---- Device inventory (MVP-6) ---- */

/* Filter bar: responsive row of labelled fields plus the apply/clear actions. */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-3);
  align-items: end;
}
.filter-bar__actions {
  display: flex;
  gap: var(--sp-2);
  align-items: end;
}

/* Table row action clusters (View / Edit / Delete). */
.row-actions {
  display: flex;
  gap: var(--sp-1);
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* List pagination controls. */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
}
.pagination__label {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

/* Detail view definition list. */
.detail-list {
  display: grid;
  grid-template-columns: minmax(120px, 200px) 1fr;
  gap: var(--sp-2) var(--sp-4);
  margin: 0 0 var(--sp-4);
}
.detail-list dt {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}
.detail-list dd {
  margin: 0;
  color: var(--text-strong);
  overflow-wrap: anywhere;
}

/* Inline checkbox field (e.g. the Active toggle). */
.field--checkbox {
  flex-direction: row;
  align-items: center;
  gap: var(--sp-2);
}
.checkbox {
  width: 1rem;
  height: 1rem;
  accent-color: var(--brand);
}
