/* =========================================
   CONTROLS & FILTERS
   ========================================= */
.controls-row { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 20px; 
    align-items: center; 
    margin-bottom: 20px; 
    border-bottom: 1px solid var(--border-color); 
    padding-bottom: 20px; 
}

.v-sep { width: 1px; height: 28px; background: var(--border-color); }

/* --- BUTTON STYLES --- */

/* 1. AD/BS Switcher (Joined Buttons) */
.cal-switcher button { 
    background: var(--bg-card); 
    color: var(--text-main); 
    border: 1px solid var(--border-color); 
    padding: 10px 16px; 
    cursor: pointer; 
    font-size: 14px; 
    transition: 0.2s; 
    font-weight: 500; 
}
.cal-switcher button:first-child { border-radius: 6px 0 0 6px; border-right: none; }
.cal-switcher button:last-child { border-radius: 0 6px 6px 0; }
.cal-switcher button:hover { background: var(--hover-bg); }
.cal-switcher button.active { background: var(--text-main); color: var(--bg-card); border-color: var(--text-main); }

/* 2. Chart Range Switcher (1M, 1Y, ALL) */
.switcher button { 
    background: var(--bg-card); 
    color: var(--text-main); 
    border: 1px solid var(--border-color); 
    padding: 10px 16px; 
    border-radius: 6px; 
    cursor: pointer; 
    font-size: 14px; 
    transition: 0.2s; 
    font-weight: 500; 
}
.switcher button:hover { background: var(--hover-bg); }
.switcher button.active { background: var(--text-main); color: var(--bg-card); border-color: var(--text-main); }

/* 3. Heatmap Tab Buttons (Daily, Weekly) - THIS WAS MISSING */
.tab-btn { 
    background: var(--bg-card); 
    color: var(--text-main); 
    border: 1px solid var(--border-color); 
    padding: 8px 14px; 
    border-radius: 6px; 
    cursor: pointer; 
    font-size: 13px; 
    transition: 0.2s; 
    font-weight: 500; 
    font-family: inherit; /* Fixes font differences */
}
.tab-btn:hover { background: var(--hover-bg); }
.tab-btn.active { background: var(--text-main); color: var(--bg-card); border-color: var(--text-main); }

/* --- INPUTS & TOGGLES --- */
.toggles { display: flex; gap: 15px; font-size: 14px; }
.toggle-label { display: flex; align-items: center; cursor: pointer; white-space: nowrap; color: var(--text-main); font-weight: 500; padding: 5px 0; }

select { 
    background: var(--bg-card); 
    color: var(--text-main); 
    border: 1px solid var(--border-color); 
    padding: 10px 16px; 
    border-radius: 6px; 
    cursor: pointer; 
    font-size: 13px; 
    transition: 0.2s; 
    font-weight: 500; 
}
select:hover { background: var(--hover-bg); }

#btn-view-table { 
    margin-left: auto; 
    border: 1px solid var(--primary-color); 
    color: var(--primary-color); 
    background: transparent; 
    font-weight: 600; 
    padding: 10px 16px;
    border-radius: 6px;
    cursor: pointer;
}
#btn-view-table:hover { background: var(--primary-color); color: #fff; }

/* =========================================
   CHART COMPONENTS
   ========================================= */
#chart-container { width: 100%; height: 500px; position: relative; z-index: 1; touch-action: pan-x; }

.legend { 
    position: absolute; left: 12px; top: 12px; z-index: 10; 
    background: rgba(30, 30, 30, 0.95); color: #fff; 
    border: 1px solid #444; padding: 12px; border-radius: 6px; 
    font-size: 14px; pointer-events: none; display: none; 
    min-width: 160px; box-shadow: 0 4px 6px rgba(0,0,0,0.3); 
}
[data-theme="light"] .legend { 
    background: rgba(255, 255, 255, 0.95); color: #000; 
    border-color: #ddd; box-shadow: 0 4px 6px rgba(0,0,0,0.1); 
}
.legend-item { display: flex; align-items: center; margin-bottom: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 10px; }

.ratio-badge { 
    background: var(--hover-bg); 
    border: 1px solid var(--border-color); 
    border-left: 5px solid var(--ratio-color); 
    padding: 10px 25px; 
    border-radius: 8px; 
    display: flex; 
    flex-direction: column; 
    align-items: flex-end; 
    min-width: 160px; 
    min-height: 85px; 
}
.ratio-badge .rb-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; font-weight: 700; letter-spacing: 0.5px; }
.ratio-badge .rb-value { font-size: 28px; font-weight: 700; color: var(--text-main); margin: 5px 0; }
.ratio-badge .rb-sub { font-size: 12px; color: var(--text-muted); }

/* =========================================
   HEATMAP
   ========================================= */
.heatmap-container { overflow-x: auto; margin-top: 15px; }
table.heatmap { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
table.heatmap th, table.heatmap td { padding: 12px 8px; text-align: center; border-bottom: 1px solid var(--border-color); border-right: 1px solid var(--border-color); color: var(--text-main); }
table.heatmap th { background: var(--hover-bg); position: sticky; top: 0; z-index: 10; font-weight: 600; color: var(--text-muted); }
table.heatmap td:first-child, table.heatmap th:first-child { position: sticky; left: 0; background: var(--bg-card); z-index: 5; border-right: 2px solid var(--border-color); font-weight: bold; text-align: left; padding-left: 15px; }

table.heatmap td.cell-up { background-color: var(--hm-up-bg) !important; color: var(--hm-up-txt) !important; font-weight: 600; }
table.heatmap td.cell-down { background-color: var(--hm-down-bg) !important; color: var(--hm-down-txt) !important; font-weight: 600; }
table.heatmap td.cell-flat { background-color: transparent; color: var(--text-muted); }

.stat-row td { font-weight: bold; background: var(--hover-bg); border-top: 2px solid var(--border-color); }
.stat-row td:first-child { text-align: right; padding-right: 15px; }

/* =========================================
   MODAL
   ========================================= */
.modal-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(0,0,0,0.7); z-index: 1000; 
    display: none; align-items: center; justify-content: center; 
    backdrop-filter: blur(2px); 
}
.modal-overlay.open { display: flex; }
.modal-content { 
    background: var(--bg-card); width: 90%; max-width: 900px; height: 85%; 
    border-radius: 12px; display: flex; flex-direction: column; 
    color: var(--text-main); border: 1px solid var(--border-color); 
    box-shadow: 0 10px 40px rgba(0,0,0,0.5); 
}
.modal-header { padding: 20px 25px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-body { flex: 1; overflow-y: auto; padding: 0; }
.modal-footer { padding: 15px 25px; border-top: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: var(--hover-bg); border-radius: 0 0 12px 12px; }

.modal-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.modal-table th { position: sticky; top: 0; background: var(--bg-card); padding: 15px; border-bottom: 2px solid var(--border-color); text-align: right; font-weight: 600; color: var(--text-muted); }
.modal-table td { padding: 12px 15px; border-bottom: 1px solid var(--border-color); text-align: right; }

/* =========================================
   TEXT CONTENT
   ========================================= */
.chart-description { line-height: 1.8; font-size: 1.05rem; }
.chart-description h2 { margin-top: 0; font-size: 1.8rem; border-bottom: 1px solid var(--border-color); padding-bottom: 15px; margin-bottom: 20px; }
.chart-description p { margin-bottom: 20px; color: var(--text-main); }
.seo-details { margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--border-color); }
.seo-details h3 { margin-bottom: 15px; font-size: 1.4rem; color: var(--text-main); }
.seo-details li { margin-bottom: 10px; color: var(--text-main); }

@media (max-width: 768px) {
    .ratio-badge { align-items: flex-start; width: 100%; border-left: 5px solid var(--ratio-color); }
    .controls-row { gap: 15px; }
    #chart-container { height: 400px; }
}


/* =========================================
   TEXT CONTENT
   ========================================= */
.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}
.pagination-controls { display: flex; align-items: center; gap: 15px; }
.p-btn {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: 0.2s;
}
.p-btn:hover { border-color: var(--primary-color); color: var(--primary-color); }
.page-jump input {
    width: 50px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    padding: 5px;
    text-align: center;
    border-radius: 4px;
    font-weight: bold;
}

/* Summary Blocks Grid */
.summary-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 20px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
}

.stat-delta {
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* METICULOUS: Table Mobile Overflow & Scroll Fix */

/* 1. The Wrapper: Force horizontal containment */
#section-data-table .table-responsive {
    width: 100%;
    overflow-x: auto; /* Enable horizontal scrolling */
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling for iOS */
    border-radius: 8px;
    position: relative;
    /* Optional: Subtle border to define the scroll area */
    border: 1px solid var(--border-color);
}

/* 2. The Table: Ensure it maintains a readable width */
#data-table {
    width: 100%;
    min-width: 700px; /* Forces the scroll on mobile, prevents squishing */
    border-collapse: collapse;
    table-layout: auto;
}

/* 3. Header & Controls: Stack for mobile screens */
@media (max-width: 768px) {
    #section-data-table .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    #section-data-table .controls-group {
        width: 100%;
        display: flex;
        flex-wrap: wrap; /* Allows date inputs to wrap on very small screens */
        gap: 10px;
    }

    /* Make date inputs more touch-friendly on mobile */
    .date-input {
        flex: 1 1 140px; /* Grow to fill space but don't get too small */
        font-size: 14px;
        padding: 8px;
    }

    /* Make filter/reset buttons consistent */
    #btn-filter, #btn-reset {
        flex: 1 1 auto;
        padding: 10px;
    }
}


.table-responsive {
    background:
        linear-gradient(to right, var(--bg-card) 30%, rgba(255, 255, 255, 0)),
        linear-gradient(to right, rgba(255, 255, 255, 0), var(--bg-card) 70%) 0 100%,
        radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.2), rgba(0,0,0,0)),
        radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.2), rgba(0,0,0,0)) 0 100%;
    background-repeat: no-repeat;
    background-color: var(--bg-card);
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
}