/* ==========================================================================
   0. Variables & Theme
   ========================================================================== */
:root {
    /* Colors */
    --primary-color: #2c3e50;
    --accent-color: #3498db;
    --bg-color: #f5f6fa;
    --panel-bg: #ffffff;
    
    /* Borders & Separators */
    --border-color: #dcdde1;
    --border-light: #eeeeee;

    /* Text */
    --text-main: #333333;
    --text-light: #666666;

    /* Dimensions */
    --header-height: 80px;
    --cell-padding: 8px;
    --cell-min-width: 100px;
}

/* ==========================================================================
   1. Reset & Global Styles
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden; /* Prevent global scroll */
}

button, input, select, textarea, .leaflet-container {
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ==========================================================================
   2. Layout Structure (Flexbox)
   ========================================================================== */
.container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* Header */
header {
    flex-shrink: 0;
    height: var(--header-height);
    padding: 0 20px;
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    z-index: 100;
}

h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Main Content Area */
main {
    flex: 1;
    display: flex;
    overflow: hidden; /* Contain children */
    padding: 10px;
    gap: 10px; /* Space between panels */
}

.data-panel {
    flex: 3; /* 60% Layout */
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.map-panel {
    flex: 2; /* 40% Layout */
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-color);
}

#map {
    width: 100%;
    height: 100%;
}

/* Map time display - bottom left corner */
.map-time-display {
    position: absolute;
    bottom: 10px;
    left: 10px;
    z-index: 400;
    background-color: rgba(255, 255, 255, 0.95);
    padding: 12px 16px;
    border-radius: 4px;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    white-space: pre-line;
    line-height: 1.6;
}

/* ==========================================================================
   3. Controls & Inputs
   ========================================================================== */
.controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

select {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.95rem;
    color: var(--text-main);
    background-color: white;
    cursor: pointer;
}

select:focus {
    outline: 2px solid var(--accent-color);
    border-color: var(--accent-color);
}

input[type="checkbox"] {
    accent-color: var(--accent-color);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

label {
    font-size: 0.95rem;
    cursor: pointer;
    user-select: none;
}

/* ==========================================================================
   4. Table Styles (Responsive Full Screen)
   ========================================================================== */
.table-container {
    flex: 1;
    width: 100%;
    overflow: hidden; /* Disable scrolling */
    min-height: 0;
    display: flex;
    flex-direction: column;
}

table {
    width: 100%;
    height: 100%; /* Fill container */
    border-collapse: separate; 
    border-spacing: 0;
    table-layout: fixed; /* Equal/Fixed layout for auto-sizing */
}

th, td {
    padding: 0;
    border: 1px solid #ffffff;
    text-align: center;
    vertical-align: middle;
    /* Auto font size based on viewport */
    font-size: min(1.2vw, 2.0vh);
    overflow: hidden; /* Hide overflow content if any */
    white-space: nowrap;
}

/* Headers */
th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: var(--primary-color);
    cursor: pointer;
    transition: background-color 0.2s;
    height: auto; /* Remove fixed height */
    font-size: min(1.8vw, 3vh);
}

/* Date header styling */
th.date-header {
    background-color: #e3f2fd;
    font-size: min(1.8vw, 3vh);
    height: 6vh;
    cursor: default;
}

/* Time header styling (Row 2) */
thead tr:nth-child(2) th {
    font-size: min(1.5vw, 2.5vh); /* Base font size */
    height: 8vh;
    vertical-align: middle;
}

.time-start {
    font-size: 1.8em; /* Much larger start time */
    font-weight: 800;
    line-height: 1;
}

.time-end {
    font-size: 1.0em; /* Normal size end time */
    font-weight: 600;
    vertical-align: 0.2em; /* Superscript-like lift */
    margin-left: 2px;
    opacity: 0.9;
}

th:hover {
    background-color: #e9ecef;
}

th.date-header:hover {
    background-color: #e3f2fd;
}

th.active-time {
    background-color: var(--primary-color);
    color: white;
    border-bottom: 3px solid var(--accent-color);
}

/* Location Header (Top Left corner) */
th.location-col {
    background-color: var(--panel-bg);
    border-right: 2px solid var(--border-color);
    height: auto;
}

/* The first cell in body rows (Location names) */
td:first-child {
    background-color: var(--panel-bg);
    font-weight: 600;
    font-size: min(1.4vw, 2.5vh);
    color: var(--primary-color);
    border-right: 2px solid var(--border-color);
}

/* Data Cells */
td:not(:first-child) {
    font-size: min(2.8vw, 5.0vh); /* Maximize value font size */
    font-weight: 500;
    line-height: 0.9;
    letter-spacing: -0.02em;
}

.cell-value {
    color: var(--text-main);
}

/* Day Boundary Marker */
th.day-start, td.day-start {
    border-left: 3px solid var(--primary-color) !important;
}

/* ==========================================================================
   5. Leaflet Map Overrides
   ========================================================================== */
.leaflet-tooltip.map-label {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    font-size: 2rem !important;
    font-weight: 700 !important;
    color: #000 !important;
    padding: 0 !important;
    margin: 0 !important;
    white-space: nowrap !important;
    /* Text stroke effect for better visibility */
    text-shadow: 
        -2px -2px 2px #fff,  
         2px -2px 2px #fff,
        -2px  2px 2px #fff,
         2px  2px 2px #fff !important;
}

.leaflet-tooltip.map-label div {
    font-size: 1.5rem !important;
    line-height: 1.4 !important;
}

.leaflet-tooltip.map-label b {
    font-size: 1.5rem !important;
}

/* ==========================================================================
   6. Responsive Design
   ========================================================================== */
@media (max-width: 768px) {
    main {
        flex-direction: column-reverse; /* Map on top on mobile usually better, or bottom? Keeping original structure */
    }
    
    .data-panel, .map-panel {
        flex: 1;
        width: 100%;
        min-height: 40vh; /* Ensure visibility */
    }

    header {
        flex-direction: column;
        height: auto;
        padding: 10px;
        gap: 10px;
    }

    .controls {
        flex-wrap: wrap;
        justify-content: center;
    }
}
