/* ============================================================
   DNA HUB — COMPONENTS
   Fonte: Design System ufficiale, Sezione 5
   ============================================================ */

/* ==================== BUTTON ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  line-height: 1;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 0 var(--space-4);
  height: 40px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--motion-fast) var(--ease-standard),
              border-color var(--motion-fast) var(--ease-standard),
              box-shadow var(--motion-fast) var(--ease-standard),
              color var(--motion-fast) var(--ease-standard);
  user-select: none;
}
.btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn--sm { height: 32px; font-size: var(--text-sm); padding: 0 var(--space-3); }
.btn--lg { height: 48px; font-size: var(--text-md); padding: 0 var(--space-6); }

/* Primary */
.btn--primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}
.btn--primary:hover { background: var(--color-primary-hover); }
.btn--primary:active { background: var(--color-primary-hover); }

/* Secondary */
.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn--secondary:hover { background: var(--color-surface-hover); border-color: var(--color-border-strong); }

/* Ghost */
.btn--ghost {
  background: transparent;
  color: var(--color-text);
}
.btn--ghost:hover { background: var(--color-surface-hover); }

/* Danger */
.btn--danger {
  background: var(--color-danger);
  color: var(--color-text-inverse);
}
.btn--danger:hover { background: #DC2626; }
.btn--danger:focus-visible { outline-color: var(--color-danger); }

/* Link */
.btn--link {
  background: transparent;
  color: var(--color-primary);
  padding: 0;
  height: auto;
  border: none;
}
.btn--link:hover { text-decoration: underline; }

/* Icon only */
.btn--icon {
  width: 40px;
  padding: 0;
}
.btn--icon.btn--sm { width: 32px; }
.btn--icon.btn--lg { width: 48px; }

/* Loading */
.btn.is-loading {
  pointer-events: none;
  color: transparent;
  position: relative;
}
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  color: var(--color-text-inverse);
}
.btn--secondary.is-loading::after,
.btn--ghost.is-loading::after { color: var(--color-text); }

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

/* ==================== INPUT ==================== */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.field__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
}
.field__label .req { color: var(--color-danger); margin-left: 2px; }
.field__helper {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}
.field__error {
  font-size: var(--text-sm);
  color: var(--color-danger);
  display: none;
}
.field.has-error .field__error { display: block; }
.field.has-error .field__helper { display: none; }

.input,
.textarea,
.select {
  width: 100%;
  font-family: inherit;
  font-size: var(--text-base);
  line-height: var(--leading-base);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  height: 40px;
  transition: border-color var(--motion-fast) var(--ease-standard),
              box-shadow var(--motion-fast) var(--ease-standard);
}
.textarea { height: auto; min-height: 96px; resize: vertical; padding: var(--space-2) var(--space-3); }
.input::placeholder,
.textarea::placeholder { color: var(--color-text-disabled); }

.input:hover,
.textarea:hover,
.select:hover { border-color: var(--color-border-strong); }

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-subtle);
}

.input:disabled,
.textarea:disabled,
.select:disabled {
  background: var(--color-surface-hover);
  color: var(--color-text-disabled);
  cursor: not-allowed;
}

.field.has-error .input,
.field.has-error .textarea,
.field.has-error .select {
  border-color: var(--color-danger);
}
.field.has-error .input:focus,
.field.has-error .textarea:focus,
.field.has-error .select:focus {
  box-shadow: 0 0 0 3px var(--color-danger-subtle);
}

/* Input con icona */
.input-wrap { position: relative; }
.input-wrap .input { padding-left: 36px; }
.input-wrap__icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-secondary);
  pointer-events: none;
}

/* ==================== BADGE ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: var(--leading-xs);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.badge--success { background: var(--color-success-subtle); color: #047857; }
.badge--warning { background: var(--color-warning-subtle); color: #B45309; }
.badge--danger  { background: var(--color-danger-subtle);  color: #B91C1C; }
.badge--info    { background: var(--color-primary-subtle); color: var(--color-primary-hover); }
.badge--neutral { background: var(--color-surface-hover); color: var(--color-text-secondary); }

/* ==================== CARD ==================== */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  transition: box-shadow var(--motion-fast) var(--ease-standard),
              border-color var(--motion-fast) var(--ease-standard);
}
.card--interactive { cursor: pointer; }
.card--interactive:hover { box-shadow: var(--shadow-md); border-color: var(--color-border-strong); }
.card--interactive:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.card__title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

/* ==================== KPI CARD ==================== */
.kpi {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  cursor: pointer;
  transition: box-shadow var(--motion-fast) var(--ease-standard),
              border-color var(--motion-fast) var(--ease-standard);
  text-align: left;
  width: 100%;
}
.kpi:hover { box-shadow: var(--shadow-md); border-color: var(--color-primary); }
.kpi:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.kpi__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}
.kpi__value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  line-height: var(--leading-2xl);
}
.kpi__delta {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  margin-top: var(--space-2);
}
.kpi__delta--up   { color: var(--color-success); }
.kpi__delta--down { color: var(--color-danger); }
.kpi__delta--flat { color: var(--color-text-secondary); }

/* ==================== TABLE ==================== */
.table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
  padding: var(--space-3) var(--space-4);
  white-space: nowrap;
  z-index: 1;
}
.table tbody td {
  padding: var(--row-padding-y) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  vertical-align: middle;
  height: var(--row-height);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background-color var(--motion-fast) var(--ease-standard); }
.table tbody tr:hover { background: var(--color-surface-hover); }
.table tbody tr.is-selected { background: var(--color-primary-subtle); }
.table tbody tr:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }

.table__empty {
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--color-text-secondary);
}

/* ==================== TABS ==================== */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--motion-fast) var(--ease-standard),
              border-color var(--motion-fast) var(--ease-standard);
}
.tab:hover { color: var(--color-text); }
.tab.is-active { color: var(--color-text); border-bottom-color: var(--color-primary); }
.tab:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; border-radius: var(--radius-sm); }
.tab__count {
  display: inline-block;
  margin-left: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  background: var(--color-surface-hover);
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
}
.tab.is-active .tab__count { background: var(--color-primary-subtle); color: var(--color-primary-hover); }

/* ==================== SKELETON ==================== */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-surface-hover) 0%,
    #E2E8F0 50%,
    var(--color-surface-hover) 100%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.5s infinite linear;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton--text  { height: 14px; margin-bottom: var(--space-2); }
.skeleton--title { height: 20px; width: 60%; margin-bottom: var(--space-3); }
.skeleton--kpi   { height: 32px; width: 40%; }

/* ==================== MODAL ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--motion-fast) var(--ease-standard),
              visibility var(--motion-fast) var(--ease-standard);
}
.modal-backdrop.is-open { opacity: 1; visibility: visible; }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  transition: transform var(--motion-fast) var(--ease-standard);
}
.modal-backdrop.is-open .modal { transform: scale(1); }
.modal--md { max-width: 640px; }

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}
.modal__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}
.modal__body {
  padding: var(--space-6);
  overflow-y: auto;
}
.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
}

/* ==================== DRAWER ==================== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--motion-fast) var(--ease-standard),
              visibility var(--motion-fast) var(--ease-standard);
}
.drawer-backdrop.is-open { opacity: 1; visibility: visible; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 100%;
  max-width: 560px;
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  z-index: 1001;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--motion-base) var(--ease-standard);
}
.drawer.is-open { transform: translateX(0); }
.drawer--sm { max-width: 400px; }
.drawer--lg { max-width: 720px; }

.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}
.drawer__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}
.drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
}
.drawer__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
}

/* ==================== TOAST ==================== */
.toast-stack {
  position: fixed;
  top: calc(var(--header-height) + var(--space-4));
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 2000;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-width: 280px;
  max-width: 400px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-3) var(--space-4);
  pointer-events: auto;
  animation: toast-in var(--motion-base) var(--ease-standard);
}
.toast--success { border-left-color: var(--color-success); }
.toast--warning { border-left-color: var(--color-warning); }
.toast--danger  { border-left-color: var(--color-danger); }

.toast__body { flex: 1; }
.toast__title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}
.toast__msg {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-top: 2px;
}
.toast__close {
  color: var(--color-text-secondary);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}
.toast__close:hover { background: var(--color-surface-hover); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ==================== TIMELINE ==================== */
.timeline {
  position: relative;
  padding-left: var(--space-8);
}
.timeline::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: var(--color-border);
}
.timeline__group { margin-bottom: var(--space-6); }
.timeline__date {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-3);
  position: relative;
  padding-left: var(--space-2);
  margin-left: calc(-1 * var(--space-8));
  padding-left: var(--space-8);
}
.timeline__item {
  position: relative;
  padding: var(--space-2) 0 var(--space-4) 0;
}
.timeline__dot {
  position: absolute;
  left: calc(-1 * var(--space-8) + 8px);
  top: 8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 2px solid var(--color-border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
}
.timeline__dot--success { border-color: var(--color-success); }
.timeline__dot--warning { border-color: var(--color-warning); }
.timeline__dot--danger  { border-color: var(--color-danger); }
.timeline__dot--info    { border-color: var(--color-primary); }

.timeline__title {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--color-text);
}
.timeline__meta {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-top: 2px;
}

/* ==================== COMMAND PALETTE ==================== */
.palette-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  z-index: 3000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--motion-fast) var(--ease-standard),
              visibility var(--motion-fast) var(--ease-standard);
}
.palette-backdrop.is-open { opacity: 1; visibility: visible; }

.palette {
  width: 100%;
  max-width: 640px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: scale(0.98);
  transition: transform var(--motion-fast) var(--ease-standard);
}
.palette-backdrop.is-open .palette { transform: scale(1); }

.palette__input-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}
.palette__input {
  flex: 1;
  border: none;
  outline: none;
  font-size: var(--text-md);
  background: transparent;
  color: var(--color-text);
}
.palette__kbd {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  background: var(--color-surface-hover);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px var(--space-2);
}
.palette__results {
  max-height: 400px;
  overflow-y: auto;
  padding: var(--space-2);
}
.palette__group { padding: var(--space-2) 0; }
.palette__group-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  padding: var(--space-2) var(--space-3);
}
.palette__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-base);
  color: var(--color-text);
}
.palette__item:hover,
.palette__item.is-active {
  background: var(--color-surface-hover);
}
.palette__item.is-active { background: var(--color-primary-subtle); color: var(--color-primary-hover); }
.palette__item-icon { color: var(--color-text-secondary); width: 20px; display: flex; justify-content: center; }
.palette__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--color-border);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

/* ==================== UTILITY VARIE ==================== */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-4) 0;
}