/* Quadra Audit Web App — palette + layout */

:root {
  --c-bg: #f7f8fa;
  --c-card: #ffffff;
  --c-border: #e5e7eb;
  --c-text: #1f2937;
  --c-text-muted: #6b7280;
  --c-primary: #166534;       /* verde Quadra */
  --c-primary-hover: #14532d;
  --c-success: #16a34a;
  --c-danger: #dc2626;
  --c-warning: #d97706;
  --c-tango: #16a34a;         /* verde */
  --c-aquila: #2563eb;        /* blu */
  --c-lanciano: #ea580c;      /* arancione */
  --c-shadow: 0 2px 4px rgba(0,0,0,0.06);
  --c-shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
  --r-md: 8px;
  --r-lg: 12px;
  --gap-sm: 8px;
  --gap-md: 16px;
  --gap-lg: 24px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.5;
  min-height: 100vh;
}

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border: none;
  padding: 10px 16px;
  border-radius: var(--r-md);
  transition: background 0.15s, opacity 0.15s, transform 0.05s;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--c-primary); color: white; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--c-primary-hover); }
button.secondary { background: #e5e7eb; color: var(--c-text); }
button.secondary:hover:not(:disabled) { background: #d1d5db; }
button.danger { background: var(--c-danger); color: white; }
button.danger:hover:not(:disabled) { background: #b91c1c; }
button.ghost { background: transparent; color: var(--c-text-muted); padding: 6px 10px; }
button.ghost:hover:not(:disabled) { color: var(--c-text); background: #f3f4f6; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"] {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: white;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(22, 101, 52, 0.1);
}

/* ===== LOGIN ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
}
.login-card {
  background: var(--c-card);
  padding: 40px 32px;
  border-radius: var(--r-lg);
  box-shadow: var(--c-shadow-lg);
  width: 100%;
  max-width: 380px;
}
.login-card h1 {
  text-align: center;
  margin-bottom: 8px;
  color: var(--c-primary);
  font-size: 28px;
}
.login-card .subtitle {
  text-align: center;
  color: var(--c-text-muted);
  margin-bottom: 32px;
  font-size: 14px;
}
.login-card label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 13px;
  color: var(--c-text);
}
.login-card .form-group { margin-bottom: 16px; }
.login-card button { width: 100%; padding: 12px; font-size: 15px; }
.login-card .error {
  background: #fef2f2;
  color: var(--c-danger);
  border: 1px solid #fecaca;
  padding: 10px 12px;
  border-radius: var(--r-md);
  margin-bottom: 16px;
  font-size: 13px;
  display: none;
}
.login-card .error.show { display: block; }

/* ===== AUDIT PAGE ===== */
.audit-page { display: flex; flex-direction: column; min-height: 100vh; }

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: white;
  border-bottom: 1px solid var(--c-border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  box-shadow: var(--c-shadow);
}
.header h1 { font-size: 18px; font-weight: 600; color: var(--c-primary); flex-shrink: 0; }
.header .counters { display: flex; gap: 12px; flex: 1; flex-wrap: wrap; }
.counter-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: white;
}
.counter-badge.tango { background: var(--c-tango); }
.counter-badge.aquila { background: var(--c-aquila); }
.counter-badge.lanciano { background: var(--c-lanciano); }
.counter-badge.total { background: var(--c-text-muted); }

.user-info { font-size: 13px; color: var(--c-text-muted); margin-right: 8px; }

/* ===== LISTA DDT ===== */
.list-view { padding: 20px 24px; flex: 1; }
.list-title { font-size: 15px; color: var(--c-text-muted); margin-bottom: 16px; }

.list-banner {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-left: 4px solid var(--c-primary);
  padding: 14px 16px;
  border-radius: var(--r-md);
  margin-bottom: 20px;
  color: var(--c-text);
  font-size: 14px;
  line-height: 1.55;
}
.list-banner .banner-icon { font-size: 22px; line-height: 1; flex-shrink: 0; margin-top: 2px; }
.list-banner .banner-text { flex: 1; }
.list-banner em { font-style: normal; font-weight: 600; color: var(--c-primary); }

@keyframes cardFadeOut {
  from { opacity: 1; transform: scale(1); max-height: 200px; margin-bottom: var(--gap-md); padding-top: 14px; padding-bottom: 14px; }
  to { opacity: 0; transform: scale(0.92); max-height: 0; margin-bottom: 0; padding-top: 0; padding-bottom: 0; overflow: hidden; }
}
.ddt-card.removing { animation: cardFadeOut 0.4s ease forwards; pointer-events: none; }
.ddt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--gap-md);
}
.ddt-card {
  background: white;
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.05s;
}
.ddt-card:hover { box-shadow: var(--c-shadow); }
.ddt-card:active { transform: translateY(1px); }
.ddt-card.tango { border-left-color: var(--c-tango); }
.ddt-card.aquila { border-left-color: var(--c-aquila); }
.ddt-card.lanciano { border-left-color: var(--c-lanciano); }
.ddt-card.conf-bassa { border-right: 4px solid var(--c-danger); }
.ddt-card .row1 { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.ddt-card .ddt-num { font-weight: 600; font-size: 15px; }
.ddt-card .ddt-id { color: var(--c-text-muted); font-size: 12px; }
.ddt-card .fornitore { color: var(--c-text); font-size: 14px; margin-bottom: 6px; }
.ddt-card .row3 { display: flex; justify-content: space-between; font-size: 12px; color: var(--c-text-muted); }
.ddt-card .totale { font-weight: 500; color: var(--c-text); }
.ddt-card .conf {
  text-transform: uppercase;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #f3f4f6;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.ddt-card .conf.bassa { background: #fef2f2; color: var(--c-danger); }
.ddt-card .conf.media { background: #fffbeb; color: var(--c-warning); }
.ddt-card .conf.alta { background: #f0fdf4; color: var(--c-success); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--c-text-muted);
}
.empty-state h2 { color: var(--c-text); margin-bottom: 8px; }

/* ===== VISTA AUDIT DDT ===== */
.audit-view { display: none; flex: 1; }
.audit-view.show { display: flex; flex-direction: column; height: 100vh; max-height: 100vh; overflow: hidden; }

.audit-header {
  position: sticky;
  top: 0;
  background: white;
  border-bottom: 1px solid var(--c-border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 10;
}
.audit-header .ddt-title { flex: 1; font-weight: 600; font-size: 15px; }
.audit-header .ddt-title small { color: var(--c-text-muted); font-weight: normal; }
.audit-header .badge-pending {
  background: var(--c-warning);
  color: white;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  display: none;
}
.audit-header .badge-pending.show { display: inline-block; }

.audit-body {
  display: grid;
  grid-template-columns: 3fr 2fr;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

@media (max-width: 1023px) { .audit-body { grid-template-columns: 65% 35%; } }
@media (max-width: 767px)  { .audit-body { grid-template-columns: 1fr; } }

.foto-pane {
  background: #1f2937;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.foto-pane.no-photo { background: #f3f4f6; color: var(--c-text-muted); font-size: 14px; }
.foto-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.foto-container img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.foto-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  gap: 6px;
  z-index: 5;
}
.foto-controls button {
  background: rgba(0, 0, 0, 0.7);
  color: white;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.foto-controls button:hover { background: rgba(0, 0, 0, 0.9); }

.data-pane {
  background: white;
  padding: 16px 20px;
  overflow-y: auto;
  border-left: 1px solid var(--c-border);
}
.data-pane h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--c-text-muted);
  margin-bottom: 10px;
  margin-top: 8px;
}
.data-pane h3:first-child { margin-top: 0; }

.field {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #f3f4f6;
  font-size: 14px;
  align-items: center;
}
.field .label { color: var(--c-text-muted); font-weight: 500; }
.field .value { color: var(--c-text); display: flex; align-items: center; gap: 6px; }
.field .value.editable { cursor: pointer; padding: 4px 8px; margin: -4px -8px; border-radius: 4px; }
.field .value.editable:hover { background: #f9fafb; }
.field .value.editable.modified { background: #fffbeb; }
.field .value .pen { opacity: 0.4; font-size: 11px; }
.field .value.editable:hover .pen { opacity: 0.9; }
.field .value input { padding: 4px 8px; font-size: 14px; height: 28px; }

.riga {
  background: #f9fafb;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.riga .riga-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 13px;
}
.riga .riga-head .num { color: var(--c-text-muted); font-size: 12px; }
.riga .desc { font-weight: 500; margin-bottom: 4px; font-size: 14px; }
.riga .desc-edit { cursor: pointer; padding: 2px 4px; margin: -2px -4px; border-radius: 3px; }
.riga .desc-edit:hover { background: #ffffff; }
.riga .desc-edit.modified { background: #fffbeb; }
.riga .riga-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 6px;
  font-size: 12px;
  color: var(--c-text-muted);
}
.riga .riga-grid .cell .lbl { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.3px; }
.riga .riga-grid .cell .val { color: var(--c-text); display: flex; align-items: center; gap: 4px; cursor: pointer; padding: 2px 4px; margin: -2px -4px; border-radius: 3px; font-size: 13px; }
.riga .riga-grid .cell .val:hover { background: white; }
.riga .riga-grid .cell .val.modified { background: #fffbeb; }
.riga .riga-grid .cell .val input { padding: 2px 4px; font-size: 13px; height: 22px; width: 80px; }

.audit-footer {
  background: white;
  border-top: 1px solid var(--c-border);
  padding: 14px 24px;
  display: flex;
  gap: 8px;
  align-items: center;
  position: sticky;
  bottom: 0;
}
.audit-footer .spacer { flex: 1; }
.audit-footer button { font-size: 14px; padding: 10px 18px; }
.audit-footer button.primary { padding: 10px 24px; font-size: 15px; }
.audit-footer .nav-buttons { display: flex; gap: 4px; }
.audit-footer .nav-buttons button { padding: 8px 12px; }

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--c-text);
  color: white;
  padding: 12px 20px;
  border-radius: var(--r-md);
  box-shadow: var(--c-shadow-lg);
  font-size: 14px;
  animation: slideUp 0.2s ease;
}
.toast.success { background: var(--c-success); }
.toast.error { background: var(--c-danger); }
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ===== DIALOG ===== */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.dialog-overlay.show { display: flex; }
.dialog {
  background: white;
  border-radius: var(--r-lg);
  padding: 24px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--c-shadow-lg);
}
.dialog h2 { margin-bottom: 8px; font-size: 18px; }
.dialog p { color: var(--c-text-muted); margin-bottom: 16px; font-size: 14px; }
.dialog .diff-list { background: #f9fafb; border-radius: var(--r-md); padding: 12px; margin-bottom: 16px; font-size: 13px; max-height: 240px; overflow-y: auto; }
.dialog .diff-row { padding: 4px 0; border-bottom: 1px solid #f3f4f6; }
.dialog .diff-row:last-child { border-bottom: none; }
.dialog .diff-row code { font-family: 'SF Mono', Monaco, Consolas, monospace; background: white; padding: 1px 4px; border-radius: 3px; border: 1px solid var(--c-border); }
.dialog .actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ===== FOTO FULLSCREEN ===== */
.fullscreen-foto {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: zoom-out;
}
.fullscreen-foto.show { display: flex; }
.fullscreen-foto img { max-width: 95vw; max-height: 95vh; user-select: none; -webkit-user-drag: none; }
.fullscreen-foto .close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
}

/* ===== LOADING ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--c-text-muted);
  font-size: 14px;
}
.loading::before {
  content: '';
  width: 18px;
  height: 18px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  margin-right: 10px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
