/* ═══════════════════════════════════════════════════════
   CTM Frontend Styles v2.0
   Tabella riepilogativa + Grafici sottostanti
   ═══════════════════════════════════════════════════════ */

/* ─── Tabella Riepilogativa ──────────────────────────── */

.ctm-tabella-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ctm-tabella {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    line-height: 1.5;
    background: #fff;
    border-radius: 0.3rem;
    overflow: hidden;
    margin:0px;
}

.ctm-tabella thead th {
    background: #008572;
    color: #fff;
    font-weight: 600;
    padding: 10px 14px;
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.ctm-tabella thead th:nth-child(n+2) {
    text-align: right;
}

.ctm-tabella tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.ctm-tabella tbody tr:last-child td { border-bottom: none; }
.ctm-tabella tbody tr:hover { background: #f4faf8; }

.ctm-tabella .ctm-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.ctm-ticker-label {
    display: block;
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
}

.ctm-up { color: #16a34a; font-weight: 600; }
.ctm-down { color: #dc2626; font-weight: 600; }

/* Semaforo */
.ctm-distanza.ctm-green { color: #16a34a; }
.ctm-distanza.ctm-yellow { color: #ca8a04; }
.ctm-distanza.ctm-red { color: #dc2626; font-weight: 700; }

tr.ctm-red { background: #fef2f2 !important; }
tr.ctm-yellow { background: #fefce8 !important; }

.ctm-aggiornamento {
    text-align: right;
    font-size: 12px;
    color: #94a3b8;
    padding-bottom: 15px;
}

.ctm-aggiornamento-disclaimer {
    text-align: left;
    font-size: 12px;
    color: #94a3b8;
    margin-top: 10px;
}

.ctm-no-data {
    padding: 20px;
    text-align: center;
    color: #94a3b8;
    font-style: italic;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px dashed #e2e8f0;
}

/* ─── Pill Periodo (compatte) ────────────────────────── */

.ctm-pill {
    display: inline-block;
    padding: 3px 10px;
    border: 1px solid #e2e8f0;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    transition: all 0.15s ease;
    line-height: 1.4;
}

.ctm-pill:hover {
    border-color: #3b82f6;
    color: #3b82f6;
}

.ctm-pill.active {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}

/* Selettore periodo globale (per [ct_grafici]) */
.ctm-periodo-selector {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    justify-content: flex-end;
}

/* ─── Grafico Singolo [ct_grafico n="X"] ─────────────── */

.ctm-chart-single {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    margin: 16px 0;
}

.ctm-chart-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid #f1f5f9;
    gap: 10px;
    flex-wrap: wrap;
}

.ctm-chart-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.ctm-chart-ticker-badge {
    font-size: 11px;
    color: #64748b;
    background: #f1f5f9;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
}

.ctm-chart-price-inline {
    font-size: 15px;
    font-weight: 700;
    color: #1e293b;
    font-variant-numeric: tabular-nums;
}

.ctm-chart-var {
    font-size: 12px;
    font-weight: 600;
}

.ctm-periodo-pills {
    display: flex;
    gap: 4px;
}

/* ─── Grafico Container (per [ct_grafici]) ───────────── */

.ctm-grafici-wrapper { margin: 20px 0; }

.ctm-chart-container {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    overflow: hidden;
}

.ctm-chart-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.ctm-chart-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
}

.ctm-chart-price {
    font-size: 15px;
    font-weight: 600;
    color: #1e293b;
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

.ctm-chart-canvas {
    border-radius: 4px;
    overflow: hidden;
}

/* ─── Legenda Compatta ───────────────────────────────── */

.ctm-chart-legend-compact {
    display: flex;
    gap: 16px;
    padding: 8px 16px;
    border-top: 1px solid #f1f5f9;
    flex-wrap: wrap;
}

.ctm-chart-single .ctm-chart-legend-compact {
    /* Già dentro il container, padding laterale ok */
}

.ctm-leg {
    font-size: 11px;
    color: #94a3b8;
    white-space: nowrap;
}

.ctm-leg-price { color: #3b82f6; }
.ctm-leg-strike { color: #16a34a; }
.ctm-leg-barrier { color: #dc2626; }

/* ─── Descrizione Sottostante ────────────────────────── */

.ctm-desc-sottostante {
    margin: 12px 0 20px;
    font-size: 14px;
    line-height: 1.7;
    color: #475569;
}

.ctm-desc-sottostante p:first-child { margin-top: 0; }
.ctm-desc-sottostante p:last-child { margin-bottom: 0; }

/* ─── Responsive ─────────────────────────────────────── */

@media (max-width: 768px) {
    .ctm-tabella { font-size: 12px; }

    .ctm-tabella thead th,
    .ctm-tabella tbody td { padding: 8px 10px; }

    .ctm-chart-single { margin: 12px 0; }
    .ctm-chart-container { padding: 12px; }
    .ctm-chart-canvas { height: 220px !important; }
    .ctm-chart-header h3 { font-size: 14px; }
    .ctm-chart-topbar { padding: 8px 12px; }
    .ctm-chart-legend-compact { padding: 6px 12px; gap: 10px; }

    .ctm-periodo-selector { justify-content: center; }
}

@media (max-width: 480px) {
    .ctm-chart-price-inline { font-size: 13px; }
    .ctm-pill { padding: 2px 8px; font-size: 10px; }
}

/* ═══════════════════════════════════════════════════════
   CALENDARIO DATE RILEVAMENTO (tabella)
   ═══════════════════════════════════════════════════════ */

.ctm-cal {
    margin: 20px 0;
}

/* Header sezione */
.ctm-cal__header {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 20px 0 15px;
}

.ctm-cal__count {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    background: #008572;
    color: #fff;
    border-radius: 10px;
    padding: 1px 8px;
    margin-left: 6px;
    vertical-align: middle;
}

/* Wrapper scroll orizzontale mobile */
.ctm-cal__table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Tabella */
.ctm-cal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.ctm-cal-th {
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 8px 10px;
    border-bottom: 2px solid #e2e8f0;
    text-align: left;
    white-space: nowrap;
}

.ctm-cal-th--num {
    text-align: right;
}

.ctm-cal-td {
    padding: 9px 10px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    vertical-align: middle;
}

.ctm-cal-td--data {
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
}

.ctm-cal-td--num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.ctm-cal-td--gg {
    text-align: right;
    white-space: nowrap;
}

.ctm-cal-tr:hover .ctm-cal-td {
    background: #f8fafc;
}

/* NA dash */
.ctm-cal-na {
    color: #cbd5e1;
}

/* Label tipo evento */
.ctm-cal-tipo {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.ctm-cal-tipo--cedola {
    background: #f0fdf9;
    color: #008572;
}

.ctm-cal-tipo--autocallable {
    background: #f0fdf9;
    color: #059669;
}

.ctm-cal-tipo--scadenza {
    background: #f1f5f9;
    color: #1e293b;
}

/* Banner autocall (rimborsato anticipatamente) */
.ctm-autocall-banner {
    background: #ecfdf5;
    border: 1px solid #6ee7b7;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: #065f46;
}

.ctm-autocall-banner strong {
    color: #047857;
}

.ctm-autocall-banner__detail {
    font-size: 12px;
    color: #059669;
    opacity: 0.8;
}

/* Badge giorni residui */
.ctm-cal-gg {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 3px;
    background: #f1f5f9;
    color: #64748b;
}

.ctm-cal-gg--urgent {
    background: #fef2f2;
    color: #dc2626;
}

.ctm-cal-gg--soon {
    background: #fefce8;
    color: #ca8a04;
}

.ctm-cal-gg--past {
    background: transparent;
    color: #cbd5e1;
    font-weight: 400;
    font-size: 10px;
}

/* Tabella passate */
.ctm-cal-table--past .ctm-cal-tr .ctm-cal-td {
    opacity: 0.5;
}

.ctm-cal-table--past .ctm-cal-tr:hover .ctm-cal-td {
    opacity: 1;
}

/* Sezione passate - collapsabile */
.ctm-cal__section--past {
    margin-top: 16px;
}

.ctm-cal__toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    background: none;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 0;
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.ctm-cal__toggle:hover { color: #64748b; }

.ctm-cal__arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
    margin-left: auto;
}

.ctm-cal__collapsible {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.ctm-cal--open .ctm-cal__collapsible {
    max-height: 2000px;
}

.ctm-cal--open .ctm-cal__arrow {
    transform: rotate(180deg);
}

/* ─── Prossima Data - Card Compatta (shortcode [ct_prossima_data]) ─── */

.ctm-next {
    display: flex;
    align-items: stretch;
    background: #fff;
    border: 1px solid #e8eef2;
    border-radius: 8px;
    overflow: hidden;
    margin: 0px;
}

/* Blocco giorni a sinistra */
.ctm-next__days {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #008572;
    color: #fff;
    padding: 16px 22px;
    min-width: 80px;
    flex-shrink: 0;
}

.ctm-next__num {
    font-size: 32px;
    font-weight: 800;
    line-height: 1;
}

.ctm-next__gg {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.85;
    margin-top: 2px;
}

/* Info a destra */
.ctm-next__info {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.ctm-next__date {
    font-size: 14px;
    font-weight: 700;
    color: #1e293b;
}

.ctm-next__tipo {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #008572;
}

.ctm-next__tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.ctm-next__tag {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    background: #f0fdf9;
    color: #008572;
    border-radius: 3px;
    border: 1px solid #d1fae5;
}

/* ─── Calendario Responsive ──────────────────────────── */

@media (max-width: 768px) {
    .ctm-cal-table {
        font-size: 12px;
    }

    .ctm-cal-th,
    .ctm-cal-td {
        padding: 7px 6px;
    }

    .ctm-next__num {
        font-size: 26px;
    }

    .ctm-next__days {
        padding: 12px 16px;
        min-width: 64px;
    }

    .ctm-next__date {
        font-size: 13px;
    }
}

/* ═══════════════════════════════════════════════════════
   SIMULATORE WHAT IF
   ═══════════════════════════════════════════════════════ */

.ctm-wif {
    margin: 24px 0;
    background: #fff;
    border-radius: 0.3rem;
    overflow: hidden;
}

.ctm-wif__header {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 14px 18px 0;
}

.ctm-wif__intro {
    font-size: 13px;
    color: #94a3b8;
    padding: 20px 20px 10px;

}

/* Slider rows */
.ctm-wif__sliders {
    padding: 14px 18px;
}

.ctm-wif__row {
    padding: 12px 0;
    border-bottom: 1px solid #f1f5f9;
}

.ctm-wif__row:last-child {
    border-bottom: none;
}

.ctm-wif__row-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.ctm-wif__nome {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
}

.ctm-wif__prezzo {
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    font-variant-numeric: tabular-nums;
}

.ctm-wif__pct-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 6px;
    background: #f1f5f9;
    color: #64748b;
}

.ctm-wif__pct-badge--up {
    background: #f0fdf4;
    color: #16a34a;
}

.ctm-wif__pct-badge--down {
    background: #fef2f2;
    color: #dc2626;
}

/* Slider input */
.ctm-wif__slider-wrap {
    padding: 0 2px;
}

.ctm-wif__slider {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #e2e8f0;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.ctm-wif__slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #008572;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    cursor: grab;
}

.ctm-wif__slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #008572;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    cursor: grab;
}

.ctm-wif__slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: #94a3b8;
    margin-top: 2px;
}

/* Row detail (barrier + distance) */
.ctm-wif__row-detail {
    display: flex;
    gap: 12px;
    margin-top: 6px;
    font-size: 13px;
    color: #94a3b8;
}

.ctm-wif__val-dist--safe { color: #16a34a; font-weight: 600; }
.ctm-wif__val-dist--warn { color: #ca8a04; font-weight: 600; }
.ctm-wif__val-dist--danger { color: #dc2626; font-weight: 600; }

/* Actions */
.ctm-wif__actions {
    padding: 0 18px 14px;
    text-align: center;
}

.ctm-wif__reset {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 5px 14px;
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.ctm-wif__reset:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

/* Esito */
.ctm-wif__esito {
    border-top: 2px solid #e8eef2;
    padding: 14px 18px;
    background: #f8fafc;
}

.ctm-wif__esito-header {
    font-size: 12px;
    font-weight: 700;
    color: #1e293b;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ctm-wif__worst-label {
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: none;
    letter-spacing: 0;
}

/* Esito items */
.ctm-wif__esito-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ctm-wif__esito-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    background: #fff;
    border: 1px solid #e8eef2;
}

.ctm-wif__esito-item--ok {
    border-color: #d1fae5;
}

.ctm-wif__esito-item--ko {
    border-color: #fecaca;
    background: #fef2f2;
}

.ctm-wif__esito-icon {
    font-size: 16px;
    flex-shrink: 0;
    line-height: 1;
    margin-top: 1px;
}

.ctm-wif__esito-text {
    flex: 1;
    min-width: 0;
}

.ctm-wif__esito-title {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 2px;
}

.ctm-wif__esito-item--ok .ctm-wif__esito-title { color: #008572; }
.ctm-wif__esito-item--ko .ctm-wif__esito-title { color: #dc2626; }

.ctm-wif__esito-desc {
    font-size: 11px;
    color: #64748b;
    line-height: 1.5;
    word-break: break-word;
}

/* Alert */
.ctm-wif__alert {
    margin-top: 10px;
    font-size: 12px;
    font-weight: 600;
    display: none;
}

.ctm-wif__alert--danger {
    color: #dc2626;
}

.ctm-wif__alert--warn {
    color: #ca8a04;
}

/* ─── Toggle collapsabile ───────────────────────────── */

.ctm-wif__toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    background: #008572;
    border: none;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    text-align: left;
    border-radius: 0.3rem 0.3rempx 0px 0px;
}

.ctm-wif__toggle-icon {
    font-size: 12px;
    color: #fff;
    transition: transform 0.2s ease;
}

.ctm-wif__toggle--open .ctm-wif__toggle-icon {
    transform: rotate(90deg);
}

.ctm-wif__body {
    padding: 0;
}

/* ─── Preset scenari ────────────────────────────────── */

.ctm-wif__presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 18px 10px;
}

.ctm-wif__preset {
    font-size: 11px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ctm-wif__preset:hover {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.ctm-wif__preset--down {
    border-color: #fecaca;
    color: #dc2626;
}

.ctm-wif__preset--down:hover {
    background: #fef2f2;
}

.ctm-wif__preset--up {
    border-color: #bbf7d0;
    color: #16a34a;
}

.ctm-wif__preset--up:hover {
    background: #f0fdf4;
}

.ctm-wif__preset--neutral {
    border-color: #e2e8f0;
    color: #64748b;
}

.ctm-wif__preset--active {
    box-shadow: 0 0 0 2px rgba(0, 133, 114, 0.3);
    border-color: #008572;
}

/* ─── Input numerico % ──────────────────────────────── */

.ctm-wif__pct-input-wrap {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    background: #f1f5f9;
    border-radius: 3px;
    padding: 1px 4px;
}

.ctm-wif__pct-input {
    width: 42px;
    border: none;
    background: transparent;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    text-align: right;
    padding: 2px 0;
    font-family: inherit;
    -moz-appearance: textfield;
}

.ctm-wif__pct-input::-webkit-outer-spin-button,
.ctm-wif__pct-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

.ctm-wif__pct-input:focus {
    outline: none;
    color: #1e293b;
}

.ctm-wif__pct-symbol {
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
}

/* ─── Punto di rottura ──────────────────────────────── */

.ctm-wif__detail-break {
    color: #94a3b8;
}

.ctm-wif__val-break {
    font-weight: 600;
}

.ctm-wif__val-break--warn {
    color: #ca8a04;
}

.ctm-wif__val-break--danger {
    color: #dc2626;
}

/* ─── What If Responsive ─────────────────────────────── */

@media (max-width: 768px) {
    .ctm-wif__row-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }

    .ctm-wif__esito-desc {
        font-size: 10px;
    }

    .ctm-wif__presets {
        gap: 4px;
    }

    .ctm-wif__preset {
        font-size: 10px;
        padding: 4px 10px;
    }
}
