/* Componenti riutilizzabili */

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-4);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: var(--fw-semibold);
  color: var(--c-primary);
}

.topbar__brand img {
  width: 28px;
  height: 28px;
}

.topbar__search {
  flex: 1;
  max-width: 560px;
  position: relative;
}

.topbar__meta {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
}

.topbar__store {
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-sm);
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: var(--fw-medium);
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.sidebar__group {
  margin-top: var(--sp-3);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-text-muted);
  padding: 0 var(--sp-2);
}

.sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  color: var(--c-text);
  font-weight: var(--fw-medium);
  transition: background 0.12s ease;
  min-height: 40px;
}

.sidebar__item:hover {
  background: var(--c-surface-2);
}

.sidebar__item.is-active {
  background: var(--c-primary-soft);
  color: var(--c-primary);
}

.sidebar__item.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.sidebar__item-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar__badge {
  margin-left: auto;
  font-size: var(--fs-xs);
  padding: 2px 6px;
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  color: var(--c-text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 40px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-md);
  font-weight: var(--fw-medium);
  font-size: var(--fs-base);
  border: 1px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn--primary {
  background: var(--c-primary);
  color: var(--c-text-invert);
}
.btn--primary:hover {
  background: var(--c-primary-hover);
}

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

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

.btn--danger {
  background: var(--c-danger);
  color: var(--c-text-invert);
}
.btn--danger:hover {
  filter: brightness(0.95);
}

.btn--sm {
  min-height: 32px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-sm);
}

.btn[disabled],
.btn.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

/* ---------- Inputs ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.field__label {
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
  font-weight: var(--fw-medium);
}

.field__hint {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

.field__error {
  font-size: var(--fs-xs);
  color: var(--c-danger);
}

.input,
.select,
.textarea {
  min-height: 40px;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: var(--fs-base);
  width: 100%;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: var(--focus-ring);
}

.input.is-error,
.select.is-error,
.textarea.is-error {
  border-color: var(--c-danger);
}

.textarea {
  min-height: 96px;
  resize: vertical;
}

/* ---------- Search input ---------- */
.search {
  position: relative;
}

.search .input {
  padding-left: 36px;
}

.search__icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--c-text-muted);
  width: 18px;
  height: 18px;
}

.search__results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-3);
  max-height: 420px;
  overflow-y: auto;
  z-index: 30;
}

.search__group {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-text-muted);
  background: var(--c-surface-2);
  border-top: 1px solid var(--c-border);
}
.search__group:first-child {
  border-top: none;
}

.search__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
}
.search__item:hover {
  background: var(--c-surface-2);
}
.search__item-title {
  font-weight: var(--fw-medium);
}
.search__item-sub {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

/* ---------- Card ---------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-1);
}

.card__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--sp-2);
}

.card__muted {
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
}

/* ---------- Table ---------- */
.table-wrap {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.table {
  width: 100%;
  font-size: var(--fs-base);
}

.table thead th {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border);
  font-weight: var(--fw-semibold);
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.table tbody td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}

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

.table tbody tr:hover {
  background: var(--c-surface-2);
}

.table__actions {
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
}

/* ---------- Badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  background: var(--c-surface-2);
  color: var(--c-text-muted);
}
.badge--primary { background: var(--c-primary-soft); color: var(--c-primary); }
.badge--success { background: var(--c-success-soft); color: var(--c-success); }
.badge--warning { background: var(--c-warning-soft); color: var(--c-warning); }
.badge--danger  { background: var(--c-danger-soft);  color: var(--c-danger); }

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
}
.pagination__info {
  margin-right: auto;
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
}

/* ---------- Empty state ---------- */
.empty {
  padding: var(--sp-7) var(--sp-4);
  text-align: center;
  color: var(--c-text-muted);
}
.empty__img {
  margin: 0 auto var(--sp-3);
  width: 120px;
  opacity: 0.9;
}
.empty__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--c-text);
  margin-bottom: var(--sp-1);
}

/* ---------- Toast ---------- */
.toast-root {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 100;
  pointer-events: none;
}
.toast {
  min-width: 260px;
  max-width: 360px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-primary);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  padding: var(--sp-3) var(--sp-4);
  pointer-events: auto;
  animation: toast-in 0.16s ease-out;
}
.toast--success { border-left-color: var(--c-success); }
.toast--error   { border-left-color: var(--c-danger); }
.toast--warning { border-left-color: var(--c-warning); }
.toast__title {
  font-weight: var(--fw-semibold);
  margin-bottom: 2px;
}
.toast__msg {
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
}
@keyframes toast-in {
  from { transform: translateY(-6px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ---------- Modal ---------- */
.modal-root {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(16, 24, 40, 0.45);
  z-index: 90;
  padding: var(--sp-4);
}
.modal-root.is-open {
  display: flex;
}
.modal {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal__header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--c-border);
}
.modal__title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
}
.modal__body {
  padding: var(--sp-4) var(--sp-5);
}
.modal__footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--c-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
}

/* ---------- Form grid ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4);
}
.form-grid .field--full {
  grid-column: 1 / -1;
}
@media (max-width: 767px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Loader ---------- */
.loader {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--c-border-strong);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: var(--sp-2);
  border-bottom: 1px solid var(--c-border);
  margin-bottom: var(--sp-4);
}
.tabs__item {
  padding: var(--sp-2) var(--sp-3);
  color: var(--c-text-muted);
  font-weight: var(--fw-medium);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tabs__item.is-active {
  color: var(--c-primary);
  border-bottom-color: var(--c-primary);
}
