/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --primary: #374151;
    --primary-dark: #1f2937;
    --primary-light: #6b7280;
    --secondary: #4b5563;
    --success: #065f46;
    --danger: #7f1d1d;
    --warning: #78350f;
    --info: #1e3a8a;
    
    /* Category Colors */
    --cat-biological: #7f1d1d;
    --cat-hygiene: #1e3a8a;
    --cat-maintenance: #065f46;
    --cat-financial: #581c87;
    --cat-social: #78350f;
    --cat-health: #0f766e;
    --cat-other: #4b5563;
    
    /* Neutrals */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f8fafc;
    min-height: 100vh;
    color: var(--gray-900);
    line-height: 1.5;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-lg);
}

/* Header */
.header {
    background: white;
    border-radius: var(--radius-md);
    padding: var(--space-xl);
    margin-bottom: var(--space-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
}

.header h1 {
    font-size: 2rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: var(--space-sm);
}

.header .subtitle {
    font-size: 1rem;
    color: var(--gray-600);
    font-weight: 400;
}

/* Controls */
.controls {
    display: flex;
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
    flex-wrap: wrap;
    align-items: flex-end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.control-group label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-600);
}

select, input[type="text"], input[type="number"] {
    padding: var(--space-sm) var(--space-md);
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-family: inherit;
    background: white;
    transition: all 0.2s;
}

select:hover, input:hover {
    border-color: var(--primary-light);
}

select:focus, input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Buttons */
.btn {
    padding: var(--space-sm) var(--space-lg);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
}

/* Main Layout */
.main-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: var(--space-xl);
}

/* Sidebar */
.sidebar {
    background: white;
    border-radius: var(--radius-md);
    padding: var(--space-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
}

.sidebar h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: var(--space-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.checkpoints-list {
    max-height: 500px;
    overflow-y: auto;
    margin-bottom: var(--space-lg);
}

/* Checkpoint Item */
.checkpoint-item {
    background: var(--gray-50);
    border: 2px solid transparent;
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    transition: all 0.2s;
}

.checkpoint-item:hover {
    border-color: var(--primary-light);
    transform: translateX(2px);
    box-shadow: var(--shadow-sm);
}

.checkpoint-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
}

.checkpoint-name {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-weight: 600;
}

.category-dot {
    width: 12px;
    height: 12px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.checkpoint-toggle {
    position: relative;
    width: 44px;
    height: 24px;
}

.checkpoint-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--gray-300);
    transition: 0.3s;
    border-radius: var(--radius-full);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: var(--radius-full);
}

.checkpoint-toggle input:checked + .toggle-slider {
    background-color: var(--success);
}

.checkpoint-toggle input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.checkpoint-details {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
    font-size: 0.875rem;
}

.checkpoint-details input[type="number"] {
    width: 60px;
    padding: var(--space-xs);
}

.checkpoint-details select {
    padding: var(--space-xs);
    font-size: 0.875rem;
}

/* Calendar View */
.calendar-container {
    background: white;
    border-radius: var(--radius-md);
    padding: var(--space-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xl);
}

.calendar-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.calendar-grid {
    display: grid;
    gap: 2px;
    background: var(--gray-200);
    padding: 2px;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.time-slot {
    background: white;
    min-height: 100px;
    padding: var(--space-md);
    position: relative;
}

.time-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: var(--space-sm);
}

.checkpoint-pill {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    color: white;
    margin: 2px;
}

.aggregated {
    background: var(--gray-600);
    color: white;
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    text-align: center;
    margin-top: var(--space-sm);
}

/* Stats */
.stats {
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-top: var(--space-lg);
    border: 1px solid var(--gray-200);
}

.stats h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: var(--space-md);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) 0;
    border-bottom: 1px solid rgba(120, 53, 15, 0.1);
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-label {
    color: var(--gray-600);
    font-size: 0.875rem;
}

.stat-value {
    font-weight: 600;
    color: var(--gray-800);
    font-size: 1rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: white;
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: slideIn 0.3s;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
}

.modal-header h3 {
    font-size: 1.5rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
    padding: var(--space-xs);
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--gray-600);
}

.form-group {
    margin-bottom: var(--space-lg);
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: var(--space-sm);
    color: var(--gray-700);
}

.form-group input,
.form-group select {
    width: 100%;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.category-selector {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: var(--space-sm);
}

.category-option {
    padding: var(--space-sm);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.category-option:hover {
    border-color: var(--primary-light);
}

.category-option.selected {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-md);
    margin-top: var(--space-xl);
}

/* Optimization Suggestions */
.optimization-suggestions {
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-top: var(--space-lg);
    border: 1px solid var(--gray-200);
}

.optimization-suggestions h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: var(--space-md);
}

.suggestions-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.suggestion-item {
    background: white;
    border-radius: var(--radius-md);
    padding: var(--space-md);
    border: 1px solid var(--gray-200);
    transition: all 0.2s;
}

.suggestion-item:hover {
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.suggestion-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.suggestion-icon {
    font-size: 1.25rem;
}

.suggestion-title {
    font-weight: 600;
    color: var(--gray-800);
    font-size: 0.9rem;
}

.suggestion-detail {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin-bottom: var(--space-sm);
    line-height: 1.4;
}

.suggestion-impact {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
}

.impact-label {
    color: var(--gray-500);
    font-weight: 500;
}

.impact-value {
    color: var(--gray-800);
    font-weight: 600;
    text-align: right;
}

.suggestion-item.time-heavy {
    border-left: 4px solid var(--danger);
}

.suggestion-item.high-frequency {
    border-left: 4px solid var(--warning);
}

.suggestion-item.batching {
    border-left: 4px solid var(--info);
}

.suggestion-item.automation {
    border-left: 4px solid var(--secondary);
}

.suggestion-item.health {
    border-left: 4px solid var(--success);
}

/* Export Section */
.export-section {
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-top: var(--space-lg);
    border: 1px solid var(--gray-200);
}

.export-section h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: var(--space-md);
}

.export-options {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* Universal Timeline */
.timeline-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-md);
}

/* Active Checkpoints Summary */
.active-checkpoints-summary {
    background: var(--gray-50);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-bottom: var(--space-xl);
    border: 1px solid var(--gray-200);
}

.active-checkpoints-summary h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: var(--space-md);
}

.category-groups {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.category-group {
    background: white;
    border-radius: var(--radius-md);
    padding: var(--space-md);
    border: 1px solid var(--gray-200);
}

.category-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.category-name {
    font-weight: 600;
    color: var(--gray-700);
}

.category-count {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.category-checkpoints {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

.checkpoint-tag {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--gray-700);
    background: white;
    transition: all 0.2s;
}

.checkpoint-tag:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.zoom-controls {
    display: flex;
    gap: var(--space-xs);
}

.universal-timeline {
    position: relative;
    padding: var(--space-xl) 0;
    min-height: 600px;
}

.timeline-axis {
    position: absolute;
    top: 0;
    left: 220px;
    right: 0;
    height: 50px;
    border-bottom: 2px solid var(--gray-300);
}

.timeline-axis-line {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--gray-300);
}

.timeline-tick {
    position: absolute;
    bottom: 0;
    height: 100%;
}

.timeline-tick-line {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 1px;
    background: var(--gray-400);
}

.timeline-tick-major .timeline-tick-line {
    height: 20px;
    background: var(--gray-600);
    width: 2px;
}

.timeline-tick-minor .timeline-tick-line {
    height: 10px;
    background: var(--gray-400);
}

.timeline-tick-label {
    position: absolute;
    bottom: 25px;
    left: -20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-600);
    white-space: nowrap;
    width: 40px;
    text-align: center;
}

.timeline-tick-major .timeline-tick-label {
    font-weight: 700;
    color: var(--gray-800);
    bottom: 30px;
}

.timeline-tracks {
    margin-top: 70px;
}

.timeline-track {
    display: flex;
    align-items: center;
    margin-bottom: var(--space-md);
    min-height: 32px;
}

.timeline-track-label {
    width: 200px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding-right: var(--space-md);
    font-size: 0.875rem;
    font-weight: 500;
}

.checkpoint-name {
    font-weight: 600;
}

.timeline-frequency {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-weight: 400;
    display: block;
    margin-top: 2px;
}

.timeline-track-line {
    flex: 1;
    position: relative;
    height: 24px;
    background: var(--gray-100);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
    overflow: hidden;
}

.timeline-event {
    position: absolute;
    top: 2px;
    bottom: 2px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.85;
    min-width: 2px;
}

.timeline-event:hover {
    opacity: 1;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.timeline-density {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.timeline-density:hover {
    opacity: 1 !important;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* Timeline responsive */
@media (max-width: 1024px) {
    .timeline-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .zoom-controls {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .timeline-track-label {
        width: 140px;
        font-size: 0.75rem;
    }
    
    .timeline-frequency {
        display: none;
    }
    
    .timeline-axis {
        left: 160px;
    }
    
    .timeline-tick-label {
        font-size: 0.625rem;
        left: -15px;
        width: 30px;
    }
    
    .checkpoint-name {
        font-size: 0.75rem;
    }
    
    .zoom-controls {
        flex-wrap: wrap;
    }
}

/* Responsive */
@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        order: 2;
    }
    
    .calendar-container {
        order: 1;
    }
}

@media (max-width: 768px) {
    .container {
        padding: var(--space-md);
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .calendar-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }
}