/* ==========================================================================
   1. GLOBAL RESETS & BASE STYLES
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

ul {
    list-style: none;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f7;
    color: #333;
    /* Desktop padding to accommodate sticky header */
    padding-top: 80px; 
    line-height: 1.5;
}

/* ==========================================================================
   2. HEADER, FOOTER & NAVIGATION
   ========================================================================== */
.header {
    background-color: #1a1a2e;
    position: fixed; /* Fixed at the top */
    top: 0;
    left: 0;
    width: 100%;
    z-index: 2000; /* High z-index to stay above charts and table headers */
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.header__content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 70px;
    max-width: 1325px;
    margin: 0 auto;
    padding: 0 20px;
}

header h1 {
    font-size: 20px;
    font-family: 'Trebuchet MS', sans-serif;
    color: #c0c1d8;
    white-space: nowrap;
}

header h1 span {
    color: #b58f6e;
}

.nav__list {
    display: flex;
    gap: 8px;
}

.date-pill {
    background-color: #60659d;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s ease;
}

.date-pill:hover {
    background-color: #4a4e7d;
}

.date-pill.active {
    background-color: #9698be;
}

footer {
    text-align: center;
    padding: 40px 0;
    color: #888;
    background-color: #eeeeee;
    font-size: 13px;
}

/* ==========================================================================
   3. LAYOUT & GRIDS (Issue 1b, 1f, 1h)
   ========================================================================== */
.container {
    max-width: 1325px;
    margin: 0 auto;
    padding: 20px;
}

section {
    margin-bottom: 30px;
}

.card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.08);
    height: 100%;
}

.card h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: #444;
}

/* Fix for Canvas/chart.js overflows in grid layouts - they tend to blow up grids. */
.two-col > *, .three-col > *, .four-col > *, .five-col > * {
    min-width: 0; 
    overflow: hidden;
}

.two-col {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

.two-col.unequal {
    grid-template-columns: 1fr 2fr;
}

.three-col {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
}

.four-col {
    display: grid;
    grid-template-columns: .75fr 1fr 1fr .55fr;
    /* grid-template-columns: 1.2fr 1.5fr 2fr 1.2fr; */
    gap: 15px;
    align-items: start; /* Prevents one tall card from stretching others */
}

.five-col {
    display: grid;
    grid-template-columns: 0.7fr 1fr 1fr 1fr 1fr;
    gap: 15px;
    align-items: start; /* Prevents one tall card from stretching others */
}

.card-placeholder {
    background: #f9f9f9;
    border: 1px dashed #ddd;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    width: 100%;
    min-height: 150px;
}

    .measureName {
    font-family: "archivo", "Trebuchet MS", Trebuchet, Tahoma, Arial, sans-serif;
    font-size: 36px;
    line-height: 0.80;
    margin-bottom: 6px;
    grid-area: name;
    }

    .measureName small {
        display: block;
        font-size: 14px;
    }

/* Fix: Removed display:flex to allow <br> to work. 
   Added vertical alignment for the High/Low labels. */
.measureHiLo { 
    font-family: "Trebuchet MS", Trebuchet, Tahoma, Arial, sans-serif;
    font-size: 12px;
    grid-area: hilow; 
    text-align: right; 
    line-height: 1.2; /* Tighter line spacing for the Hi/Lo block */
    align-self: start;
}

/* Ensure the average number is large and aligned to the bottom right */
.measureAvg { 
    font-family: "archivo", "Trebuchet MS", Trebuchet, Tahoma, Arial, sans-serif;
    font-size: 35px;
    line-height: 1;
    grid-area: avg; 
    text-align: right;
    align-self: end;
}

    .measureAvg small { 
        font-family: "archivo", "Trebuchet MS", Trebuchet, Tahoma, Arial, sans-serif;
        font-size: 14px;
        grid-area: avg; 
        text-align: right; 
    }

/* ==========================================================================
   CLEAN START AT READINGS IN DAYS BADGES
   ========================================================================== */

/* Container for the 1st column of the 5-col grid */
.measureCardBadges {
    display: flex;
    gap: 10px;           /* Space between badges */
    height: 100%;        /* Fill the .five-col row height */
    width: 100%;
    align-items: stretch;
    /* outline: 2px solid magenta; <- in case I need it again. */
}

.badge-item {
    flex: 1;             /* Force 50/50 split of the parent width */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    padding: 5px;
    color: white;
    min-width: 0;        /* Critical for flex-shrink */
}

/* Gradient backgrounds */
.badge-readings { background: linear-gradient(135deg, #c1cbb5, #808f6e); }
.badge-days { background: linear-gradient(135deg, #c1cbb5, #3a3845); }

.badge-number {
    font-family: "archivo", sans-serif;
    font-size: clamp(1.5rem, 4vw, 2.5rem); /* Responsive scaling font */
    font-weight: 700;
    line-height: 1;
}

.badge-label {
    font-size: clamp(0.6rem, 1.5vw, 0.75rem);
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.9;
    margin-top: 4px;
}


/* ==========================================================================
   4. COMPONENT SPECIFIC STYLES
   ========================================================================== */

/* Now Viewing Card Fix (Issue 1c) */

.measureCard {
    background: #efefef;
    border-radius: 4px;
    padding: 20px;
    /* box-shadow: 0 2px 5px rgba(0,0,0,0.08);*/
    height: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "name  hilow"
        "avg   avg";
    row-gap: 6px;
    position: relative; /* This keeps the warning icon "stuck" to this card */
}

/* The warning badge */
.warning-badge {
    position: absolute;
    top: -10px;    /* Offsets it slightly above the top edge */
    right: -10px;  /* Offsets it slightly past the right edge */
    font-size: 1.2rem;
    display: none; /* Hidden by default */
    z-index: 10;   /* Ensures it stays on top of other elements */
}

/* Ensure the aggregate card doesn't wrap its numbers */
    #periodAggregateSummaryCard table {
        width: 100%;
        white-space: nowrap;
    }

/* Control the Donut size so it doesn't ruin the row height */
#normalDonutChart {
    width: 100% !important;
    max-height: 130px; /* Limits how tall the donut can get */
    object-fit: contain;
}

/* Combined Rolling Controls - DESKTOP (Issue 1a) */
.rolling-controls-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
}

.rolling-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 15px;
    background: #f0f2f5;
    border-radius: 8px;
    border: 1px solid #ddd;
    font-size: 14px;
}

.control-label {
    font-weight: 600;
    margin-right: 5px;
}

/* ✅ DESKTOP: Radio buttons in a horizontal row */
.radio-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 15px;
}

.control-option {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.sys-text { color: #d32f2f; font-weight: 600; }
.dia-text { color: #1976d2; font-weight: 600; }

/* ==========================================================================
   5. DATA TABLE STYLES
   ========================================================================== */
.bp-raw-table-wrapper {
    max-height: 450px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 6px;
}

.bp-raw-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    table-layout: auto;
}

.bp-raw-table th {
    position: sticky;
    top: 0;
    background: #f8f9fa;
    z-index: 10;
    text-align: left;
    padding: 10px;
    border-bottom: 2px solid #dee2e6;
}

.bp-raw-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #eee;
}

.bp-risk { background-color: #fff4f4; color: #d32f2f; font-weight: bold; }

/* ==========================================================================
   RAW DATA TABLE - Bug fixes:
   ========================================================================== */

/* Force table to respect our width constraints */
.bp-raw-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

/* 1. All standard cells: Shrink to fit, No wrapping */
.bp-raw-table th,
.bp-raw-table td {
    white-space: nowrap;
    width: 1%;
    padding: 8px 10px;
    text-align: center;
}

/* 2. Exceptions: Left align labels and dates */
.bp-raw-table .date-cell,
.bp-raw-table .category-cell {
    text-align: left;
}

/* 3. The "Greedy" Column: Comments takes all leftover space */
.bp-raw-table .comments-col {
    width: auto !important;
    white-space: normal !important;
    word-break: break-word;
    text-align: left;
    min-width: 200px; /* Gives it room to be the primary 'text' column */
}

/* Hide specific columns on mobile to keep things readable */
@media (max-width: 600px) {
    .hide-mobile {
        display: none !important;
    }
}


/* ==========================================================================
   6. CONSOLIDATED RESPONSIVE QUERIES
   ========================================================================== */

/* TABLET VIEW (Under 1024px) */
@media (max-width: 1024px) {
    .five-col { grid-template-columns: 1fr 1fr; }
    .four-col { grid-template-columns: 1fr 1fr; }
    .three-col { grid-template-columns: 1fr 1fr; }
}

/* MOBILE VIEW (Under 768px - Targets your TCL phone width) */
@media (max-width: 768px) {
    body {
        padding-top: 140px; /* Extra space for the stacked header */
    }

    .header__content {
        flex-direction: column;
        padding: 15px 0;
        gap: 10px;
    }

    /* Affect the height of the pulse line graph on mobile only without affecting it's .two-col histogram neighbor */
    /* Target: #Pluse section → .two-col → first .card → the div containing canvas */
    :is(#Pluse, #PulsePressure) .card:first-child > div[style*="aspect-ratio"] {
        height: 250px !important;
        aspect-ratio: auto !important;
    }

    /* squish Reading Categories over Time */
    :is(#ReadingCategories) .card:first-child > div[style*="height"] {
        height: 200px !important;
        aspect-ratio: auto !important;
    }

    /* Force all grid layouts to single column for a mobile phone */
    .two-col, .two-col.unequal, .three-col, .four-col, .five-col {
        grid-template-columns: 1fr !important;
    }

    /* Tighten up summary cards for small screens */
    #periodAggregateSummaryCard, #readingCategoriesSummaryCard {
        font-size: 11px !important;
    }

    /* ✅ MOBILE: 7 day rolling SD radio buttons - Stack everything vertically */

    /* 1. Force the heading and the control box to stack vertically */
    .rolling-controls-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
        text-align: center;
    }

    /* 2. Remove any side-margins on the title so it centers perfectly */
    .rolling-controls-container h3 {
        margin: 0 0 5px 0 !important;
        text-align: center;
        width: 100%;
    }

    /* Stack the whole control box vertically */
    .rolling-controls {
        flex-direction: column !important;
        align-items: center !important;
        gap: 8px !important;
        padding: 12px !important;
    }

    /* Center the "Standard Deviation Band:" text */
    .control-label {
        text-align: center;
        width: 100%;
        font-weight: bold;
        font-size: 13px;
        margin-bottom: 4px;
        margin-right: 0; /* Override desktop margin */
    }

    /* Make the buttons sit in a nice centered row underneath the text */
    .radio-group {
        display: flex;
        flex-direction: row;
        justify-content: center;
        gap: 15px; /* Plenty of space between Sys, Dia, No Band */
        width: 100%;
    }

    .control-option {
        font-size: 14px;
        white-space: nowrap;
    }

    .info-drawer {
        width: 100vw; /* Use Viewport Width to be explicit */
        max-width: 100%;
        
    }

    .hide-mobile {
        display: none !important;
    }
}

/* ==========================================================================
   DOCUMENTATION SLIDING DRAWER
   ========================================================================== */

.info-icon{
    cursor: pointer;
}

.info-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 400px;
    background: #ffffff;
    box-shadow: -5px 0 15px rgba(0,0,0,0.15);
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
    box-sizing: border-box;
}

.info-drawer.open {
    transform: translateX(0);
}

.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: none;
    z-index: 1999;
}

.drawer-overlay.open {
    display: block;
}

/* Drawer Header Layout */
.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #eeeeee;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.drawer-header h2 {
    margin: 0;
    font-size: 1.4rem;
    color: #333;
}

/* The "x" Button Styling */
.close-btn {
    background: #f5f5f5;
    border: none;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    color: #888;
    width: 40px;
    height: 40px;
    border-radius: 50%; /* Makes it a circle */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.close-btn:hover {
    background: #e0e0e0;
    color: #333;
}

.close-btn:active {
    background: #d0d0d0;
}

/* Drawer Content Styling */
.drawer-content h3 {
    font-size: 1.1rem;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
    margin-top: 20px;
    color: #333;
}

.drawer-content p {
    font-size: 0.95rem;
    line-height: 1.5;
    color: #555;
}

/* Minimalist List for Drawer */
.doc-list {
    list-style: none;
    padding: 0;
    margin: 15px 0;
}

.doc-list li {
    margin-bottom: 10px;
    line-height: 1.4;
}

/* ==========================================================================
   GENERAL STUFF
   ========================================================================== */

.noscript-warning {
  background: #ffdddd;
  color: #900;
  padding: 15px;
  border: 1px solid #cc0000;
  margin: 20px;
  border-radius: 6px;
  font-weight: bold;
  text-align: center;
}