/* =========================================================================
   Kerala Gold - Premium Dark Glassmorphism Theme
   ========================================================================= */

:root {
    /* Color Palette */
    --bg-dark: #0f172a;
    --bg-surface: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    
    --primary-accent: #fbbf24;     /* Gold Accent */
    --primary-dark: #d97706;
    --green-up: #34d399;
    --red-down: #f87171;
    
    --text-main: #ffffff;
    --text-muted: #cbd5e1;
    
    /* Glows */
    --glow-gold: 0 0 20px rgba(251, 191, 36, 0.15);
    --glow-surface: 0 0 30px rgba(0, 0, 0, 0.4);
    
    /* Layout & Shadow */
    --glass-blur: blur(16px);
    --shadow-soft: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    --border-radius: 16px;
    
    --font-sans: 'Outfit', sans-serif;
    --transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --anim-speed: 0.6s;
}

/* ================== GLOBAL RESETS ================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-dark);
    color: var(--text-main);
    background-image: 
        radial-gradient(at 0% 0%, rgba(251, 191, 36, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(52, 211, 153, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(15, 23, 42, 1) 0px, transparent 50%);
    background-attachment: fixed;
    min-height: 100vh;
    line-height: 1.6;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ================== TYPOGRAPHY & UTILS ================== */
.text-green { color: var(--green-up); }
.text-red { color: var(--red-down); }

/* ================== GLASSMORPHISM COMPONENTS ================== */
.glass-navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-color);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

@media (max-width: 640px) {
    .nav-container {
        flex-direction: column;
        padding: 1.5rem 1rem;
        text-align: center;
        gap: 1.25rem;
    }
    .nav-links {
        justify-content: center;
        width: 100%;
        gap: 1.5rem;
    }
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    transition: var(--transition);
}

@media (max-width: 480px) {
    .logo {
        font-size: 1.25rem;
    }
}

.logo-accent {
    color: var(--primary-accent);
}

.nav-links {
    display: flex;
    gap: 2rem;
    list-style: none;
}

.nav-links a {
    font-weight: 500;
    color: var(--text-muted);
    transition: var(--transition);
}

.nav-links a:hover, .nav-links a.active {
    color: var(--primary-accent);
}

.glass-card {
    background: var(--bg-surface);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-soft), var(--glow-surface);
}

/* ================== CUSTOM SELECT PILL ================== */
.select-wrapper {
    position: relative;
    display: inline-block;
}

.custom-select-trigger {
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.3);
    color: var(--primary-accent);
    padding: 0.4rem 1.2rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.custom-select-trigger:hover {
    background: rgba(251, 191, 36, 0.2);
    box-shadow: var(--glow-gold);
}

.custom-select-trigger::after {
    content: '▼';
    font-size: 0.6rem;
}

#state-select {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

/* ================== LAYOUT ================== */
.dashboard-container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}

@media (max-width: 640px) {
    .dashboard-container {
        margin: 1rem auto;
        padding: 0 1rem;
    }
}

.summary-cards {
    display: grid;
    /* 4 equal columns on desktop (now that sidebar is removed) */
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
    margin-bottom: 2rem;
}

/* Tablet: 2 columns */
@media (max-width: 900px) {
    .summary-cards {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
}

@media (max-width: 640px) {
    .summary-cards {
        grid-template-columns: 1fr 1fr; /* 2-column grid on mobile */
        gap: 0.9rem;
    }
}

@media (max-width: 360px) {
    .summary-cards {
        grid-template-columns: 1fr; /* Fall back to 1 col on very small screens */
    }
}

.stat-card.primary-stat {
    border-color: rgba(251, 191, 36, 0.3);
    box-shadow: var(--shadow-soft), var(--glow-gold);
}

.stat-card h4 {
    font-size: 0.85rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 700;
}

.stat-card h2 {
    font-size: 2.5rem;
    font-weight: 600;
    margin: 0.5rem 0;
    color: var(--primary-accent);
}

@media (max-width: 640px) {
    .stat-card h2 {
        font-size: 1.5rem; /* Smaller to fit 2-column layout */
        margin: 0.3rem 0;
    }
    .stat-card h4 {
        font-size: 0.7rem;
        letter-spacing: 0.8px;
    }
    .stat-card {
        padding: 1rem;
    }
    .trend-indicator, .date-label {
        font-size: 0.75rem;
    }
}

.stat-card {
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-8px) scale(1.02);
    border-color: rgba(251, 191, 36, 0.3);
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.6);
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.05),
        transparent
    );
    transition: 0.5s;
}

.stat-card:hover::after {
    left: 100%;
}

.badge {
    background: rgba(251, 191, 36, 0.15);
    color: var(--primary-accent);
    padding: 0.3rem 0.8rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 0.5rem;
    vertical-align: middle;
    border: 1px solid rgba(251, 191, 36, 0.2);
}

.content-grid {
    display: block; /* Full width, no sidebar */
}

/* Chart Canvas: Responsive Height */
.chart-canvas-wrapper {
    position: relative;
    width: 100%;
    height: 280px;
}

@media (max-width: 640px) {
    .chart-canvas-wrapper {
        height: 210px;
    }
}

@media (max-width: 400px) {
    .chart-canvas-wrapper {
        height: 185px;
    }
}

/* ================== INSIGHTS ROW ================== */
.insights-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (max-width: 900px) {
    .insights-row {
        grid-template-columns: 1fr;
    }
}

.insight-card {
    padding: 1.5rem;
}

.averages-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 1.25rem;
    margin-top: 1rem;
}

.avg-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.avg-item:last-child {
    border-bottom: none;
}

.avg-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.avg-value-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    text-align: right;
}

.avg-price {
    font-weight: 600;
    font-size: 1.1rem;
}

.avg-indicator {
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    background: rgba(255,255,255,0.05);
}

/* Range Visual */
.range-visual-container {
    margin-top: 1.5rem;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 2rem;
    font-weight: 600;
}

.range-track {
    position: relative;
    height: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 99px;
    margin-bottom: 1.5rem;
}

.range-fill {
    position: absolute;
    height: 100%;
    left: 0;
    width: 0%; /* Dynamic */
    background: linear-gradient(90deg, var(--primary-accent), #f59e0b);
    border-radius: 99px;
}

.range-marker {
    position: absolute;
    width: 3px;
    height: 24px;
    background: #ffffff;
    top: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
    z-index: 5;
}

.marker-label {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: #ffffff;
    color: #000000;
    font-size: 0.6rem;
    font-weight: 800;
    padding: 0.1rem 0.4rem;
    border-radius: 2px;
    text-transform: uppercase;
}

.range-status {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.section-header {
    margin-bottom: 1.5rem;
}

.section-header h3 {
    margin-bottom: 1.2rem;
    color: var(--text-main);
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.section-header h3::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 24px;
    background: var(--primary-accent);
    border-radius: 2px;
}

/* ================== SPOT PRICES WIDGET ================== */
.spot-prices-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .spot-prices-grid {
        grid-template-columns: 1fr;
    }
}

.spot-card {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    transition: var(--transition);
}

.spot-card:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(15, 23, 42, 0.6);
}

.spot-header {
    padding: 0.75rem 1rem;
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border-color);
}

.carat-22 { 
    background: linear-gradient(90deg, rgba(217, 119, 6, 0.2), transparent);
    color: #fbbf24; 
}
.carat-24 { 
    background: linear-gradient(90deg, rgba(251, 191, 36, 0.2), transparent);
    color: #fef3c7; 
}

.spot-row {
    display: flex;
    justify-content: space-between;
    padding: 0.8rem 1.2rem;
    font-size: 0.95rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-muted);
}

.spot-row:last-child {
    border-bottom: none;
}

.spot-row span:last-child {
    color: var(--text-main);
    font-weight: 600;
    font-family: monospace;
    font-size: 1.05rem;
}

@media (max-width: 480px) {
    .spot-row {
        padding: 0.65rem 0.9rem;
        font-size: 0.85rem;
    }
    .spot-row span:last-child {
        font-size: 0.95rem;
    }
    .spot-header {
        font-size: 0.8rem;
        padding: 0.6rem 0.9rem;
    }
    .spot-prices-container h3 {
        font-size: 1.1rem;
    }
}

.spot-row.highlight {
    background: rgba(251, 191, 36, 0.05);
}

.spot-row.highlight span:last-child {
    color: var(--primary-accent);
}

/* ================== TABLES ================== */
.table-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* Inline row tags in the table */
.row-tag {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.tag-month-high { background: rgba(251,191,36,0.2);  color: #fbbf24; }
.tag-month-low  { background: rgba(167,139,250,0.2);  color: #a78bfa; }
.tag-high       { background: rgba(248,113,113,0.2); color: var(--red-down); }
.tag-low        { background: rgba(52,211,153,0.2);  color: var(--green-up); }

.modern-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-family: inherit;
    color-scheme: dark;
}

.table-wrapper {
    overflow-x: auto;
}

.premium-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 0.5rem;
    min-width: 320px; /* Reduced from 450px */
}

@media (max-width: 600px) {
    .premium-table {
        font-size: 0.85rem;
        min-width: unset; /* Let it flow naturally */
    }
    .premium-table td, .premium-table th {
        padding: 0.6rem 0.75rem;
    }
    .table-header-flex {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .table-header-flex h3 {
        font-size: 1.1rem;
    }
}

.premium-table th {
    text-align: left;
    padding: 1rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.premium-table tbody tr {
    background: rgba(255, 255, 255, 0.03);
    transition: var(--transition);
}

.premium-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.premium-table td {
    padding: 1rem;
}

.premium-table td:first-child { border-radius: 8px 0 0 8px; }
.premium-table td:last-child { border-radius: 0 8px 8px 0; }

.row-high td { border-top: 1px solid rgba(248, 113, 113, 0.3); border-bottom: 1px solid rgba(248, 113, 113, 0.3); }
.row-low td { border-top: 1px solid rgba(52, 211, 153, 0.3); border-bottom: 1px solid rgba(52, 211, 153, 0.3); }

/* ================== AD PLACEMENTS ================== */
.ad-placement {
    background: repeating-linear-gradient(
        45deg,
        rgba(255,255,255,0.02),
        rgba(255,255,255,0.02) 10px,
        rgba(255,255,255,0.01) 10px,
        rgba(255,255,255,0.01) 20px
    );
    border: 1px dashed var(--border-color);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    overflow: hidden;
}

.ad-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0,0,0,0.5);
    color: #94a3b8;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
}

.top-banner-ad {
    max-width: 900px;
    margin: 2rem auto 0;
    border-radius: 12px;
    min-height: 100px;
    background-color: rgba(30, 41, 59, 0.5);
}

.sidebar-ad {
    border-radius: var(--border-radius);
    min-height: 400px;
    flex-direction: column;
}

.sticky-ad {
    position: sticky;
    top: 100px;
}

.ad-mock-image {
    width: 100%;
    height: 150px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border-radius: 8px;
    margin: 1rem 0;
    opacity: 0.8;
}

.ad-content-vertical {
    padding: 1.5rem;
    width: 100%;
}

.ad-cta {
    width: 100%;
    background: white;
    color: black;
    border: none;
    padding: 0.75rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.ad-cta:hover {
    background: var(--primary-accent);
}

.floating-ad {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #000;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 10px 25px -5px rgba(251, 191, 36, 0.5);
    cursor: pointer;
    font-weight: 700;
    z-index: 1000;
    transition: transform 0.3s;
}

.floating-ad:hover {
    transform: scale(1.1) rotate(5deg);
}

/* ================== FOOTER ================== */
.modern-footer {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    margin-top: 3rem;
}

.footer-links {
    margin-top: 1rem;
}

.footer-links a {
    margin: 0 0.5rem;
}

.footer-links a:hover {
    color: var(--primary-accent);
}

/* ================== ANIMATIONS ================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.glass-card {
    animation: fadeInUp var(--anim-speed) ease-out forwards;
}

.stat-card:nth-child(1) { animation-delay: 0.1s; }
.stat-card:nth-child(2) { animation-delay: 0.2s; }
.stat-card:nth-child(3) { animation-delay: 0.3s; }
.stat-card:nth-child(4) { animation-delay: 0.4s; }
.stat-card:nth-child(5) { animation-delay: 0.5s; }

.primary-column .glass-card:nth-child(1) { animation-delay: 0.6s; }
.primary-column .glass-card:nth-child(2) { animation-delay: 0.7s; }
.primary-column .glass-card:nth-child(3) { animation-delay: 0.8s; }


/* ================================================
   COMPREHENSIVE MOBILE OVERRIDE — ≤500px
   Ensures perfect layout on all phone screens
   ================================================ */
@media (max-width: 500px) {

    /* --- Navbar --- */
    .nav-container {
        flex-direction: column;
        padding: 1rem 0.75rem;
        gap: 0.75rem;
        text-align: center;
    }
    .nav-links {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.75rem;
    }
    .logo {
        font-size: 1.2rem;
    }

    /* --- Stat Cards: 2×2 grid --- */
    .summary-cards {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }
    .stat-card {
        padding: 0.85rem !important;
    }
    .stat-card h2 {
        font-size: 1.35rem !important;
        margin: 0.25rem 0 !important;
    }
    .stat-card h4 {
        font-size: 0.65rem !important;
        letter-spacing: 0.5px !important;
    }
    .trend-indicator, .date-label {
        font-size: 0.7rem !important;
    }

    /* --- Insights Row: stack vertically --- */
    .insights-row {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }
    .insight-card {
        padding: 1rem !important;
    }
    .avg-price {
        font-size: 1rem !important;
    }

    /* --- Spot Prices: stack the two carat cards --- */
    .spot-prices-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }

    .spot-row {
        padding: 0.55rem 0.8rem !important;
        font-size: 0.82rem !important;
    }
    .spot-row span:last-child {
        font-size: 0.88rem !important;
    }
    .spot-header {
        font-size: 0.78rem !important;
        padding: 0.5rem 0.8rem !important;
    }

    /* --- Chart: tighter height --- */
    .chart-canvas-wrapper {
        height: 190px !important;
    }

    /* --- Section headings --- */
    .section-header h3,
    .glass-card h3 {
        font-size: 1.05rem !important;
        margin-bottom: 0.75rem !important;
    }

    /* --- Price table --- */
    .premium-table {
        font-size: 0.82rem !important;
        min-width: unset !important;
    }
    .premium-table td,
    .premium-table th {
        padding: 0.5rem 0.6rem !important;
    }
    .table-header-flex h3 {
        font-size: 1rem !important;
    }

    /* --- Dashboard padding --- */
    .dashboard-container {
        padding: 0 0.75rem !important;
        margin-top: 0.75rem !important;
    }

    /* --- Glass card default padding --- */
    .glass-card {
        padding: 1rem !important;
    }
}

/* --- Split Tables Formatter --- */
@media (max-width: 900px) {
    .two-column-tables {
        grid-template-columns: 1fr !important;
        gap: 0 !important;
    }
    .desktop-header-only {
        display: none !important;
    }
    #gold-table-2 {
        display: none !important;
    }
}
