/* Global styling */
.main-footer {
    text-align: center;
    padding: 15px 0;
    font-size: 0.85rem;
    color: #64748b;
    margin-top: auto;
    width: 100%;
    border-top: 1px solid rgba(0,0,0,0.05); /* Subtle separation */
}

:root {
    --bg-color: #f3f4f6;
    --text-color: #1f2937;
    --border-color: #9ca3af; /* Stronger border color for a clear grid */
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --sector-bg: #f8fafc;
    --cell-bg: #ffffff;
    --cell-hover: #f1f5f9;
    --cell-active: #dbeafe;
    
    font-family: 'Inter', sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
}

/* App Container */
.app-container {
    max-width: 100%;
    margin: 0;
    padding: 10px 20px;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

#today-col {
    background: #fde047 !important; /* Vibrant yellow */
    color: #1e293b !important; /* Dark text for contrast */
    position: sticky !important; /* ENSURE IT STAYS VISIBLE */
    top: 0;
    z-index: 10;
}

#today-col div {
    color: #1e293b !important;
}

#today-col::after {
    content: 'OGGI';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: #facc15; /* Sslightly darker yellow for badge */
    color: #1e293b;
    font-size: 0.6rem;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 800;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    z-index: 15;
}

/* New class for highlighting the whole column */
.today-cell {
    background-color: #fefce8 !important; /* Extremely light yellow tint */
}

.delayed-row {
    background-color: #fff1f2 !important; /* Light rose/red background */
}

/* Vacation and Vehicle Highlights */
.activity-cell.is-vacation {
    background-color: #fef9c3 !important; /* Light Yellow (Tailwind yellow-100) */
}

.activity-cell.is-vacation:hover {
    background-color: #fef08a !important; /* Slightly darker yellow on hover (Tailwind yellow-200) */
}

.vacation-label {
    font-size: 0.65rem;
    font-weight: 800;
    color: #854d0e; /* Dark yellow/brown text */
    padding: 2px 4px;
    background: rgba(254, 240, 138, 0.8);
    border-radius: 4px;
    margin-bottom: 4px;
    text-transform: uppercase;
    display: inline-block;
    pointer-events: none;
}

.vehicle-indicator {
    position: absolute;
    bottom: 4px;
    right: 4px;
    font-size: 1.3rem; /* Larger */
    z-index: 25; /* Even higher */
    cursor: help;
    pointer-events: none;
    filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.8)) drop-shadow(0 1px 2px rgba(0,0,0,0.3));
    line-height: 1;
}

.activity-cell.has-vehicle, .vacation-cell.has-vehicle {
    background-color: #f0f9ff !important; /* Very light sky blue */
}

/* Mixed state: both vacation and vehicle */
.activity-cell.is-vacation.has-vehicle, .vacation-cell.is-vacation.has-vehicle {
    background: linear-gradient(135deg, #fef9c3 50%, #f0f9ff 50%) !important;
}

.delayed-row td {
    border-bottom-color: #fecdd3 !important;
}

.delayed-date {
    color: #e11d48 !important; /* Rose-600 */
    font-weight: 700 !important;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    padding: 15px 25px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

.month-selector {
    display: flex;
    align-items: center;
    gap: 15px;
}

.month-selector button {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 5px 10px;
    border-radius: 6px;
    transition: background 0.2s;
}

.month-selector button:hover {
    background: var(--border-color);
}

.month-selector h2 {
    font-size: 1.1rem;
    font-weight: 500;
    min-width: 150px;
    text-align: center;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.filters {
    display: flex;
    gap: 10px;
    margin-right: 10px;
}

.filters select, .filters input {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

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

.user-info {
    font-size: 0.9rem;
    color: #64748b;
}

.btn-logout {
    background: #ef4444;
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.2s;
}

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

.toggle-btn {
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.toggle-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-hover);
}

/* Main Content */
.app-main {
    flex-grow: 1;
    overflow: hidden;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
}

.calendar-wrapper {
    flex-grow: 1;
    overflow: auto;
    /* Custom scrollbar */
}

.calendar-wrapper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.calendar-wrapper::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    text-align: left;
    border-top: 1px solid var(--border-color);
    border-left: 1px solid var(--border-color);
}

th, td {
    padding: 11px;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    min-width: 88px;
    vertical-align: middle;
}

thead th {
    background: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 10;
    font-weight: 600;
    color: #475569;
    font-size: 0.9rem;
    white-space: nowrap;
}

/* Left pinned columns */
.col-sector {
    background: #f8fafc;
    position: sticky;
    left: 0;
    z-index: 11;
    min-width: 176px;
    max-width: 176px;
}

.col-user {
    background: #f8fafc;
    position: sticky;
    left: 176px; /* Exactly matches sector width */
    z-index: 11;
    min-width: 198px;
    max-width: 198px;
}

/* Make top-left corner above everything */
thead .col-sector, thead .col-user {
    z-index: 12;
}

td.sector-cell {
    font-weight: 600;
    color: #ffffff;
    vertical-align: middle;
    background: #475569; /* Distinct slate color */
    text-align: center;
    box-shadow: 2px 0 5px rgba(0,0,0,0.05); /* Slight shadow to show elevation when scrolling */
}

td.user-cell {
    font-weight: 500;
    background: #f8fafc;
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
}

/* Activity cell */
td.activity-cell {
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
    height: auto;
    min-height: 55px;
    padding: 4px; /* Less padding for better stacking */
    overflow: visible; /* CRITICAL for spanning bars */
    vertical-align: top;
}

.activity-cell .cell-content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 47px;
    position: relative; /* Anchor for absolute items */
    overflow: visible;
}

td.activity-cell:hover {
    background: var(--cell-hover);
}

td.activity-cell.drag-over {
    background: var(--cell-active);
    border: 2px dashed var(--primary-color);
}

/* Weekend cells */
td.weekend-cell, th.weekend-cell {
    background: #fff9c4 !important; /* Soft yellow */
}
th.weekend-cell {
    color: #856404 !important;
    border-bottom: 2px solid #ffe082 !important;
}

/* Holiday cells */
td.holiday-cell, th.holiday-cell {
    background: #fecaca !important; /* Light red */
}
th.holiday-cell {
    color: #991b1b !important;
    font-weight: 800 !important;
    border-bottom: 3px solid #fca5a5 !important;
}

.activity-item {
    font-size: 0.75rem;
    padding: 4px 10px;
    margin-bottom: 2px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    flex-direction: column;
    gap: 1px;
    border: 1px solid rgba(0,0,0,0.1);
    position: relative;
    height: 38px;
    justify-content: center;
    background-color: #3b82f6;
    color: white;
    user-select: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    box-sizing: border-box;
}

.activity-item.is-spanning {
    position: absolute;
    left: 0;
    /* Span logic: N * 100% + (N-1) * (gap_between_cells) 
       td padding is 4px on each side. gap between wrappers = 8px + 1px border = 9px.
    */
    width: calc(var(--span) * 100% + (var(--span) - 1) * 9px); 
    top: calc(var(--slot) * 42px); /* 38px height + 4px gap */
    z-index: 10;
    text-align: center;
    align-items: center; /* Center horizontally in flex */
}

.activity-item.is-spanning.is-start {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}
.activity-item.is-spanning.is-end {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}
.activity-item.is-spanning.is-middle {
    border-radius: 0;
}

.activity-item.is-placeholder {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    pointer-events: none;
}

/* Hide these legacy classes as we move to is-spanning */
.activity-item.is-start:not(.is-spanning),
.activity-item.is-end:not(.is-spanning),
.activity-item.is-middle:not(.is-spanning) {
    display: none;
}

.activity-item .activity-time {
    font-size: 0.65rem;
    opacity: 0.9;
    font-weight: 600;
    margin-bottom: 2px;
}

.activity-item.status-aperto {
    background-color: #3b82f6;
    color: white;
}

.activity-item.status-chiuso {
    background-color: #10b981;
    color: white;
}

.activity-item.status-ritardo {
    background-color: #ef4444;
    color: white;
}

.activity-item.status-annullato {
    background-color: #e2e8f0;
    color: #475569;
}

.activity-item {
    position: relative; /* For indicator positioning */
}

.comment-indicator {
    position: absolute;
    top: -2px;
    right: 2px;
    font-size: 0.7rem;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.2));
}

.activity-item.copy-source {
    outline: 3px solid #10b981;
    outline-offset: -2px;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
    z-index: 10;
}

/* Context Menu */
.context-menu {
    position: absolute;
    z-index: 1000;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 5px 0;
    min-width: 150px;
    display: none; /* Hidden by default */
}

.context-menu hr {
    border: 0;
    border-top: 1px solid #e2e8f0;
    margin: 5px 0;
}

.context-menu-item {
    padding: 8px 15px;
    font-size: 0.9rem;
    color: var(--text-color);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.context-menu-item:hover {
    background: var(--cell-hover);
    color: var(--primary-color);
}

.context-menu-item.danger:hover {
    color: #ef4444;
    background: #fef2f2;
}

.activity-item:active {
    cursor: grabbing;
    opacity: 0.8;
}

.activity-input {
    width: 100%;
    border: 1px solid var(--primary-color);
    border-radius: 4px;
    padding: 4px;
    font-family: inherit;
    font-size: 0.8rem;
    outline: none;
}
/* Custom Activity Tooltip (Balloon) */
.activity-tooltip {
    position: fixed;
    z-index: 2000;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    pointer-events: none;
    max-width: 300px;
    font-size: 0.9rem;
    color: var(--text-color);
    line-height: 1.4;
}

.activity-tooltip .tooltip-header {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 6px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 4px;
}

.activity-tooltip .tooltip-comment {
    margin-top: 8px;
    font-style: italic;
    color: #64748b;
    display: flex;
    gap: 6px;
    align-items: flex-start;
}

.activity-tooltip .tooltip-comment::before {
    content: '💬';
    font-style: normal;
}

/* Modern Modal Styling */
.modern-modal {
    border: none;
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 90%;
    max-width: 450px;
    margin: auto;
}

.modern-modal::backdrop {
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
}

.modern-modal header {
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
}

.modern-modal .close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: #475569;
}

.form-group textarea, .form-group input, .form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

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

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.modern-modal footer {
    padding: 16px 20px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    background: #f8fafc;
}

.right-actions {
    display: flex;
    gap: 10px;
}

.modern-modal button {
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-size: 0.9rem;
}

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

.btn-danger { background: #fee2e2; color: #ef4444; }
.btn-danger:hover { background: #fecaca; }

#btn-modal-cancel:hover { background: #e2e8f0; }

/* Fleet Management Styles */
.fleet-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.fleet-actions input {
    flex: 1;
    min-width: 0;
}

#fleet-table-body td {
    padding: 12px;
    border-bottom: 1px solid #f1f5f9;
}

#fleet-table-body tr:hover {
    background: #f8fafc;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: #f1f5f9;
}

.vehicle-status {
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 999px;
    font-weight: 600;
}

.status-available { background: #dcfce7; color: #166534; }
.status-occupied { background: #fee2e2; color: #991b1b; }

/* Modern Modal Styles */
.modern-modal {
    padding: 0;
    border: none;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    background: white;
    overflow: hidden;
    animation: modal-appear 0.3s ease-out;
}

@keyframes modal-appear {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modern-modal::backdrop {
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
}

.modal-header {
    background: #f8fafc;
    padding: 18px 24px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: #1e293b;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.close-modal-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    border-radius: 6px;
    transition: all 0.2s;
}

.close-modal-btn:hover {
    background: #f1f5f9;
    color: #475569;
}

/* Re-usable button and form styles */
.btn-modern {
    padding: 10px 18px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

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

.btn-modern-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.2);
}

.btn-modern-secondary {
    background: white;
    color: #64748b;
    border-color: #e2e8f0;
}

.btn-modern-secondary:hover {
    background: #f8fafc;
    color: #475569;
}

.form-field {
    margin-bottom: 18px;
}

.form-field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: 6px;
}

.form-field input, .form-field select, .form-field textarea {
    width: 100%;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    font-family: inherit;
    font-size: 0.95rem;
    color: #1e293b;
    transition: all 0.2s;
}

.form-field input:focus, .form-field select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* --- Printed Activity Calendar --- */
@media print {
    @page {
        size: landscape;
        margin: 5mm;
    }

    /* NUCLEAR HIDE: Everything in app-container is hidden */
    .app-container, .main-footer, #context-menu, dialog, .scripts-container {
        display: none !important;
    }

    /* SHOW ONLY THE ISOLATED VIEW */
    #print-view {
        display: block !important;
        width: 280mm !important;
        margin: 0 auto !important;
        background: white !important;
        color: black !important;
    }

    .print-header {
        text-align: center !important;
        margin-bottom: 5mm !important;
    }

    .print-header h2 {
        font-size: 18pt !important;
        margin: 0 !important;
    }

    #print-view #calendar-table {
        display: table !important;
        width: 100% !important;
        border-collapse: collapse !important;
        table-layout: fixed !important;
    }

    #print-view th, #print-view td {
        border: 1px solid #000 !important;
        padding: 1px !important;
        font-size: 6pt !important;
        height: 18pt !important;
        position: static !important; /* RESET STICKY/PINNED */
        left: auto !important;
        z-index: auto !important;
        vertical-align: middle !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    #print-view .col-sector { width: 15mm !important; }
    #print-view .col-user { 
        width: 35mm !important; 
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    /* REUSE STATUS INDICATORS */
    #print-view .activity-item {
        display: block !important;
        position: absolute !important;
        width: 10pt !important;
        height: 10pt !important;
        border-radius: 50% !important;
        text-indent: -9999px !important;
        border: 1px solid rgba(0,0,0,0.3) !important;
        margin: 0 !important;
    }

    #print-view td { position: relative !important; } /* Need relative for absolute dots */

    #print-view .activity-item:nth-child(1) { left: 50%; top: 50%; transform: translate(-50%, -50%); }
    #print-view .activity-item:nth-child(2) { left: 1px; top: 1px; }
    
    #print-view .activity-item.is-spanning {
        width: calc(var(--span) * 100% + (var(--span) - 1) * 1px - 4px) !important;
        height: 4pt !important;
        border-radius: 2pt !important;
        top: 50% !important;
        left: 2px !important;
        transform: translateY(-50%) !important;
    }

    #print-view .status-chiuso { background-color: #22c55e !important; }
    #print-view .status-ritardo { background-color: #ef4444 !important; }
    #print-view .status-aperto { background-color: #3b82f6 !important; }

    .print-footer {
        text-align: center !important;
        margin-top: 5mm !important;
        font-size: 8pt !important;
        color: #666 !important;
        border-top: 1px solid #ccc !important;
        padding-top: 2mm !important;
    }
}
/* Responsive Mobile Adjustments */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        padding: 15px;
    }
    .header-actions {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 10px;
    }
    .filters {
        flex-direction: column;
        width: 100%;
    }
    .filters select, .filters input {
        width: 100%;
    }
    .month-selector {
        width: 100%;
        justify-content: space-between;
    }
    .col-sector {
        min-width: 80px;
        max-width: 80px;
        font-size: 0.8rem;
    }
    .col-user {
        left: 80px; /* Adjust left offset */
        min-width: 120px;
        max-width: 120px;
        font-size: 0.8rem;
    }
    th, td {
        min-width: 50px;
        padding: 6px;
        font-size: 0.8rem;
    }
    .activity-item {
        font-size: 0.65rem;
        padding: 2px 4px;
        height: 28px;
    }
    .activity-item .activity-time {
        font-size: 0.55rem;
    }
    .modern-modal {
        width: 100%;
        max-width: 100%;
        margin: 10px;
    }
    .form-row, .modal-body > div[style*="display: flex"] {
        flex-direction: column;
    }
    .modal-footer {
        flex-direction: column;
        gap: 10px;
    }
    .modal-footer > div {
        width: 100%;
        display: flex;
        justify-content: space-between;
    }
}
@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1.2rem;
    }
    .col-sector { display: none; } /* Hide sector column on very small screens to save space */
    .col-user {
        left: 0;
        min-width: 100px;
        max-width: 100px;
    }
}
