:root {
    --primary-color: #40B29A;
    --primary-hover: #359681;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --danger-color: #FF7A5A;
    --danger-hover: #E86A4C;
    --success-color: #40B29A;
    --warning-color: #FF7A5A;
    --missed-color: #FF7A5A;
    
    --bg-color: #f8fafc;
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --border-radius-md: 12px;
    --border-radius-lg: 16px;
    --transition-fast: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden; /* Prevent horizontal shake */
    width: 100%;
}

/* Layout */
.dashboard-container {
    display: flex;
    height: 100vh;
    width: 100%;
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.sidebar-header p { 
    font-size: 0.875rem; 
    color: var(--text-secondary); 
    padding-left: 36px; 
}

.sidebar-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 20px;
    text-align: center;
    background-color: rgba(64, 178, 154, 0.03);
    transition: var(--transition-fast);
}

.upload-area:hover { border-color: var(--primary-color); background-color: rgba(64, 178, 154, 0.08); }
.upload-area i { font-size: 1.5rem; color: var(--primary-color); margin-bottom: 8px; display: block; }
.upload-area p { font-size: 0.75rem; margin-bottom: 12px; color: var(--text-secondary); }
.upload-area input { display: none; }

/* Filter Accordion */
.sidebar-filter {
    border-top: 1px solid var(--border-color);
    padding-top: 24px;
}

.sidebar-filter h3 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.filter-accordion details {
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.filter-accordion summary {
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    background-color: #f8fafc;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-accordion summary::-webkit-details-marker { display: none; }

.filter-accordion summary i {
    width: 20px;
    color: var(--primary-color);
}

.filter-badge {
    margin-left: auto;
    font-size: 0.70rem;
    color: var(--primary-color);
    font-weight: 600;
    background-color: rgba(64, 178, 154, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
    transition: var(--transition-fast);
}

/* Filter Accordion Styles */

.filter-accordion .filter-options {
    padding: 0 14px 14px 14px; /* Adjust for bulk actions */
    background-color: white;
    max-height: 250px;
    overflow-y: auto;
}

.filter-bulk-actions {
    position: sticky;
    top: 0;
    background-color: white;
    padding: 10px 0;
    margin-bottom: 4px;
    display: flex;
    gap: 12px;
    border-bottom: 1px solid #f1f5f9;
    z-index: 5;
}

.filter-bulk-actions button {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary-color);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
    opacity: 0.8;
}

.filter-bulk-actions button:hover {
    opacity: 1;
}

.filter-bulk-actions button.active {
    opacity: 1;
    font-weight: 700;
    color: var(--primary-color);
}

.filter-list-disabled {
    opacity: 0.5;
    pointer-events: none;
    user-select: none;
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    padding: 6px 0;
    cursor: pointer;
}

.filter-item.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.filter-item input { accent-color: var(--primary-color); }

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Mobile Nav */
.mobile-nav {
    display: none;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background-color: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.mobile-menu-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--primary-color);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.mobile-menu-btn:hover {
    background-color: rgba(64, 178, 154, 0.05);
}

.mobile-logo {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Sticky Header */
.sticky-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: rgba(248, 250, 252, 0.95);
    backdrop-filter: blur(8px);
    padding: 24px 32px;
    border-bottom: 1px solid var(--border-color);
}

.sticky-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.content-body {
    padding: 32px;
    flex: 1;
}

/* Metrics Cards */
.metric-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius-md);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.metric-card.highlight {
    background: linear-gradient(135deg, #40B29A 0%, #359681 100%);
    color: white;
    border: none;
}
.metric-card.highlight h3 { color: rgba(255, 255, 255, 0.9); }
.metric-card.highlight .metric-value { color: white; }
.metric-card.highlight .metric-icon { background-color: rgba(255, 255, 255, 0.2); color: white; }

.metric-card.metric-neutral {
    background-color: #f1f5f9;
    border: 1px solid #cbd5e1;
}
.metric-card.metric-neutral .metric-icon {
    background-color: #e2e8f0;
    color: #64748b;
}

.metric-card.metric-accent {
    background-color: #fff7ed;
    border: 1px solid #ffedd5;
}
.metric-card.metric-accent .metric-icon {
    background-color: rgba(255, 122, 90, 0.1);
    color: #FF7A5A;
}
.metric-card.metric-accent h3 { color: #c2410c; }
.metric-card.metric-accent .metric-value { color: #ea580c; }

.metric-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background-color: rgba(64, 178, 154, 0.1);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.metric-content h3 { font-size: 0.75rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 2px; }
.metric-value { font-size: 1.5rem; font-weight: 700; }
.metric-card small { font-size: 0.7rem; opacity: 0.8; }

/* Charts Layout */
.chart-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
    min-width: 0;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.chart-card.full-width { grid-column: 1 / -1; }

.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

/* Custom HTML Legend */
.custom-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin-top: 10px;
    font-size: 0.85rem;
    padding-bottom: 5px;
}
.custom-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}
.custom-legend-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

/* Slim Scrollbar Customization */
#trendScrollContainer::-webkit-scrollbar {
    height: 8px;
}
#trendScrollContainer::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}
#trendScrollContainer::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
#trendScrollContainer::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

.chart-container-inner {
    height: 100%;
    min-width: 100%;
}

.chart-container-radar { height: 450px; }
.chart-container-pie { height: 250px; }
.chart-container-small { height: 200px; }

/* Buttons & Utils */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    width: 100%;
    transition: var(--transition-fast);
}

.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); color: white; }
.btn-secondary { background-color: #f1f5f9; color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-secondary:hover:not(:disabled) { background-color: var(--secondary-color); color: white; border-color: var(--secondary-color); }
.btn-danger { background-color: #fef2f2; color: var(--danger-color); border: 1px solid #fee2e2; }
.btn-danger:hover { background-color: var(--danger-color); color: white; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-text { background: none; border: none; color: var(--primary-color); font-size: 0.7rem; cursor: pointer; }

.btn-summary-csv { 
    background-color: #f1f5f9; 
    color: var(--text-secondary); 
    border: 1px solid var(--border-color);
    width: auto;
    padding: 6px 12px;
    font-size: 0.75rem;
}
.btn-summary-csv:hover { 
    background-color: var(--secondary-color); 
    color: white; 
    border-color: var(--secondary-color); 
}

/* Header Utilities */
.flex-header { display: flex; justify-content: space-between; align-items: center; }
.flex-header-left { display: flex; justify-content: flex-start; align-items: center; gap: 20px; }

/* Mode Switcher */
.mode-switcher {
    display: flex;
    background-color: #f1f5f9;
    padding: 4px;
    border-radius: 8px;
    gap: 4px;
}

.btn-mode {
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: none;
    color: var(--text-secondary);
    transition: var(--transition-fast);
}

.btn-mode.active {
    background-color: white;
    color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

/* Table */
.data-table-section { padding: 0 !important; overflow: hidden; }
.flex-header h3 { 
    white-space: nowrap; 
    margin-right: 16px; 
}

.dashboard-footer {
    padding: 32px 0;
    text-align: center;
    border-top: 1px solid var(--border-color);
    margin-top: 24px;
}
.dashboard-footer p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.7;
}
.flex-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 20px 24px; 
    border-bottom: 1px solid var(--border-color); 
}
.table-filters input {
    width: 320px;
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    font-size: 0.85rem;
    transition: var(--transition-fast);
}
.table-filters input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(64, 178, 154, 0.1);
}
.table-container { overflow-x: auto; max-height: 600px; }
table { width: 100%; border-collapse: collapse; }
th { position: sticky; top: 0; background: #f8fafc; z-index: 10; padding: 12px 16px; font-size: 0.75rem; font-weight: 700; text-align: left; color: var(--text-secondary); border-bottom: 1px solid var(--border-color); }
td { padding: 12px 16px; font-size: 0.8rem; border-bottom: 1px solid var(--border-color); }
.status-badge { padding: 2px 8px; border-radius: 4px; font-size: 0.7rem; font-weight: 700; }
.status-completed { background: rgba(64, 178, 154, 0.1); color: var(--primary-color); }
.status-missed { background: rgba(255, 122, 90, 0.1); color: var(--danger-color); }

@media (max-width: 1024px) {
    body {
        overflow: auto; /* Allow body scroll on mobile */
    }

    .dashboard-container {
        display: block;
        height: auto;
    }

    /* Sidebar Mobile */
    .sidebar {
        position: fixed;
        left: -320px; /* Slightly more than width */
        top: 0;
        width: 300px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.active {
        left: 0;
    }

    /* Main Content Mobile */
    .main-content {
        height: auto;
        overflow: visible;
    }

    .mobile-nav {
        display: flex;
        position: fixed; /* stickyから変更 */
        top: 0;
        left: 0;
        width: 100%;
        z-index: 100;
        background-color: var(--sidebar-bg); /* 背景を確実に白に */
    }

    .sticky-header {
        position: fixed; /* stickyから変更 */
        top: 64px; /* mobile-navの高さ付近に固定 */
        left: 0;
        width: 100%;
        padding: 8px 4px;
        z-index: 90;
        background-color: var(--bg-color); /* main backgroundと合わせる */
        border-bottom: 1px solid var(--border-color);
    }

    .sticky-metrics {
        grid-template-columns: repeat(4, 1fr);
        gap: 4px; /* Narrower gap for iPhone */
    }

    .content-body {
        padding: 170px 8px 12px 8px; /* 固定ヘッダーの高さ分（ナヴィ+メトリクス）だけトップを確保 */
    }

    /* Smaller Metrics for Mobile Row */
    .metric-card {
        padding: 6px 2px;
        flex-direction: column;
        gap: 2px;
        text-align: center;
        min-height: 70px;
        justify-content: center;
        overflow: hidden;
    }

    .metric-icon {
        width: 24px;
        height: 24px;
        font-size: 0.7rem;
        border-radius: 4px;
    }

    .metric-content h3 {
        font-size: 0.52rem; /* Extremely small for 4 in a row */
        margin-bottom: 0;
        white-space: nowrap;
        letter-spacing: -0.5px;
    }

    .metric-value {
        font-size: 0.9rem;
    }

    .metric-card small {
        font-size: 0.5rem;
    }

    /* Charts Stacked */
    .charts-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .chart-card {
        padding: 16px;
        margin-bottom: 16px;
    }

    .chart-container-radar {
        height: 350px;
    }

    /* Table adjustments */
    .table-filters input {
        width: 100%;
    }

    .flex-header {
        flex-direction: row; /* 横並びに戻す */
        justify-content: space-between;
        align-items: center;
        gap: 8px;
        padding: 12px 16px;
    }

    .flex-header h3 {
        margin-right: 0;
        font-size: 0.85rem; /* タイトルを少し小さくしてスペース確保 */
    }

    .btn-summary-csv {
        width: auto; /* 全幅解除 */
        padding: 4px 10px;
        font-size: 0.7rem;
    }

    table th, table td {
        padding: 8px 12px;
        font-size: 0.75rem;
    }
}

/* PPE Metrics */
.ppe-metrics-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 200px;
    padding: 0 10px;
}

.ppe-metric-box {
    text-align: center;
    flex: 1;
}

.ppe-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 500;
}

.ppe-value {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary-color);
}

.ppe-metric-box:last-child .ppe-value {
    color: #64B5F6;
}

.ppe-metric-divider {
    width: 1px;
    height: 60px;
    background-color: var(--border-color);
}

.summary-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}
.summary-rate {
    font-size: 0.9rem;
    line-height: 1.2;
}
.summary-fraction {
    font-size: 0.7rem;
    line-height: 1;
}
