/* Base Styles */
:root {
    --table-header-bg: #23272f;
    /* dark header */
    --table-category-bg: linear-gradient(to right, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.3));
    /* darker category like before */
    --bg-color: #1a2847;
    /* Deep navy blue from flag */
    --card-bg: #273a5e;
    /* Slightly lighter navy */
    --text-primary: #f1f5f9;
    --text-secondary: #9eb4d4;
    /* Softer blue-gray */
    --accent-color: #5b8fd1;
    /* Light blue from flag rays */
    --accent-bright: #6ba3e8;
    /* Brighter blue accent */
    --golden-accent: #f5a623;
    /* Golden yellow from flag hexagon */
    --border-color: #3d5278;
    /* Navy-blue border */
    --hover-color: #324567;
    /* Slightly lighter on hover */
    --trend-up: #4ade80;
    --trend-down: #f87171;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    line-height: 1.6;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: clamp(0.25rem, 1vw, 1rem) clamp(0.5rem, 2vw, 2rem);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
}

/* Header */
header {
    text-align: center;
    margin-bottom: clamp(0.5rem, 1.5vh, 1.5rem);
    flex-shrink: 0;
}

h1 {
    font-size: clamp(1rem, 4vw, 2.5rem);
    font-weight: 700;
    margin-top: 0;
    /* margin-bottom: clamp(0.125rem, 0.5vh, 0.5rem); */
    margin-bottom: 0;
    background: linear-gradient(135deg, var(--golden-accent) , var(--accent-bright));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
}

header p {
    font-size: clamp(0.625rem, 1.5vw, 1rem);
    margin: 0;
}

.subtitle {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}
.footer-content {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
}

.subtitle-left {
    flex: 1;
    text-align: right;
    padding-right: 0.5em;
}
.disclaimer {
    flex: 1;
    text-align: left;
    padding-right: 0.5em;
}

.subtitle-middle {
    padding: 0em 0.5em;
}


.subtitle-right {
    flex: 1;
    text-align: left;
    padding-left: 0.5em;
}
.api-credit {
    flex: 1;
    text-align: right;
    padding-left: 0.5em;
}

.separator {
    flex-shrink: 0;
}

.footer-content a {
    color: var(--accent-bright);
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer-content a:hover {
    color: var(--golden-accent);
}

.footer-right {
    color: var(--text-secondary);
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    table-layout: fixed;
}

/* Fixed column widths for consistency across tabs */
th:nth-child(1),
td:nth-child(1) {
    width: 40%;
}

th:nth-child(2),
td:nth-child(2),
th:nth-child(3),
td:nth-child(3),
th:nth-child(4),
td:nth-child(4) {
    width: 20%;
}

thead {
    background: linear-gradient(to bottom, rgba(91, 143, 209, 0.12), rgba(91, 143, 209, 0.05));
    position: sticky;
    top: 0;
    z-index: 10;
}

thead th {
    background-color: var(--table-header-bg);
}

th {
    padding: clamp(0.5rem, 1.5vw, 1rem) clamp(0.5rem, 2vw, 1.5rem);
    font-weight: 600;
    color: var(--accent-bright);
    text-transform: uppercase;
    font-size: clamp(0.7rem, 1.5vw, 0.875rem);
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: clamp(0.5rem, 1.5vw, 1rem) clamp(0.5rem, 2vw, 1.5rem);
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    font-size: clamp(0.8rem, 1.8vw, 1rem);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background-color: var(--hover-color);
    transition: background-color 0.2s ease;
}

/* Category Header */
.category-header td {
    background: var(--table-category-bg);
    color: var(--golden-accent);
    font-weight: 700;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    padding: clamp(0.5rem, 1.5vw, 1rem) clamp(0.75rem, 2vw, 1.5rem);
}

/* Currency Wrapper */
.currency-wrapper {
    display: flex;
    align-items: center;
    gap: clamp(0.25rem, 0.8vw, 0.5rem);
    font-family: 'Roboto Mono', monospace;
    font-weight: 500;
    font-size: clamp(0.8rem, 1.8vw, 1rem);
}

.currency-icon {
    width: clamp(14px, 2.5vw, 20px);
    height: clamp(14px, 2.5vw, 20px);
    object-fit: contain;
    filter: drop-shadow(0 0 2px rgba(245, 166, 35, 0.3));
}

/* Item Name with Icon */
.item-name-wrapper {
    display: flex;
    align-items: center;
    gap: clamp(0.35rem, 1vw, 0.5rem);
}

.item-icon {
    width: clamp(18px, 3vw, 24px);
    height: clamp(18px, 3vw, 24px);
    object-fit: contain;
    flex-shrink: 0;
}

/* Trend Styles */
.trend-up {
    color: var(--trend-up);
}

.trend-down {
    color: var(--trend-down);
}

.trend-arrow {
    margin-left: 0.25rem;
    font-size: 0.8em;
}

/* Tabs */
.tabs-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: clamp(0.25rem, 1vw, 0.5rem);
    margin-bottom: clamp(0.5rem, 1.5vh, 1rem);
    flex-shrink: 0;
}

.tab-button {
    display: flex;
    align-items: center;
    gap: clamp(0.25rem, 0.8vw, 0.5rem);
    padding: clamp(0.5rem, 1.2vw, 0.75rem) clamp(0.75rem, 2vw, 1.25rem);
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: clamp(0.75rem, 1.5vw, 0.875rem);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-button:hover {
    background-color: var(--hover-color);
    color: var(--text-primary);
}

.tab-button.active {
    background-color: var(--accent-color);
    border-color: var(--accent-bright);
    color: var(--text-primary);
}

.tab-icon {
    width: clamp(1.25em, 3vw, 2em);
    height: clamp(1.25em, 3vw, 2em);
    object-fit: contain;
    flex-shrink: 0;
    filter: invert(91%) sepia(10%) saturate(77%) hue-rotate(171deg) brightness(105%) contrast(96%);
}

/* Price Disclaimer for derived prices */
.price-disclaimer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, rgba(91, 143, 209, 0.1), rgba(245, 166, 35, 0.08));
    border: 1px solid rgba(91, 143, 209, 0.2);
    border-radius: 0.5rem;
    font-size: clamp(0.7rem, 1.4vw, 0.8rem);
    color: var(--text-secondary);
    flex-shrink: 0;
    animation: fadeIn 0.3s ease;
}

.price-disclaimer .disclaimer-icon {
    color: var(--accent-bright);
    font-size: 1em;
    opacity: 0.9;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* List Container */
.list-container {
    background-color: var(--card-bg);
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    overflow: hidden;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Table Wrapper for scrollable content */
.table-wrapper {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

.table-wrapper::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari/Opera */
}

/* Scroll fade indicator */
.list-container {
    position: relative;
}

.list-container::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(to top, var(--card-bg) 0%, var(--card-bg) 20%, transparent 100%);
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s ease;
    border-radius: 0 0 0.75rem 0.75rem;
}

.list-container.scrolled-bottom::after {
    opacity: 0;
}

/* Scroll indicator arrow */
.scroll-indicator {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    opacity: 0.7;
    pointer-events: none;
    z-index: 5;
    transition: opacity 0.3s ease;
}

.scroll-indicator::after {
    content: '▼';
    font-size: 0.625rem;
    animation: bounce 1.5s infinite;
}

.list-container.scrolled-bottom .scroll-indicator {
    opacity: 0;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(4px);
    }
}

/* Averages wrapper - hidden on desktop */
.averages-wrapper {
    display: none;
}

/* Loading & Error States */
.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
    font-size: 1rem;
}

.error {
    text-align: center;
    padding: 2rem;
    color: var(--trend-down);
    background-color: rgba(248, 113, 113, 0.1);
    border-radius: 0.5rem;
    margin-top: 1rem;
}

footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    padding-top: clamp(0.25rem, 1vh, 0.5rem);
    font-size: clamp(0.5rem, 1.2vw, 0.875rem);
    color: var(--text-secondary);
}

footer a {
    color: var(--accent-bright);
    text-decoration: none;
    transition: color 0.2s ease;
}

footer a:hover {
    color: var(--golden-accent);
}

.hidden {
    display: none;
}

/* Responsive - Tablet */
@media (max-width: 768px) {
    /* Tabs - horizontal scroll on tablet */
    .tabs-container {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: var(--border-color) transparent;
        padding-bottom: 0.5rem;
    }

    .tabs-container::-webkit-scrollbar {
        height: 4px;
    }

    .tabs-container::-webkit-scrollbar-track {
        background: transparent;
    }

    .tabs-container::-webkit-scrollbar-thumb {
        background-color: var(--border-color);
        border-radius: 2px;
    }

    .tab-button {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Table adjustments */
    th {
        background-color: var(--table-header-bg);
    }

    .category-header td {
        background: var(--table-category-bg);
    }
}

/* Responsive - Mobile */
@media (max-width: 480px) {
    header {
        text-align: center;
        margin-top: clamp(0.5rem, 1.5vh, 1.5rem);
        margin-bottom: 0;
        flex-shrink: 0;
    }

    h1 {
        font-size: clamp(1rem, 4vw, 2.5rem);
        font-weight: 700;
        margin-top: 0;
        /* margin-bottom: clamp(0.125rem, 0.5vh, 0.5rem); */
        margin-bottom: 0;
        background: linear-gradient(135deg, var(--accent-bright), var(--golden-accent));
        background-clip: text;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        line-height: 1.2;
    }

    header p {
        font-size: clamp(0.625rem, 1.5vw, 1rem);
        margin: 0;
    }

    /* Tabs - scrollable horizontal layout */
    .tabs-container {
        justify-content: flex-start;
        margin-left: calc(-1 * clamp(0.5rem, 2vw, 0.75rem));
        margin-right: calc(-1 * clamp(0.5rem, 2vw, 0.75rem));
        padding-left: clamp(0.5rem, 2vw, 0.75rem);
        padding-right: clamp(0.5rem, 2vw, 0.75rem);
    }

    .tab-button {
        min-height: 44px;
        justify-content: center;
        border-radius: 0.375rem;
    }

    /* Table - convert to card layout */
    .list-container {
        border-radius: 0.5rem;
        border: none;
        background-color: transparent;
    }

    /* Price disclaimer - more compact on mobile */
    .price-disclaimer {
        padding: 0.375rem 0.75rem;
        margin-bottom: 0.375rem;
        font-size: 0.65rem;
        border-radius: 0.375rem;
    }

    .table-wrapper {
        -webkit-overflow-scrolling: touch;
        padding: 0;
    }

    table {
        display: block;
        border-collapse: collapse;
    }

    thead {
        display: none;
        /* Hide table headers on mobile */
    }

    tbody {
        display: block;
    }

    /* Reset fixed widths on mobile */
    td {
        width: auto !important;
        padding: 0;
        border: none;
    }

    tr {
        display: block;
        margin-bottom: clamp(0.5rem, 2vw, 0.75rem);
        background-color: var(--card-bg);
        border-radius: 0.5rem;
        border: 1px solid var(--border-color);
        padding: clamp(0.625rem, 2.5vw, 0.875rem);
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    tr:hover {
        background-color: var(--card-bg);
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    /* Category Header as Card */
    .category-header {
        background: var(--table-category-bg);
        padding: clamp(0.5rem, 2vw, 0.75rem) clamp(0.625rem, 2.5vw, 0.875rem);
        margin-bottom: 0.5rem;
        border-radius: 0.5rem;
    }

    .category-header td {
        display: block;
        padding: 0;
        border: none;
        font-size: clamp(0.875rem, 3.5vw, 1rem);
        font-weight: 700;
        color: var(--golden-accent);
        background: transparent;
    }

    .category-header:hover {
        transform: none;
        box-shadow: none;
    }

    /* Item rows as cards */
    td::before {
        display: none;
    }

    /* Recreate the card layout - stack vertically */
    tr:not(.category-header) {
        display: flex;
        flex-direction: column;
        gap: clamp(0.5rem, 2vw, 0.75rem);
    }

    /* Item name takes full width */
    tr:not(.category-header) td:first-child {
        font-weight: 600;
        font-size: clamp(0.8125rem, 3.5vw, 0.9375rem);
        color: var(--accent-bright);
        padding-left: 0 !important;
        padding-bottom: clamp(0.25rem, 1vw, 0.375rem);
        border-bottom: 1px solid rgba(91, 143, 209, 0.2);
    }

    /* Current price takes full width */
    tr:not(.category-header) td:nth-child(2) {
        display: flex;
        flex-direction: column;
        gap: clamp(0.25rem, 1vw, 0.375rem);
        padding-bottom: clamp(0.375rem, 1.5vw, 0.5rem);
        border-bottom: 1px solid rgba(91, 143, 209, 0.1);
    }

    /* Hide individual avg cells on mobile, show wrapper */
    tr:not(.category-header) td:nth-child(3),
    tr:not(.category-header) td:nth-child(4) {
        display: none;
    }

    tr:not(.category-header) .averages-wrapper {
        display: block;
    }

    /* Averages row - side by side */
    .card-averages-row {
        display: flex;
        gap: clamp(0.75rem, 3vw, 1rem);
    }

    .card-avg-cell {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: clamp(0.25rem, 1vw, 0.375rem);
    }

    /* Price cells with labels */
    tr:not(.category-header) td:nth-child(2)::before,
    .card-avg-cell::before {
        content: attr(data-label);
        display: block;
        font-size: clamp(0.625rem, 2.5vw, 0.75rem);
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        font-weight: 600;
        white-space: nowrap;
    }

    tr:not(.category-header) td:nth-child(2)::before {
        content: 'CURRENT PRICE';
    }

    .card-avg-cell[data-label="7-day"]::before {
        content: '7-DAY AVG';
    }

    .card-avg-cell[data-label="30-day"]::before {
        content: '30-DAY AVG';
    }

    .currency-wrapper {
        font-size: clamp(0.8125rem, 3.5vw, 0.9375rem);
    }

    /* Loading and error states */
    .loading {
        padding: clamp(1.5rem, 5vw, 2rem) clamp(0.75rem, 2vw, 1rem);
    }

    .error {
        padding: clamp(1rem, 4vw, 1.5rem) clamp(0.75rem, 2vw, 1rem);
        border-radius: 0.5rem;
        margin: clamp(0.5rem, 2vw, 0.75rem);
    }

    /* Footer */
    footer {
        margin-top: 0;
        padding-bottom: 0;
    }
}

/* Extra small devices */
@media (max-width: 360px) {
    .tabs-container {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* Mobile Landscape Mode - maximize table visibility */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        overflow: auto; /* Allow body scroll if needed */
    }

    .container {
        padding: 0.25rem 0.5rem;
        overflow: visible;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
    }

    /* Collapse header in landscape */
    header {
        margin-bottom: 0.25rem;
    }

    h1 {
        font-size: 1rem;
        line-height: 1;
    }

    header p,
    .subtitle {
        display: none;
    }

    /* Compact tabs */
    .tabs-container {
        margin-bottom: 0.25rem;
        gap: 0.25rem;
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
    }

    .tab-button {
        padding: 0.35rem 0.5rem;
        font-size: 0.7rem;
        min-height: 32px;
        border-radius: 0.25rem;
    }

    .tab-icon {
        width: 1em;
        height: 1em;
    }

    /* Make table container take remaining space but allow scroll */
    .list-container {
        flex: 1;
        min-height: 150px;
        border-radius: 0.375rem;
    }

    /* Compact table styling */
    th {
        padding: 0.35rem 0.5rem;
        font-size: 0.65rem;
    }

    td {
        padding: 0.35rem 0.5rem;
        font-size: 0.75rem;
    }

    .category-header td {
        padding: 0.35rem 0.5rem;
        font-size: 0.8rem;
    }

    .currency-wrapper {
        font-size: 0.75rem;
        gap: 0.2rem;
    }

    .currency-icon {
        width: 12px;
        height: 12px;
    }

    /* Hide scroll indicator in landscape - takes up space */
    .scroll-indicator {
        display: none;
    }

    /* Compact disclaimer in landscape */
    .price-disclaimer {
        padding: 0.25rem 0.5rem;
        margin-bottom: 0.25rem;
        font-size: 0.6rem;
        border-radius: 0.25rem;
    }

    .list-container::after {
        height: 30px;
    }

    /* Compact footer */
    footer {
        padding-top: 0.25rem;
        font-size: 0.5rem;
    }

    /* Hide footer content to save space, show only essential */
    .footer-content .disclaimer,
    .footer-content .separator,
    .footer-content .api-credit {
        display: none;
    }
}