/* Common styles shared across all pages */

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Space Grotesk', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: all 0.3s ease;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    /* Prevent iOS from auto-inflating font sizes in landscape */
    -webkit-text-size-adjust: 100%;
    /* Contain stray horizontal overflow without breaking position: sticky
       (clip, unlike hidden, does not turn overflow-y into a scroll container) */
    overflow-x: clip;
}

/* Comfortable gutters that tighten on small screens */
.container,
.container-fluid {
    padding-left: clamp(1rem, 4vw, 1.5rem);
    padding-right: clamp(1rem, 4vw, 1.5rem);
}

/* Consistent vertical spacing for the main content area on every page */
main.container,
main.container-fluid {
    padding-top: 1.5rem;
    padding-bottom: 3rem;
}

/* Themed, slim scrollbars across the app */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--primary-color-rgb), 0.5) transparent;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(var(--primary-color-rgb), 0.45);
    border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: rgba(var(--primary-color-rgb), 0.7);
}

.app-container {
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Animated Background */
.animated-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(-45deg, var(--primary-color), var(--secondary-color), var(--accent-color));
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    opacity: 0.03;
    z-index: -1;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Common Card Styles */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    transition: transform 0.25s ease, box-shadow 0.25s ease, background-color 0.3s ease, border-color 0.3s ease;
    overflow: hidden;
    height: 100%;
}

.card:hover {
    box-shadow: var(--shadow-hover);
    border-color: rgba(var(--primary-color-rgb), 0.25);
}

.card-header {
    background-color: var(--card-header-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1.25rem 1.5rem;
    font-weight: 600;
    vertical-align: middle;
}

/* Consistent card / section titles across every page */
.card-header h1,
.card-header h2,
.card-header h3,
.card-header h4 {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.card-body {
    padding: 1.5rem;
    max-height: 80vh; /* Use viewport height for better responsiveness */
    overflow: auto; /* Add scrollbar when needed */
}

/* Common Button Styles */
.btn {
    border-radius: 8px;
    font-weight: 500;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn:focus-visible {
    box-shadow: var(--ring);
    outline: none;
}

/* Comfortable inputs (>= mobile tap target) */
.form-control,
.form-select {
    min-height: 44px;
    border-radius: 8px;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
}

.btn-outline-primary {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-outline-primary:hover {
    background-color: var(--primary-color);
    color: white;
}

/* Common Text Styles */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-color);
    margin-bottom: 1rem;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--secondary-color);
}

/* Common Chart Styles */
.chart-container {
    position: relative;
    height: 65vh; /* Use viewport height for better responsiveness */
    min-height: 400px; /* Minimum height on all devices */
    max-height: 700px; /* Maximum height on large screens */
    width: 100%;
    margin: 20px 0;
    /* display: flex; */
    /* align-items: center; */
    /* justify-content: center; */
    /* overflow: hidden; */
}

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

/* Common Loading Styles */
.loading-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(var(--primary-color-rgb), 0.15);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
}

/* Bootstrap spinner tinting to match the theme */
.spinner-border {
    color: var(--primary-color) !important;
}

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

/* Common Error Message Styles */
.error-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
    color: var(--negative-color);
}

/* Responsive Styles */
@media (max-width: 1200px) {
    .chart-container {
        height: 60vh;
        min-height: 400px;
        max-height: 650px;
    }
}

@media (max-width: 992px) {
    .chart-container {
        height: 55vh;
        min-height: 350px;
        max-height: 600px;
    }
}

@media (max-width: 768px) {
    .chart-container {
        height: 50vh;
        min-height: 300px;
        max-height: 500px;
    }
}

@media (max-width: 576px) {
    .chart-container {
        height: 45vh;
        min-height: 250px;
        max-height: 400px;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .chart-container {
        height: 70vh;
        min-height: 200px;
    }
}

/* Momentum scrolling for horizontally scrollable tables on touch devices */
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

/* Small-screen refinements */
@media (max-width: 576px) {
    .card-header,
    .card-body {
        padding: 1.15rem;
    }

    h1 {
        font-size: 1.6rem;
    }

    h2 {
        font-size: 1.3rem;
    }

    /* Keep buttons easy to tap */
    .btn {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
}

/* ============================================================
   Unified design-system components (consistent on every page)
   ============================================================ */

/* --- Tables --- */
.table,
.gainers-table,
.volatility-table,
.sentiment-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text-color);
    font-size: 0.925rem;
    margin-bottom: 0;
}

.table thead th,
.gainers-table th,
.volatility-table th,
.sentiment-table th {
    background-color: var(--table-header-bg);
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--table-border);
    white-space: nowrap;
}

.table tbody td,
.gainers-table td,
.volatility-table td,
.sentiment-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--table-border);
    vertical-align: middle;
    color: var(--text-color);
}

.table tbody tr,
.gainers-table tbody tr,
.volatility-table tbody tr,
.sentiment-table tbody tr {
    transition: background-color 0.15s ease;
}

.table tbody tr:hover,
.gainers-table tbody tr:hover,
.volatility-table tbody tr:hover,
.sentiment-table tbody tr:hover {
    background-color: var(--table-hover);
}

.table tbody tr:last-child td,
.gainers-table tbody tr:last-child td,
.volatility-table tbody tr:last-child td,
.sentiment-table tbody tr:last-child td {
    border-bottom: none;
}

/* --- Segmented control: time-range & timeframe buttons --- */
.time-range-buttons,
.timeframe-selector {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    margin: 1.25rem 0;
    flex-wrap: wrap;
}

.time-range-button,
.btn-timeframe {
    padding: 0.5rem 1.1rem;
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.time-range-button:hover,
.btn-timeframe:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background-color: rgba(var(--primary-color-rgb), 0.08);
}

.time-range-button.active,
.btn-timeframe.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--button-text);
    box-shadow: 0 4px 12px rgba(var(--primary-color-rgb), 0.3);
}

/* --- Stat typography (containers styled per page) --- */
.stat-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.35rem;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-color);
    line-height: 1.3;
    word-break: break-word;
}

/* --- Change pill / badge --- */
.price-change {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-pill);
    font-weight: 600;
    font-size: 0.82rem;
    width: fit-content;
}

.price-change.positive {
    color: var(--positive-color);
    background-color: rgba(var(--positive-color-rgb), 0.12);
}

.price-change.negative {
    color: var(--negative-color);
    background-color: rgba(var(--negative-color-rgb), 0.12);
}

/* --- Section sub-headings (e.g. rankings, legends) --- */
.section-title {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 1rem;
}
