/* Dark theme styling */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #1a1a1a;
    color: #e0e0e0;
    padding: 12px;
    height: 100vh;
    /* Prevent scrolling on body - only container scrolls */
    overflow: hidden;
}

.container {
    max-width: 100%;
    /* Enable scrolling ONLY on container, not body */
    overflow-x: auto;
    overflow-y: auto;
    /* Fixed height */
    height: calc(100vh - 80px);
    position: relative;
    /* Smooth scrolling on mobile */
    -webkit-overflow-scrolling: touch;
    /* Visual indicator for scrolling */
    scrollbar-width: thin;
    scrollbar-color: #39ff14 #1a1a1a;
    /* Ensure content isn't cut off at bottom */
    padding-bottom: 20px;
}

/* Custom scrollbar for webkit browsers (Chrome, Safari) */
.container::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.container::-webkit-scrollbar-track {
    background: #1a1a1a;
    border-radius: 4px;
}

.container::-webkit-scrollbar-thumb {
    background: #39ff14;
    border-radius: 4px;
}

.container::-webkit-scrollbar-thumb:hover {
    background: #2ecc00;
}

.header-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 12px;
    gap: 12px;
    position: relative;  /* For absolute positioning of DL controls */
}

h1 {
    color: #ffffff;
    margin: 0;
    font-size: 1.4rem;
}

.month-navigation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.month-display {
    color: #ffffff;
    font-size: 1rem;
    font-weight: 500;
    min-width: 120px;
    text-align: center;
}

/* Sync Status Indicator */
.sync-status {
    font-size: 0.75rem;
    color: #888;
    display: flex;
    align-items: center;
    gap: 5px;
}

.sync-status .sync-syncing {
    display: none;
    color: #39ff14;
    animation: pulse 1.5s ease-in-out infinite;
}

.sync-status .sync-saved {
    display: none;
    color: #39ff14;
}

.sync-status .sync-error {
    display: none;
    color: #ff4444;
}

.sync-status.syncing .sync-syncing {
    display: inline;
}

.sync-status.saved .sync-saved {
    display: inline;
}

.sync-status.error .sync-error {
    display: inline;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.nav-btn {
    padding: 3px 6px;
    background-color: #39ff14;
    color: #000000;
    border: none;
    border-radius: 3px;
    font-size: 0.75rem;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
    min-width: 24px;
}

.nav-btn:hover {
    background-color: #2ecc00;
}

.nav-btn:active {
    background-color: #22a000;
}

table {
    width: 100%;
    border-collapse: separate; /* Changed from collapse to separate for better sticky support */
    border-spacing: 0; /* Remove spacing between cells */
    background-color: #2a2a2a;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    font-size: 0.8rem;
    table-layout: fixed;
    /* Ensure table maintains minimum width for all columns */
    /* Updated for additional health columns */
    min-width: 1000px;
    /* Note: border-radius removed to ensure sticky positioning works correctly */
}

thead {
    background-color: #1a1a1a;
    position: sticky;
    top: 0;
    z-index: 100;
}

th {
    padding: 2px 1px;
    text-align: center;
    font-weight: 600;
    color: #ffffff;
    border-bottom: 2px solid #444;
    white-space: normal;
    word-wrap: break-word;
    line-height: 1.0;
    font-size: 0.6rem;
    position: sticky;
    top: 0;
    background-color: #1a1a1a;
    z-index: 100; /* Increased from 10 to stay visible when scrolling */
    user-select: none;
}

/* Freeze the Date column (first column) - stays visible when scrolling horizontally */
th.col-date {
    position: sticky;
    left: 0;
    top: 0; /* Also sticky at top */
    z-index: 110; /* Highest z-index - above header (100) and date cells (5) */
    background-color: #1a1a1a;
    /* Add shadow to indicate frozen column */
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
    border-right: 2px solid #39ff14;
}

.resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    cursor: col-resize;
    background-color: transparent;
    z-index: 110; /* Above sticky header */
}

.resize-handle:hover {
    background-color: #39ff14;
    opacity: 0.5;
}

td {
    padding: 1px 1px;
    border-bottom: 1px solid #333;
    position: relative;
    font-size: 0.65rem;
    word-wrap: break-word;
    text-align: center;
}

/* Column width constraints - Very compact by default, only meal columns are extended */
th.col-date,
td.col-date {
    max-width: 45px; /* Very compact for date column */
    min-width: 45px;
    text-align: center;
}

/* Freeze the Date column cells in tbody - stays visible when scrolling horizontally */
td.col-date {
    position: sticky;
    left: 0;
    z-index: 5; /* Above regular cells but below header */
    background-color: #2a2a2a; /* Opaque background - matches default row color */
    /* Add shadow to match header */
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.2);
    border-right: 2px solid #39ff14;
}

/* Today's row date cell - ensure it matches the row highlight with OPAQUE background */
tbody tr.today-row td.col-date {
    background-color: #1a3a1a !important; /* Opaque dark green - no transparency */
    border-left: 3px solid #39ff14;
}

/* Ensure alternating row colors work with sticky date column */
tbody tr:nth-child(even) td.col-date {
    background-color: #252525;
}

/* Today's row overrides alternating colors */
tbody tr.today-row:nth-child(even) td.col-date {
    background-color: #1a3a1a !important; /* Opaque dark green - no transparency */
}

tbody tr:hover td.col-date {
    background-color: #333;
}

/* Today's row hover state */
tbody tr.today-row:hover td.col-date {
    background-color: #1f451f !important; /* Opaque lighter green on hover - no transparency */
}

th.col-compact-checkbox,
td.col-compact-checkbox {
    max-width: 16px; /* Super compact for checkboxes */
    min-width: 16px;
    text-align: center;
}

th.col-compact-number,
td.col-compact-number {
    max-width: 20px; /* Super compact for numbers */
    min-width: 20px;
    text-align: center;
}

th.col-compact-time,
td.col-compact-time {
    max-width: 32px; /* Super compact for time */
    min-width: 32px;
    text-align: center;
}

th.col-workout,
td.col-workout {
    max-width: 32px; /* Super compact for workout */
    min-width: 32px;
    text-align: center;
}

th.col-meal,
td.col-meal {
    max-width: 180px; /* Extended for meal columns - Breakfast, Lunch, Dinner, Snacks */
    min-width: 180px;
    text-align: center;
}

th.col-health,
td.col-health {
    max-width: 30px; /* Super compact for health column */
    min-width: 30px;
    text-align: center;
}

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

/* Today's row highlight - light neon green */
tbody tr.today-row {
    background-color: rgba(57, 255, 20, 0.15) !important; /* Light neon green with transparency */
    border-left: 3px solid #39ff14;
}

tbody tr.today-row td {
    background-color: transparent;
}

tbody tr.today-row:hover {
    background-color: rgba(57, 255, 20, 0.25) !important; /* Slightly brighter on hover */
}

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

tbody tr:last-child td {
    border-bottom: none;
}

/* Editable cell styling */
.editable {
    cursor: pointer;
    position: relative;
}

.editable:hover {
    background-color: #3a3a3a;
}

/* Rest day overlay - light blue background for specific metrics */
.rest-day-cell {
    background-color: rgba(135, 206, 250, 0.25) !important; /* Light blue with transparency */
}

.rest-day-cell:hover {
    background-color: rgba(135, 206, 250, 0.35) !important; /* Slightly brighter on hover */
}

/* Traveling overlay - light red background for specific metrics */
.traveling-cell {
    background-color: rgba(255, 99, 71, 0.25) !important; /* Light red with transparency */
}

.traveling-cell:hover {
    background-color: rgba(255, 99, 71, 0.35) !important; /* Slightly brighter on hover */
}

/* Healthy Eating color overlays - color-coded based on eating quality */
.health-high {
    background-color: rgba(144, 238, 144, 0.3) !important; /* Light green for high */
}

.health-high:hover {
    background-color: rgba(144, 238, 144, 0.4) !important; /* Brighter green on hover */
}

.health-medium {
    background-color: rgba(255, 255, 153, 0.3) !important; /* Light yellow for medium */
}

.health-medium:hover {
    background-color: rgba(255, 255, 153, 0.4) !important; /* Brighter yellow on hover */
}

.health-low {
    background-color: rgba(255, 99, 71, 0.3) !important; /* Light red for low */
}

.health-low:hover {
    background-color: rgba(255, 99, 71, 0.4) !important; /* Brighter red on hover */
}

.editable input,
.editable select {
    width: 100%;
    padding: 1px 2px;
    background-color: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #39ff14;
    border-radius: 2px;
    font-size: 0.65rem;
    font-family: inherit;
    text-align: center;
}

.editable input:focus,
.editable select:focus {
    outline: none;
    background-color: #333;
}

/* Checkbox styling */
.checkbox-cell {
    text-align: center;
}

.checkbox-cell input[type="checkbox"] {
    width: 12px;
    height: 12px;
    cursor: pointer;
    accent-color: #39ff14;
}

/* Date cell styling */
.date-cell {
    font-weight: 500;
    color: #39ff14;
    white-space: nowrap;
    font-size: 0.65rem;
    text-align: center;
    /* Sticky positioning is handled by td.col-date selector */
}


/* Number input styling */
input[type="number"] {
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Time input styling (MM:SS format for mile run) */
.editable input[placeholder="MM:SS"] {
    font-family: monospace;
    text-align: center;
    letter-spacing: 0.5px;
}

/* ============================================================================
   Authentication & Security Styles
   ============================================================================ */

/* Access Denied Screen */
.access-denied {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: #1a1a1a;
    color: #e0e0e0;
    padding: 20px;
    text-align: center;
}

.access-denied h1 {
    color: #ff4444;
    font-size: 2rem;
    margin-bottom: 20px;
}

.access-denied p {
    font-size: 1.1rem;
    margin-bottom: 30px;
    max-width: 600px;
    line-height: 1.6;
}

.retry-btn {
    padding: 12px 24px;
    background-color: #39ff14;
    color: #000000;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.retry-btn:hover {
    background-color: #2ecc00;
}

.retry-btn:active {
    background-color: #22a000;
}

/* Session Timeout Warning */
.session-warning {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: #ff8800;
    color: #000000;
    padding: 15px 20px;
    border-radius: 6px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    max-width: 300px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.session-warning-content {
    font-size: 0.9rem;
    line-height: 1.4;
}

.session-warning-content p {
    margin: 5px 0;
}

.session-warning-content p:first-child {
    font-weight: 600;
}

/* Responsive design - Tablet */
@media (max-width: 1200px) {
    th, td {
        font-size: 0.7rem;
        padding: 3px 3px;
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    body {
        padding: 8px;
    }
    
    .container {
        /* More space for table on mobile */
        max-height: calc(100vh - 100px);
        height: calc(100vh - 80px);
        /* Better touch scrolling with hardware acceleration */
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        transform: translateZ(0);
        will-change: scroll-position;
        contain: layout style paint;
    }
    
    h1 {
        font-size: 1.2rem;
        margin-bottom: 4px;
    }
    
    .header-controls {
        margin-bottom: 8px;
        gap: 8px;
    }
    
    .month-navigation {
        gap: 12px;
    }
    
    .month-display {
        font-size: 0.9rem;
        min-width: 100px;
    }
    
    .nav-btn {
        padding: 6px 10px;
        font-size: 0.85rem;
        min-width: 32px;
        min-height: 32px;
        /* Better touch target */
        touch-action: manipulation;
    }
    
    table {
        /* Larger minimum width to prevent squishing - updated for health columns */
        min-width: 1100px;
        font-size: 0.75rem;
        /* GPU acceleration for smooth scrolling */
        transform: translateZ(0);
        backface-visibility: hidden;
        -webkit-font-smoothing: antialiased;
    }
    
    th {
        padding: 6px 3px;
        font-size: 0.55rem;
        line-height: 1.2;
        /* Better readability */
        white-space: nowrap;
        /* Ensure headers always visible */
        position: sticky;
        top: 0;
        z-index: 500 !important;
        background-color: #1a1a1a;
        will-change: transform;
        transform: translateZ(0);
    }
    
    td {
        padding: 6px 3px;
        font-size: 0.6rem;
    }
    
    /* Increase column widths slightly for better mobile usability */
    th.col-date,
    td.col-date {
        min-width: 70px;
        max-width: 70px;
    }
    
    th.col-compact-checkbox,
    td.col-compact-checkbox {
        min-width: 32px;
        max-width: 32px;
    }
    
    th.col-compact-number,
    td.col-compact-number {
        min-width: 40px;
        max-width: 40px;
    }
    
    th.col-compact-time,
    td.col-compact-time {
        min-width: 50px;
        max-width: 50px;
    }
    
    th.col-workout,
    td.col-workout {
        min-width: 55px;
        max-width: 55px;
    }
    
    th.col-meal,
    td.col-meal {
        min-width: 75px;
        max-width: 75px;
    }
    
    th.col-health,
    td.col-health {
        min-width: 55px;
        max-width: 55px;
    }
    
    /* Larger inputs for easier touch interaction */
    .editable input,
    .editable select {
        padding: 4px 3px;
        font-size: 0.7rem;
        min-height: 28px;
    }
    
    .checkbox-cell input[type="checkbox"] {
        width: 18px;
        height: 18px;
        /* Better touch target */
        cursor: pointer;
    }
    
    .date-cell {
        font-size: 0.7rem;
    }
    
    /* Disable resize handles on mobile */
    .resize-handle {
        display: none;
    }
    
    /* Better scrollbar visibility on mobile */
    .container::-webkit-scrollbar {
        height: 10px;
    }
    
    .container::-webkit-scrollbar-thumb {
        background: #39ff14;
        border-radius: 5px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    body {
        padding: 6px;
    }
    
    h1 {
        font-size: 1rem;
    }
    
    .container {
        max-height: calc(100vh - 90px);
        height: calc(100vh - 90px);
        /* Even more aggressive GPU acceleration */
        transform: translate3d(0, 0, 0);
        -webkit-transform: translate3d(0, 0, 0);
    }
    
    .month-display {
        font-size: 0.85rem;
        min-width: 90px;
    }
    
    .nav-btn {
        padding: 5px 8px;
        font-size: 0.8rem;
        min-width: 28px;
        min-height: 28px;
    }
    
    table {
        /* Updated for health columns */
        min-width: 1150px;
    }
    
    th {
        padding: 5px 2px;
        font-size: 0.5rem;
    }
    
    td {
        padding: 5px 2px;
        font-size: 0.55rem;
    }
    
    .editable input,
    .editable select {
        padding: 3px 2px;
        font-size: 0.65rem;
        min-height: 26px;
    }
    
    /* Larger scrollbar on small devices */
    .container::-webkit-scrollbar {
        height: 12px;
    }
    
    /* Mobile security UI */
    .access-denied {
        padding: 15px;
    }
    
    .access-denied h1 {
        font-size: 1.5rem;
    }
    
    .access-denied p {
        font-size: 1rem;
    }
    
    .session-warning {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
        padding: 12px 15px;
    }
    
    /* Additional scroll optimization for small devices */
    .container {
        /* Even more aggressive GPU acceleration */
        transform: translate3d(0, 0, 0);
        -webkit-transform: translate3d(0, 0, 0);
    }
    
    /* Ensure headers remain strongly visible */
    thead {
        z-index: 500 !important;
    }
    
    th {
        z-index: 500 !important;
    }
    
    th.col-date {
        z-index: 600 !important;
    }
}


/* CSV Import/Export Buttons - Top Right of Header */
.csv-buttons {
    /* Fixed positioning at bottom left for easy access */
    position: fixed;
    bottom: 20px;
    left: 20px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    color: #888;
    z-index: 1000;
    background: rgba(26, 26, 26, 0.95);
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #333;
}

.csv-controls {
    /* Fixed positioning at bottom left for easy access */
    position: fixed;
    bottom: 20px;
    left: 20px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    color: #888;
    z-index: 1000;
    background: rgba(26, 26, 26, 0.95);
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #333;
}

.csv-label {
    color: #888;
    font-size: 0.85rem;
}

.csv-separator {
    color: #666;
    font-size: 0.85rem;
}

.csv-btn {
    background: transparent;
    border: 1px solid #444;
    color: #39ff14;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 1.1rem;
    transition: all 0.2s;
    line-height: 1;
}

.csv-btn:hover {
    border-color: #39ff14;
    background: rgba(57, 255, 20, 0.1);
    transform: translateY(-1px);
}

.csv-btn:active {
    transform: translateY(0);
}

/* Responsive adjustments for mobile */
@media (max-width: 768px) {
    /* Hide CSV buttons on mobile - better UX, use desktop for exports */
    .csv-buttons,
    .csv-controls {
        display: none !important;
    }
    
    /* Optimize scrolling performance on mobile */
    .container {
        /* Hardware acceleration for smooth scrolling */
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        /* GPU acceleration */
        transform: translateZ(0);
        will-change: scroll-position;
        /* Reduce repaints for smoother experience */
        contain: layout style paint;
        /* Better height calculation without CSV buttons */
        height: calc(100vh - 80px);
    }
    
    /* Force GPU layer for better scroll performance */
    table {
        transform: translateZ(0);
        backface-visibility: hidden;
        /* Smoother rendering during scroll */
        -webkit-font-smoothing: antialiased;
    }
    
    /* Strengthen sticky headers - ALWAYS visible */
    thead {
        position: sticky;
        top: 0;
        z-index: 500 !important; /* Very high - nothing blocks headers */
        background-color: #1a1a1a;
        /* Shadow makes headers stand out during scroll */
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
    }
    
    th {
        position: sticky;
        top: 0;
        z-index: 500 !important;
        background-color: #1a1a1a;
        /* Ensure headers are opaque */
        opacity: 1;
        /* Performance optimization */
        will-change: transform;
        transform: translateZ(0);
    }
    
    /* Date column - visible in both scroll directions */
    th.col-date {
        position: sticky;
        left: 0;
        top: 0;
        z-index: 600 !important; /* Highest priority */
        background-color: #1a1a1a;
        /* Double shadow for both scroll directions */
        box-shadow: 
            2px 0 8px rgba(0, 0, 0, 0.5),    /* Right shadow */
            0 2px 8px rgba(0, 0, 0, 0.6);    /* Bottom shadow */
    }
    
    /* Date cells in body - also sticky */
    td.col-date {
        position: sticky;
        left: 0;
        z-index: 50; /* Below headers but above regular cells */
        background-color: #2a2a2a;
        box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
    }
    
    /* Ensure today's row date cell stays visible */
    tbody tr.today-row td.col-date {
        background-color: #1a3a1a !important;
        z-index: 50;
    }
}

