/* components.css — reusable UI primitives. */

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */
.btn {
  --btn-bg: var(--surface-2);
  --btn-border: var(--border);
  --btn-text: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.62rem 1.05rem;
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-text);
  font-weight: 600;
  font-size: 0.93rem;
  line-height: 1.1;
  text-decoration: none;
  transition:
    transform 140ms ease,
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  color: var(--btn-text);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled,
.btn[aria-busy="true"] {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

.btn-primary {
  --btn-bg: var(--accent);
  --btn-border: var(--accent);
  --btn-text: var(--accent-ink);
}

.btn-primary:hover {
  --btn-bg: var(--accent-strong);
  --btn-border: var(--accent-strong);
  color: var(--accent-ink);
}

.btn-ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  --btn-text: var(--text-muted);
}

.btn-ghost:hover {
  --btn-bg: var(--surface-2);
  --btn-border: var(--border);
  --btn-text: var(--text);
}

.btn-outline {
  --btn-bg: transparent;
  --btn-border: var(--border-strong);
}

.btn-danger {
  --btn-bg: rgba(248, 113, 113, 0.12);
  --btn-border: rgba(248, 113, 113, 0.32);
  --btn-text: #fecaca;
}

.btn-danger:hover {
  --btn-bg: rgba(248, 113, 113, 0.2);
  --btn-border: rgba(248, 113, 113, 0.5);
}

.btn-sm {
  min-height: 36px;
  padding: 0.4rem 0.7rem;
  font-size: 0.83rem;
}

.btn-lg {
  min-height: 52px;
  padding: 0.8rem 1.4rem;
  font-size: 1rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 42px;
  min-height: 42px;
  padding: 0;
}

.btn .spinner {
  width: 15px;
  height: 15px;
  border-width: 2px;
}

/* ------------------------------------------------------------------ */
/* Forms                                                               */
/* ------------------------------------------------------------------ */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
}

.field > label,
.label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
}

.field .help,
.help {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.field .error,
.error-text {
  font-size: 0.8rem;
  color: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text);
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

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

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14);
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

input[type="checkbox"],
input[type="radio"] {
  width: 1.05rem;
  min-height: auto;
  height: 1.05rem;
  accent-color: var(--accent);
}

.check {
  display: flex;
  align-items: start;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.check input {
  margin-top: 0.25rem;
  flex: 0 0 auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

legend {
  padding-inline: 0.4rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
}

/* ------------------------------------------------------------------ */
/* Surfaces, cards and badges                                          */
/* ------------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-pad {
  padding: clamp(1rem, 2vw, 1.5rem);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-plain::before {
  display: none;
}

.badge-success {
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.28);
  background: rgba(52, 211, 153, 0.09);
}

.badge-warning {
  color: var(--warning);
  border-color: rgba(251, 191, 36, 0.28);
  background: rgba(251, 191, 36, 0.09);
}

.badge-danger {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.28);
  background: rgba(248, 113, 113, 0.09);
}

.badge-accent {
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.28);
  background: rgba(56, 189, 248, 0.09);
}

.badge-muted {
  color: var(--text-dim);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------ */
/* Alerts and toasts                                                   */
/* ------------------------------------------------------------------ */
.alert {
  display: flex;
  gap: 0.75rem;
  align-items: start;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.alert strong {
  color: var(--text);
}

.alert-success {
  border-color: rgba(52, 211, 153, 0.3);
  background: rgba(52, 211, 153, 0.08);
  color: #bbf7d0;
}

.alert-error {
  border-color: rgba(248, 113, 113, 0.3);
  background: rgba(248, 113, 113, 0.08);
  color: #fecaca;
}

.alert-warning {
  border-color: rgba(251, 191, 36, 0.3);
  background: rgba(251, 191, 36, 0.08);
  color: #fde68a;
}

.alert-info {
  border-color: rgba(56, 189, 248, 0.3);
  background: rgba(56, 189, 248, 0.08);
  color: #bae6fd;
}

#toast-region {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: min(380px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: start;
  gap: 0.7rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.9rem;
  animation: toast-in 180ms ease both;
}

.toast-success {
  border-left: 3px solid var(--success);
}

.toast-error {
  border-left: 3px solid var(--danger);
}

.toast-info {
  border-left: 3px solid var(--accent);
}

.toast-message {
  flex: 1;
}

.toast-close {
  background: none;
  border: 0;
  color: var(--text-dim);
  padding: 0 0.15rem;
  font-size: 1rem;
  line-height: 1;
}

.toast.is-leaving {
  animation: toast-out 160ms ease both;
}

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

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ------------------------------------------------------------------ */
/* Modal / dialog                                                      */
/* ------------------------------------------------------------------ */
.modal {
  width: min(680px, calc(100vw - 2rem));
  max-height: min(86vh, 900px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.modal-wide {
  width: min(920px, calc(100vw - 2rem));
}

.modal::backdrop {
  background: rgba(2, 6, 10, 0.76);
  backdrop-filter: blur(3px);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem 1.35rem;
  border-bottom: 1px solid var(--border);
}

.modal-head h2,
.modal-head h3 {
  font-size: 1.15rem;
}

.modal-body {
  padding: 1.35rem;
  overflow-y: auto;
  max-height: calc(86vh - 145px);
}

.modal-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.7rem;
  padding: 1rem 1.35rem;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.modal-close {
  background: none;
  border: 0;
  color: var(--text-muted);
  font-size: 1.25rem;
  padding: 0.2rem;
  border-radius: 6px;
}

.modal-close:hover {
  color: var(--text);
  background: var(--surface-2);
}

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

table.data {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.data th,
table.data td {
  padding: 0.8rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data th {
  color: var(--text-dim);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--bg-soft);
  position: sticky;
  top: 0;
  z-index: 1;
}

table.data tbody tr:hover {
  background: rgba(255, 255, 255, 0.015);
}

table.data tbody tr:last-child td {
  border-bottom: 0;
}

table.data .actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

.table-empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------ */
/* Empty states, skeletons, pagination                                 */
/* ------------------------------------------------------------------ */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  padding: clamp(2rem, 6vw, 4rem) 1.5rem;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 1.35rem;
}

.empty h3 {
  font-size: 1.05rem;
}

.empty p {
  max-width: 46ch;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.055),
    transparent
  );
  transform: translateX(-100%);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

.skeleton-card {
  height: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 2rem;
}

.pagination button {
  min-width: 38px;
  min-height: 38px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 8px;
  font-size: 0.85rem;
}

.pagination button:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--text);
}

.pagination button[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

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

.pagination .ellipsis {
  color: var(--text-dim);
  padding-inline: 0.2rem;
}

/* ------------------------------------------------------------------ */
/* Misc                                                               */
/* ------------------------------------------------------------------ */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

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

.loading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  padding: 2.5rem;
  color: var(--text-muted);
}

.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.14);
  color: var(--accent);
  font-weight: 700;
  flex: 0 0 auto;
}

.divider {
  height: 1px;
  background: var(--border);
  margin-block: 1rem;
}

.dl {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.55rem 1rem;
  font-size: 0.9rem;
}

.dl dt {
  color: var(--text-dim);
}

.dl dd {
  color: var(--text);
  overflow-wrap: anywhere;
}

@media (max-width: 700px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .dl {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .dl dd {
    margin-bottom: 0.65rem;
  }

  .modal {
    width: 100%;
    max-height: 92vh;
    border-radius: var(--radius) var(--radius) 0 0;
    margin: auto 0 0;
  }

  .modal::backdrop {
    background: rgba(2, 6, 10, 0.82);
  }

  .modal-body {
    max-height: calc(92vh - 145px);
  }
}
