/* ============ CSS CUSTOM PROPERTIES - THEME ============ */

:root {
    /* Light mode (default) */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --primary-dark: #1e40af;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --overlay-bg: rgba(0, 0, 0, 0.5);
    --nav-bg: rgba(255, 255, 255, 0.8);
    --card-hover: #f8fafc;
    --input-bg: #ffffff;
}

/* Dark mode */
.dark {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #475569;
    --primary: #3b82f6;
    --primary-light: #60a5fa;
    --primary-dark: #2563eb;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --overlay-bg: rgba(0, 0, 0, 0.7);
    --nav-bg: rgba(30, 41, 59, 0.9);
    --card-hover: #334155;
    --input-bg: #334155;
}

/* Transition douce entre modes */
body,
.page,
header,
nav,
.modal > div,
input,
select,
textarea,
button {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* ============ STYLES ESSENTIELS (Tailwind ne gere pas) ============ */

/* Safe area pour iOS */
.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Pages - affichage */
.page {
    display: none;
}

.page.active {
    display: block;
}

/* Navigation - etat actif */
.nav-item.active {
    color: var(--primary);
}

/* Modal - affichage */
.modal {
    display: none;
}

.modal:not(.hidden) {
    display: flex;
}

/* ============ DARK MODE - TAILWIND OVERRIDES ============ */

/* Body background */
.dark body,
body.dark {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* Navigation dark */
.dark nav {
    background: var(--nav-bg);
    border-color: var(--border-color);
}

.dark .nav-item {
    color: var(--text-secondary);
}

.dark .nav-item.active {
    color: var(--primary-light);
}

/* Headers dark */
.dark header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}

/* Cards dark - override Tailwind bg-white */
.dark .bg-white {
    background-color: var(--bg-secondary) !important;
}

.dark .bg-gray-50 {
    background-color: var(--bg-primary) !important;
}

.dark .bg-gray-100 {
    background-color: var(--bg-tertiary) !important;
}

/* Text colors dark */
.dark .text-gray-800,
.dark .text-gray-700 {
    color: var(--text-primary) !important;
}

.dark .text-gray-600,
.dark .text-gray-500 {
    color: var(--text-secondary) !important;
}

/* Borders dark */
.dark .border-gray-200,
.dark .border-gray-300 {
    border-color: var(--border-color) !important;
}

.dark .border-t {
    border-color: var(--border-color);
}

.dark .divide-gray-100 > * + * {
    border-color: var(--border-color);
}

/* Inputs dark */
.dark input,
.dark select,
.dark textarea {
    background-color: var(--input-bg);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.dark input::placeholder,
.dark textarea::placeholder {
    color: var(--text-secondary);
}

.dark input:focus,
.dark select:focus,
.dark textarea:focus {
    border-color: var(--primary);
}

/* Buttons dark */
.dark .bg-gray-100:hover {
    background-color: var(--bg-tertiary) !important;
}

.dark .hover\:bg-gray-100:hover {
    background-color: var(--bg-tertiary) !important;
}

.dark .hover\:bg-gray-200:hover {
    background-color: #475569 !important;
}

/* Radio cards dark */
.dark .peer-checked\:bg-blue-50 {
    background-color: rgba(59, 130, 246, 0.15) !important;
}

/* Toast dark */
.dark #toast {
    background-color: var(--bg-secondary);
}

/* Warnings/alerts dark */
.dark .bg-amber-100 {
    background-color: rgba(245, 158, 11, 0.2) !important;
}

.dark .bg-amber-50 {
    background-color: rgba(245, 158, 11, 0.15) !important;
}

.dark .text-amber-800 {
    color: #fcd34d !important;
}

.dark .border-amber-200,
.dark .border-amber-300 {
    border-color: rgba(245, 158, 11, 0.4) !important;
}

/* Danger zone dark */
.dark .bg-red-50 {
    background-color: rgba(239, 68, 68, 0.15) !important;
}

.dark .border-red-200 {
    border-color: rgba(239, 68, 68, 0.4) !important;
}

.dark .text-red-700,
.dark .text-red-600 {
    color: #fca5a5 !important;
}

/* Share buttons hover dark */
.dark .bg-blue-50:hover,
.dark .hover\:bg-blue-100:hover {
    background-color: rgba(59, 130, 246, 0.2) !important;
}

.dark .bg-green-50:hover,
.dark .hover\:bg-green-100:hover {
    background-color: rgba(34, 197, 94, 0.2) !important;
}

.dark .bg-amber-50:hover,
.dark .hover\:bg-amber-100:hover {
    background-color: rgba(245, 158, 11, 0.2) !important;
}

/* ============ CALENDRIER ============ */

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.calendar-header {
    text-align: center;
    font-weight: 600;
    padding: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    border-radius: 8px;
    font-size: 14px;
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 4px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
}

.calendar-day:hover {
    background: var(--card-hover);
}

.calendar-day.other-month {
    opacity: 0.3;
}

.calendar-day.today {
    border: 3px solid var(--primary);
    font-weight: 700;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.calendar-day.has-presence:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px var(--shadow-color);
}

.calendar-day.vacation-day {
    background: linear-gradient(135deg, rgba(254, 243, 199, 0.3), rgba(253, 230, 138, 0.3));
    border-color: #f59e0b;
}

.dark .calendar-day.vacation-day {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(245, 158, 11, 0.1));
}

.calendar-day-number {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 12px;
    font-weight: 600;
    z-index: 1;
}

.calendar-day-badges {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
    padding-top: 16px;
}

.presence-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    min-height: 20px;
    border-radius: 4px;
    color: white;
    font-weight: 700;
    font-size: 11px;
    padding: 2px 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.presence-badge.full-day {
    width: 90%;
}

.presence-badge.half-day {
    width: 45%;
}

.presence-badge.half-day.morning {
    align-self: flex-start;
    margin-left: 2px;
}

.presence-badge.half-day.afternoon {
    align-self: flex-end;
    margin-right: 2px;
}

.vacation-icon-small {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 12px;
    opacity: 0.7;
}

/* ============ LEGENDE CALENDRIER ============ */

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-primary);
}

.legend-color-square {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* ============ HISTORIQUE - VUES ============ */

.history-view {
    display: none;
}

.history-view:not(.hidden) {
    display: block;
}

.view-toggle.active {
    background: var(--primary);
    color: white;
}

/* Vue Timeline */
.timeline {
    position: relative;
    padding-left: 100px;
}

.timeline-item {
    position: relative;
    padding-bottom: 30px;
    display: flex;
    align-items: flex-start;
}

.timeline-date {
    position: absolute;
    left: -100px;
    top: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    width: 80px;
    text-align: right;
    padding-right: 15px;
    line-height: 1.4;
}

.timeline-dot {
    position: absolute;
    left: -12px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid var(--bg-primary);
    box-shadow: 0 0 0 2px var(--primary);
    z-index: 1;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 16px;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}

.timeline-item:last-child::before {
    display: none;
}

/* Vue groupee - mois header */
.month-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    cursor: pointer;
    border-radius: 12px 12px 0 0;
}

.month-content {
    padding: 12px;
    background: var(--bg-secondary);
}

/* ============ TOAST ============ */

#toast {
    pointer-events: none;
}

#toast:not(.opacity-0) {
    pointer-events: auto;
}

.toast-success {
    background-color: #10b981 !important;
}

.toast-error {
    background-color: #ef4444 !important;
}

/* ============ COULEURS CLIENTS ============ */

.client-color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

/* ============ GRAPHIQUE STATS ============ */

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

/* Barres de distribution */
.client-bar-track {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.client-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* ============ EXPORT - APERCU ============ */

.export-preview pre,
.email-preview pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    margin: 0;
    line-height: 1.6;
}

/* Section pliable */
.collapse-icon {
    transition: transform 0.2s;
}

.collapse-icon.rotated {
    transform: rotate(90deg);
}

/* Detail mois dans export */
.month-detail-header {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}

/* ============ RESPONSIVE ============ */

@media (max-width: 480px) {
    .calendar-grid {
        gap: 2px;
    }

    .calendar-day {
        font-size: 12px;
        padding: 2px;
    }

    .calendar-day-number {
        font-size: 10px;
    }

    .presence-badge {
        font-size: 9px;
        min-height: 16px;
        padding: 1px 4px;
    }

    .timeline {
        padding-left: 20px;
    }

    .timeline-date {
        position: static;
        width: auto;
        text-align: left;
        padding-right: 0;
        margin-bottom: 8px;
        font-size: 12px;
        background: var(--primary);
        color: white;
        padding: 4px 10px;
        border-radius: 12px;
        display: inline-block;
    }

    .timeline-item {
        flex-direction: column;
    }

    .timeline-dot {
        left: -14px;
    }

    .timeline-item::before {
        left: -8px;
    }
}

@media (min-width: 768px) {
    .calendar-grid {
        gap: 8px;
    }
}

/* ============ PWA INSTALL BANNER ============ */

.install-banner {
    animation: slideDown 0.3s ease-out;
}

.install-banner-show {
    animation: slideDown 0.3s ease-out;
}

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

/* Dark mode pour bannieres */
.dark #ios-install-banner {
    background: linear-gradient(135deg, #1f2937, #111827);
}

.dark #ios-install-banner .bg-white\/10 {
    background-color: rgba(255, 255, 255, 0.05);
}

/* ============ SHARE BUTTONS SVG ============ */

.share-btn svg {
    transition: transform 0.2s;
}

.share-btn:hover svg {
    transform: scale(1.1);
}

.dark .share-btn .text-gray-600 {
    color: #94a3b8;
}

.dark .share-btn .text-blue-600 {
    color: #60a5fa;
}

.dark .share-btn .text-green-600 {
    color: #4ade80;
}

.dark .share-btn .text-amber-600 {
    color: #fbbf24;
}

/* ============ THEME BUTTONS ============ */

.theme-btn.active {
    border-color: var(--primary) !important;
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

.dark .theme-btn {
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.dark .theme-btn:hover {
    border-color: var(--primary-light);
}

.dark .theme-btn.active {
    border-color: var(--primary-light) !important;
    background-color: rgba(96, 165, 250, 0.15);
    color: var(--primary-light);
}

/* ============ DETECTION AUTO PREFERS-COLOR-SCHEME ============ */

@media (prefers-color-scheme: dark) {
    :root:not(.light) {
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-tertiary: #334155;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --border-color: #475569;
        --primary: #3b82f6;
        --primary-light: #60a5fa;
        --primary-dark: #2563eb;
        --shadow-color: rgba(0, 0, 0, 0.3);
        --overlay-bg: rgba(0, 0, 0, 0.7);
        --nav-bg: rgba(30, 41, 59, 0.9);
        --card-hover: #334155;
        --input-bg: #334155;
    }
}

/* ============ RECENT DAYS COLOR BAR ============ */

.day-item {
    display: flex;
    align-items: stretch;
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.day-color-bar {
    width: 6px;
    flex-shrink: 0;
}

.day-item .day-info {
    flex: 1;
    padding: 12px 16px;
}

.day-item .day-date {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.day-item .day-client {
    color: var(--text-secondary);
    font-size: 14px;
}

.day-item .day-duration {
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 4px;
}

.day-item .day-notes {
    color: var(--text-secondary);
    font-size: 12px;
    font-style: italic;
    margin-top: 4px;
}

.day-item .day-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
}

/* ============ CALENDAR DETAIL MODAL ============ */

.day-detail-item {
    display: flex;
    align-items: stretch;
    background: var(--bg-tertiary);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 12px;
}

.day-detail-item .detail-color-bar {
    width: 6px;
    flex-shrink: 0;
}

.day-detail-item .detail-content {
    flex: 1;
    padding: 12px 16px;
}

.day-detail-item .detail-client {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.day-detail-item .detail-notes {
    color: var(--text-secondary);
    font-size: 12px;
    font-style: italic;
    margin-top: 8px;
}

.day-detail-item .detail-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
}

.detail-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.detail-badge.full {
    background: #dcfce7;
    color: #166534;
}

.detail-badge.half {
    background: #fef3c7;
    color: #92400e;
}

.detail-badge.vacation {
    background: #fef3c7;
    color: #92400e;
}

.vacation-detail {
    border: 2px solid #f59e0b;
}

/* ============ EXPORT DAYS LIST ============ */

.days-list {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-style: italic;
}

.export-table .detail-row {
    background: var(--bg-tertiary);
}

.export-table .month-detail-header {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 4px;
}

.export-table .detail-line {
    font-size: 13px;
    color: var(--text-secondary);
    padding-left: 12px;
}

/* ============ EXPORT TABLE IMPROVED ============ */

.export-table {
    width: 100%;
    border-collapse: collapse;
}

.export-table th {
    text-align: left;
    padding: 12px 8px;
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    color: var(--text-primary);
}

.export-table td {
    padding: 12px 8px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}

.export-table .days-cell {
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
    text-align: center;
}

.export-table .dates-cell {
    font-size: 14px;
    line-height: 1.6;
}

.export-table .dates-cell strong {
    color: var(--primary);
}

.client-color-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
}

/* Legende pour les jours differes */
.deferred-legend {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 12px;
    padding: 8px 12px;
    background: #fef3c7;
    border-radius: 8px;
    border-left: 3px solid #f59e0b;
}

.dark .deferred-legend {
    background: rgba(245, 158, 11, 0.15);
}

/* Badge pour jours differes */
.deferred-badge {
    display: inline-block;
    font-size: 10px;
    background: #f59e0b;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    font-weight: 500;
    vertical-align: middle;
}

/* ============ OFFLINE MODE STYLES ============ */

/* Offline banner animation */
#offline-banner {
    animation: slideDown 0.3s ease-out;
}

#offline-banner.show {
    display: block !important;
}

/* Pulse animation for pending sync count */
@keyframes pulse-amber {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

#pending-sync-count:not(.hidden) {
    animation: pulse-amber 2s ease-in-out infinite;
}

/* Sync button loading state */
#btn-force-sync.syncing {
    pointer-events: none;
    opacity: 0.7;
}

#btn-force-sync.syncing::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 6px;
    border: 2px solid white;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

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

/* Toast notifications for sync */
.toast-info {
    background-color: #3b82f6 !important;
}

.toast-warning {
    background-color: #f59e0b !important;
}

/* Offline indicator in header */
.offline-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: rgba(245, 158, 11, 0.2);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: #fcd34d;
}

.offline-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #f59e0b;
    border-radius: 50%;
    animation: pulse-amber 1.5s ease-in-out infinite;
}

/* Form elements disabled state when offline */
body.offline button[type="submit"]:not(.allow-offline),
body.offline .share-btn:not(.allow-offline) {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Dark mode adjustments for offline banner */
.dark #offline-banner {
    background-color: rgba(245, 158, 11, 0.15) !important;
    border-color: rgba(245, 158, 11, 0.3) !important;
}

.dark #offline-banner .text-amber-800 {
    color: #fcd34d !important;
}

.dark #offline-banner .text-amber-700 {
    color: #fbbf24 !important;
}

.dark #offline-banner .bg-amber-200 {
    background-color: rgba(245, 158, 11, 0.3) !important;
}

.dark #btn-force-sync {
    background-color: #d97706;
}

.dark #btn-force-sync:hover {
    background-color: #b45309;
}

/* iOS-specific sync button styles */
.ios-sync-info {
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 8px;
    font-size: 11px;
    color: var(--text-secondary);
}

.ios-sync-info strong {
    color: var(--primary);
}

/* Queued items indicator */
.queued-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.dark .queued-badge {
    background: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}

.queued-badge::before {
    content: '⏳';
    font-size: 10px;
}
