/**
 * Toolbox MSP — Stile condiviso v1.0
 * Incluso in ogni pagina con <link rel="stylesheet" href="style.css">
 * Ogni HTML mantiene solo il CSS specifico del proprio modulo.
 */

/* === TOKENS === */
:root {
  /* Colori base */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  /* Colori accento */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fef2f2;
  --warn: #f59e0b;
  --warn-light: #fffbeb;
  --positive: #16a34a;
  --positive-light: #f0fdf4;

  /* Bordi e ombre */
  --border: #e2e8f0;
  --border-focus: #2563eb;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);

  /* Raggi */
  --radius: 6px;
  --radius-lg: 10px;

  /* Font */
  --font-main: Arial, Helvetica, sans-serif;
  --font-mono: Consolas, 'Courier New', monospace;
}

/* === RESET === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* === HEADER === */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-left h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* === PULSANTE DASHBOARD === */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: var(--font-main);
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-back:hover {
  color: var(--text);
  background: var(--border);
}

/* === PULSANTI === */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-family: var(--font-main);
  font-weight: 600;
  color: #ffffff;
  background: var(--primary);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-family: var(--font-main);
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-outline:hover {
  background: var(--surface-alt);
  border-color: var(--text-muted);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-family: var(--font-main);
  font-weight: 600;
  color: #ffffff;
  background: var(--danger);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* === CONTAINER === */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

/* === CARD === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.card-body {
  padding: 16px;
}

/* === TABELLE === */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--surface-alt);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

table th.sortable {
  cursor: pointer;
  user-select: none;
}

table th.sortable:hover {
  color: var(--primary);
}

table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table tr:hover td {
  background: var(--primary-light);
}

table .mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

/* === BADGE === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-radius: 4px;
  white-space: nowrap;
}

.badge-danger {
  background: var(--danger-light);
  color: var(--danger);
}

.badge-warn {
  background: var(--warn-light);
  color: #b45309;
}

.badge-positive {
  background: var(--positive-light);
  color: var(--positive);
}

.badge-muted {
  background: var(--surface-alt);
  color: var(--text-muted);
}

.badge-primary {
  background: var(--primary-light);
  color: var(--primary);
}

/* === FORM === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  font-family: var(--font-main);
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-row .form-group {
  flex: 1;
}

/* === MODALE === */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

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

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  z-index: 300;
  transition: opacity 0.3s, transform 0.3s;
  opacity: 0;
  transform: translateY(10px);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

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

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state .emoji {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 16px;
}

/* === LOADING === */
.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--text-muted);
  font-size: 14px;
}

/* === TOOLBAR LISTA === */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.list-toolbar .counter {
  font-size: 13px;
  color: var(--text-muted);
}

/* === FILTRI === */
.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.filters input,
.filters select {
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--font-main);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filters input:focus,
.filters select:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* === LISTA ITEMS === */
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: box-shadow 0.15s;
}

.list-item:hover {
  box-shadow: var(--shadow-sm);
}

.list-item .title-row {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.list-item .meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.list-actions {
  display: flex;
  gap: 6px;
}

.list-actions button {
  padding: 4px 10px;
  font-size: 12px;
  font-family: var(--font-main);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.15s;
}

.list-actions button:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.list-actions button.action-danger:hover {
  background: var(--danger-light);
  color: var(--danger);
}

/* === CONFIRM DIALOG === */
.confirm-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 250;
  align-items: center;
  justify-content: center;
}

.confirm-overlay.active {
  display: flex;
}

.confirm-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 24px;
  max-width: 400px;
  text-align: center;
}

.confirm-box p {
  margin-bottom: 16px;
  font-size: 14px;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* === UTILITY === */
.hidden {
  display: none !important;
}

.view-hidden {
  display: none !important;
}

.text-mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

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

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

/* ── AUTOCOMPLETE ── */
.ac-wrap {
  position: relative;
}
.ac-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 180px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 10;
}
.ac-list.open { display: block; }
.ac-item {
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background .1s;
}
.ac-item:hover, .ac-item.active {
  background: var(--primary-light);
}
.ac-item.ac-add {
  color: var(--primary);
  font-weight: 600;
  border-top: 1px solid var(--border);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .app-header {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-left h1 {
    font-size: 15px;
  }

  .container {
    padding: 16px;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .modal {
    width: 95%;
    max-width: none;
  }

  .list-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .filters {
    flex-direction: column;
    width: 100%;
  }

  .filters input,
  .filters select {
    width: 100%;
  }

  table {
    font-size: 12px;
  }

  table th,
  table td {
    padding: 8px 6px;
  }
}
