/* ======================================================
   Gestione Presenze - Congresso GEI - Web App Styles
   ====================================================== */

:root {
    --primary-color: #2c3e50;
    --primary-light: #34495e;
    --accent-color: #3498db;
    --success-color: #27ae60;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --info-color: #9b59b6;
}

/* Navbar custom */
.bg-primary-custom {
    background-color: var(--primary-color) !important;
}

.text-primary-custom {
    color: var(--primary-color) !important;
}

/* Body */
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: #f5f6fa;
    font-size: 0.9rem;
}

/* Cards */
.card {
    border: none;
    border-radius: 8px;
}

.card-header {
    border-radius: 8px 8px 0 0 !important;
}

/* Table */
#data-table {
    font-size: 0.85rem;
}

#data-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    font-size: 0.8rem;
    padding: 8px 10px;
    white-space: nowrap;
    background-color: var(--primary-color);
    color: white;
    border: none;
}

#data-table tbody tr {
    cursor: pointer;
    transition: background-color 0.15s;
}

#data-table tbody tr:hover {
    background-color: #e8f4fd !important;
}

#data-table tbody tr.selected {
    background-color: #d4edfc !important;
    outline: 2px solid var(--accent-color);
}

#data-table td {
    padding: 6px 10px;
    vertical-align: middle;
}

/* Scrollbar custom */
.table-responsive::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #bbb;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Buttons */
.btn-sm {
    font-size: 0.82rem;
    padding: 4px 10px;
}

/* Modal form */
.modal-form-group {
    margin-bottom: 1rem;
}

.modal-form-group label {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.modal-form-group .form-control,
.modal-form-group .form-select {
    font-size: 0.9rem;
}

.modal-form-group .form-control:focus,
.modal-form-group .form-select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25);
}

.modal-form-group .form-control.is-invalid {
    border-color: var(--danger-color);
    background-image: none;
}

.modal-form-group .invalid-feedback {
    font-size: 0.78rem;
}

.field-readonly {
    background-color: #ecf0f1 !important;
    color: #7f8c8d !important;
}

/* Toast */
.toast {
    min-width: 300px;
}

/* History table */
.history-table {
    font-size: 0.83rem;
}

.history-table .old-value {
    color: var(--danger-color);
    text-decoration: line-through;
}

.history-table .new-value {
    color: var(--success-color);
    font-weight: 600;
}

/* Statistics progress bars */
.progress {
    border-radius: 10px;
    overflow: hidden;
}

.progress-bar {
    transition: width 0.6s ease;
}

/* Footer */
.footer {
    font-size: 0.8rem;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
}

.loading-overlay.show {
    display: flex;
}

/* Badge custom */
.badge {
    font-weight: 500;
}

/* ==========================================================
   RESPONSIVE / MOBILE STYLES
   ========================================================== */

/* --- Touch-friendly base (applies to all touch devices) --- */
@media (pointer: coarse) {
    /* Minimum 44px touch targets (Apple HIG / Material guidelines) */
    .btn, .form-control, .form-select, .form-check-input {
        min-height: 44px;
    }
    .form-check-input {
        width: 1.4em;
        height: 1.4em;
    }
    #data-table tbody tr {
        min-height: 48px;
    }
    /* Larger action buttons for touch */
    .action-btn-touch {
        min-width: 40px;
        min-height: 40px;
        padding: 6px 10px !important;
        font-size: 1rem !important;
    }
}

/* --- Tablet landscape & small desktop (≤992px) --- */
@media (max-width: 992px) {
    #data-table td {
        max-width: 160px !important;
    }
}

/* --- Tablet portrait (≤768px) --- */
@media (max-width: 768px) {
    body {
        padding-bottom: 70px; /* space for mobile FAB */
    }

    main.container-fluid {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .navbar-brand .badge {
        display: none;
    }
    .navbar-brand span.fw-bold {
        font-size: 0.95rem;
    }

    /* Toolbar: stack groups vertically */
    .toolbar-actions {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }
    .toolbar-actions .vr {
        display: none;
    }
    .toolbar-actions .btn-group,
    .toolbar-actions .input-group {
        width: 100%;
        max-width: 100% !important;
    }
    .toolbar-actions .input-group {
        flex-grow: 1 !important;
    }

    /* Table */
    #data-table {
        font-size: 0.78rem;
    }
    #data-table td {
        padding: 8px 6px;
        max-width: 120px !important;
    }
    #data-table thead th {
        padding: 8px 6px;
        font-size: 0.75rem;
    }
    .table-responsive {
        max-height: calc(100vh - 360px) !important;
    }

    /* Modals fullscreen on tablet */
    .modal-lg, .modal-xl {
        max-width: 95vw;
    }
}

/* --- Phone (≤576px) --- */
@media (max-width: 576px) {
    body {
        font-size: 0.85rem;
        padding-bottom: 80px;
    }

    main.container-fluid {
        padding-left: 6px !important;
        padding-right: 6px !important;
        margin-top: 8px !important;
    }

    .navbar {
        padding: 4px 8px;
    }
    .navbar-brand i.fs-4 {
        font-size: 1.1rem !important;
    }
    .navbar-brand span.fw-bold {
        font-size: 0.85rem;
    }

    /* Hide desktop toolbar, show mobile toolbar */
    .desktop-toolbar {
        display: none !important;
    }
    .mobile-toolbar {
        display: flex !important;
    }

    /* Mobile toolbar */
    .mobile-toolbar {
        gap: 6px;
        padding: 8px 0;
    }
    .mobile-toolbar .btn {
        flex: 1;
        font-size: 0.8rem;
        white-space: nowrap;
    }
    .mobile-search {
        width: 100%;
    }
    .mobile-search .input-group {
        max-width: 100% !important;
    }

    /* Table - hide columns class */
    .hide-mobile {
        display: none !important;
    }

    #data-table {
        font-size: 0.75rem;
    }
    #data-table td {
        padding: 10px 4px;
        max-width: 90px !important;
    }
    #data-table thead th {
        padding: 8px 4px;
        font-size: 0.7rem;
    }
    /* Make select-all checkbox column narrow */
    #data-table th:first-child,
    #data-table td:first-child {
        width: 30px !important;
        padding: 8px 2px;
    }

    .table-responsive {
        max-height: calc(100vh - 300px) !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Action column stacked on phone */
    .action-cell {
        display: flex;
        flex-direction: column;
        gap: 2px;
        align-items: center;
    }
    .action-cell .btn {
        width: 36px;
        height: 36px;
        padding: 4px !important;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Card for mobile row detail view */
    .mobile-card-view .card {
        margin-bottom: 10px;
        border-left: 3px solid var(--accent-color);
    }
    .mobile-card-view .card-body {
        padding: 10px;
    }
    .mobile-card-view .field-label {
        font-weight: 600;
        color: var(--primary-color);
        font-size: 0.75rem;
        text-transform: uppercase;
    }
    .mobile-card-view .field-value {
        font-size: 0.85rem;
        margin-bottom: 4px;
    }
    .mobile-card-view .card-actions {
        display: flex;
        gap: 8px;
        justify-content: flex-end;
        padding-top: 8px;
        border-top: 1px solid #eee;
    }

    /* Modals full screen on phone */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        min-height: 100vh;
    }
    .modal-content {
        border-radius: 0;
        min-height: 100vh;
    }
    .modal-dialog-scrollable .modal-content {
        max-height: 100vh;
    }
    .modal-body {
        padding: 12px;
    }

    /* Form elements larger for touch */
    .modal-form-group .form-control,
    .modal-form-group .form-select {
        font-size: 1rem;
        padding: 10px 12px;
        min-height: 48px;
    }
    .modal-form-group label {
        font-size: 0.9rem;
        margin-bottom: 6px;
    }

    /* Footer compact */
    .footer {
        font-size: 0.7rem;
        padding: 6px 0 !important;
    }

    /* Statistics page */
    .col-md-4.col-sm-6 {
        padding-left: 6px;
        padding-right: 6px;
    }

    /* Toast on mobile */
    .toast-container {
        left: 10px !important;
        right: 10px !important;
        bottom: 80px !important;
    }
    .toast {
        min-width: auto;
        width: 100%;
    }
}

/* --- Very small phones (≤400px) --- */
@media (max-width: 400px) {
    .navbar-brand span.fw-bold {
        font-size: 0.78rem;
    }
    #data-table {
        font-size: 0.7rem;
    }
    #data-table td {
        max-width: 70px !important;
    }
}

/* ==========================================================
   FLOATING ACTION BUTTON (FAB)
   ========================================================== */
.fab-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1040;
    display: none; /* shown via JS on mobile */
}

.fab-main {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background-color: var(--success-color);
    color: white;
    font-size: 1.5rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.fab-main:hover,
.fab-main:active {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.fab-menu {
    position: absolute;
    bottom: 64px;
    right: 0;
    display: none;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}

.fab-menu.open {
    display: flex;
}

.fab-action {
    display: flex;
    align-items: center;
    gap: 8px;
    animation: fabSlideUp 0.2s ease-out;
}

@keyframes fabSlideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fab-action-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    color: white;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    cursor: pointer;
}

.fab-action-label {
    background: rgba(0,0,0,0.75);
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    white-space: nowrap;
}

/* Show FAB only on small screens */
@media (max-width: 768px) {
    .fab-container {
        display: block;
    }
}

/* ==========================================================
   MOBILE view toggle (table <-> card)
   ========================================================== */
.view-toggle {
    display: none;
}

@media (max-width: 576px) {
    .view-toggle {
        display: inline-flex;
    }
}

/* ==========================================================
   SWIPE HINT (visual cue for horizontal scroll)
   ========================================================== */
.swipe-hint {
    display: none;
    text-align: center;
    padding: 6px;
    font-size: 0.75rem;
    color: #999;
}

@media (max-width: 576px) {
    .swipe-hint {
        display: block;
    }
}

/* ==========================================================
   PULL TO REFRESH indicator
   ========================================================== */
.ptr-indicator {
    text-align: center;
    height: 0;
    overflow: hidden;
    transition: height 0.2s;
    color: var(--accent-color);
}

.ptr-indicator.active {
    height: 40px;
    line-height: 40px;
}

/* Print styles */
@media print {
    .navbar, .footer, .btn, .form-control, .modal, .fab-container {
        display: none !important;
    }
    
    #data-table {
        font-size: 0.75rem;
    }
}
