/* ============================================
   Custom CSS - Elettricisti Illuminati
   ============================================ */

/* ============================================
   SweetAlert2 Wide Modal - Responsive
   ============================================ */
.swal-wide {
    width: 95vw !important;
    max-width: 1800px !important;
    background-color: white !important;
}

.swal2-popup.swal-wide {
    max-height: 90vh !important;
}

.swal2-popup.swal-wide .swal2-html-container {
    max-height: calc(90vh - 120px) !important;
    overflow-y: auto !important;
}

/* Responsive SweetAlert2 */
@media (max-width: 767.98px) {
    .swal-wide {
        width: 98vw !important;
        margin: 0.5rem !important;
    }

    .swal2-popup.swal-wide {
        max-height: 95vh !important;
    }

    .swal2-popup.swal-wide .swal2-html-container {
        max-height: calc(95vh - 100px) !important;
        padding: 0.5rem !important;
    }

    .swal2-title {
        font-size: 1.25rem !important;
    }
}

/* ============================================
   Native Sgocciolamento Modal
   ============================================ */
.sgocciolamento-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.sgocciolamento-overlay.active {
    display: flex;
}

.sgocciolamento-overlay.visible {
    opacity: 1;
}

.sgocciolamento-modal {
    background: white;
    border-radius: 8px;
    width: 95vw;
    max-width: 1800px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.sgocciolamento-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    border-bottom: 2px solid #e3e6f0;
    flex-shrink: 0;
    background: #f8f9fc;
}

.sgocciolamento-modal-header h4 {
    margin: 0;
    font-size: 1.25rem;
    color: #343a40;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 15px;
}

.sgocciolamento-modal-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    cursor: pointer;
    color: #6c757d;
    padding: 0 8px;
    line-height: 1;
    flex-shrink: 0;
}

.sgocciolamento-modal-close:hover {
    color: #000;
}

.sgocciolamento-modal-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0;
}

@media (max-width: 767.98px) {
    .sgocciolamento-modal {
        width: 98vw;
        height: 95vh;
        border-radius: 4px;
    }

    .sgocciolamento-modal-header {
        padding: 10px 15px;
    }

    .sgocciolamento-modal-header h4 {
        font-size: 1rem;
    }
}

/* ============================================
   Sgocciolamento Table Styles
   ============================================ */
.sgocciolamento-toolbar {
    flex-shrink: 0;
    z-index: 100;
    background: white;
    padding: 10px 15px;
    border-bottom: 2px solid #e3e6f0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

@media (max-width: 575.98px) {
    .sgocciolamento-toolbar {
        justify-content: stretch;
    }

    .sgocciolamento-toolbar .btn {
        flex: 1 1 auto;
    }
}

/* Table scroll area - fills remaining modal space, scrolls both axes */
.sgocciolamento-table-scroll-area {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 15px;
}

#tabella_sgocciolamento {
    width: 100%;
    table-layout: auto;
}

#tabella_sgocciolamento thead th.sticky-col-step,
#tabella_sgocciolamento tbody td.sticky-col-step {
    position: sticky;
    left: 0;
    z-index: 10;
    background-color: white;
    border-right: 2px solid #dee2e6;
}

#tabella_sgocciolamento thead th.sticky-col-detail,
#tabella_sgocciolamento tbody td.sticky-col-detail {
    position: sticky;
    left: 80px;
    z-index: 10;
    background-color: white;
    border-right: 2px solid #dee2e6;
    min-width: 200px;
}

#tabella_sgocciolamento thead th {
    position: sticky;
    top: 0;
    z-index: 11;
    background-color: #f8f9fc;
}

#tabella_sgocciolamento thead th.sticky-col-step,
#tabella_sgocciolamento thead th.sticky-col-detail {
    z-index: 12;
}

/* floating-scroll inside the modal */
.sgocciolamento-overlay .fl-scrolls {
    z-index: 10001;
}

/* Mobile adjustments for sticky columns */
@media (max-width: 767.98px) {
    #tabella_sgocciolamento {
        min-width: 600px;
    }
    
    #tabella_sgocciolamento thead th.sticky-col-step,
    #tabella_sgocciolamento tbody td.sticky-col-step {
        left: 0;
        min-width: 50px;
        max-width: 50px;
    }
    
    #tabella_sgocciolamento thead th.sticky-col-detail,
    #tabella_sgocciolamento tbody td.sticky-col-detail {
        left: 50px;
        min-width: 120px;
        max-width: 150px;
    }

    #tabella_sgocciolamento td,
    #tabella_sgocciolamento th {
        font-size: 0.75rem;
        padding: 0.375rem 0.25rem;
    }
    
    #tabella_sgocciolamento th {
        white-space: normal;
        word-wrap: break-word;
        line-height: 1.2;
    }

    #tabella_sgocciolamento td input {
        font-size: 0.75rem;
        padding: 0.25rem;
        min-width: 50px;
        max-width: 80px;
        width: 100%;
    }
    
    #tabella_sgocciolamento td input[type="number"] {
        width: 70px;
    }
}

/* ============================================
   Drag and Drop Step Rows
   ============================================ */
.step-row {
    transition: all 0.2s ease;
    position: relative;
}

.step-row.dragging {
    opacity: 0.4;
    border-left-color: #0d6efd !important;
    background-color: #f8f9fa;
}

.step-row.drag-over {
    background-color: #e7f3ff !important;
    border: 2px dashed #0d6efd !important;
    border-radius: 4px;
    transform: scale(1.02);
    box-shadow: 0 4px 8px rgba(13, 110, 253, 0.2);
}

.step-drag-handle {
    cursor: move;
    padding: 5px;
    color: #6c757d;
}

.step-drag-handle:hover {
    color: #0d6efd;
}

/* ============================================
   Hero Section Text Styles
   ============================================ */
section.hero h1,
section.hero h1.display-4,
section.hero h1.display-5,
section.hero h1.display-5.display-md-4,
section.hero h1.display-5.display-md-4.mb-3.fw-bold,
section.hero h1.fw-bold,
.card section.hero h1,
.card .card-body section.hero h1,
.card-body section.hero h1.display-5,
.card section.hero h1.display-5.fw-bold,
.card .card-body section.hero h1.display-5.display-md-4.mb-3.fw-bold,
section.hero p.lead,
section.hero .lead,
section.hero p.lead em {
    color: #ffffff !important;
    text-shadow: -1px 0 #000, 0 1px #000, 1px 0 #000, 0 -1px #000;
}

/* Responsive hero text */
@media (max-width: 767.98px) {
    section.hero h1.display-4,
    section.hero h1.display-5,
    section.hero h1 {
        font-size: 1.75rem !important;
    }

    section.hero p.lead {
        font-size: 1rem !important;
    }
}

/* ============================================
   Card Title Styles (Non-Hero)
   ============================================ */
main .card-body:not(:has(.hero)) h4.mb-3,
main .card:not(:has(.hero)) .card-body h4.mb-3 {
    color: #343a40 !important;
    text-shadow: none !important;
}

main .card:not(:has(.hero)) h4.card-title .text-span,
main .card:not(:has(.hero)) h4.card-title {
    color: #343a40 !important;
    text-shadow: none !important;
}

/* ============================================
   Esperti Section Card Styles
   ============================================ */
section#esperti .card-body .card-title,
section#esperti .card-body .card-title .text-span,
section#esperti .card-body h3.card-title,
section#esperti .card-body h3.card-title .text-span,
section#esperti .card-body h3.display-6.card-title,
section#esperti .card-body h3.display-6.card-title .text-span,
section#esperti .card-body h6,
section#esperti .card-body p {
    color: #495057 !important;
    text-shadow: none !important;
}

/* ============================================
   Lesson Title Ellipsis
   ============================================ */
.lesson-title {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* ============================================
   Form Responsive Improvements
   ============================================ */

/* Better spacing for form rows */
.row.mb-3 > [class*="col-"] {
    margin-bottom: 0.75rem;
}

@media (min-width: 768px) {
    .row.mb-3 > [class*="col-"] {
        margin-bottom: 0;
    }
}

/* Responsive button groups in forms */
form .btn-group,
form .d-flex.gap-2 {
    flex-wrap: wrap;
}

@media (max-width: 575.98px) {
    form .btn-group .btn,
    form .d-flex.gap-2 .btn {
        flex: 1 1 100%;
        margin-bottom: 0.5rem;
    }
}

/* ============================================
   Table Responsive Improvements
   ============================================ */

/* Prevent horizontal overflow in tables */
.table-responsive {
    margin-bottom: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    display: block;
}

/* Ensure table-responsive doesn't break desktop layout */
@media (min-width: 768px) {
    .table-responsive {
        display: block;
    }
}

/* Fix tables with w-100 class on mobile - allow them to be wider than viewport */
.table-responsive .table.w-100 {
    width: auto !important;
    min-width: 100%;
}

@media (min-width: 768px) {
    .table-responsive .table.w-100 {
        width: 100% !important;
    }
}

/* Allow text wrapping in table cells on mobile (override nowrap) */
@media (max-width: 767.98px) {
    .table-responsive .table.nowrap th,
    .table-responsive .table.nowrap td {
        white-space: normal !important;
        word-wrap: break-word;
        word-break: break-word;
    }
    
    .table-responsive .table th,
    .table-responsive .table td {
        white-space: normal;
        word-wrap: break-word;
        word-break: break-word;
        padding: 0.5rem 0.375rem;
        font-size: 0.875rem;
    }
    
    .table-responsive .table th {
        font-size: 0.8125rem;
        font-weight: 600;
    }
    
    .table-responsive .table.table-sm th,
    .table-responsive .table.table-sm td {
        padding: 0.375rem 0.25rem;
        font-size: 0.8125rem;
    }
}

/* Better button display in table cells */
.table td .btn-group {
    display: inline-flex;
    flex-wrap: nowrap;
}

@media (max-width: 767.98px) {
    .table td .btn-group {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .table td .btn-group .btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    .table td .btn {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
}

/* Fix DataTables responsive mode */
@media (max-width: 767.98px) {
    .dataTables_wrapper .dataTables_scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .dataTables_wrapper .dataTables_scrollBody {
        overflow-x: auto !important;
        overflow-y: visible !important;
    }
    
    .dataTables_wrapper .dataTables_paginate {
        text-align: center;
        margin-top: 0.5rem;
    }
    
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        margin-bottom: 0.5rem;
    }
    
    .dataTables_wrapper .dataTables_length select,
    .dataTables_wrapper .dataTables_filter input {
        width: 100%;
        margin-top: 0.25rem;
    }
}

/* Fix table-responsive-vertical */
.table-responsive-vertical {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

/* Fix tables without table-responsive wrapper */
@media (max-width: 767.98px) {
    .content-page .table:not(.table-responsive .table),
    .container-fluid .table:not(.table-responsive .table) {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .content-page .table:not(.table-responsive .table) {
        margin-left: -0.75rem;
        margin-right: -0.75rem;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

/* Ensure wrapper doesn't cause overflow */
@media (max-width: 991.98px) {
    .wrapper {
        overflow-x: hidden;
        max-width: 100%;
    }
    
    .content {
        overflow-x: hidden;
        max-width: 100%;
    }
}

/* Badge responsive */
@media (max-width: 575.98px) {
    .badge {
        font-size: 0.65rem;
        padding: 0.25rem 0.4rem;
    }
}

/* ============================================
   Video/Iframe Responsive
   ============================================ */

/* Make all iframes responsive by default */
iframe {
    max-width: 100%;
}

/* Video container for aspect ratio preservation */
.video-wrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    overflow: hidden;
}

.video-wrapper iframe,
.video-wrapper video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* ============================================
   Pagination Responsive
   ============================================ */

@media (max-width: 575.98px) {
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    .pagination .page-link {
        padding: 0.375rem 0.5rem;
        font-size: 0.875rem;
    }

    .pagination .page-item:not(.active):not(:first-child):not(:last-child):not(.disabled) {
        display: none;
    }

    .pagination .page-item:nth-child(2),
    .pagination .page-item:nth-last-child(2) {
        display: block;
    }
}

/* ============================================
   Alert Responsive
   ============================================ */

@media (max-width: 575.98px) {
    .alert {
        padding: 0.75rem;
        font-size: 0.875rem;
    }

    .alert .btn-close {
        padding: 1rem;
    }
}

/* ============================================
   Navigation Tab Responsive
   ============================================ */

@media (max-width: 767.98px) {
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .nav-tabs .nav-item {
        flex-shrink: 0;
    }

    .nav-tabs .nav-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
        white-space: nowrap;
    }
}

/* ============================================
   Dropdown Responsive
   ============================================ */

@media (max-width: 575.98px) {
    .dropdown-menu {
        width: auto;
        min-width: auto;
    }

    .dropdown-item {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
        white-space: nowrap;
    }
}

/* ============================================
   List Group Responsive
   ============================================ */

@media (max-width: 575.98px) {
    .list-group-item {
        padding: 0.75rem;
    }

    .list-group-item .d-flex {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ============================================
   Progress Bar Responsive
   ============================================ */

.progress {
    height: 0.75rem;
}

@media (min-width: 768px) {
    .progress {
        height: 1rem;
    }
}

/* ============================================
   Tooltip/Popover Responsive
   ============================================ */

@media (max-width: 575.98px) {
    .tooltip-inner {
        max-width: 200px;
        font-size: 0.75rem;
    }

    .popover {
        max-width: 280px;
    }

    .popover-body {
        font-size: 0.875rem;
    }
}

/* ============================================
   Breadcrumb Responsive
   ============================================ */

@media (max-width: 575.98px) {
    .breadcrumb {
        font-size: 0.75rem;
    }

    .breadcrumb-item + .breadcrumb-item::before {
        padding-right: 0.25rem;
    }

    .breadcrumb-item + .breadcrumb-item {
        padding-left: 0.25rem;
    }
}

/* ============================================
   Accordion Responsive
   ============================================ */

@media (max-width: 575.98px) {
    .accordion-button {
        padding: 0.75rem;
        font-size: 0.875rem;
    }

    .accordion-body {
        padding: 0.75rem;
    }
}

/* ============================================
   Admin Layout Specific Responsive
   ============================================ */

/* Content page adjustments */
@media (max-width: 991.98px) {
    .content-page {
        padding: 0.5rem;
    }

    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

/* Page title responsive */
.page-title {
    font-size: 1.25rem;
    line-height: 1.3;
}

@media (min-width: 768px) {
    .page-title {
        font-size: 1.5rem;
    }
}

@media (min-width: 992px) {
    .page-title {
        font-size: 1.75rem;
    }
}

/* ============================================
   Utility Overrides
   ============================================ */

/* Ensure tables don't break layout */
.table {
    word-wrap: break-word;
}

/* Better touch targets */
@media (max-width: 991.98px) {
    .btn {
        min-height: 38px;
    }

    .form-control,
    .form-select {
        min-height: 38px;
    }

    a.dropdown-item {
        padding: 0.625rem 1rem;
    }
}
