/* ==========================================================================
   Rapportini di Intervento - Foglio di Stile Principale & Stampa A4
   ========================================================================== */

:root {
  --primary: #1a56db;
  --primary-dark: #1e429f;
  --primary-light: #ebf5ff;
  --success: #0e9f6e;
  --success-light: #def7ec;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #e02424;
  --danger-light: #fde8e8;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
  font-size: 15px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --------------------------------------------------------------------------
   HEADER & NAVBAR
   -------------------------------------------------------------------------- */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--gray-900);
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: white;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: 0 2px 4px rgba(26, 86, 219, 0.3);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--gray-500);
  font-weight: 500;
}

.nav-tabs {
  display: flex;
  gap: 0.5rem;
  background: var(--gray-100);
  padding: 4px;
  border-radius: var(--radius-md);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--gray-600);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
}

.nav-tab:hover {
  color: var(--gray-900);
  background: rgba(255, 255, 255, 0.6);
}

.nav-tab.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.badge-count {
  background: var(--gray-200);
  color: var(--gray-700);
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 9999px;
  font-weight: 700;
}

.nav-tab.active .badge-count {
  background: var(--primary-light);
  color: var(--primary);
}

/* --------------------------------------------------------------------------
   MAIN CONTAINER & SECTIONS
   -------------------------------------------------------------------------- */
.main-container {
  max-width: 1280px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  flex: 1;
  width: 100%;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.2s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --------------------------------------------------------------------------
   CARDS & GRIDS
   -------------------------------------------------------------------------- */
.card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--gray-100);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-900);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-subtitle {
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-top: 2px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

/* --------------------------------------------------------------------------
   FORM CONTROLS
   -------------------------------------------------------------------------- */
.form-group {
  margin-bottom: 1.1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  color: var(--gray-900);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.15);
}

textarea.form-control {
  min-height: 110px;
  resize: vertical;
  font-family: inherit;
}

select.form-control {
  cursor: pointer;
}

.input-help {
  font-size: 0.78rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

/* --------------------------------------------------------------------------
   BADGES & ACCENTS
   -------------------------------------------------------------------------- */
.badge-number {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 0.45rem 1rem;
  border-radius: 9999px;
  font-weight: 700;
  font-size: 1rem;
  border: 1px solid rgba(26, 86, 219, 0.2);
}

.badge-hours {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--success-light);
  color: var(--success);
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1.1rem;
  border: 1px solid rgba(14, 159, 110, 0.25);
}

.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-status.inviato {
  background: var(--success-light);
  color: var(--success);
}

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

.badge-status.bozza {
  background: var(--warning-light);
  color: var(--warning);
}

/* --------------------------------------------------------------------------
   SIGNATURE PAD
   -------------------------------------------------------------------------- */
.signature-wrapper {
  background: #ffffff;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  position: relative;
  transition: border-color 0.2s;
}

.signature-wrapper:hover, .signature-wrapper:focus-within {
  border-color: var(--primary);
}

.signature-canvas {
  width: 100%;
  height: 180px;
  background-color: #fafbfc;
  border-radius: var(--radius-sm);
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.signature-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--gray-200);
}

.signature-info {
  font-size: 0.82rem;
  color: var(--gray-500);
}

/* --------------------------------------------------------------------------
   BUTTONS
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 4px rgba(26, 86, 219, 0.25);
}

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

.btn-success {
  background: var(--success);
  color: white;
  box-shadow: 0 2px 4px rgba(14, 159, 110, 0.25);
}

.btn-success:hover {
  background: #047451;
}

.btn-secondary {
  background: white;
  color: var(--gray-700);
  border-color: var(--gray-300);
}

.btn-secondary:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

.btn-danger {
  background: white;
  color: var(--danger);
  border-color: var(--danger-light);
}

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

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 0.85rem 1.6rem;
  font-size: 1.05rem;
}

.action-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.85rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--gray-200);
}

/* --------------------------------------------------------------------------
   TABLES & LISTS
   -------------------------------------------------------------------------- */
.table-responsive {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  background: #ffffff;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.92rem;
}

.table th {
  background: var(--gray-50);
  color: var(--gray-700);
  font-weight: 600;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}

.table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

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

.table tr:hover td {
  background-color: #f9fafb;
}

/* --------------------------------------------------------------------------
   SEARCH & FILTERS BAR
   -------------------------------------------------------------------------- */
.filter-bar {
  background: #ffffff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.search-input-wrapper {
  flex: 1;
  min-width: 240px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
}

.search-input {
  padding-left: 2.4rem;
}

/* --------------------------------------------------------------------------
   MODALS
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.65);
  backdrop-filter: blur(2px);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-backdrop.open {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal-box {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 860px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gray-900);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-400);
  line-height: 1;
}

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

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* --------------------------------------------------------------------------
   TOAST NOTIFICATIONS
   -------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  color: white;
  font-size: 0.92rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideUp 0.25s ease-out;
  max-width: 380px;
}

.toast-success { background: #065f46; }
.toast-error { background: #991b1b; }
.toast-info { background: #1e40af; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --------------------------------------------------------------------------
   DOCUMENTO A4 PER ANTEPRIMA & STAMPA PDF
   -------------------------------------------------------------------------- */
.printable-report {
  background: #ffffff;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 30px 36px;
  color: #111827;
  font-family: Arial, Helvetica, sans-serif;
  border: 1px solid #e5e7eb;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.rep-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #1a56db;
  padding-bottom: 16px;
  margin-bottom: 20px;
}

.rep-company-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: #1a56db;
  margin-bottom: 4px;
}

.rep-company-meta {
  font-size: 0.82rem;
  color: #4b5563;
  line-height: 1.4;
}

.rep-doc-title-box {
  text-align: right;
}

.rep-doc-name {
  font-size: 1.3rem;
  font-weight: 800;
  color: #111827;
  text-transform: uppercase;
}

.rep-doc-number {
  font-size: 1.15rem;
  font-weight: 700;
  color: #1a56db;
  margin-top: 4px;
}

.rep-doc-date {
  font-size: 0.85rem;
  color: #4b5563;
  margin-top: 2px;
}

.rep-section {
  margin-bottom: 18px;
}

.rep-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #1a56db;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 4px;
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}

.rep-box-client {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 12px 14px;
}

.rep-client-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}

.rep-grid-info {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 12px 14px;
}

.rep-info-item label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #64748b;
  display: block;
}

.rep-info-item span {
  font-size: 0.95rem;
  font-weight: 600;
  color: #0f172a;
}

.rep-hours-highlight {
  color: #0e9f6e !important;
  font-size: 1.05rem !important;
  font-weight: 800 !important;
}

.rep-text-content {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 0.92rem;
  line-height: 1.6;
  white-space: pre-wrap;
  min-height: 80px;
}

.rep-signature-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px dashed #cbd5e1;
}

.rep-signature-box {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 10px;
  height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #ffffff;
}

.rep-signature-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #64748b;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 4px;
}

.rep-signature-img {
  max-height: 75px;
  max-width: 100%;
  object-fit: contain;
  margin: auto auto 4px auto;
  display: block;
}

.rep-signature-footer {
  font-size: 0.7rem;
  color: #94a3b8;
  text-align: right;
}

.rep-footer-notes {
  margin-top: 24px;
  text-align: center;
  font-size: 0.72rem;
  color: #94a3b8;
  border-top: 1px solid #f1f5f9;
  padding-top: 8px;
}

/* --------------------------------------------------------------------------
   STILI DI STAMPA (@media print)
   -------------------------------------------------------------------------- */
@media print {
  body {
    background: #ffffff;
    color: #000000;
    margin: 0;
    padding: 0;
  }

  .app-header,
  .nav-tabs,
  .action-bar,
  .filter-bar,
  .modal-header,
  .modal-footer,
  .signature-controls,
  .toast-container,
  button,
  .btn,
  #tab-history,
  #tab-clients,
  #tab-settings {
    display: none !important;
  }

  .main-container {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .modal-backdrop {
    position: static !important;
    background: transparent !important;
    padding: 0 !important;
    display: block !important;
  }

  .modal-box {
    box-shadow: none !important;
    border: none !important;
    max-width: 100% !important;
  }

  .printable-report {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    max-width: 100% !important;
    page-break-after: avoid;
  }
}

/* --------------------------------------------------------------------------
   RESPONSIVE LAYOUT (SMARTPHONE / TABLET)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    align-items: stretch;
  }

  .nav-tabs {
    overflow-x: auto;
    width: 100%;
  }

  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }

  .action-bar {
    flex-direction: column-reverse;
  }

  .action-bar .btn {
    width: 100%;
  }

  .rep-grid-info {
    grid-template-columns: 1fr;
  }

  .rep-signature-block {
    grid-template-columns: 1fr;
  }
}

/* --------------------------------------------------------------------------
   STILI AUTENTICAZIONE 2FA & UPLOAD LOGO
   -------------------------------------------------------------------------- */
.totp-input {
  font-size: 1.8rem;
  letter-spacing: 0.35em;
  text-align: center;
  font-weight: 700;
  max-width: 260px;
  margin: 0 auto;
  font-family: monospace;
}

.qr-box {
  background: #ffffff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
  display: inline-block;
  box-shadow: var(--shadow-sm);
}

.qr-img {
  width: 190px;
  height: 190px;
  display: block;
  margin: 0 auto;
}

.secret-key-display {
  background: var(--gray-100);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-family: monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
  display: inline-block;
  margin-top: 0.5rem;
  letter-spacing: 0.1em;
}

.logo-upload-card {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-align: center;
  background: var(--gray-50);
  transition: all 0.2s;
  cursor: pointer;
}

.logo-upload-card:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.logo-preview-img {
  max-height: 90px;
  max-width: 240px;
  object-fit: contain;
  margin-bottom: 0.75rem;
  border-radius: var(--radius-sm);
  display: block;
  margin-left: auto;
  margin-right: auto;
}
