:root {
    --wpec-primary: #0073aa;
    --wpec-btn-text: #ffffff;
    --wpec-bg: #f9f9f9;
    --wpec-radius: 8px;
    --wpec-accent: #65c466;
    --wpec-accent-bg: #e8f6ea;
    --wpec-blue: #0b5cab;
    --wpec-blue-light: #e6f0fa;
    --wpec-amber: #a97100;
    --wpec-amber-light: #fff5db;
    --wpec-orange: #b54a1f;
    --wpec-orange-light: #ffe8e3;
    --wpec-purple: #5e3ab6;
    --wpec-purple-light: #efe7ff;
}

.wpec-calculator-container {
    max_width: 800px;
    margin: 0 auto;
    padding: 20px;
    background: var(--wpec-bg);
    border-radius: var(--wpec-radius);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Tabs Style */
.wpec-tabs {
    display: flex;
    margin-bottom: 20px;
    gap: 10px;
}

.wpec-tab {
    flex: 1;
    padding: 10px;
    background: #e0e0e0;
    border: none;
    border-radius: var(--wpec-radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.wpec-tab.active {
    background-color: var(--wpec-primary);
    color: var(--wpec-btn-text);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.wpec-form-group {
    margin-bottom: 15px;
}

.wpec-form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #333;
}

.wpec-form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: var(--wpec-radius);
    font-size: 16px;
    box-sizing: border-box;
    height: 44px;
    line-height: 22px;
}

.wpec-form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: var(--wpec-radius);
    font-size: 16px;
    box-sizing: border-box;
    height: 44px;
    line-height: 22px;
}

.wpec-form-group input[type="checkbox"] {
    width: auto;
    padding: 0;
    margin-right: 8px;
    vertical-align: middle;
}

.wpec-form-group label.wpec-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
    margin-bottom: 0;
}

.wpec-btn {
    display: block;
    width: 100%;
    padding: 12px;
    background-color: var(--wpec-primary);
    color: var(--wpec-btn-text);
    border: none;
    border-radius: var(--wpec-radius);
    font-size: 18px;
    cursor: pointer;
    transition: opacity 0.3s;
}

.wpec-btn:hover {
    opacity: 0.9;
}

.wpec-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#wpec-results {
    margin-top: 30px;
    display: none;
}

.wpec-current-status {
    background: rgba(0,0,0,0.05);
    padding: 15px;
    border-radius: var(--wpec-radius);
    text-align: center;
    margin-bottom: 20px;
}

.wpec-results-table {
    width: 100%;
    border-collapse: collapse;
}

.wpec-results-table th, .wpec-results-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}
.wpec-offer-logo {
    max-width: 300px;
    max-height: 48px;
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: center;
    vertical-align: middle;
    margin-right: 10px;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    display: inline-block;
}

.wpec-results-table th {
    background-color: rgba(0,0,0,0.05);
    font-weight: bold;
}

.wpec-best-price {
    background-color: rgba(56, 178, 172, 0.1);
    border-left: 5px solid #38b2ac;
}

.wpec-tag-best {
    background-color: #38b2ac;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
}

.wpec-saving-positive {
    color: #276749;
    font-weight: bold;
}

.wpec-saving-negative {
    color: #c53030;
}

.wpec-action-btn {
    display: inline-block;
    padding: 6px 12px;
    background-color: #333;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 14px;
}
.wpec-action-btn:hover {
    background-color: #555;
}

/* Admin UI */
.wpec-admin-wrap {
    padding: 20px;
    background: linear-gradient(180deg, #f6fbff 0%, #ffffff 100%);
}
.wpec-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    margin-bottom: 30px;
}
@media (min-width: 640px) {
    .wpec-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (min-width: 1024px) {
    .wpec-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}
.wpec-card {
    background: #fff;
    border: 1px solid #e6e8eb;
    border-radius: var(--wpec-radius);
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
    padding: 20px;
}
.wpec-card::before {
    content: "";
    display: block;
    height: 4px;
    border-radius: var(--wpec-radius) var(--wpec-radius) 0 0;
    margin: -20px -20px 12px;
    background: var(--wpec-card-bar, var(--wpec-primary));
}
.wpec-card:hover {
    box-shadow: 0 4px 10px rgba(0,0,0,.08);
    transform: translateY(-1px);
    transition: all .2s ease;
}
.wpec-card h3 {
    margin: 0 0 8px 0;
    font-size: 16px;
    color: #1f2937;
}
.wpec-card h3 .dashicons {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    margin-right: 6px;
    background: var(--wpec-icon-bg, #eef2ff);
    color: var(--wpec-icon-color, #111827);
}
.wpec-metric {
    font-size: 28px;
    font-weight: 700;
    color: #111827;
}
.wpec-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.wpec-badge.up {
    background: var(--wpec-accent-bg);
    color: var(--wpec-accent);
}
.wpec-badge.down {
    background: #fdecea;
    color: #c53030;
}

/* Card Variants */
.wpec-card--primary {
    --wpec-card-bar: var(--wpec-blue);
    --wpec-icon-bg: var(--wpec-blue-light);
    --wpec-icon-color: var(--wpec-blue);
    background: linear-gradient(180deg, var(--wpec-blue-light), #ffffff);
    border-color: #bcd3f1;
}
.wpec-card--primary .wpec-metric { color: var(--wpec-blue); }

.wpec-card--electric {
    --wpec-card-bar: var(--wpec-amber);
    --wpec-icon-bg: var(--wpec-amber-light);
    --wpec-icon-color: var(--wpec-amber);
    background: linear-gradient(180deg, var(--wpec-amber-light), #ffffff);
    border-color: #f7d686;
}
.wpec-card--electric .wpec-metric { color: var(--wpec-amber); }

.wpec-card--gas {
    --wpec-card-bar: var(--wpec-orange);
    --wpec-icon-bg: var(--wpec-orange-light);
    --wpec-icon-color: var(--wpec-orange);
    background: linear-gradient(180deg, var(--wpec-orange-light), #ffffff);
    border-color: #f5b3a5;
}
.wpec-card--gas .wpec-metric { color: var(--wpec-orange); }

.wpec-card--segment {
    --wpec-card-bar: var(--wpec-purple);
    --wpec-icon-bg: var(--wpec-purple-light);
    --wpec-icon-color: var(--wpec-purple);
    background: linear-gradient(180deg, var(--wpec-purple-light), #ffffff);
    border-color: #cfc0f7;
}
.wpec-card--segment .wpec-badge.up { background: #e6f5ea; color: #2f855a; }
.wpec-card--segment .wpec-badge { background: #f3f4f6; color: #374151; }
.wpec-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}
.wpec-filter-bar select,
.wpec-filter-bar input[type="date"] {
    height: 36px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 0 10px;
}
.wpec-filter-bar input[type="text"] {
    height: 36px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 0 10px;
}
.wpec-table {
    width: 100%;
}
.wpec-table .widefat thead th {
    background: #f8fafc;
}
.wpec-table .widefat td,
.wpec-table .widefat th {
    vertical-align: middle;
}
.wpec-select-all {
    width: 16px;
    height: 16px;
}

.wpec-two-col {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}
.wpec-main-col {
    flex: 1 1 auto;
}
.wpec-side-col {
    flex: 0 0 300px;
}
.wpec-table-wrap {
    width: 100%;
    overflow-x: auto;
}
.wpec-table-wrap thead th {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 2;
    box-shadow: inset 0 -1px 0 #e5e7eb, 0 1px 0 #e5e7eb;
}
.wpec-trend {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 120px;
    padding: 10px 0;
}
.wpec-trend-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(22px, 1fr));
    gap: 10px;
    align-items: end;
    height: 140px;
    padding: 10px 0;
}
.wpec-trend-grid .trend-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}
.wpec-trend .wpec-trend-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    width: 28px;
}
.wpec-trend .bar {
    width: 20px;
    background: var(--wpec-accent);
    border-radius: 4px;
}
.wpec-trend-grid .trend-item .bar {
    width: 100%;
    background: var(--wpec-accent);
    border-radius: 4px;
}
.wpec-trend .label {
    font-size: 10px;
    color: #6b7280;
    text-align: center;
}
.wpec-trend-grid .trend-item .label {
    font-size: 10px;
    color: #6b7280;
    text-align: center;
}
.wpec-table-wrap table {
    min-width: 780px;
}

.wpec-trend-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.wpec-trend-select {
    height: 32px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 0 8px;
}
.wpec-kpi {
    margin-top: 6px;
    font-size: 12px;
    color: #6b7280;
}
.wpec-kpi .pct {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 999px;
    font-weight: 600;
}
.wpec-kpi .pct.up { background: #e6f5ea; color: #2f855a; }
.wpec-kpi .pct.down { background: #fdecea; color: #c53030; }
.wpec-kpi .pct.flat { background: #f3f4f6; color: #374151; }

.wpec-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.wpec-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    background: #fff;
    color: #374151;
    cursor: pointer;
    user-select: none;
}
.wpec-chip.active { border-color: var(--wpec-primary); color: var(--wpec-primary); background: #eef6ff; }
.wpec-chip--luce { border-color: #f7d686; }
.wpec-chip--luce.active { color: #a97100; background: #fff5db; }
.wpec-chip--gas { border-color: #f5b3a5; }
.wpec-chip--gas.active { color: #b54a1f; background: #ffe8e3; }
.wpec-chip--privato { border-color: #cfc0f7; }
.wpec-chip--privato.active { color: #5e3ab6; background: #efe7ff; }
.wpec-chip--business { border-color: #cfc0f7; }
.wpec-chip--business.active { color: #5e3ab6; background: #efe7ff; }

.wpec-sparkline {
    height: 40px;
}
.wpec-sparkline svg {
    width: 100%;
    height: 40px;
}
.wpec-sparkline .line {
    fill: none;
    stroke: var(--wpec-blue);
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.wpec-sparkline .area {
    fill: var(--wpec-blue);
    fill-opacity: .12;
}
.wpec-sparkline .dot {
    fill: #fff;
    stroke: var(--wpec-blue);
    stroke-width: 1.5;
    opacity: 0;
    transition: opacity .15s ease;
}
.wpec-sparkline .hit { fill: transparent; pointer-events: all; }
.wpec-sparkline .pt:hover .dot { opacity: 1; }
.wpec-sparkline .tt {
    font-size: 10px;
    fill: #374151;
    opacity: 0;
    transition: opacity .15s ease;
}
.wpec-sparkline .pt:hover .tt { opacity: 1; }
.wpec-sparkline .grid line {
    stroke: #e6effa;
    stroke-width: 1;
    shape-rendering: crispEdges;
}
.wpec-sparkline .grid-v line {
    stroke: #f1f5fb;
    stroke-width: 1;
    shape-rendering: crispEdges;
}
.wpec-sparkline .ma-line {
    fill: none;
    stroke: #7da2d6;
    stroke-width: 1;
    stroke-dasharray: 3 2;
    stroke-linecap: round;
}

/* Etichette mesi sotto sparkline */
.wpec-sparkline-labels {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0;
    margin-top: 4px;
}
.wpec-sparkline-labels .lbl {
    font-size: 10px;
    color: #6b7280;
    text-align: center;
}

/* Toggle filtri e layout inline */
.wpec-filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 600;
}
.wpec-filter-bar {
    display: none;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}
.wpec-filter-bar.is-open { display: flex; }
.wpec-filter-bar label {
    margin-right: 6px;
    color: #374151;
}
.wpec-filter-bar select,
.wpec-filter-bar input[type="date"],
.wpec-filter-bar input[type="text"] {
    height: 36px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 0 10px;
}

@media (max-width: 640px) {
    .wpec-card { padding: 16px; }
    .wpec-card h3 { font-size: 14px; }
    .wpec-card h3 .dashicons { width: 20px; height: 20px; }
    .wpec-metric { font-size: 22px; }
    .wpec-two-col { flex-direction: column; }
    .wpec-side-col { flex: 1 1 auto; }
    .wpec-filter-bar { gap: 8px; }
    .wpec-filter-bar.is-open { display: flex; }
    .wpec-filter-bar label { display: block; width: 100%; }
    .wpec-filter-bar select,
    .wpec-filter-bar input[type="date"],
    .wpec-filter-bar input[type="text"] { width: 100%; }
    .wpec-trend { height: 90px; gap: 6px; }
    .wpec-trend-grid { grid-template-columns: repeat(12, minmax(18px, 1fr)); height: 110px; gap: 6px; }
    .wpec-trend .wpec-trend-col { width: 22px; }
    .wpec-trend .bar { width: 16px; }
    .wpec-trend .label { font-size: 9px; }
    .wpec-trend-grid .trend-item .label { font-size: 9px; }
    .widefat th, .widefat td { font-size: 12px; }
    .wpec-offer-logo { width: 64px; height: 28px; }
}

/* Filtri ordinati */
.wpec-filter-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}
