/* ╔══════════════════════════════════════════════════════════════╗
   ║  It's so expensive - Enhanced design with clear hierarchy   ║
   ╚══════════════════════════════════════════════════════════════╝ */

/* ═══ Spacing System (6px base unit, compact) ═══ */
:root {
    --space-1: 6px;
    --space-2: 12px;
    --space-3: 18px;
    --space-4: 24px;
    --accent-ocean: #00B4D8;  /* Bright ocean blue */
    --accent-coral: #F77F00;  /* Vibrant coral orange */
}

/* Dark mode improved contrast */
[style*="--text-color: #fff"] {
    --text-color: #ededed !important;
    --text-color-alt: #8a8a8a !important;
    --background-color: #0a0a0a !important;
}

/* Wider layout */
body {
    max-width: calc(min(140ch, round(down, 100%, 1ch)));
}

/* ═══ 1. Two-column header layout ═══ */
.site-header-grid {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--text-color);
}

/* Theme toggle in top right of header */
.theme-toggle-header {
    position: absolute;
    top: 0;
    right: 0;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-color-alt);
    text-align: right;
    white-space: nowrap;
    min-height: 20px;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.header-right {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    justify-content: center;
    padding: var(--space-3);
    background: var(--background-color-alt);
    min-height: 200px;
}

.site-title {
    font-size: 3rem;
    line-height: 1.2;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: -0.02em;
}

.site-subtitle {
    font-size: 1.1rem;
    color: var(--text-color-alt);
    margin: 0;
    font-weight: var(--font-weight-normal);
}

.meta-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: 0.9rem;
    color: var(--text-color-alt);
    margin-top: var(--space-2);
}

.meta-info strong {
    color: var(--text-color);
}

.insight-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.insight-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--text-color-alt);
    letter-spacing: 0.05em;
}

.insight-value {
    font-size: 1.5rem;
    font-weight: var(--font-weight-bold);
    color: var(--text-color);
    min-height: 1.8rem;
}

/* ═══ 3. Section Headers ═══ */
h2 {
    text-transform: uppercase;
    font-size: 1.2rem;
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.05em;
    margin: var(--space-4) 0 var(--space-3) 0;
    color: var(--text-color);
}

hr {
    margin: var(--space-4) 0;
    border: none;
    border-top: 1px solid var(--text-color);
    opacity: 0.3;
}

/* ═══ 4. Filter Block (grouped, no boxes) ═══ */
.filter-block {
    margin: var(--space-3) 0;
}

.filter-label {
    display: block;
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--text-color-alt);
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-2);
}

.filter-grid input,
.filter-grid select {
    min-height: 44px; /* Better touch target */
}

/* ═══ 5. Loading States ═══ */
.loading-state {
    text-align: center;
    padding: var(--space-4);
    color: var(--text-color-alt);
}

.loading-text {
    font-weight: var(--font-weight-medium);
}

.loading-dots {
    display: inline-block;
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Loading skeleton animation */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--background-color-alt) 0%,
        var(--background-color) 50%,
        var(--background-color-alt) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 2px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-row {
    height: 40px;
}

.skeleton-text {
    display: inline-block;
    height: 1em;
    width: 100%;
}

.skeleton-text.short {
    width: 60%;
}

.skeleton-text.medium {
    width: 80%;
}

.skeleton-chart {
    height: 400px;
    width: 100%;
}

.skeleton-table {
    height: 300px;
    width: 100%;
}

.hidden {
    display: none !important;
}

/* ═══ 6. Tables - Improved readability ═══ */
.table-container {
    overflow-x: auto;
    margin: var(--space-3) 0;
}

.products-table tbody tr:nth-child(even) {
    background: var(--background-color-alt);
}

.products-table thead th {
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    font-weight: var(--font-weight-bold);
}

/* Sticky first column on mobile */
.sticky-col {
    position: sticky;
    left: 0;
    background: var(--background-color);
    z-index: 1;
}

.products-table tbody tr:nth-child(even) .sticky-col {
    background: var(--background-color-alt);
}

/* ═══ 7. Price Highlighting with Accent ═══ */
.price {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.price.cheapest {
    font-weight: var(--font-weight-bold);
    color: var(--accent-ocean);
}

.price.cheapest::before {
    content: '→ ';
}

/* De-emphasize non-cheapest prices */
.products-table td:not(.price.cheapest).price {
    opacity: 0.6;
}

/* ═══ 8. Store Rankings ═══ */
.rank-1 {
    font-weight: var(--font-weight-bold);
    color: var(--accent-ocean);
}

.rank-1::before {
    content: '#';
}

/* ═══ 9. Chart Section ═══ */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    margin: var(--space-3) 0;
}

.chart-figure {
    margin: 0;
    min-height: 400px;
}

#asciiChart {
    display: block;
    white-space: pre;
    margin: 0;
    overflow-x: auto;
}

.chart-table {
    display: flex;
    align-items: start;
    min-height: 300px;
}

figcaption {
    min-height: 20px;
}

.products-section {
    min-height: 500px;
}

/* ═══ Data Freshness Indicators ═══ */

.data-legend {
    margin-top: var(--space-2);
    padding: var(--space-2);
    border-top: 1px solid var(--border-color);
    font-size: 0.875rem;
    color: var(--text-color-alt);
    display: flex;
    gap: var(--space-3);
    align-items: center;
    flex-wrap: wrap;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.legend-item sup {
    font-size: 0.75rem;
}

/* Price freshness indicators */
sup.verified-indicator {
    color: var(--accent-ocean);
    font-size: 0.7rem;
    margin-left: 0.1rem;
    opacity: 0.8;
}

sup.estimate-indicator {
    color: var(--text-color-alt);
    font-size: 0.7rem;
    margin-left: 0.1rem;
    opacity: 0.6;
}

/* ═══ 10. Responsive ═══ */
/* ═══ Enhanced Visual Elements ═══ */

/* Section borders (simple) */
.chart-section,
.products-section {
    border: 1px solid var(--border-color);
    padding: var(--space-3);
    margin-bottom: var(--space-4);
}

/* Separator line before products section */
.products-section {
    border-top: 2px solid var(--text-color);
    margin-top: var(--space-4);
}

/* Table hover effects */
.products-table tbody tr {
    transition: background-color 0.15s ease;
}

.products-table tbody tr:hover {
    background-color: var(--background-color-alt);
}

#storeTable tbody tr {
    transition: background-color 0.15s ease;
}

#storeTable tbody tr:hover {
    background-color: var(--background-color-alt);
}

/* Column sorting indicators */
th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: calc(var(--space-2) + 12px) !important;
}

th.sortable::after {
    content: '▲▼';
    position: absolute;
    right: var(--space-1);
    font-size: 0.6rem;
    color: var(--text-color-alt);
    opacity: 0.3;
}

th.sortable:hover::after {
    opacity: 0.6;
}

th.sortable.sort-asc::after {
    content: '▲';
    opacity: 1;
    color: var(--accent-ocean);
}

th.sortable.sort-desc::after {
    content: '▼';
    opacity: 1;
    color: var(--accent-ocean);
}

/* Cursor blink animation for inputs */
input[type="text"]:focus,
input[type="search"]:focus,
textarea:focus {
    animation: cursor-blink 1s step-end infinite;
}

@keyframes cursor-blink {
    0%, 50% { border-color: var(--text-color); }
    51%, 100% { border-color: var(--accent-ocean); }
}

/* Spinner animation (replaces skeleton loaders) */
.spinner {
    display: inline-block;
    font-size: 1.5rem;
    line-height: 1;
    animation: spinner-rotate 1s steps(10) infinite;
}

@keyframes spinner-rotate {
    0% { content: '⠋'; }
    10% { content: '⠙'; }
    20% { content: '⠹'; }
    30% { content: '⠸'; }
    40% { content: '⠼'; }
    50% { content: '⠴'; }
    60% { content: '⠦'; }
    70% { content: '⠧'; }
    80% { content: '⠇'; }
    90% { content: '⠏'; }
    100% { content: '⠋'; }
}

.spinner::after {
    content: '⠋';
    animation: spinner-frames 1s steps(10) infinite;
}

@keyframes spinner-frames {
    0% { content: '⠋'; }
    10% { content: '⠙'; }
    20% { content: '⠹'; }
    30% { content: '⠸'; }
    40% { content: '⠼'; }
    50% { content: '⠴'; }
    60% { content: '⠦'; }
    70% { content: '⠧'; }
    80% { content: '⠇'; }
    90% { content: '⠏'; }
}

/* Price difference highlights */
tr.biggest-difference {
    background-color: rgba(247, 127, 0, 0.1) !important;
}

tr.biggest-difference:hover {
    background-color: rgba(247, 127, 0, 0.15) !important;
}

.price-diff-badge {
    display: inline;
    padding: 0 6px;
    margin-left: var(--space-1);
    font-size: 0.75rem;
    background: var(--accent-coral);
    color: #fff;
    border-radius: 3px;
    font-weight: bold;
    cursor: help;
    position: relative;
    line-height: 1;
}

/* Mobile-friendly: show tooltip on touch/click */
.price-diff-badge::after {
    content: attr(data-mobile-text);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-color);
    color: var(--background-color);
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 0.7rem;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    margin-bottom: 4px;
    z-index: 100;
}

.price-diff-badge.show-tooltip::after {
    opacity: 1;
}

/* Desktop hover */
@media (hover: hover) {
    .price-diff-badge:hover::after {
        opacity: 1;
    }
}

/* ═══ Media Queries ═══ */

@media (max-width: 768px) {
    body {
        padding: var(--space-2);
    }

    .site-title {
        font-size: 2rem;
    }

    .site-header-grid {
        grid-template-columns: 1fr;
        gap: var(--space-2);
        margin-bottom: var(--space-2);
        padding-bottom: var(--space-2);
    }

    .header-right {
        padding: var(--space-2);
        gap: var(--space-1);
        min-height: auto;
    }

    .header-left {
        gap: var(--space-1);
    }

    .insight-item {
        gap: 2px;
    }

    .insight-label {
        font-size: 0.75rem;
    }

    .insight-value {
        font-size: 1.2rem;
    }

    .chart-section,
    .products-section {
        padding: var(--space-2);
        margin-bottom: var(--space-2);
    }

    .chart-grid {
        grid-template-columns: 1fr;
        gap: var(--space-3);
    }

    .filter-grid {
        grid-template-columns: 1fr;
    }

    /* Improve table readability on mobile */
    .table-container {
        margin-left: calc(-1 * var(--space-2));
        margin-right: calc(-1 * var(--space-2));
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .products-table {
        font-size: 0.8rem;
    }

    .products-table th,
    .products-table td {
        padding: var(--space-1);
        white-space: nowrap;
    }

    /* Make store table more compact */
    #storeTable {
        font-size: 0.9rem;
    }

    #storeTable th,
    #storeTable td {
        padding: var(--space-1);
    }

    /* Adjust chart for mobile */
    #asciiChart {
        font-size: 0.7rem;
        -webkit-overflow-scrolling: touch;
    }

    figcaption {
        font-size: 0.75rem;
    }

    h2 {
        font-size: 1rem;
        margin: var(--space-3) 0 var(--space-2) 0;
    }
}

@media (max-width: 480px) {
    .site-title {
        font-size: 1.75rem;
    }

    .site-subtitle {
        font-size: 0.95rem;
    }

    .meta-info {
        font-size: 0.8rem;
    }

    .products-table {
        font-size: 0.75rem;
    }

    .insight-value {
        font-size: 1.1rem;
    }

    #asciiChart {
        font-size: 0.6rem;
    }
}
