/*
 * BerlinEcho Spritpreise Widget – Frontend-Styles
 * Mobile-First, keine externen Framework-Abhängigkeiten.
 */

.be-spritpreise-widget {
    --be-sp-primary: #c41e3a;
    --be-sp-primary-dark: #9a1529;
    --be-sp-green: #0a6b2e;
    --be-sp-red: #c41e3a;
    --be-sp-yellow: #b87500;
    --be-sp-bg: #fff;
    --be-sp-border: #e4e4e4;
    --be-sp-text: #1a1a1a;
    --be-sp-text-muted: #666;
    --be-sp-bg-alt: #f7f7f7;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    color: var(--be-sp-text);
    background: var(--be-sp-bg);
    border: 1px solid var(--be-sp-border);
    border-radius: 8px;
    padding: 16px;
    margin: 20px 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    box-sizing: border-box;
}

.be-spritpreise-widget * {
    box-sizing: border-box;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.be-sp-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.be-sp-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 1.1rem;
}

.be-sp-live-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--be-sp-red);
    display: inline-block;
    animation: be-sp-pulse 2s infinite ease-in-out;
    flex-shrink: 0;
}

@keyframes be-sp-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.5; transform: scale(1.3); }
}

.be-sp-updated {
    font-size: 0.8rem;
    color: var(--be-sp-text-muted);
    font-weight: normal;
    margin-left: auto;
}

.be-sp-filter {
    display: flex;
    gap: 4px;
    background: var(--be-sp-bg-alt);
    padding: 4px;
    border-radius: 6px;
    width: 100%;
    overflow-x: auto;
}

.be-sp-tab {
    flex: 1;
    min-width: 90px;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: var(--be-sp-text);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.be-sp-tab:hover {
    background: rgba(0,0,0,0.04);
}

.be-sp-tab.is-active {
    background: var(--be-sp-primary);
    color: #fff;
}

/* ── Stats ─────────────────────────────────────────────────────────────── */
.be-sp-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

@media (min-width: 640px) {
    .be-sp-stats {
        grid-template-columns: repeat(4, 1fr);
    }
}

.be-sp-stat {
    background: var(--be-sp-bg-alt);
    padding: 10px 12px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.be-sp-stat-label {
    font-size: 0.75rem;
    color: var(--be-sp-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.be-sp-stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ── Karte ─────────────────────────────────────────────────────────────── */
.be-sp-map-wrap {
    position: relative;
    margin-bottom: 16px;
}

.be-sp-map {
    height: 320px;
    border-radius: 6px;
    border: 1px solid var(--be-sp-border);
    background: #e8e8e8;
}

.be-sp-locate {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 400;
    padding: 8px 12px;
    background: var(--be-sp-bg);
    border: 1px solid var(--be-sp-border);
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    color: var(--be-sp-text);
}

.be-sp-locate:hover {
    background: var(--be-sp-bg-alt);
}

/* ── Leaflet-Marker-Customisation ──────────────────────────────────────── */
.be-sp-price-marker {
    background: var(--be-sp-green);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    border: 2px solid #fff;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.be-sp-price-marker.is-average { background: var(--be-sp-yellow); }
.be-sp-price-marker.is-high    { background: var(--be-sp-red); }

/* ── Tabelle ───────────────────────────────────────────────────────────── */
.be-sp-table-wrap {
    overflow-x: auto;
    margin-bottom: 12px;
    border: 1px solid var(--be-sp-border);
    border-radius: 6px;
}

.be-sp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.be-sp-table th,
.be-sp-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--be-sp-border);
}

.be-sp-table thead th {
    background: var(--be-sp-bg-alt);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--be-sp-text-muted);
}

.be-sp-table tbody tr:last-child td {
    border-bottom: none;
}

.be-sp-table tbody tr:hover {
    background: var(--be-sp-bg-alt);
}

.be-sp-th-rank,
.be-sp-td-rank {
    width: 40px;
    text-align: center;
    font-weight: 700;
    color: var(--be-sp-text-muted);
}

.be-sp-td-rank.is-top {
    color: var(--be-sp-primary);
}

.be-sp-td-name {
    min-width: 140px;
}

.be-sp-td-name strong {
    display: block;
    font-weight: 600;
}

.be-sp-td-name small {
    color: var(--be-sp-text-muted);
    font-size: 0.8rem;
}

.be-sp-th-price,
.be-sp-td-price {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    white-space: nowrap;
}

.be-sp-th-delta,
.be-sp-td-delta {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 0.85rem;
    white-space: nowrap;
}

.be-sp-delta-pos { color: var(--be-sp-red); }
.be-sp-delta-neg { color: var(--be-sp-green); }

.be-sp-td-route a {
    color: var(--be-sp-primary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
}

.be-sp-td-route a:hover {
    text-decoration: underline;
}

.be-sp-loading,
.be-sp-error {
    text-align: center;
    padding: 24px !important;
    color: var(--be-sp-text-muted);
    font-style: italic;
}

.be-sp-error {
    color: var(--be-sp-red);
    font-style: normal;
}

/* Mobile: Bezirk-Spalte ausblenden */
@media (max-width: 640px) {
    .be-sp-th-district,
    .be-sp-td-district {
        display: none;
    }

    .be-sp-th-delta,
    .be-sp-td-delta {
        display: none;
    }

    .be-sp-table th,
    .be-sp-table td {
        padding: 8px 8px;
    }
}

/* ── Footer ────────────────────────────────────────────────────────────── */
.be-sp-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding-top: 12px;
    border-top: 1px solid var(--be-sp-border);
    font-size: 0.8rem;
    color: var(--be-sp-text-muted);
}

.be-sp-source a {
    color: var(--be-sp-text-muted);
    text-decoration: underline;
}

.be-sp-source a:hover {
    color: var(--be-sp-primary);
}

.be-sp-refresh {
    padding: 6px 12px;
    border: 1px solid var(--be-sp-border);
    background: var(--be-sp-bg);
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--be-sp-text);
}

.be-sp-refresh:hover {
    background: var(--be-sp-bg-alt);
}

/* ── Dark-Mode-Support ─────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
    .be-spritpreise-widget {
        --be-sp-bg: #1a1a1a;
        --be-sp-border: #333;
        --be-sp-text: #f0f0f0;
        --be-sp-text-muted: #a0a0a0;
        --be-sp-bg-alt: #242424;
    }
}
