/* ═══════════════════════════════════════════════════════
   Download Center — Overlay (prefix dl-)  · v3 redesign
   Dark theme, token-based. Foglio Excel + footer software-style.
   ═══════════════════════════════════════════════════════ */

/* ── Backdrop ── */
.dl-overlay {
  position: fixed;
  inset: 0;
  z-index: 9200;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--overlay-bg);
  backdrop-filter: blur(var(--overlay-blur));
  font-family: var(--font-ui);
}
.dl-overlay.open { display: flex; }

/* ── Panel ── */
.dl-panel {
  width: min(900px, 96vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  box-shadow: var(--overlay-shadow);
  color: var(--text);
  overflow: hidden;
}

/* ── Header ── */
.dl-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--surface-veil) 0%, transparent 100%);
}
.dl-head-info { display: flex; align-items: center; gap: 12px; }
.dl-head-icon {
  width: 34px; height: 34px;
  background: var(--blue-dim);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: var(--blue); flex-shrink: 0;
}
.dl-title { font-size: 1.05rem; font-weight: 700; color: var(--text-bright); }
.dl-sub { font-size: 0.82rem; color: var(--text-dim); margin-top: 2px; }

/* ── Close button (standard 26×26) ── */
.dl-close {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--text-dim);
  font-size: 1.2rem; border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--ease), color var(--ease); flex-shrink: 0;
}
.dl-close:hover { background: var(--hover-medium); color: var(--text-bright); }

/* ── Body ── */
.dl-body { padding: 20px 22px 4px; overflow-y: auto; flex: 1; }
.dl-body::-webkit-scrollbar { width: 5px; }
.dl-body::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 2px; }

.dl-section { margin-bottom: 22px; }
.dl-label {
  font-size: 0.76rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px;
}
.dl-top-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* ── Empty notice ── */
.dl-empty-notice {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; background: var(--amber-dim);
  border: 1px solid rgba(255, 184, 51, .2); border-radius: var(--radius-sm);
  font-size: 0.90rem; color: var(--amber); margin-bottom: 18px; line-height: 1.45;
}
.dl-empty-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }

/* ── Text inputs (date) ── */
.dl-input {
  width: 100%; padding: 9px 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-bright);
  font-family: var(--font-ui); font-size: 0.95rem; color-scheme: dark;
  transition: border-color var(--ease), box-shadow var(--ease); box-sizing: border-box;
}
.dl-input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-dim); }
.dl-input:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Date from/to ── */
.dl-dates-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.dl-date-field { display: flex; flex-direction: column; gap: 5px; }
.dl-date-lbl { font-size: 0.82rem; color: var(--text-muted); font-weight: 600; letter-spacing: .03em; }

/* ═══════════════════════════════════════════════════════
   Slider doppia maniglia
   ═══════════════════════════════════════════════════════ */
.dl-slider-wrap { display: flex; flex-direction: column; gap: 6px; user-select: none; }
.dl-slider-labels { display: flex; justify-content: space-between; padding: 0 2px; }
.dl-slider-lbl-val { font-size: 0.92rem; font-weight: 700; color: var(--blue); min-width: 40px; }
.dl-slider-labels .dl-slider-lbl-val:last-child { text-align: right; }
.dl-slider-track-wrap { position: relative; height: 24px; display: flex; align-items: center; }
.dl-slider-rail { position: absolute; left: 0; right: 0; height: 4px; background: var(--border-hi); border-radius: 2px; pointer-events: none; z-index: 0; }
.dl-slider-fill { position: absolute; height: 4px; background: var(--blue); border-radius: 2px; pointer-events: none; z-index: 1; }
.dl-range {
  position: absolute; left: 0; right: 0; width: 100%; height: 4px;
  background: transparent; -webkit-appearance: none; appearance: none;
  outline: none; border: none; pointer-events: none; z-index: 2; margin: 0;
}
/* La maniglia "Dal" sta SOPRA la "Al": così resta afferrabile anche quando le
   due coincidono al bordo (es. intraday con storico in memoria tutto nell'anno
   max -> from e to entrambi a destra). Senza, la "Al" (ultima nel DOM) la copre
   e diventa impossibile trascinare il "Dal". I thumb hanno pointer-events:all,
   gli input pointer-events:none, quindi il "Al" resta comunque afferrabile dove
   non si sovrappone. */
#dlSliderFrom { z-index: 3; }
.dl-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--blue); border: 2px solid var(--panel); cursor: pointer;
  pointer-events: all; transition: background var(--ease), transform var(--ease);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.dl-range::-webkit-slider-thumb:hover { background: var(--blue-hover); transform: scale(1.15); }
.dl-range::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--blue); border: 2px solid var(--panel); cursor: pointer;
  pointer-events: all; transition: background var(--ease), transform var(--ease);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.dl-range::-moz-range-thumb:hover { background: var(--blue-hover); transform: scale(1.15); }
.dl-range:disabled::-webkit-slider-thumb { opacity: 0.35; cursor: not-allowed; }
.dl-range:disabled::-moz-range-thumb { opacity: 0.35; cursor: not-allowed; }
.dl-range::-moz-range-track { background: transparent; }
.dl-slider-bounds { display: flex; justify-content: space-between; padding: 0 2px; margin-top: 2px; }
.dl-slider-bound-lbl { font-size: 0.82rem; color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════
   Notice dati misti + toggle
   ═══════════════════════════════════════════════════════ */
.dl-mixed {
  display: flex; gap: 12px; padding: 13px 15px;
  background: var(--amber-dim); border: 1px solid rgba(255, 184, 51, .22);
  border-radius: var(--radius-md); align-items: flex-start;
}
.dl-mixed-ic { font-size: 1.05rem; color: var(--amber); flex-shrink: 0; margin-top: 1px; }
.dl-mixed-body { flex: 1; }
.dl-mixed-title { font-size: 0.92rem; font-weight: 700; color: var(--amber); margin-bottom: 3px; }
.dl-mixed-txt { font-size: 0.86rem; color: var(--text-soft); line-height: 1.5; }
.dl-mixed-txt b { color: var(--text-bright); }
.dl-mixed-toggle { display: flex; align-items: center; gap: 9px; margin-top: 11px; cursor: pointer; user-select: none; }
.dl-sw { width: 38px; height: 21px; border-radius: 11px; background: var(--border-hi); position: relative; transition: background var(--ease); flex-shrink: 0; }
.dl-sw::after { content: ''; position: absolute; width: 15px; height: 15px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: left var(--ease); }
.dl-mixed-toggle.on .dl-sw { background: var(--amber); }
.dl-mixed-toggle.on .dl-sw::after { left: 20px; }
.dl-sw-lbl { font-size: 0.88rem; font-weight: 600; color: var(--text-bright); }

/* variante info (serie uniforme a frequenza grezza) */
.dl-mixed-info { background: var(--blue-dim); border-color: rgba(77, 166, 255, .25); }
.dl-mixed-info .dl-mixed-ic, .dl-mixed-info .dl-mixed-title { color: var(--blue); }

/* ═══════════════════════════════════════════════════════
   Foglio Excel (colonne + anteprima)
   ═══════════════════════════════════════════════════════ */
.dl-label-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dl-daymode { text-transform: none; letter-spacing: 0; }

.dl-va-hint { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; line-height: 1.5; }
.dl-va-hint b { color: var(--text-soft); }
.dl-arrow-hint { color: var(--blue); }

.dl-sheet-wrap { border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--card); }
.dl-sheet { border-collapse: collapse; width: 100%; font-size: 0.82rem; table-layout: fixed; }
.dl-sheet th, .dl-sheet td {
  padding: 7px 9px; text-align: right;
  border-bottom: 1px solid var(--border); border-right: 1px solid var(--border);
  font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dl-sheet th:last-child, .dl-sheet td:last-child { border-right: none; }
.dl-sheet td:first-child, .dl-sheet th:first-child { text-align: left; color: var(--text-soft); }
.dl-sheet tbody tr:last-child td { border-bottom: none; }
.dl-sheet tbody tr:nth-child(even) td { background: rgba(255, 255, 255, .015); }
.dl-sheet-empty { text-align: center !important; color: var(--text-muted); padding: 22px !important; }
.dl-col-off { opacity: 0.26; text-decoration: line-through; text-decoration-color: var(--text-muted); }

.dl-sheet th {
  position: relative; background: var(--panel); cursor: pointer; user-select: none;
  transition: background var(--ease);
}
.dl-sheet th:hover { background: var(--toolbar-active); }
.dl-th-inner { display: flex; align-items: center; justify-content: flex-end; gap: 5px; }
.dl-sheet th:first-child .dl-th-inner { justify-content: flex-start; }
.dl-th-chk { width: 12px; height: 12px; accent-color: var(--blue); pointer-events: none; flex-shrink: 0; }
.dl-th-name { font-weight: 700; color: var(--text-bright); letter-spacing: .01em; }
.dl-sheet th.off .dl-th-name { color: var(--text-muted); text-decoration: line-through; }
.dl-sheet th.off .dl-th-chk { opacity: 0.4; }
.dl-sort-arrow { color: var(--blue); font-size: 0.9rem; padding: 0 1px; }

.dl-sheet-foot {
  padding: 7px 12px; font-size: 0.78rem; color: var(--text-muted);
  border-top: 1px solid var(--border); background: var(--surface-veil);
  display: flex; justify-content: space-between; align-items: center;
}
.dl-sheet-foot b { color: var(--text-bright); }

/* ═══════════════════════════════════════════════════════
   Footer software-style
   ═══════════════════════════════════════════════════════ */
.dl-foot {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; flex-shrink: 0; position: relative;
}
.dl-info {
  flex: 1; font-size: 0.86rem; color: var(--text-dim); min-height: 1.1em;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.dl-info b { color: var(--text-bright); font-weight: 600; }
.dl-info .dl-sep { color: var(--border-hi); }
.dl-info.ok { color: var(--green); } .dl-info.ok b { color: var(--green); }
.dl-info.err { color: var(--red); } .dl-info.err b { color: var(--red); }
.dl-info-locked { color: var(--amber); font-weight: 600; }

/* Opzioni avanzate (ghost button) */
.dl-ghost {
  display: flex; align-items: center; gap: 7px; padding: 10px 15px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--card); color: var(--text-soft);
  font-family: var(--font-ui); font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}
.dl-ghost:hover { background: var(--hover-subtle); color: var(--text-bright); border-color: var(--border-hi); }
.dl-ghost.active { border-color: var(--blue); color: var(--blue); }
.dl-chev { font-size: 0.7rem; transition: transform var(--ease); }
.dl-ghost.active .dl-chev { transform: rotate(180deg); }

/* Split download button */
.dl-split { display: flex; align-items: stretch; }
.dl-split .dl-main {
  display: flex; align-items: center; gap: 8px; padding: 11px 18px; border: none; cursor: pointer;
  background: var(--blue); color: #fff; font-family: var(--font-ui); font-size: 0.98rem; font-weight: 600;
  border-radius: var(--radius-md) 0 0 var(--radius-md); transition: background var(--ease);
}
.dl-split .dl-caret {
  display: flex; align-items: center; padding: 0 13px; border: none; cursor: pointer;
  background: var(--blue); color: #fff; border-left: 1px solid rgba(255, 255, 255, .22);
  border-radius: 0 var(--radius-md) var(--radius-md) 0; font-size: 0.7rem; transition: background var(--ease);
}
.dl-split .dl-main:hover:not(:disabled), .dl-split .dl-caret:hover:not(:disabled) { background: var(--blue-hover); }
.dl-split .dl-main:disabled, .dl-split .dl-caret:disabled { opacity: .4; cursor: default; }

/* Scrim per chiusura menu */
.dl-scrim { position: absolute; inset: 0; z-index: 40; display: none; }
.dl-scrim.show { display: block; }

/* Popover (menu formati + opzioni avanzate) */
.dl-pop {
  position: absolute; bottom: calc(100% + 8px);
  background: var(--panel); border: 1px solid var(--border-hi);
  border-radius: var(--radius-md); box-shadow: 0 10px 34px rgba(0, 0, 0, .6);
  padding: 8px; z-index: 50; display: none;
}
.dl-pop.open { display: block; animation: dlPopIn .14s ease; }
@keyframes dlPopIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Menu formati */
.dl-fmt-menu { right: 22px; width: 320px; padding: 6px; }
.dl-fmt-item { display: flex; align-items: center; gap: 12px; padding: 10px 11px; border-radius: var(--radius-sm); cursor: pointer; transition: background var(--ease); }
.dl-fmt-item:hover { background: var(--hover-medium); }
.dl-fmt-ic {
  width: 38px; height: 38px; flex-shrink: 0; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 800; letter-spacing: .02em;
}
.dl-ic-csv { background: rgba(38, 217, 127, .14); color: var(--green); }
.dl-ic-json { background: rgba(167, 139, 250, .16); color: var(--purple); }
.dl-ic-txt { background: rgba(138, 144, 171, .16); color: var(--text-dim); }
.dl-ic-xls { background: rgba(38, 217, 127, .12); color: #1e9e63; border: 1px solid rgba(38, 217, 127, .3); }
.dl-fmt-meta { flex: 1; min-width: 0; }
.dl-fmt-name { font-size: 0.94rem; font-weight: 600; color: var(--text-bright); }
.dl-fmt-desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; }
.dl-fmt-ext {
  font-family: var(--font-data); font-size: 0.74rem; color: var(--text-dim);
  background: var(--card); border: 1px solid var(--border); border-radius: 4px; padding: 2px 6px;
}
.dl-fmt-sep { height: 1px; background: var(--border); margin: 5px 8px; }

/* Opzioni avanzate popover */
.dl-adv-pop { right: 22px; width: 340px; padding: 14px; }
.dl-adv-row { margin-bottom: 14px; }
.dl-adv-row:last-child { margin-bottom: 0; }
.dl-adv-lbl {
  font-size: 0.78rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 7px;
  display: flex; justify-content: space-between; align-items: center;
}
.dl-adv-note { font-size: 0.72rem; color: var(--text-faint); text-transform: none; letter-spacing: 0; font-weight: 500; }

.dl-seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.dl-seg button {
  border: none; background: var(--card); color: var(--text-dim);
  padding: 7px 12px; font-family: var(--font-ui); font-size: 0.83rem; font-weight: 600;
  cursor: pointer; transition: background var(--ease), color var(--ease);
}
.dl-seg button + button { border-left: 1px solid var(--border); }
.dl-seg button.active { background: var(--blue-dim); color: var(--blue); }

/* ── Responsive ── */
@media (max-width: 720px) {
  .dl-top-grid { grid-template-columns: 1fr; gap: 18px; }
  .dl-foot { flex-wrap: wrap; }
  .dl-info { flex-basis: 100%; order: -1; margin-bottom: 4px; }
}

/* ═══════════════════════════════════════════════════════
   Dialog di avanzamento download (chunk loop)
   Centrato, overlay scuro, z-index sopra l'overlay del Center.
   ═══════════════════════════════════════════════════════ */
.dl-dlg-overlay {
  position: absolute;
  inset: 0;
  z-index: 9300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .58);
  backdrop-filter: blur(2px);
}
.dl-dlg {
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .6);
  padding: 22px 22px 18px;
  color: var(--text);
  font-family: var(--font-ui);
}
.dl-dlg-head { display: flex; align-items: center; gap: 13px; margin-bottom: 18px; }
.dl-dlg-title { font-size: 1.02rem; font-weight: 700; color: var(--text-bright); }
.dl-dlg-sub { font-size: 0.82rem; color: var(--text-dim); margin-top: 2px; }

/* spinner / stato icona */
.dl-dlg-spin {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 50%;
  border: 3px solid var(--border-hi); border-top-color: var(--blue);
  animation: dlDlgSpin .8s linear infinite;
}
@keyframes dlDlgSpin { to { transform: rotate(360deg); } }
.dl-dlg-spin.done {
  border-color: var(--green); animation: none; position: relative;
}
.dl-dlg-spin.done::after {
  content: '✓'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--green); font-size: 1rem; font-weight: 700;
}
.dl-dlg-spin.err {
  border-color: var(--red); animation: none; position: relative;
}
.dl-dlg-spin.err::after {
  content: '✕'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--red); font-size: 1rem; font-weight: 700;
}

/* barra di progresso */
.dl-dlg-bar {
  height: 8px; border-radius: 4px; background: var(--border-hi);
  overflow: hidden; margin-bottom: 6px;
}
.dl-dlg-fill {
  height: 100%; width: 0%; background: var(--blue); border-radius: 4px;
  transition: width .35s ease;
}
.dl-dlg-pct {
  font-size: 0.8rem; font-weight: 700; color: var(--blue);
  text-align: right; margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

.dl-dlg-status {
  font-size: 0.86rem; color: var(--text-soft); line-height: 1.5;
  min-height: 2.4em; margin-bottom: 10px;
}
.dl-dlg-status.ok { color: var(--green); font-weight: 600; }
.dl-dlg-status.err { color: var(--red); font-weight: 600; }

.dl-dlg-meta {
  display: flex; justify-content: space-between;
  font-size: 0.78rem; color: var(--text-muted);
  font-variant-numeric: tabular-nums; margin-bottom: 18px;
}

.dl-dlg-actions { display: flex; justify-content: flex-end; gap: 10px; }
.dl-dlg-btn {
  padding: 9px 18px; border-radius: var(--radius-md); cursor: pointer;
  font-family: var(--font-ui); font-size: 0.9rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--card); color: var(--text-soft);
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}
.dl-dlg-btn:hover { background: var(--hover-medium); color: var(--text-bright); border-color: var(--border-hi); }
.dl-dlg-cancel:hover { border-color: var(--red); color: var(--red); }
.dl-dlg-retry, .dl-dlg-close {
  background: var(--blue); color: #fff; border-color: var(--blue);
}
.dl-dlg-retry:hover, .dl-dlg-close:hover { background: var(--blue-hover); color: #fff; border-color: var(--blue-hover); }
