/* ========================================
   Commodities Page Styles
   ======================================== */

.commodities-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background-color: var(--bg-main);
    min-height: 0;
}

.commodities-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-light);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.commodities-header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px 12px;
}

.commodities-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}

.title-group {
    flex: 1;
}

.commodities-title {
    font-family: var(--font-brand);
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.commodities-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

.header-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.update-time {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.source-badge {
    font-size: 11px;
    padding: 3px 10px;
    background: rgba(99, 102, 241, 0.1);
    color: #6366F1;
    border-radius: 20px;
    font-weight: 600;
}

/* Finance Sub-Navigation */
.finance-sub-nav {
    display: flex;
    gap: 24px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding: 4px 0;
}

.finance-sub-nav::-webkit-scrollbar {
    display: none;
}

.sub-nav-item {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    padding-bottom: 12px;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sub-nav-item:hover {
    color: var(--text-primary);
}

.sub-nav-item.active {
    color: var(--text-primary);
    border-bottom-color: var(--text-primary);
}

/* ========================================
   Commodity Groups & Tables
   ======================================== */

.commodities-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 32px 60px; /* Reduced top padding as Top Assets is above */
}

.top-assets-scroll {
    margin-bottom: 0;
    padding: 12px 32px;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 32px; /* Increased gap for ticker feel */
}

/* Ticker-style adjustments for Top Assets on this page */
.top-assets-scroll .top-asset-card {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    width: auto !important;
    box-shadow: none !important;
    display: flex;
    align-items: center;
    gap: 12px;
}

.top-assets-scroll .asset-value {
    font-size: 14px;
    font-weight: 700;
}

.top-assets-scroll .asset-name {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
}

.top-assets-scroll .asset-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-assets-scroll [id^="spark-"] {
    display: none !important; /* Hide small sparklines to make it a clean ticker */
}

.table-container {
    background: var(--bg-light);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.commodity-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    text-align: left;
}

.commodity-table th {
    background: rgba(0, 0, 0, 0.02);
    padding: 14px 16px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
}

.commodity-table td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

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

.commodity-table tr:hover td {
    background: rgba(0, 0, 0, 0.015);
}

/* Columns */
.crop-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.crop-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 15px;
}

.crop-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.crop-date {
    font-size: 11px;
    color: var(--text-tertiary);
    font-family: var(--font-ui);
    font-weight: 500;
}

.crop-location {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

.col-price { 
    text-align: right;
    width: 160px;
    min-width: 160px;
    max-width: 160px;
    font-family: 'JetBrains Mono', 'Roboto Mono', monospace; 
    font-size: 15px; 
}

.col-change, .col-percent, .col-monthly, .col-yearly {
    text-align: right;
    font-family: var(--font-ui);
}

.badge-change {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 12px;
    background: transparent !important;
}

.badge-change.positive { color: #059669; }
.badge-change.negative { color: #DC2626; }
.badge-change.neutral { color: var(--text-tertiary); }

.col-trend-span {
    padding: 4px 16px 12px !important;
    border-top: none !important;
    border-bottom: 1px solid var(--border-color);
}

.commodity-row td {
    border-bottom: none !important;
}

.commodity-sparkline-row td {
    border-bottom: 1px solid var(--border-color);
    padding-top: 0 !important;
}

.commodity-sparkline-row:hover td {
    background: rgba(0, 0, 0, 0.015);
}

.sparkline-container {
    width: 100% !important;
    min-width: 0;
    display: block;
}

.commodity-table tr.selected td {
    background: rgba(99, 102, 241, 0.05);
}

/* Indicators */
.positive { color: #10B981; }
.negative { color: #EF4444; }

/* ========================================
   Empty State
   ======================================== */

.commodities-empty {
    padding: 80px 20px;
    text-align: center;
}

.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }

/* ========================================
   Animations
   ======================================== */

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

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 1024px) {
    /* Keep key columns visible; allow horizontal scroll instead of hiding. */
    .col-monthly, .col-yearly { display: table-cell; }
}

@media (max-width: 768px) {
    .commodities-header-inner { padding: 20px 16px 8px; }
    .commodities-content { padding: 16px; }
    .col-change { display: none; }
    .commodities-title { font-size: 24px; }
    .commodities-title-row { flex-direction: column; align-items: flex-start; gap: 12px; }
    .header-meta { align-items: flex-start; }
}

@media (max-width: 768px) {
    /* Ensure the remaining numeric columns have room and can be scrolled into view. */
    .col-price { min-width: 140px; }
    .col-percent { min-width: 110px; }
    .col-monthly, .col-yearly { min-width: 80px; }
}

/* ========================================
   Commodities Filter & Advanced Logic
   ======================================== */

.filter-container {
    margin-bottom: 20px;
    padding: 15px;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.filter-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #374151;
}

.multiselect-wrapper {
    position: relative;
}

.multiselect-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    box-sizing: border-box;
}

.multiselect-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.multiselect-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    min-height: 32px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #3b82f6;
    color: white;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
}

.tag-remove {
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.tag-remove:hover {
    opacity: 1;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #d1d5db;
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.autocomplete-dropdown.active {
    display: block;
}

/* Premium header search wrapper: ensure dropdown positions correctly */
.premium-search-input-wrapper {
    position: relative;
}

/* Match premium input look/feel */
.premium-search-container .autocomplete-dropdown {
    top: calc(100% + 6px);
    border-top: 1px solid #d1d5db;
    border-radius: 12px;
    max-height: 340px;
    overflow-y: auto;
}

/* Panel above the table (date + search + week strip) */
.commodities-filter-panel {
    margin-bottom: 14px;
}

/* Make "Tafuta bidhaa" take remaining width */
.commodities-filter-panel .commodities-controls {
    width: 100%;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: nowrap; /* keep Tafuta + Leo side-by-side */
    flex-direction: row; /* override finance.css mobile column */
}

.commodities-filter-panel .commodities-control--date {
    flex: 0 0 170px;
    max-width: 170px;
}

.commodities-filter-panel .commodities-date-controls {
    justify-content: flex-end;
}

.commodities-filter-panel .commodities-control--search {
    flex: 1 1 auto;
    max-width: none;
    min-width: 0; /* allow input to shrink on narrow screens */
}

/* Match input size to the Leo button style */
.commodities-filter-panel .premium-search-input {
    height: 38px !important;
    border-radius: 10px !important;
    font-size: 13px !important;
    padding: 0 14px !important;
}

.commodities-filter-panel .premium-search-input:focus {
    box-shadow: 0 0 0 3px rgba(0, 184, 148, 0.08), 0 2px 10px rgba(0, 0, 0, 0.04) !important;
}

/* Stable vertical rhythm between controls, week strip, tags, and table */
.commodities-filter-panel .commodities-week-strip {
    margin-top: 12px;
}

.commodities-filter-panel #selectedTags {
    margin-top: 10px;
}

@media (max-width: 480px) {
    /* Keep same row on mobile by tightening widths */
    .commodities-filter-panel .commodities-controls {
        gap: 10px;
        flex-direction: row;
        align-items: flex-end;
    }

    .commodities-filter-panel .commodities-control--date {
        flex: 0 0 132px;
        max-width: 132px;
    }

    /* Reduce vertical whitespace in the filter panel */
    .commodities-filter-panel .commodities-week-strip {
        margin-top: 8px;
    }

    .commodities-filter-panel #selectedTags {
        margin-top: 6px;
    }

    .commodities-date-controls {
        margin-bottom: 6px;
    }
}

/* ========================================
   Commodities Date Week Strip (like Earnings)
   ======================================== */

.commodities-date-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.cal-btn {
    background: none;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 800;
    color: var(--text-secondary, #6b7280);
    cursor: pointer;
    transition: all 0.15s ease;
}

.cal-btn:hover {
    background: rgba(0, 0, 0, 0.03);
    color: var(--text-primary, #111827);
}

.cal-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.commodities-week-strip {
    display: flex;
    gap: 0;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-light, #fff);
}

.commodities-week-strip--full {
    width: 100%;
}

.commodities-week-day {
    flex: 1;
    text-align: center;
    padding: 10px 6px 12px;
    cursor: pointer;
    border-right: 1px solid var(--border-color, #e5e7eb);
    transition: background 0.15s ease;
    user-select: none;
}

.commodities-week-day:last-child { border-right: none; }

.commodities-week-day:hover { background: rgba(0, 0, 0, 0.02); }
.commodities-week-day.active { background: rgba(16, 185, 129, 0.07); }

.commodities-week-day.disabled {
    cursor: not-allowed;
    background: rgba(0, 0, 0, 0.015);
}

.commodities-week-day.disabled:hover { background: rgba(0, 0, 0, 0.015); }

.commodities-week-day.today .day-name {
    color: #059669;
    font-weight: 900;
}

.commodities-week-day .day-name {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-secondary, #6b7280);
    text-transform: uppercase;
    margin-bottom: 3px;
}

.commodities-week-day .day-date {
    font-size: 14px;
    font-weight: 900;
    color: var(--text-primary, #111827);
    margin-bottom: 4px;
}

.commodities-week-day.disabled .day-date {
    color: var(--text-secondary, #9ca3af);
}

.commodities-week-day .day-count {
    font-size: 11px;
    color: var(--text-tertiary, #9ca3af);
    font-weight: 700;
}

.commodities-week-day .day-count.has-data {
    color: #059669;
}

@media (max-width: 480px) {
    .commodities-week-day .day-date { font-size: 13px; }
    .commodities-week-day { padding: 9px 4px 11px; }
}

.autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 14px;
    color: #374151;
    transition: background-color 0.2s;
}

.autocomplete-item:hover {
    background-color: #f3f4f6;
}

.autocomplete-item.selected {
    background-color: #dbeafe;
    color: #1e40af;
    font-weight: 500;
}

.commodities-table-wrapper {
    position: relative;
    min-height: 400px;
}

.loading-indicator {
    display: none;
    text-align: center;
    padding: 40px;
    color: #6b7280;
}

.loading-indicator.active {
    display: block;
}

.table-container {
    max-height: 800px;
    overflow-y: auto;
    overflow-x: auto;
}

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

.commodity-table thead {
    position: sticky;
    top: -1px;
    background: white;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.commodity-table th,
.commodity-table td {
    white-space: nowrap;
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.commodity-table th:first-child,
.commodity-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 4; /* above non-sticky cells */
    background: var(--bg-light);
}

.commodity-table thead th:first-child {
    z-index: 20; /* always above scrolling body cells */
    background: rgba(0, 0, 0, 0.02);
}

/* Ensure header cells always paint above body cells (prevents overlap on pinned column) */
.commodity-table thead th {
    position: sticky;
    top: 0;
    z-index: 12;
    background: rgba(var(--bg-light-rgb, 255, 255, 255), 0.96);
    backdrop-filter: blur(8px);
}

/* Column sizing: keep widths stable while allowing horizontal scroll on mobile */
.commodity-table th.col-name,
.commodity-table td.col-name {
    min-width: 220px;
}

.commodity-table th.col-price,
.commodity-table td.col-price {
    min-width: 150px;
}

.commodity-table th.col-percent,
.commodity-table td.col-percent {
    min-width: 110px;
}

.commodity-table th.col-monthly,
.commodity-table td.col-monthly,
.commodity-table th.col-yearly,
.commodity-table td.col-yearly {
    min-width: 80px;
}

@media (max-width: 768px) {
    .premium-table-wrapper .commodity-table {
        min-width: 760px;
    }
}

@media (max-width: 480px) {
    /* Mobile: let columns hug content more closely */
    .commodity-table th,
    .commodity-table td {
        padding: 10px 12px;
    }

    .commodity-table th.col-name,
    .commodity-table td.col-name {
        min-width: 165px;
        white-space: normal; /* allow wrapping for long commodity names */
    }

    .commodity-table th.col-price,
    .commodity-table td.col-price {
        min-width: 135px;
    }

    .commodity-table th.col-percent,
    .commodity-table td.col-percent {
        min-width: 95px;
    }

    .commodity-table th.col-monthly,
    .commodity-table td.col-monthly,
    .commodity-table th.col-yearly,
    .commodity-table td.col-yearly {
        min-width: 70px;
    }

    .premium-table-wrapper .commodity-table {
        min-width: 640px;
    }
}

.commodity-table th:first-child::after,
.commodity-table td:first-child::after {
    content: '';
    position: absolute;
    top: 0;
    right: -1px;
    width: 1px;
    height: 100%;
    background: #e5e7eb;
}

.commodity-table td:first-child {
    box-shadow: 12px 0 14px -16px rgba(0, 0, 0, 0.24);
}

.commodity-table tbody tr:hover {
    background-color: #f9fafb;
}

.filter-info {
    font-size: 13px;
    color: #6b7280;
    margin-top: 8px;
}

.commodity-row--link {
    cursor: pointer;
}

.commodity-row--link:hover {
    background-color: rgba(99, 102, 241, 0.06) !important;
}

.commodity-row--link:focus-visible {
    outline: 2px solid rgba(99, 102, 241, 0.45);
    outline-offset: -2px;
}

/* Detail cards: padding so section titles are not clipped by overflow:hidden + border-radius */
.commodity-detail-view .glass-data-card {
    padding: 24px 28px 28px;
    overflow: hidden;
}

.commodity-detail-view .glass-data-card .premium-table-wrapper {
    padding-top: 0;
}

.commodity-detail-back {
    margin-bottom: 10px;
}

.commodity-detail-price-block {
    text-align: right;
    flex-shrink: 0;
}

.commodity-detail-price-range {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.commodity-detail-price-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.commodity-detail-price-range strong {
    font-family: var(--font-brand);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.commodity-detail-price-sep {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin: 0 4px;
}

.commodity-detail-unit {
    font-size: 12px;
    color: var(--text-secondary);
}

.commodity-detail-section-title {
    margin: 0 0 14px;
    font-size: 16px;
    font-weight: 700;
}

.commodity-detail-chart-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.commodity-trend-chart {
    min-height: 340px;
}

.commodity-trend-chart.chart-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.commodity-trend-chart.chart-loading::after {
    content: 'Inapakia mchoro...';
}

.commodity-fundamentals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.commodity-fundamentals-grid .metric-item--wide {
    grid-column: 1 / -1;
}

.commodity-detail-history-table {
    width: 100%;
}

@media (max-width: 720px) {
    .commodity-detail-price-block {
        text-align: left;
        width: 100%;
    }

    .commodity-detail-price-range {
        align-items: flex-start;
    }
}
