/* =========================================
VARIABILI & RESET
========================================= */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --success-hover: #059669;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --secondary: #64748b;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --transition: all 0.2s ease;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =========================================
2. LOGIN PAGE
========================================= */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 100%);
}
.login-card {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
}
.login-header { text-align: center; margin-bottom: 1.5rem; }
.login-header i { font-size: 2.5rem; color: var(--primary); margin-bottom: 0.5rem; }
.login-header h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 0.25rem; }
.login-header p { color: var(--text-muted); font-size: 0.9rem; }
.btn-home {
  display: inline-block;
  margin: 1rem 0;
  color: var(--primary);
  font-weight: 500;
  text-decoration: none;
}
.btn-home:hover { text-decoration: underline; }
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.35rem;
}
.form-control {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: #fff;
  transition: var(--transition);
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.alert-error, .alert {
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.88rem;
}
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.info-box {
  background: #eff6ff;
  color: #1e40af;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid #bfdbfe;
  font-size: 0.85rem;
  margin-top: 1rem;
}
.btn-login, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
}
.btn-login { background: var(--primary); color: #fff; }
.btn-login:hover { background: var(--primary-hover); }
.footer {
  text-align: center;
  margin-top: 2rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* =========================================
3. MAIN INTERFACE
========================================= */
.user-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  font-size: 0.88rem;
}
.user-info { display: flex; align-items: center; gap: 0.5rem; }
.logout-btn {
  color: var(--danger);
  font-weight: 500;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.logout-btn:hover { background: #fef2f2; text-decoration: none; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem 3rem; }
.page-header { margin-bottom: 1.5rem; }
.page-title { font-size: 1.5rem; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 0.6rem; }
.page-subtitle { color: var(--text-muted); font-size: 0.95rem; margin-top: 0.2rem; }
.alert { margin-bottom: 1.5rem; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card h3, .card h4 { margin-bottom: 1rem; color: var(--text); }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}
.text-muted { color: var(--text-muted); font-size: 0.82rem; margin-top: 0.3rem; }
.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.btn { width: auto; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-hover); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: #475569; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 0.45rem 0.8rem; font-size: 0.82rem; }
.warning-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  margin: 1rem 0;
  font-size: 0.88rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

/* =========================================
4. TABLES & PREVIEW
========================================= */
.table-responsive { overflow-x: auto; margin: 1rem 0; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.preview-table th, .preview-table td {
  padding: 0.8rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.preview-table th { background: #f8fafc; font-weight: 600; color: var(--text-muted); }
.preview-table tr:hover { background: #f9fafb; }
.old-value { color: var(--text-muted); text-decoration: line-through; opacity: 0.85; }
.new-value { color: var(--success); font-weight: 500; }
.pagination-container { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; margin: 1.5rem 0 1rem; }
.page-info { background: #f1f5f9; padding: 0.4rem 0.8rem; border-radius: var(--radius-sm); font-size: 0.82rem; }

/* =========================================
5. MOBILE OPTIMIZATION (Smartphone)
========================================= */
@media (max-width: 768px) {
  :root { --font-base: 0.85rem; }
  body { font-size: var(--font-base); line-height: 1.4; }
  
  /* 📉 Riduzione icone globale */
  i.fas, i.far, i.fal, i.fab, i.fad { font-size: 0.82em; }
  .login-header i { font-size: 2rem; }
  .page-title i, .card h3 i, .card h4 i, .alert i, .warning-box i, .info-box i { font-size: 0.88em; }
  .form-group label i, .user-info i { font-size: 0.85em; }

  /* 📉 Testi e spaziatura */
  .login-header h1 { font-size: 1.25rem; }
  .login-header p { font-size: 0.82rem; }
  .page-title { font-size: 1.2rem; }
  .page-subtitle { font-size: 0.82rem; }
  .card h3, .card h4 { font-size: 1.05rem; margin-bottom: 0.7rem; }
  .form-group label { font-size: 0.78rem; }
  .text-muted { font-size: 0.75rem; }
  
  /* 📱 Form e Pulsanti (touch-friendly ma compatti) */
  .login-container, .container { padding-left: 0.9rem; padding-right: 0.9rem; }
  .login-card { padding: 1.25rem; max-width: 100%; }
  .card { padding: 1rem; margin-bottom: 1rem; }
  .form-control { padding: 0.65rem 0.8rem; font-size: 0.88rem; }
  .btn, .btn-login { padding: 0.7rem 0.9rem; font-size: 0.88rem; min-height: 44px; }
  .btn-sm { padding: 0.35rem 0.65rem; font-size: 0.76rem; }
  
  /* Layout adattivo */
  .user-bar { flex-direction: column; align-items: flex-start; gap: 0.5rem; padding: 0.6rem 0.9rem; margin-bottom: 1rem; }
  .user-info { font-size: 0.82rem; width: 100%; justify-content: space-between; }
  .logout-btn { align-self: flex-end; }
  .form-grid { grid-template-columns: 1fr; gap: 0.7rem; }
  .action-buttons { flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
  
  /* Tabelle e Paginazione */
  .preview-table { font-size: 0.78rem; }
  .preview-table th, .preview-table td { padding: 0.55rem 0.65rem; }
  .pagination-container { gap: 0.35rem; }
  .page-info { font-size: 0.72rem; padding: 0.3rem 0.6rem; }
  
  /* Box informativi */
  .warning-box, .alert, .info-box { font-size: 0.8rem; padding: 0.65rem 0.8rem; gap: 0.4rem; }
  .info-box { margin-top: 0.8rem; }
}

/* Utility & Overrides */
input[type="text"], input[type="password"], select, textarea { font-family: inherit; }
select.form-control {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.2em;
  padding-right: 2.2rem;
}