:root {
    --primary: #4338ca; /* Indigo-700 */
    --primary-hover: #3730a3;
    --primary-light: #e0e7ff;
    --bg-color: #f8fafc; /* Slate-50 */
    --surface: #ffffff;
    --text-main: #0f172a; /* Slate-900 */
    --text-muted: #64748b; /* Slate-500 */
    --border-color: #e2e8f0; /* Slate-200 */
    
    --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-floating: 0 0 40px rgba(0,0,0,0.08);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    
    --bottom-nav-height: 65px;
    --sidebar-width: 360px;
    
    /* Type accents */
    --color-tp: #10b981; /* Emerald */
    --color-td: #f59e0b; /* Amber */
    --color-cm: #ec4899; /* Pink */
    --color-exam: #ef4444; /* Red */
}

* {
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0; padding: 0;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
    flex-direction: column;
}

/* --- Layout Architecture --- */
.app-layout {
    display: flex;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* Main Calendar Container */
.main-calendar {
    flex-grow: 1;
    height: 100%;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Sidebar Container */
.sidebar {
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    display: none;
    flex-direction: column;
    overflow-y: auto;
    position: absolute;
    top: 0; left: 0;
    z-index: 100;
    padding-bottom: var(--bottom-nav-height);
}

/* Mobile specific displays */
.mobile-view-active { display: flex !important; }
.mobile-view-hidden { display: none !important; }

.tab-section {
    padding: 24px 20px;
    display: none; /* toggled via JS on mobile */
    flex-direction: column;
}
.tab-section.active-tab { display: flex; }

.section-header {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

/* --- UI Forms ("Ajouter") --- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
}

.floating-label-group {
    position: relative;
}

.floating-label-group input {
    width: 100%;
    padding: 16px 16px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 1rem;
    color: var(--text-main);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.floating-label-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}

.floating-label-group label {
    position: absolute;
    top: 50%;
    left: 16px;
    transform: translateY(-50%);
    font-size: 1rem;
    color: var(--text-muted);
    pointer-events: none;
    transition: 0.2s ease all;
    background: var(--surface);
    padding: 0 4px;
}

.floating-label-group input:focus ~ label,
.floating-label-group input:not(:placeholder-shown) ~ label {
    top: -2px;
    left: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
}


.btn-primary {
    width: 100%;
    padding: 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(67, 56, 202, 0.25);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 6px 16px rgba(67, 56, 202, 0.3); }

/* Suggestions Dropdown */
#suggestions-box {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    max-height: 250px;
    overflow-y: auto;
    z-index: 2000;
    box-shadow: var(--shadow-lg);
    display: none;
}
.suggestion-item {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:active, .suggestion-item:hover { background-color: var(--bg-color); }
.suggestion-item span:first-child { font-weight: 500; font-size: 0.95rem; }
.suggestion-type {
    font-size: 0.7rem; color: var(--primary); background: var(--primary-light);
    padding: 4px 8px; border-radius: 12px; font-weight: 600; text-transform: uppercase;
}

/* --- Groupes List --- */
.saved-item {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.2s;
}
.saved-item.active-saved, .saved-item:active, .saved-item:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.saved-info { display: flex; flex-direction: column; gap: 4px; overflow: hidden; flex-grow: 1; }
.saved-title { font-weight: 600; font-size: 1rem; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-meta { font-size: 0.8rem; color: var(--text-muted); }

.delete-btn {
    background: none; border: none;
    color: #ef4444; font-size: 1.2rem;
    padding: 12px; cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s, transform 0.2s;
}
.delete-btn:active { background: #fee2e2; transform: scale(0.9); }
.delete-btn:hover { background: #fee2e2; }

/* --- Calendar Overrides --- */
#calendar { padding: 10px; height: 100%; width: 100%; }

.fc { font-family: 'Inter', sans-serif !important; }
.fc-theme-standard th { border: none !important; border-bottom: 1px solid var(--border-color) !important; padding: 12px 0 !important; font-weight: 600; color: var(--text-muted); text-transform: capitalize; }
.fc-theme-standard td { border-color: var(--border-color) !important; }
.fc-header-toolbar { padding: 8px 10px 16px !important; margin-bottom: 0 !important; border-bottom: 1px solid var(--border-color); }

.fc-toolbar-title { font-size: 1.2rem !important; font-weight: 700 !important; color: var(--text-main); }
.fc-button-primary { background: var(--surface) !important; color: var(--text-main) !important; border: 1px solid var(--border-color) !important; border-radius: 8px !important; text-transform: capitalize !important; font-weight: 500 !important; box-shadow: var(--shadow-sm) !important; transition: all 0.2s; margin-left: 4px !important;}
.fc-button-primary:active { transform: scale(0.95); }
.fc-button-active { background: var(--primary) !important; color: white !important; border-color: var(--primary) !important; }
.fc-today-button { background: var(--bg-color) !important; }
.fc-timegrid-slot { height: 44px !important; }
.fc-theme-standard .fc-timegrid-slot-label { border: none !important; }
.fc-timegrid-axis-cushion { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }
.fc-timegrid-slot-label-cushion { 
    font-size: 0.75rem; color: var(--text-muted); font-weight: 500;
    position: relative;
    top: -25px;
}
.fc-col-header-cell-cushion { color: var(--text-main); }
.fc-day-today { background-color: rgba(224, 231, 255, 0.4) !important; }

/* Native-feeling Event Tiles */
.fc-v-event {
    border: none !important;
    border-radius: 6px !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.08);
    margin: 1px 2px !important;
    overflow: hidden;
    background: #fff; /* fallback */
    border-left: 4px solid var(--primary) !important; /* Default left border */
    transition: filter 0.2s, transform 0.1s;
}
.fc-v-event:active { filter: brightness(0.9); transform: scale(0.98); }

.event-content {
    padding: 6px 8px;
    display: flex; flex-direction: column; gap: 2px;
    height: 100%; color: var(--evt-text, var(--text-main));
    background-color: var(--evt-bg, #f1f5f9); /* Dynamically set in JS */
}
.event-title { font-weight: 700; font-size: 0.8rem; line-height: 1.25; word-break: break-word; overflow: hidden; color: var(--evt-text, var(--text-main)); }
@media (max-width: 768px) {
    .event-title { font-size: 0.65rem; line-height: 1.15; }
    .event-info, .event-prof { font-size: 0.65rem; }
}
.event-type { display: inline-block; font-size: 0.65rem; font-weight: 700; letter-spacing: 0.5px; opacity: 0.8; }
.event-info { font-size: 0.75rem; color: var(--evt-text-muted, var(--text-muted)); display: flex; align-items: center; gap: 4px; margin-top: auto; }
.event-prof { font-size: 0.7rem; font-weight: 600; color: var(--evt-text-muted, var(--text-muted)); }

/* Color Modifiers for events based on data-type */
.evt-tp { border-left-color: var(--color-tp) !important; }
.evt-td { border-left-color: var(--color-td) !important; }
.evt-cm { border-left-color: var(--color-cm) !important; }
.evt-exam { border-left-color: var(--color-exam) !important; }

/* --- Bottom Navigation (Mobile) --- */
.bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-height);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-color);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 1000;
}
.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s;
}
.nav-btn i { font-size: 1.25rem; transition: transform 0.2s; }
.nav-btn.active { color: var(--primary); }
.nav-btn.active i { transform: scale(1.1); font-weight: 900; }

/* --- Modal (Bottom Sheet Mobile / Centered Desktop) --- */
.modal-backdrop {
    display: flex; position: fixed; inset: 0; z-index: 5000;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    align-items: flex-end; /* Bottom sheet align */
    justify-content: center;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-backdrop.show { opacity: 1; pointer-events: auto; }

.modal-content {
    background: var(--surface);
    padding: 32px 24px 24px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-floating);
    position: relative;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.1);
    max-height: 90vh;
    overflow-y: auto;
}
.modal-backdrop.show .modal-content { transform: translateY(0); }

/* Drag handle indicator */
.modal-content::before {
    content: ''; position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
    width: 40px; height: 5px; background: #cbd5e1; border-radius: 10px;
}

.close-modal { position: absolute; top: 20px; right: 24px; font-size: 1.5rem; background: var(--bg-color); width: 32px; height: 32px; display: flex; align-items:center; justify-content:center; border-radius: 50%; cursor: pointer; color: var(--text-muted); transition: all 0.2s; }
.close-modal:active { background: #e2e8f0; }

.modal-header { font-size: 1.35rem; font-weight: 700; color: var(--text-main); margin-bottom: 24px; padding-right: 32px; line-height: 1.3; }
.modal-type-badge { display: inline-block; background: var(--primary-light); color: var(--primary); font-size: 0.75rem; font-weight: 700; padding: 6px 12px; border-radius: 20px; margin-bottom: 16px; letter-spacing: 0.5px; }

.modal-row { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.modal-icon { color: var(--primary); font-size: 1.2rem; width: 24px; text-align: center; margin-top: 2px; opacity: 0.9; }
.modal-text { display: flex; flex-direction: column; color: var(--text-main); flex-grow: 1; }
.modal-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; margin-bottom: 4px; letter-spacing: 0.5px;}
.modal-val { font-size: 1rem; line-height: 1.4; font-weight: 500; }

/* --- Loading State --- */
.loading-overlay {
    display: none; position: absolute; inset: 0;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 4000; flex-direction: column; justify-content: center; align-items: center;
}
.pulse-loader {
    width: 60px; height: 60px;
    background: var(--primary);
    border-radius: 50%;
    animation: pulse 1.5s infinite cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 20px rgba(67, 56, 202, 0.4);
}
.pulse-loader i { color: white; font-size: 24px; }
@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(67, 56, 202, 0.4); }
    70% { transform: scale(1); box-shadow: 0 0 0 20px rgba(67, 56, 202, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(67, 56, 202, 0); }
}
.loading-text { margin-top: 20px; font-weight: 600; color: var(--primary); font-size: 1.1rem; letter-spacing: -0.01em; }

/* --- Confirm Dialog Override --- */
.modal-backdrop.centered { align-items: center; }
.modal-backdrop.centered .modal-content { border-radius: var(--radius-lg); transform: translateY(20px) scale(0.95); margin: 0 20px; }
.modal-backdrop.centered.show .modal-content { transform: translateY(0) scale(1); }
.modal-backdrop.centered .modal-content::before { display: none; }

/* --- Desktop Layout Adaptations --- */
@media (min-width: 769px) {
    .app-layout { flex-direction: row; }
    .bottom-nav { display: none; }
    
    .sidebar {
        position: relative;
        display: flex !important; /* Always visible */
        width: var(--sidebar-width);
        min-width: var(--sidebar-width);
        border-right: 1px solid var(--border-color);
        padding-bottom: 0;
        box-shadow: var(--shadow-lg);
        z-index: 10;
    }

    .main-calendar { display: flex !important; }
    
    .tab-section { display: flex; padding: 32px 24px; border-bottom: 1px solid var(--border-color); }
    .section-header { font-size: 1.25rem; }
    
    .modal-backdrop { align-items: center; }
    .modal-content { border-radius: var(--radius-lg); transform: translateY(20px) scale(0.95); }
    .modal-backdrop.show .modal-content { transform: translateY(0) scale(1); }
    .modal-content::before { display: none; } /* Hide drag handle */
    
    #calendar { padding: 24px; }
    .fc-header-toolbar { padding: 0 0 24px !important; margin-bottom: 24px !important; }
    .fc-toolbar-title { font-size: 1.75rem !important; }
}
