/* ==========================================================================
   1. VARIABLES & DESIGN SYSTEM
   ========================================================================== */
:root {
  /* Typography */
  --font-family-mono: "Roboto Mono", monospace;
  --font-size-base: 14px;

  /* Color Palette */
  --color-primary: #4c4c4c;
  --color-primary-dark: #323232;
  --color-bg-light: #f8f8f8;
  --color-bg-modal: #f8f6f0;
  --color-border: #aaaaaa;
  --color-text: #202020;
  --color-white: #ffffff;

  /* Status Colors */
  --status-ok: #009a00;
  --status-ko: #9a0000;
  --status-waiting-agent: #ffff00;
  --status-waiting-lead: #36e4ff;
  --status-imminent: #00009a;
  --status-no-answer: #ff9800;

  /* UI Effects */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-pill: 50px;
  --shadow-overlay: 0px 10px 30px rgba(0, 0, 0, 0.3);
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.08);
  --transition-fast: all 0.2s ease;

  /* External Libraries Config */
  --fc-timegrid-slot-lane-height: 3.5rem;
}

/* ==========================================================================
   2. BASE & RESET
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body, div, input, textarea, select, option, table, td, tr, th {
  font-family: var(--font-family-mono);
  font-optical-sizing: auto;
  font-weight: 400;
  font-size: var(--font-size-base);
  color: var(--color-text);
}

textarea, select, input {
  margin: 0;
  padding: 6px 10px;
  min-width: 250px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

textarea:focus, select:focus, input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(76, 76, 76, 0.2);
}

/* ==========================================================================
   3. UTILITIES & TYPOGRAPHY
   ========================================================================== */
.w300 { font-weight: 300 !important; }
.w400 { font-weight: 400 !important; }
.w500 { font-weight: 500 !important; }
.w600 { font-weight: 600 !important; }
.w700 { font-weight: 700 !important; }

.italic { font-style: italic !important; }
.mwauto { min-width: auto !important; }
.optElementid { min-width: auto !important; }

.clearer {
  width: 100%;
  height: 1px;
  clear: both;
}

/* ==========================================================================
   4. MODALS & WINDOWS
   ========================================================================== */
.obscurer {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  background-color: rgba(50, 50, 50, 0.85);
  backdrop-filter: blur(2px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.windowform,
.window2form {
  display: none;
  /*width: clamp(300px, 70%, 90%);*/
  width: fit-content;
  min-width: 60%;
  max-width: 90%;
  position: relative;
  background-color: var(--color-bg-modal);
  padding: 24px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-overlay);
  overflow-y: auto;
  max-height: 70vh;
  margin: 0 auto;
}

.windowform { z-index: 101; }
.window2form { position: absolute; z-index: 201; }

/* Custom Scrollbars */
.windowform::-webkit-scrollbar,
.window2form::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.windowform::-webkit-scrollbar-track,
.window2form::-webkit-scrollbar-track {
  background: transparent;
}

.windowform::-webkit-scrollbar-thumb,
.window2form::-webkit-scrollbar-thumb {
  background-color: var(--color-primary-dark);
  border-radius: 10px;
}

.windowform h1 {
  font-size: 1.15rem;
  margin-top: 0;
  margin-bottom: 16px;
  font-weight: 600;
}

#closewindow {
  float: right;
  cursor: pointer;
  width: 28px;
  height: 28px;
  aspect-ratio: 1/1;
  margin: 0;
  background-image: url("../template/ui-icon/line/close-circle.svg");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transition: transform var(--transition-fast);
  opacity: 0.8;
}

#closewindow:hover {
  background-image: url("../template/ui-icon/solid/close-circle.svg");
  opacity: 1;
  transform: scale(1.1);
}

/* ==========================================================================
   5. BUTTONS, ICONS & COMPONENTS
   ========================================================================== */
.myIcon {
  vertical-align: middle;
  width: 20px;
  height: 20px;
  cursor: pointer;
  margin: 3px;
  transition: transform var(--transition-fast);
}

.myIcon:hover {
  transform: scale(1.15);
}

.big {
  width: 36px !important;
  height: 36px !important;
}

.littleButton {
  width: fit-content;
  min-width: 100px !important;
  margin: 5px;
  padding: 6px 12px;
  cursor: pointer;
  border: 1px solid var(--color-primary);
  background-color: var(--color-white);
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.littleButton:hover {
  background-color: var(--color-primary);
  color: var(--color-white);
}

.msgbox {
  width: 100%;
  border: 1px solid var(--color-primary);
  border-left: 4px solid var(--color-primary);
  padding: 10px;
  margin: 8px 0;
  background-color: #f0f0f0;
  border-radius: var(--radius-sm);
}

.crm_badge {
  width: 200px;
  float: left;
  margin: 10px;
  padding: 12px;
  text-align: left;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-white);
  box-shadow: var(--shadow-card);
}

/* ==========================================================================
   6. TABLES & DATA WRAPPERS
   ========================================================================== */
.windowform table,
.tablePerc {
  width: 100%;
  border-collapse: collapse;
}

.windowform table th,
.tablePerc th {
  color: var(--color-white);
  text-transform: uppercase;
  background-color: var(--color-primary);
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  letter-spacing: 0.5px;
}

.windowform table tr,
.tablePerc td {
  border-bottom: 1px solid var(--color-border);
}

.tablePerc td {
  padding: 10px;
  text-align: center;
}

#contatti {
  width: 100%;
  overflow-x: auto;
}

#container_table_container_parsed .tabulator,
#container_table_container_parsed .tabulator-table {
  min-width: 100%;
}

.table_container {
  max-height: 80vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tabulator .tabulator-row,
.tabulator .tabulator-cell {
  min-height: 38px !important;
}

.tabulator .tabulator-row:hover {
  background-color: #fffde7 !important;
  transition: background-color var(--transition-fast);
}

.tabulator .tabulator-row a {
  text-decoration: none;
  font-weight: 600;
  color: var(--color-primary-dark);
}

.tabulator .tabulator-header .tabulator-col .tabulator-header-filter input {
  width: 100% !important;
  box-sizing: border-box;
  min-width: auto;
}

.tabulator-page.active {
  background-color: #c8e6c9 !important;
  font-weight: bold;
}

#pagination_header {
  text-align: center;
  margin: 10px 0;
}

#myrowcounter {
  background-color: var(--color-primary);
  color: var(--color-white);
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  padding: 6px;
  margin-top: 10px;
  border-radius: var(--radius-sm);
  clear: both;
}

/* ==========================================================================
   7. MONITORING & AGENT WIDGETS
   ========================================================================== */
#agent_load {
  position: fixed;
  top: 12px;
  right: 12px;
  width: fit-content;
  padding: 8px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  z-index: 100;
  background-color: var(--color-bg-light);
}

#agent_load .title {
  background-color: var(--color-primary);
  color: var(--color-white);
  text-align: center;
  text-transform: uppercase;
  width: 100%;
  padding: 4px 8px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  border-radius: 2px;
}

.monitor {
  width: 100%;
}

.monitor .mylabel {
  display: inline-block;
  width: 100px;
}

.monitorBar {
  display: inline-block;
  max-width: 85px;
  background: linear-gradient(to right, #00c853 0%, #ffeb3b 75%, #d50000 100%);
  background-size: 85px 100%;
  background-repeat: no-repeat;
  margin: 1px;
  text-align: center;
  border-radius: 2px;
}

.inactiveBar {
  display: inline-block;
  margin: 1px;
  padding: 0 4px;
  text-align: center;
  background-color: var(--status-waiting-lead);
  color: #000;
  border-radius: 2px;
}

/* Status Icons */
.status-icon {
  border-radius: var(--radius-pill);
  font-weight: bold;
  font-size: 11px;
  width: 24px;
  height: 24px;
  border: 1.5px solid var(--color-primary-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.status-icon:hover {
  transform: scale(1.1);
}

.all { border: 1px solid #000; }
.status-no-event { background-color: var(--color-border); }
.status-action-ok { background-color: var(--status-ok); color: var(--color-white); }
.status-action-ko { background-color: var(--status-ko); color: var(--color-white); }
.status-waiting-for-agent { background-color: var(--status-waiting-agent); color: #000; }
.status-waiting-for-lead { background-color: var(--status-waiting-lead); color: #000; }
.status-recall { background-color: #000; color: var(--color-white); }
.status-appointment-imminent { background-color: var(--status-imminent); color: var(--color-white); }
.status-no-answer { background-color: var(--status-no-answer); color: #000; }

/* ==========================================================================
   8. DASHBOARD & GRAPHICS
   ========================================================================== */
.graphBox {
  width: 48%;
  margin: 1%;
  float: left;
  height: 400px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-white);
  padding: 12px;
  box-shadow: var(--shadow-card);
}

/* ==========================================================================
   9. AUTHENTICATION & FORMS
   ========================================================================== */
.loginbox {
  margin: 60px auto;
  padding: 32px 24px 40px;
  border: 1px solid var(--color-border);
  background-color: var(--color-bg-light);
  width: clamp(280px, 90%, 360px);
  border-radius: var(--radius-md);
  text-align: center;
  box-shadow: var(--shadow-card);
}

.loginbox img {
  width: 130px;
  height: auto;
  margin-bottom: 16px;
}

.loginbox input {
  margin: 8px 0;
  width: 100%;
  text-align: center;
}

/* ==========================================================================
   CUSTOM RADIO CONTROLS (Filtri Tabella a Matrice)
   ========================================================================== */

/* 1. Permettiamo all'intestazione delle sole colonne filtro con radio di espandersi */
.tabulator .tabulator-header .tabulator-col:has(.container-radio),
.tabulator .tabulator-header .tabulator-col:has(.container-radio) .tabulator-col-content {
  overflow: visible !important;
  white-space: normal !important;
}

/* 2. Limitiamo la larghezza SOLO al wrapper diretto dei radio button */
.tabulator-header-filter:has(.container-radio),
div:has(> label.container-radio) {
  max-width: 44px !important;
  display: block !important;
  margin: 0 auto !important;
}

/* 3. Il label resta compatto e fluttuante */
label.container-radio {
  display: block !important;
  float: left !important;
  margin: 0 !important;
  padding: 0 !important;
  width: 20px !important;  /* 16px cerchio + 4px margine totale */
  height: 20px !important;
  cursor: pointer;
}

/* Nascondiamo l'input radio originale */
.container-radio input {
  display: none !important;
}

/* Cerchio personalizzato */
.checkmark {
  height: 16px;
  width: 16px;
  margin: 2px;
  border-radius: 50%;
  padding: 0;
  float: left !important;
  cursor: pointer;
  position: relative;
  box-sizing: border-box;
}

/* Pallino interno (selezionato) */
.checkmark::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  background: #555;
  border: 1px solid #fff;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.15s ease;
}

/* Mostriamo il pallino quando attivo */
.container-radio input:checked ~ .checkmark::after {
  display: block !important;
  transform: translate(-50%, -50%) scale(1);
}

/* ==========================================================================
   10. FULLCALENDAR INTEGRATION
   ========================================================================== */
.fc .fc-timegrid-slot {
  height: 50px !important;
}

.fc .fc-daygrid-event-harness {
  overflow-x: hidden;
}

.fc-v-event .fc-event-main {
  color: var(--color-primary) !important;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ==========================================================================
   11. PRINT STYLES
   ========================================================================== */
@media print {
  body * {
    visibility: hidden;
  }

  #calendar, #calendar * {
    visibility: visible;
  }

  #calendar {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }

  .fc-scroller,
  .fc-scroller-liquid-absolute {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    position: relative !important;
  }

  .fc-timegrid-axis {
    height: auto !important;
  }
}

/* ==========================================================================
   12. MOBILE & RESPONSIVE DESIGN (Max-width: 768px)
   ========================================================================== */
@media screen and (max-width: 768px) {

  /* --- 1. Form & Input adattivi --- */
  textarea, select, input {
    min-width: 100% !important;
    width: 100% !important;
    font-size: 16px !important; /* Previene lo zoom automatico su iOS Safari */
    padding: 10px 12px;         /* Area di tocco migliorata */
  }

  /* --- 2. Modali e Finestre Sovrapposte --- */
  .windowform,
  .window2form {
    width: 95% !important;
    min-width: 95% !important;
    max-width: 95% !important;
    max-height: 85vh !important;
    padding: 16px;
    margin: 10px auto;
  }

  /* --- 3. Struttura Layout & Card (Rimozione Float) --- */
  .graphBox {
    width: 100% !important;
    float: none !important;
    margin: 10px 0 !important;
    height: auto;
    min-height: 300px;
  }

  .crm_badge {
    width: 100% !important;
    float: none !important;
    margin: 10px 0 !important;
  }

  /* --- 4. Tabelle e Tabulator (Scroll Orizzontale Flessibile) --- */
  .windowform table,
  .tablePerc,
  #contatti,
  .table_container {
    display: block;
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .tabulator .tabulator-row,
  .tabulator .tabulator-cell {
    min-height: 44px !important; /* Standard touch-target per dispositivi mobili */
  }

  /* --- 5. Pulsanti & Elementi Cliccabili --- */
  .littleButton {
    width: 100% !important;
    min-width: 100% !important;
    padding: 12px;
    margin: 8px 0;
    font-size: 15px;
  }

  .myIcon {
    width: 28px;
    height: 28px;
    margin: 6px;
  }

  .status-icon {
    width: 32px;
    height: 32px;
    font-size: 13px;
  }

  /* --- 6. Schermata di Login --- */
  .loginbox {
    width: 90% !important;
    margin: 20px auto !important;
    padding: 24px 16px;
  }

  .loginbox img {
    width: 110px;
  }

 /* --- 7. Radio Button & Checkmark --- */
  label.container-radio {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    margin: 0 !important;
    width: 22px !important;
    height: 22px !important;
    flex-shrink: 0 !important; /* Blocca la compressione Flexbox su mobile */
  }

  .checkmark {
    height: 22px !important;
    width: 22px !important;
    min-width: 22px !important;   /* Impedisce lo schiacciamento orizzontale */
    min-height: 22px !important;  /* Impedisce lo schiacciamento verticale */
    margin: 0 !important;
    float: none !important;
    flex-shrink: 0 !important;   /* FONDAMENTALE: impedisce a flexbox di deformare il cerchio */
    aspect-ratio: 1 / 1 !important; /* Forza il rapporto 1:1 (cerchio perfetto) */
    box-sizing: border-box !important;
  }

  .checkmark::after {
    width: 10px !important;
    height: 10px !important;
    aspect-ratio: 1 / 1 !important;
  }

  /* --- 8. Widget Monitor & Agent Load --- */
  #agent_load {
    top: auto;
    bottom: 12px;
    right: 12px;
    left: 12px;
    width: calc(100% - 24px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  }

  .monitor .mylabel {
    width: 80px;
    font-size: 12px;
  }

  .monitorBar,
  .inactiveBar {
    max-width: 60px;
    font-size: 11px;
  }
}