/* ========================================================================
   QMS Mercury Dark – Tokens & Base Theme
   Design System Globale per Quality Management System
   ======================================================================== */

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  overflow-x: hidden;
  overflow-y: scroll;
}

:root {
  /* Palette Mercury Dark */
  --qms-bg: #0b1020;
  --qms-surface: #121a2f;            /* base card */
  --qms-surface-2: #0f162a;          /* toolbar / input */
  --qms-surface-3: #0b1224;          /* header ribbon */
  --qms-grad-1: #101c33;             /* gradient card start */
  --qms-grad-2: #0e1a30;             /* gradient card end */
  
  /* Typography */
  --qms-text: #e9eef7;
  --qms-muted: #a7b5cd;
  
  /* Brand Colors */
  --qms-primary: #ff4d4d;            /* headline rosso vivo (screenshot) */
  --qms-accent: #23c4ff;             /* link / micro accent */
  
  /* Stati Semantici */
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --info: #3b82f6;
  
  /* Chip/Tag */
  --chip: #223154;
  --chip-text: #d6e4ff;
  
  /* UI Elements */
  --border: #223154;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  
  /* Spacing & Effects */
  --radius-xl: 18px;
  --radius: 12px;
  --pad: 16px;
  --pad-lg: 22px;
  
  /* Typography */
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* ========== Reset leggero (non aggressivo) ========== */
.qms * {
  box-sizing: border-box;
}

.qms body,
.qms {
  background: var(--qms-bg);
  color: var(--qms-text);
  font-family: var(--font);
  line-height: 1.6;
}

/* Link NO underline, NO viola visited */
.qms a,
.qms a:visited {
  color: var(--qms-text);
  text-decoration: none;
}

.qms a:hover {
  color: var(--qms-accent);
}

/* ========== Layout ========== */
/* Grid & Spacing Unificati */
:root {
  --qms-gap: 18px;           /* distanza tra card */
  --qms-pad-card: 20px;      /* padding interno uniforme */
}

.qms .container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px;
}

/* ========== Header Ribbon / Banner Sezione ========== */
/* Come screenshot "Registro Non Conformità" */
.qms .ribbon {
  background: var(--qms-surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 18px var(--pad-lg);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.qms .ribbon .title {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--qms-primary);
  margin: 0;
  line-height: 1.2;
}

.qms .ribbon .subtitle {
  color: var(--qms-muted);
  margin-top: 6px;
  font-size: 0.95rem;
}

/* ========== Grid System Unificato ========== */
.qms .grid {
  display: grid;
  gap: var(--qms-gap);
}

.qms .grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.qms .grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.qms .grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Responsive Grid */
@media (max-width: 1100px) {
  .qms .grid.cols-3,
  .qms .grid.cols-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 700px) {
  .qms .grid.cols-2,
  .qms .grid.cols-3,
  .qms .grid.cols-4 {
    grid-template-columns: 1fr;
  }
}

/* ========== Card Unificate (Stessa elevazione, padding, raggio) ========== */
.qms .card {
  background: linear-gradient(180deg, #101c33, #0e1a30);
  border: 1px solid var(--border);
  border-radius: var(--qms-radius-xl);
  padding: var(--qms-pad-card);
  box-shadow: var(--shadow);
  min-height: 160px;              /* evita card "saltellanti" */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.3s;
  word-wrap: break-word;          /* evita overflow titoli lunghi */
}

.qms .card:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

/* ========== Typography ========== */
.qms h1,
.qms h2,
.qms h3 {
  margin: 0 0 10px;
  font-weight: 800;
  color: var(--qms-text);
}

.qms h1 {
  font-size: 2rem;
}

.qms h2 {
  font-size: 1.25rem;
}

.qms h3 {
  font-size: 1.1rem;
}

/* Tipografia coerente nelle card */
.qms .card h2 {
  font-size: 1.12rem;
  font-weight: 800;
  margin: 0 0 6px;
  letter-spacing: 0.2px;
}

.qms .card .muted {
  color: var(--qms-muted);
  line-height: 1.45;
  font-size: 0.98rem;
}

.qms .muted {
  color: var(--qms-muted);
  font-size: 0.98rem;
}

.qms p,
.qms .muted {
  font-size: 0.98rem;
}

.qms .text-accent {
  color: var(--qms-accent);
}

/* ========== Chip / Pill ========== */
.qms .chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.qms .chip {
  background: var(--chip);
  color: var(--chip-text);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  display: inline-flex;     /* allineamento baseline */
  align-items: center;
  line-height: 1;
}

/* ========== Bottoni ========== */
.qms .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--qms-surface-2);
  color: var(--qms-text);
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  text-decoration: none;
  font-family: inherit;
}

.qms .btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.qms .btn.primary {
  background: var(--qms-primary);
  border-color: transparent;
  color: #fff;
}

.qms .btn.primary:hover {
  background: #ff3333;
}

.qms .btn.accent {
  background: var(--qms-accent);
  border-color: transparent;
  color: #000;
}

.qms .btn.ghost {
  background: transparent;
  border-color: var(--border);
}

/* ========== Tabelle ========== */
.qms table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 10px;
}

.qms th {
  color: #cfe0f6;
  text-align: left;
  padding: 10px 12px;
  font-weight: 700;
  background: rgba(10, 102, 194, 0.08);
}

.qms td {
  background: var(--qms-surface);
  border: 1px solid var(--border);
  padding: 12px;
}

.qms tr td:first-child {
  border-radius: 12px 0 0 12px;
}

.qms tr td:last-child {
  border-radius: 0 12px 12px 0;
}

.qms tr:hover td {
  background: rgba(18, 26, 47, 0.8);
}

/* ========== Form ========== */
.qms label {
  display: block;
  margin: 10px 0 6px;
  color: #cfe0f6;
  font-weight: 500;
}

.qms input,
.qms select,
.qms textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--qms-surface-2);
  color: var(--qms-text);
  font-family: inherit;
  font-size: 1rem;
}

.qms input:focus,
.qms select:focus,
.qms textarea:focus {
  outline: 2px solid var(--qms-accent);
  outline-offset: 2px;
}

.qms input::placeholder {
  color: var(--qms-muted);
}

/* ========== Badge Stato ========== */
.qms .badge {
  padding: 5px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  display: inline-block;
}

.qms .badge.ok {
  background: rgba(34, 197, 94, 0.16);
  color: #b2f7c7;
}

.qms .badge.warn {
  background: rgba(245, 158, 11, 0.16);
  color: #ffd491;
}

.qms .badge.err {
  background: rgba(239, 68, 68, 0.16);
  color: #ffb7b7;
}

.qms .badge.info {
  background: rgba(59, 130, 246, 0.16);
  color: #a8c9ff;
}

/* ========== Toast (minimal per feedback) ========== */
.qms-toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.qms-toast .t {
  padding: 10px 14px;
  border-radius: 12px;
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 600;
  pointer-events: auto;
  min-width: 220px;
  animation: slideInToast 0.3s ease-out;
}

@keyframes slideInToast {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.qms-toast .t.ok {
  background: #16a34a;
}

.qms-toast .t.err {
  background: #dc2626;
}

.qms-toast .t.info {
  background: #2563eb;
}

.qms-toast .t.warn {
  background: #f59e0b;
}

/* ========== Icon Bottoncini ========== */
.qms .icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--qms-surface-2);
  border: 1px solid var(--border);
  color: #cfe0f6;
  cursor: pointer;
  transition: all 0.2s;
}

.qms .icon-btn:hover {
  filter: brightness(1.05);
  background: rgba(35, 196, 255, 0.1);
}

/* ========== Toolbar / Actions ========== */
.qms .toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 12px 0;
}

/* ========== Stats Cards ========== */
.qms .stat-card {
  text-align: center;
  padding: 1.5rem;
}

.qms .stat-card .value {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--qms-primary);
  line-height: 1;
  margin-bottom: 0.5rem;
}

.qms .stat-card .label {
  color: var(--qms-muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ========== Utility Classes ========== */
.qms .flex {
  display: flex;
}

.qms .flex-col {
  flex-direction: column;
}

.qms .items-center {
  align-items: center;
}

.qms .justify-between {
  justify-content: space-between;
}

.qms .gap-2 {
  gap: 0.5rem;
}

.qms .gap-4 {
  gap: 1rem;
}

.qms .mt-4 {
  margin-top: 1rem;
}

.qms .mb-4 {
  margin-bottom: 1rem;
}

/* ========== Accessibility ========== */
.qms .sr-only {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.qms [aria-label] {
  outline-offset: 2px;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .qms .container {
    padding: 12px;
  }
  
  .qms .ribbon {
    padding: 14px 16px;
  }
  
  .qms .ribbon .title {
    font-size: 1.3rem;
  }
  
  .qms .card {
    padding: 16px;
  }
  
  .qms table {
    font-size: 0.9rem;
  }
  
  .qms td,
  .qms th {
    padding: 8px;
  }
}

/* ========== Print Styles ========== */
@media print {
  .qms {
    background: white;
    color: black;
  }
  
  .qms .card,
  .qms .ribbon {
    border: 1px solid #ccc;
    box-shadow: none;
    page-break-inside: avoid;
  }
}


/* === CARICHI ARRIVO: componenti coerenti === */
.qms .toolbar-right{display:flex;gap:10px;justify-content:flex-end;margin:16px 0}
.qms .kpi-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:14px;margin:14px 0}
@media(max-width:1000px){.qms .kpi-grid{grid-template-columns:repeat(2,1fr)}}
.qms .kpi{background:linear-gradient(180deg,#121a2f,#0f162a);border:1px solid var(--border);
  border-radius:14px;padding:14px;text-align:center;box-shadow:var(--shadow)}
.qms .kpi .n{font-size:1.6rem;font-weight:900;color:#cfe0f6;line-height:1}
.qms .kpi .l{margin-top:6px;color:var(--qms-muted);font-weight:600;letter-spacing:.2px}

/* accordion/tabella scura coerente */
.qms .accordion{border:1px solid var(--border);border-radius:14px;overflow:hidden}
.qms .accordion .item{border-bottom:1px solid var(--border);background:var(--qms-surface)}
.qms .accordion .head{padding:12px 14px;display:flex;align-items:center;gap:10px;cursor:pointer}
.qms .accordion .body{padding:12px 14px;background:var(--qms-surface-2)}
.qms .pair{display:grid;grid-template-columns:220px 1fr;gap:12px;margin:8px 0}
.qms .pair .k{color:#cfe0f6;font-weight:600}

/* === LIMITI: filtri e tabella coerenti === */
.qms .filters{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px;margin:12px 0 16px}
@media(max-width:1100px){.qms .filters{grid-template-columns:repeat(2,1fr)}}
@media(max-width:700px){.qms .filters{grid-template-columns:1fr}}
.qms .filters .actions{display:flex;gap:10px;align-items:end}

/* Tabella con sticky header (liste lunghe) */
.qms .table-wrap{overflow:auto;border-radius:12px}
.qms table.qms{width:100%;border-collapse:separate;border-spacing:0 8px}
.qms table.qms thead th{position:sticky;top:0;background:#101c33;border-bottom:1px solid var(--border);z-index:1}

/* === AUDIT: timeline / agenda === */
.qms .timeline{display:grid;gap:12px;margin-top:12px}
.qms .tl-item{display:grid;grid-template-columns:160px 1fr;gap:14px;align-items:start}
@media(max-width:760px){.qms .tl-item{grid-template-columns:1fr}}
.qms .tl-date{background:var(--qms-surface);border:1px solid var(--border);border-radius:12px;padding:10px;text-align:center}
.qms .tl-dot{width:10px;height:10px;border-radius:50%;background:var(--qms-primary);display:inline-block;margin-right:6px}
.qms .tl-body{background:var(--qms-surface);border:1px solid var(--border);border-radius:12px;padding:14px}
.qms .tl-body .row{display:flex;gap:12px;flex-wrap:wrap;margin-top:6px}

/* === FULLCALENDAR: Mercury Dark === */
.qms .calendar-wrap { margin-top: 16px; background: var(--qms-surface); border:1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 10px }

/* Layout e testo */
.qms .fc { color: var(--qms-text); font-family: var(--font); }
.qms .fc .fc-toolbar.fc-header-toolbar{ margin-bottom: 12px }
.qms .fc .fc-toolbar-title{ font-weight: 900; letter-spacing:.2px }

/* Bottoni → pulsanti veri */
.qms .fc .fc-button{
  background: rgba(255,255,255,.06); border:1px solid rgba(255,255,255,.12);
  color:#e9eef7; border-radius:12px; padding:8px 12px; text-transform:none; box-shadow:0 6px 18px rgba(0,0,0,.15)
}
.qms .fc .fc-button:hover{ filter:brightness(1.08) }
.qms .fc .fc-button-primary{ background:#ff4d4d; border-color:transparent } /* evidenzia "Oggi" se serve */
.qms .fc .fc-button:focus{ box-shadow:none; outline:2px solid var(--qms-accent) }

/* Intestazioni giorni */
.qms .fc .fc-col-header-cell{ background:#101c33; color:#cfe0f6; border:1px solid var(--border) }

/* Celle e bordi */
.qms .fc-theme-standard td, .qms .fc-theme-standard th{ border:1px solid var(--border) }
.qms .fc .fc-daygrid-day{ background: #0f162a }
.qms .fc .fc-day-today{ background: rgba(35,196,255,.08) }

/* Eventi leggibili */
.qms .fc .fc-event{ background: #2563eb; border:none; border-radius:8px; padding:2px 6px }
.qms .fc .fc-event-title, .qms .fc .fc-event-time{ color:#fff }

/* Altezze */
.qms .fc .fc-scroller-harness, .qms .fc .fc-scroller{ scrollbar-color:#445 #111 }

/* ========== MODAL STYLES ========== */
.qms-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.qms-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.qms-modal-content {
  position: relative;
  background: var(--qms-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow: hidden;
  animation: slideUp 0.3s ease;
  z-index: 10000;
}

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

.qms-modal-header h2 {
  margin: 0;
  font: 700 18px/1.2 Inter, system-ui;
  color: var(--qms-text);
}

.qms-modal-close {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--qms-muted);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.qms-modal-close:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--qms-text);
}

.qms-modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  max-height: calc(85vh - 80px);
}

.qms-modal-footer {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--qms-surface-2);
}

/* Animazioni modal */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

/* Form styles dentro modal */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font: 600 13px/1.3 Inter, system-ui;
  color: var(--qms-muted);
  margin-bottom: 0.5rem;
}

.qms-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--qms-surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--qms-text);
  font: 500 14px/1.4 Inter, system-ui;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.qms-input:focus {
  outline: none;
  border-color: var(--qms-accent);
  background: var(--qms-surface);
}

.qms-input::placeholder {
  color: var(--qms-muted);
  opacity: 0.6;
}

textarea.qms-input {
  resize: vertical;
  min-height: 80px;
  font-family: Inter, system-ui;
}

/* Grid helpers */
.grid {
  display: grid;
  gap: 1rem;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 768px) {
  .grid.cols-2,
  .grid.cols-3 {
    grid-template-columns: 1fr;
  }
  
  .qms-modal-content {
    max-height: 95vh;
  }
}
