/* =======================================================================
   VARIABLES & GLOBAL STYLES
   ======================================================================= */
:root{
    --bg:#f6f8fb; /* Background color of the page */
    --card:#ffffff; /* Background color of the main content cards */
    --muted:#7c7e81; /* Muted text color (secondary information) */
    --accent:#0b72ff; /* Primary interactive color (e.g., Connect button) */
    --success:#10b981; /* Success state color (e.g., Start button) */
    --radius:14px; /* Global border radius */
    --pad:16px; /* Padding standard */
    --maxw:720px; /* Maximum width for the main container */
    --danger:#dc2626; /* Primary color for high-intensity or danger states */
    --text:#0f172a; /* Default text color */
    --border:#e6eefc; /* Default border color */
    --shadow:0 6px 18px rgba(15,23,42,0.06);
}

/* Modern Dark Mode Palette */
body.dark-mode {
    --bg:#020617; /* Deep slate background */
    --card:#0f172a; /* Lighter slate card */
    --muted:#94a3b8; /* Slate 400 */
    --accent:#38bdf8; /* Bright sky blue */
    --text:#f8fafc; /* Near white text */
    --border:#1e293b; /* Darker borders */
    --shadow:0 10px 25px rgba(0,0,0,0.3);
    --radius:20px; /* More rounded, modern look in dark mode */
}

/* Base reset and typography */
html, body{
    height:100%;
    margin:0;
    overflow:hidden; /* Prevents the browser-level pull-to-refresh gesture */
    background:var(--bg);
    font-family: 'Inter', Segoe UI, system-ui, sans-serif;
    color:var(--text); 
    font-size:16px;
    transition: background-color 0.3s ease, color 0.3s ease;
    overscroll-behavior: none;
}

/* =======================================================================
   LAYOUT COMPONENTS
   ======================================================================= */

/* Main overall wrapper container - Now handles scrolling internally */
.wrap{
    height: 100dvh; /* Uses dynamic viewport height for mobile browsers */
    overflow-y: auto; /* Allows content to scroll without triggering refresh */
    -webkit-overflow-scrolling: touch; /* Ensures smooth momentum scrolling on iOS */
    max-width:var(--maxw);
    margin:0 auto;
    padding:24px 12px;
    box-sizing: border-box;
}

/* Header layout for title and button */
header{
    display:flex;
    align-items:center;
    gap:12px
}

/* Content grid layout (responsive) */
.grid{
    display:grid;
    grid-template-columns:1fr;
    gap:12px;
    margin-top:16px
}

/* Media query for tablet/desktop view */
@media(min-width:720px){
    .grid{
        grid-template-columns:320px 1fr
    }
}

/* Layout for quartile averages */
.quartile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    border-left: 1px solid var(--border);
    padding-left: 6px;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

/* Standard card styling */
.card{
    background:var(--card);
    border-radius:var(--radius);
    padding:var(--pad);
    border: 1px solid var(--border);
    box-shadow:var(--shadow);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease, border-radius 0.3s ease;
}

/* Container for status elements (e.g., BPM/MaxHR row) */
.stat-group {
    display:flex;
    align-items:flex-start;
    gap:6px;
}

/* Specific container for displaying multiple status values side-by-side */
/* Align elapsed time to the right side */
.stat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.metric-pair {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.metric-pair:last-child {
    align-items: flex-end;
}

/* Align activity log button to the right */
.control-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.control-bar > div:last-child {
    margin-left: auto;
}

/* Container for the activity log section */
/* Ensure the activity log section doesn't have extra spacing */
.activity-log-section {
    margin-top: 10px;
    margin-bottom: 0;
}

/* Remove any extra padding/margin from the activity log card */
.card .control-bar {
    margin-bottom: 12px;
}



/* =======================================================================
   TYPOGRAPHY & SPECIFIC ELEMENTS
   ======================================================================= */

h1{
    font-size:20px;
    margin:0;
    font-weight:700
}

.subtitle{
    color:var(--muted);
    font-size:13px;
    font-weight:800
}

/* Large, impactful display number (BPM) */
.big{
    font-size:36px;
    font-weight:800;
    color:var(--danger); /* High visibility for core metric */
    line-height:1;
    font-variant-numeric: tabular-nums;
    min-width: 80px; /* Prevents layout shifting when switching to triple digits */
}

/* Reusable class for secondary metric values */
.metric-value {
    font-size: 22px;
    font-weight: 800;
    line-height: 1;
}

.metric-value.danger {
    color: var(--danger);
}

/* Labels used for descriptive text (e.g., "Status", "Heart Rate") */
.label{
    color:var(--muted);
    font-size:13px;
    font-weight:800;
    line-height:1
}

/* Muted color class for text */
.muted{
    color:var(--muted)
}

/* Styling for the elapsed time display */
.elapsed-display{
    font-size:28px;
    font-weight:700;
    color:var(--text);
    letter-spacing: -0.5px;
    /* Ensures numbers align vertically */
    font-variant-numeric: tabular-nums; 
}

/* =======================================================================
   FORMS & CONTROLS
   ======================================================================= */

/* General button styling: optimizations for touch devices */
button{
    font-family: inherit;
    font-size: 14px;
    /* Mobile touch optimizations: larger targets, remove highlight and tap delay */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    min-height: 48px;
    padding: 14px 16px;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 1px 0 rgba(0,0,0,0.02);
    /* Ensures buttons scale correctly within flex containers */
    flex-shrink: 0; 
}

/* Primary button (accent color) */
button.primary{
    background:var(--accent);
    color:#fff;
    border:none;
    font-weight:700
}

/* Ghost/secondary button (outline style) */
button.ghost{
    background:transparent;
    border:1px solid var(--border);
    color:var(--accent)
}

/* Success state button (green) */
button.success{
    background:var(--success);
    color:#fff;
    border:none;
    font-weight:700
}

/* Danger state button (red) */
button.danger{
    background:var(--danger);
    color:#fff;
    border:none;
    font-weight:700
}

/* Disabled state styling */
button:disabled{
    opacity:0.4;
    cursor:not-allowed
}

/* Log scrolling area */
#log{
    max-height:120px;
    overflow:auto;
    font-family:monospace;
    background:var(--bg);
    padding:8px;
    border-radius:8px;
    border:1px solid var(--border)
}

/* Refined scrollbar for the log area */
#log::-webkit-scrollbar {
    width: 6px;
}

#log::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

/* Control panel layout (Start, Stop, Reset) */
.controls {
    display: flex;
    gap: 10px;
    padding: 0;
    margin-bottom: 16px;
    background: none;
    box-shadow: none;
    border-radius: 0;
}

.controls > button { 
    flex: 1; 
    min-width: 0; 
}
