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

:root {
  --navy:      #1e2d4d;
  --navy-dark: #162240;
  --yellow:    #f5c518;
  --yellow-bg: #fff8e1;
  --bg:        #f0f2f5;
  --white:     #ffffff;
  --border:    #dde1e9;
  --text:      #1a1a2e;
  --text-muted:#6b7280;
  --red:       #dc2626;
  --green:     #16a34a;
  --blue:      #2563eb;
  --orange:    #ea580c;
  --radius-card: 8px;
  --radius-input: 4px;
  --shadow:    0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

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

/* =============================================
   LOGIN PAGE
   ============================================= */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--navy) 0%, #2a4080 100%);
}

.login-card {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.5px;
}

.login-logo .accent {
  color: var(--yellow);
}

.login-logo p {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--navy);
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
  outline: none;
  color: var(--text);
}

.form-group input:focus {
  border-color: var(--navy);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--navy);
  color: var(--white);
  border: none;
  border-radius: var(--radius-input);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-msg {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius-input);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.error-msg.visible {
  display: block;
}

/* =============================================
   DASHBOARD LAYOUT
   ============================================= */
.dashboard-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--navy);
  color: var(--white);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-brand h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-brand .dot {
  width: 8px;
  height: 8px;
  background: var(--yellow);
  border-radius: 50%;
}

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

.header-user span {
  font-size: 13px;
  opacity: 0.85;
}

.btn-change-pwd {
  padding: 6px 14px;
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.35);
  border-radius: var(--radius-input);
  color: var(--white);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-change-pwd:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.6);
}

.btn-logout {
  padding: 6px 14px;
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.35);
  border-radius: var(--radius-input);
  color: var(--white);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-logout:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.6);
}

/* Main content */
.main-content {
  flex: 1;
  padding: 24px 28px;
}

/* Filters bar */
.filters-bar {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-input,
.filter-select {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  background: var(--white);
}

.filter-input {
  flex: 1;
  min-width: 220px;
}

.filter-select {
  min-width: 160px;
}

.filter-input:focus,
.filter-select:focus {
  border-color: var(--navy);
}

.filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-reset {
  padding: 8px 14px;
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 13px;
  font-family: inherit;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-reset:hover {
  border-color: var(--navy);
  color: var(--navy);
}

/* Table wrapper */
.table-card {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1100px;
}

thead {
  background: var(--navy);
  color: var(--white);
}

thead th {
  padding: 12px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

thead th.col-yellow {
  background: #253a61;
  color: var(--yellow);
}

thead th[data-col] {
  cursor: pointer;
  user-select: none;
}

thead th[data-col]:hover {
  background: #2a3f6b;
}

thead th[data-col]::after {
  content: ' ⇅';
  opacity: 0.35;
  font-size: 11px;
}

thead th[data-col].sort-asc::after {
  content: ' ↑';
  opacity: 1;
}

thead th[data-col].sort-desc::after {
  content: ' ↓';
  opacity: 1;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

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

tbody tr:hover {
  background: #f7f8fa;
}

tbody td {
  padding: 10px 14px;
  font-size: 13px;
  vertical-align: middle;
}

tbody td.col-yellow {
  background: var(--yellow-bg);
}

tbody tr:hover td.col-yellow {
  background: #fff3c4;
}

.cell-codice {
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
}

.cell-cliente {
  font-weight: 500;
}

.cell-titolo {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-date {
  white-space: nowrap;
  color: var(--text-muted);
}

/* Badges stato */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-orange {
  background: #fff0e6;
  color: var(--orange);
}

.badge-blue {
  background: #eff6ff;
  color: var(--blue);
}

.badge-gray {
  background: #f3f4f6;
  color: #6b7280;
}

/* Toggle "In controllo" */
.toggle-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}

.toggle {
  position: relative;
  width: 42px;
  height: 22px;
  display: inline-block;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.25s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  left: 3px;
  top: 3px;
  transition: transform 0.25s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle input:checked + .toggle-slider {
  background: var(--yellow);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* Date input inline */
.inline-date {
  border: 1.5px solid transparent;
  border-radius: var(--radius-input);
  padding: 5px 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  width: 130px;
  transition: border-color 0.2s, background 0.2s;
  outline: none;
}

.inline-date:hover,
.inline-date:focus {
  border-color: var(--navy);
  background: var(--white);
}

/* Select inline categorizzazione */
.inline-select {
  border: 1.5px solid transparent;
  border-radius: var(--radius-input);
  padding: 5px 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  width: 100%;
  min-width: 160px;
  max-width: 200px;
  transition: border-color 0.2s, background 0.2s;
  outline: none;
  cursor: pointer;
}

.inline-select:hover,
.inline-select:focus {
  border-color: var(--navy);
  background: var(--white);
}

/* Spinner */
.spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 6px;
  vertical-align: middle;
}

.spinner.visible {
  display: inline-block;
}

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

/* Footer tabella */
.table-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Loading state */
.loading-row td {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-card);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: auto;
  max-width: 320px;
}

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

.toast-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: var(--green);
}

.toast-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--red);
}

.toast-icon {
  font-size: 16px;
  flex-shrink: 0;
}

/* Empty state */
.empty-row td {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Refresh button */
.btn-refresh {
  padding: 8px 16px;
  background: var(--navy);
  color: var(--white);
  border: none;
  border-radius: var(--radius-input);
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-refresh:hover {
  background: var(--navy-dark);
}

/* =============================================
   SUCCESS MSG & LINK FORGOT
   ============================================= */
.success-msg {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #16a34a;
  padding: 10px 14px;
  border-radius: var(--radius-input);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.success-msg.visible {
  display: block;
}

.link-forgot {
  color: var(--text-muted);
  font-size: 13px;
  text-decoration: none;
}

.link-forgot:hover {
  color: var(--navy);
  text-decoration: underline;
}

/* =============================================
   ADMIN PAGE
   ============================================= */
.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.admin-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
}

.btn-action {
  padding: 5px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--white);
  color: var(--text);
}

.btn-edit:hover {
  border-color: var(--navy);
  color: var(--navy);
}

.btn-pwd:hover {
  border-color: var(--orange);
  color: var(--orange);
}

/* =============================================
   MODALE
   ============================================= */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

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

.modal-card {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  width: 100%;
  max-width: 420px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

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

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

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

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 768px) {
  .main-content {
    padding: 16px;
  }

  .filters-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-input,
  .filter-select {
    width: 100%;
  }

  .header {
    padding: 0 16px;
  }
}
