* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top: 5px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-content h2 {
    font-size: 1.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.loading-content p {
    font-size: 1em;
    opacity: 0.9;
    font-style: italic;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Hide main content initially to prevent flash of old content */
#mainContent {
    opacity: 0;
    transition: opacity 0.3s ease;
}

#mainContent.loaded {
    opacity: 1;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.9;
    margin-bottom: 10px;
}

.last-updated {
    font-size: 0.9em;
    opacity: 0.8;
    font-style: italic;
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.card {
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
}

.card-header {
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.card-header h2 {
    font-size: 1.5em;
    margin: 0;
}

.gold-card .card-header {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
}

.silver-card .card-header {
    background: linear-gradient(135deg, #C0C0C0 0%, #808080 100%);
}

.card-body {
    padding: 25px;
}

.metric {
    margin-bottom: 20px;
}

.metric-label {
    display: block;
    font-size: 0.9em;
    color: #666;
    margin-bottom: 5px;
    font-weight: 500;
}

.metric-value {
    display: block;
    font-size: 2em;
    font-weight: bold;
    color: #333;
}

.metric-value-small {
    display: block;
    font-size: 1.2em;
    font-weight: bold;
    color: #333;
}

.metric-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-top: 15px;
}

.positive {
    color: #10b981;
}

.negative {
    color: #ef4444;
}

.chart-container {
    margin-bottom: 30px;
}

.chart-controls {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.zoom-controls {
    display: flex;
    gap: 5px;
    margin-left: auto;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.btn.active {
    background: rgba(255, 255, 255, 0.4);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-zoom {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    font-size: 14px;
    min-width: 40px;
}

.btn-zoom:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.btn-zoom:active {
    transform: scale(0.95);
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .btn:hover,
    .btn-zoom:hover {
        transform: none;
    }
    
    .btn:active,
    .btn-zoom:active {
        transform: scale(0.95);
        background: rgba(255, 255, 255, 0.4);
    }
    
    .card:hover {
        transform: none;
    }
    
    tbody tr:hover {
        background-color: transparent;
    }
    
    tbody tr:active {
        background-color: #f9fafb;
    }
}

#priceChart,
#priceChart100gm {
    max-height: 500px;
    width: 100% !important;
    height: auto !important;
}

.chart-container .card-body {
    position: relative;
    height: 400px;
    padding: 15px;
}

.chart-container canvas {
    max-width: 100%;
    height: 100% !important;
}

.table-container {
    margin-bottom: 30px;
}

.table-wrapper {
    overflow-x: auto;
    max-height: 500px;
    overflow-y: auto;
}

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

thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85em;
    letter-spacing: 0.5px;
}

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

tbody tr:nth-child(even) {
    background-color: #f9fafb;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #666;
    font-style: italic;
}

/* Loading Screen Mobile */
@media (max-width: 768px) {
    .loading-spinner {
        width: 50px;
        height: 50px;
        border-width: 4px;
    }
    
    .loading-content h2 {
        font-size: 1.2em;
    }
    
    .loading-content p {
        font-size: 0.9em;
    }
}

/* Responsive Design - Mobile First Approach */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        max-width: 100%;
    }
    
    header {
        padding: 15px;
        margin-bottom: 20px;
        border-radius: 12px;
    }
    
    header h1 {
        font-size: 1.4em;
        line-height: 1.3;
        margin-bottom: 8px;
    }
    
    .subtitle {
        font-size: 0.95em;
        margin-bottom: 8px;
        line-height: 1.4;
    }
    
    .last-updated {
        font-size: 0.8em;
    }
    
    .analytics-grid {
        grid-template-columns: 1fr;
        gap: 15px;
        margin-bottom: 20px;
    }
    
    .card {
        border-radius: 12px;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    }
    
    .card-header {
        padding: 15px;
    }
    
    .card-header h2 {
        font-size: 1.1em;
        line-height: 1.3;
    }
    
    .card-body {
        padding: 15px;
    }
    
    .metric {
        margin-bottom: 15px;
    }
    
    .metric-label {
        font-size: 0.85em;
        margin-bottom: 4px;
    }
    
    .metric-value {
        font-size: 1.6em;
    }
    
    .metric-value-small {
        font-size: 1.1em;
    }
    
    .metric-row {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-top: 12px;
    }
    
    .chart-container {
        margin-bottom: 20px;
    }
    
    .chart-controls {
        flex-direction: column;
        gap: 8px;
        margin-top: 12px;
    }
    
    .btn {
        padding: 10px 14px;
        font-size: 0.9em;
        width: 100%;
        text-align: center;
        min-height: 44px; /* Better touch target */
    }
    
    .zoom-controls {
        margin-left: 0;
        margin-top: 8px;
        width: 100%;
        justify-content: space-between;
    }
    
    .btn-zoom {
        padding: 10px 16px;
        font-size: 0.9em;
        min-width: 50px;
        min-height: 44px; /* Better touch target */
        flex: 1;
    }
    
    .chart-container .card-body {
        height: 350px;
        padding: 12px;
        min-height: 350px;
    }
    
    #priceChart,
    #priceChart100gm {
        max-height: 100% !important;
        height: 100% !important;
        width: 100% !important;
    }
    
    .table-container {
        margin-bottom: 20px;
    }
    
    .table-wrapper {
        max-height: 500px;
        border-radius: 8px;
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    table {
        font-size: 0.85em;
        min-width: 100%;
        width: max-content;
    }
    
    th, td {
        padding: 10px 8px;
        font-size: 0.85em;
        white-space: nowrap;
    }
    
    th {
        font-size: 0.75em;
        padding: 12px 8px;
        position: sticky;
        top: 0;
        z-index: 10;
    }
}

/* Tablet View */
@media (min-width: 769px) and (max-width: 1024px) {
    body {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2em;
    }
    
    .analytics-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 18px;
    }
    
    .metric-value {
        font-size: 1.8em;
    }
    
    .chart-container .card-body {
        height: 450px;
        padding: 15px;
    }
    
    #priceChart,
    #priceChart100gm {
        max-height: 100% !important;
        height: 100% !important;
        width: 100% !important;
    }
}

/* Small Mobile Devices */
@media (max-width: 480px) {
    body {
        padding: 8px;
    }
    
    header {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    header h1 {
        font-size: 1.2em;
    }
    
    .subtitle {
        font-size: 0.85em;
    }
    
    .card-header {
        padding: 12px;
    }
    
    .card-header h2 {
        font-size: 1em;
    }
    
    .card-body {
        padding: 12px;
    }
    
    .metric-value {
        font-size: 1.4em;
    }
    
    .metric-value-small {
        font-size: 1em;
    }
    
    .chart-container .card-body {
        height: 300px;
        padding: 10px;
        min-height: 300px;
    }
    
    #priceChart,
    #priceChart100gm {
        max-height: 100% !important;
        height: 100% !important;
        width: 100% !important;
    }
    
    .table-wrapper {
        max-height: 400px;
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 100%;
        width: max-content;
    }
    
    th, td {
        padding: 8px 6px;
        font-size: 0.8em;
        white-space: nowrap;
    }
    
    th {
        font-size: 0.7em;
        padding: 10px 6px;
        position: sticky;
        top: 0;
        z-index: 10;
    }
}

/* Scrollbar Styling */
.table-wrapper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #764ba2;
}

/* Mobile-specific improvements */
@media (max-width: 768px) {
    /* Prevent horizontal scroll except for tables */
    * {
        max-width: 100%;
    }
    
    /* Allow table wrapper to scroll */
    .table-wrapper {
        max-width: 100%;
        overflow-x: auto;
        overflow-y: auto;
    }
    
    .table-wrapper * {
        max-width: none;
    }
    
    /* Better text selection */
    ::selection {
        background: rgba(102, 126, 234, 0.3);
        color: #333;
    }
    
    /* Improve card touch targets */
    .card {
        -webkit-tap-highlight-color: rgba(102, 126, 234, 0.1);
    }
    
    /* Better focus states for accessibility */
    .btn:focus,
    .btn-zoom:focus {
        outline: 2px solid rgba(255, 255, 255, 0.5);
        outline-offset: 2px;
    }
    
    /* Smooth transitions */
    .card,
    .btn,
    .btn-zoom {
        transition: all 0.2s ease;
    }
    
    /* Improve table readability on mobile */
    .table-wrapper {
        -webkit-overflow-scrolling: touch;
        border: 1px solid rgba(255, 255, 255, 0.2);
        overflow-x: auto !important;
        overflow-y: auto !important;
        max-height: 500px !important;
    }
    
    table {
        display: table !important;
        width: 100%;
        min-width: 600px; /* Ensure table is wide enough to show all columns */
    }
    
    thead {
        display: table-header-group !important;
    }
    
    tbody {
        display: table-row-group !important;
    }
    
    tr {
        display: table-row !important;
    }
    
    th, td {
        display: table-cell !important;
    }
    
    /* Better spacing for stacked elements */
    .chart-container + .table-container,
    .table-container + .chart-container {
        margin-top: 20px;
    }
}

/* Landscape mobile optimization */
@media (max-width: 768px) and (orientation: landscape) {
    .chart-container .card-body {
        height: 280px;
        padding: 10px;
    }
    
    #priceChart,
    #priceChart100gm {
        max-height: 100% !important;
        height: 100% !important;
        width: 100% !important;
    }
    
    .table-wrapper {
        max-height: 300px;
    }
    
    header h1 {
        font-size: 1.3em;
    }
    
    .subtitle {
        font-size: 0.9em;
    }
}
