/* =============================================
   ChantierBZH — Main Stylesheet
   ============================================= */

/* CSS Variables */
:root {
    --sidebar-width: 250px;
    --sidebar-collapsed-width: 60px;
    --sidebar-bg: #1a2535;
    --sidebar-text: #adb5bd;
    --sidebar-active: #fff;
    --sidebar-hover-bg: rgba(255,255,255,.07);
    --sidebar-active-bg: #0d6efd;
    --topbar-height: 56px;
    --zone-not-started: #6c757d;
    --zone-in-progress: #0dcaf0;
    --zone-ready: #fd7e14;
    --zone-received: #198754;
    --zone-nc: #dc3545;
    --zone-reserved: #ffc107;
}

/* Layout */
body {
    min-height: 100vh;
    background: #f4f6f9;
    font-size: .9rem;
}

#sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    flex-shrink: 0;
    transition: width .25s ease;
    overflow: hidden;
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    z-index: 1025;
}

#sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

#sidebar .sidebar-brand {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    white-space: nowrap;
    overflow: hidden;
}

#sidebar .brand-text {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    margin-left: 8px;
    transition: opacity .2s;
}

#sidebar.collapsed .brand-text,
#sidebar.collapsed .nav-label,
#sidebar.collapsed .sidebar-section-title {
    opacity: 0;
    pointer-events: none;
}

#sidebar .nav-link {
    color: var(--sidebar-text);
    padding: 9px 16px;
    border-radius: 6px;
    margin: 1px 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    transition: background .15s, color .15s;
    white-space: nowrap;
    overflow: visible; /* nécessaire pour le tooltip CSS en collapsed */
    position: relative;
}

#sidebar .nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: #fff;
}

#sidebar .nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active);
    font-weight: 600;
}

#sidebar .nav-link i {
    font-size: 1rem;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

#sidebar .sidebar-section-title {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(255,255,255,.35);
    padding: 14px 24px 4px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity .2s;
    display: block;
}

/* Projet actif bloc */
.sidebar-project-block {
    padding: 10px 16px 10px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    border-top: 1px solid rgba(255,255,255,.06);
    background: rgba(255,255,255,.03);
}
.sidebar-project-label {
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .1em;
    color: rgba(255,255,255,.3);
    text-transform: uppercase;
    margin-bottom: 6px;
}
.sidebar-project-name {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    text-decoration: none;
    font-size: .83rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-radius: 6px;
    padding: 4px 6px;
    margin: 0 -6px;
    transition: background .15s;
}
.sidebar-project-name:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
}
.sidebar-project-name span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-project-switch {
    display: block;
    margin-top: 5px;
    font-size: .7rem;
    color: rgba(255,255,255,.35);
    text-decoration: none;
    transition: color .15s;
}
.sidebar-project-switch:hover {
    color: rgba(255,255,255,.65);
}

/* Main content */
#mainContent {
    margin-left: var(--sidebar-width);
    transition: margin-left .25s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

body.sidebar-collapsed #mainContent {
    margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed #sidebar {
    width: var(--sidebar-collapsed-width);
}

/* Top navbar - padding-top pour le contenu sous la navbar fixe */
#mainContent {
    padding-top: var(--topbar-height);
}

/* Page content */
.page-content {
    padding: 24px;
    flex: 1;
    overflow-x: hidden; /* empêche tout débordement horizontal de la page */
    min-width: 0;       /* évite que les enfants flex gonflent la colonne */
}

/* Cards */
.hover-card {
    transition: transform .2s, box-shadow .2s;
}
.hover-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,.12) !important;
}

/* Stat cards */
.stat-card {
    border-left: 4px solid;
}

/* Zone status colors */
.zone-badge-not_started { background-color: var(--zone-not-started) !important; color: #fff; }
.zone-badge-in_progress { background-color: var(--zone-in-progress) !important; color: #000; }
.zone-badge-ready_reception { background-color: var(--zone-ready) !important; color: #fff; }
.zone-badge-received { background-color: var(--zone-received) !important; color: #fff; }
.zone-badge-non_conforming { background-color: var(--zone-nc) !important; color: #fff; }
.zone-badge-reserved { background-color: var(--zone-reserved) !important; color: #000; }

/* Status dots */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

/* Notification badge */
#notifBadge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 9px;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    padding: 0 4px;
    border-radius: 8px;
}

/* Breadcrumbs */
.breadcrumb {
    font-size: .8rem;
}

/* Tables */
.table thead th {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #495057;
}

/* Progress bars */
.progress { border-radius: 4px; }

/* Avatar */
.avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

/* Upload dropzone */
.dropzone-area {
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
}
.dropzone-area:hover,
.dropzone-area.dragover {
    border-color: #0d6efd;
    background: rgba(13,110,253,.04);
}

/* Notifications dropdown */
#notifDropdown {
    width: 340px;
    max-height: 420px;
    overflow-y: auto;
}

/* Signature canvas */
.signature-canvas {
    background: #fafafa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
}

/* Flash messages auto-dismiss */
.alert.auto-dismiss {
    animation: fadeOut 0.5s ease 4.5s forwards;
}
@keyframes fadeOut {
    from { opacity: 1; max-height: 100px; margin-bottom: 1rem; }
    to { opacity: 0; max-height: 0; margin-bottom: 0; padding: 0; overflow: hidden; }
}

/* Mobile */
@media (max-width: 768px) {
    #sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
        transition: transform .25s ease;
        z-index: 1045; /* au-dessus de tout sur mobile */
    }
    #sidebar.mobile-open {
        transform: translateX(0);
    }
    #mainContent {
        margin-left: 0 !important;
    }
    .page-content {
        padding: 16px;
    }
}

/* Backdrop mobile sidebar */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1040;
    transition: opacity .25s ease;
}
.sidebar-backdrop.show {
    display: block;
}

/* Tooltip natif pour le mode collapsed */
#sidebar.collapsed .nav-link {
    overflow: visible;
}
#sidebar.collapsed .nav-link::after {
    content: attr(data-label);
    position: absolute;
    left: calc(var(--sidebar-collapsed-width) + 6px);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(15,20,35,.92);
    color: #fff;
    padding: 4px 10px;
    border-radius: 5px;
    font-size: .75rem;
    font-weight: 500;
    white-space: nowrap;
    z-index: 1060;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
#sidebar.collapsed .nav-link:hover::after {
    opacity: 1;
}

/* Print */
@media print {
    #sidebar, #mainNavbar, .no-print { display: none !important; }
    #mainContent { margin-left: 0 !important; padding-top: 0 !important; }
    .page-content { padding: 0; }
}

/* ─── Annotateur plein écran ─────────────────────────────────────────── */
/* Mode fullscreen natif (Fullscreen API) */
#planAnnotatorWrap:fullscreen,
#planAnnotatorWrap:-webkit-full-screen {
    background: #fff;
    padding: 12px;
    overflow: auto;
    display: flex;
    flex-direction: column;
}
#planAnnotatorWrap:fullscreen #qcPlanContainer,
#planAnnotatorWrap:-webkit-full-screen #qcPlanContainer {
    flex: 1;
    max-height: none !important;
}
/* Fallback CSS overlay (si Fullscreen API non dispo) */
#planAnnotatorWrap.qc-manual-fs {
    position: fixed !important;
    inset: 0 !important;
    z-index: 10000 !important;
    background: #fff;
    padding: 12px;
    overflow: auto;
    display: flex;
    flex-direction: column;
}
#planAnnotatorWrap.qc-manual-fs #qcPlanContainer {
    flex: 1;
    max-height: none !important;
    height: 100%;
}
#planAnnotatorWrap.qc-manual-fs canvas { max-width: 100%; }

/* ─── Planning hebdomadaire ──────────────────────────────────────────── */
.week-grid-header {
    display: grid;
    grid-template-columns: minmax(200px,2fr) repeat(7,1fr) 120px;
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    font-size: .78rem;
}
.week-grid-header > div,
.week-grid-row > div {
    padding: 6px 6px;
    border-right: 1px solid #dee2e6;
}
.week-grid-header > div:last-child,
.week-grid-row > div:last-child { border-right: 0; }
.week-grid-row {
    display: grid;
    grid-template-columns: minmax(200px,2fr) repeat(7,1fr) 120px;
    border-bottom: 1px solid #dee2e6;
    align-items: center;
    transition: background .15s;
}
.week-grid-row:hover { background: #f8f9fa; }
.week-grid-row.task-done { background: #f0fff4; }
.week-day-active { border-radius: 4px; height: 18px; display: block; min-width: 6px; }
.week-day-col { text-align: center; }
.week-day-col.is-today { background: #fff3cd; }
.week-today-hdr { background: #ffc107 !important; color: #212529 !important; }
@media (max-width: 768px) {
    .week-grid-header,
    .week-grid-row { grid-template-columns: 1fr auto; }
    .week-day-col,
    .week-actions { display: none; }
    .week-day-col.is-today,
    .week-actions { display: block; }
}

/* ─── Planning chantier (table hebdomadaire) ──────────────────────────── */
.planning-week-title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
}
.planning-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .8rem;
    table-layout: fixed;
}
.planning-table th,
.planning-table td {
    border: 1px solid #ced4da;
    padding: 4px 6px;
    vertical-align: top;
}
.planning-table thead th {
    background: #e9ecef;
    text-align: center;
    font-weight: 700;
    font-size: .78rem;
    padding: 5px 4px;
    white-space: nowrap;
}
.planning-table thead th.pt-today-hdr { background: #ffc107; color: #212529; }
.planning-table td.pt-today-cell      { background: #fffbea; }
.planning-table td.pt-zone-cell {
    background: #f8f9fa;
    font-weight: 600;
    font-size: .78rem;
    white-space: nowrap;
    min-width: 130px;
    max-width: 180px;
}
.planning-table td.pt-zone-cell .zone-code  { font-size: .72rem; color: #6c757d; }
.planning-table td.pt-remarks-cell          { font-size: .75rem; color: #6c757d; min-width: 120px; }
.pt-task-chip {
    display: block;
    padding: 2px 5px;
    margin-bottom: 2px;
    border-radius: 3px;
    border-left: 3px solid transparent;
    line-height: 1.3;
    position: relative;
    cursor: default;
}
.pt-task-chip.pt-done  { opacity: .5; text-decoration: line-through; }
.pt-task-chip.pt-late  { color: #dc3545; font-weight: 700; }
.pt-validate-btn {
    float: right;
    border: none;
    background: transparent;
    color: #198754;
    padding: 0 0 0 4px;
    font-size: .9em;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s;
}
.pt-task-chip:hover .pt-validate-btn { opacity: 1; }
.pt-add-hint {
    display: block;
    text-align: center;
    opacity: 0;
    color: #adb5bd;
    cursor: pointer;
    transition: opacity .15s;
    font-size: 1rem;
    line-height: 1.6;
}
.planning-table td:hover .pt-add-hint { opacity: 1; }
/* Points clés */
.planning-keypoints {
    border-top: 1px solid #ced4da;
    padding: 6px 10px;
    font-size: .8rem;
    background: #f8f9fa;
}
.planning-keypoints .kp-label {
    font-weight: 700;
    white-space: nowrap;
    padding-right: 8px;
}

/* ─── Planning : impression ──────────────────────────────────────────── */
@media print {
    /* Masquer tout sauf le planning */
    .sidebar, .topbar, nav, .navbar,
    .btn, button,
    .d-flex.gap-2.flex-wrap,          /* boutons d'action */
    .d-flex.align-items-center.gap-2.mb-3, /* navigation semaines */
    .planning-keypoints button,
    .pt-validate-btn,
    .pt-add-hint {
        display: none !important;
    }
    body { background: #fff !important; }
    .page-content, .container, .container-fluid { margin: 0 !important; padding: 0 !important; }
    .card { box-shadow: none !important; border: none !important; }
    .card-body { padding: 0 !important; }
    .planning-week-title { font-size: 13pt; margin-bottom: 4px; }
    .planning-table { font-size: 8pt; }
    .planning-table th,
    .planning-table td { border: 1px solid #999 !important; padding: 3px 4px !important; }
    .planning-table thead th { background: #e0e0e0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .planning-table thead th.pt-today-hdr { background: #ffc107 !important; }
    .planning-table td.pt-today-cell { background: #fffbea !important; }
    .pt-task-chip { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .planning-keypoints { border-top: 1px solid #999 !important; }
}

/* En-tete d'impression planning */
.print-only-header { display: none !important; }
@media print {
    .print-only-header { display: block !important; }
}
