/* BARAPP - Style CSS v1.5 */

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.5;
    min-height: 100vh;
    /* Impedisci lo scroll orizzontale su schermi stretti */
    overflow-x: hidden;
}

/* App Container */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Topbar */
/*
 * Topbar
 *
 * The header is kept slim and simple.  By default it stretches across
 * the top of the viewport and contains just three logical areas:
 * the menu toggle on the left, the logo in the centre and the
 * personal/sync controls on the right.  We use flexbox with
 * space‑between to ensure the items spread evenly across the available
 * width.  Padding is reduced to avoid horizontal overflow on small
 * screens.  Height is later overridden in the mobile media query.
 */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: #1e293b;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.menu-toggle {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.menu-toggle:hover {
    background: rgba(255,255,255,0.1);
}

.logo-header {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* The logo size is responsive: we reduce its height on smaller devices
   later in the mobile section.  No vertical margin is necessary when
   displayed inline. */
.header-logo {
    height: 28px;
}

/* Right‑hand controls inside the topbar (personal area & sync).  Use
   flexbox with a small gap to avoid icons sticking together. */
.topbar-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.today-forecast {
    font-size: 0.85rem;
    color: #cbd5e1;
    font-weight: 500;
}

/* Header icons */
.header-icon {
    width: 28px;
    height: 28px;
    margin-right: 12px;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.header-icon:hover {
    background: rgba(255,255,255,0.1);
}

.sync-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sync-btn:hover {
    background: rgba(255,255,255,0.2);
    transform: rotate(180deg);
}

.sync-btn.syncing {
    animation: spin 1s linear infinite;
}

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

/* Sidebar */
.sidebar {
    position: fixed;
    left: -280px;
    top: 64px;
    bottom: 0;
    width: 260px;
    background: white;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    z-index: 900;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
}

.sidebar.open {
    left: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #e2e8f0;
}

.sidebar-logo {
    width: 120px;
}

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

.nav-menu {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: #475569;
    text-decoration: none;
    transition: all 0.2s;
    border-left: 4px solid transparent;
}

.nav-item:hover {
    background: #f1f5f9;
    color: #1e293b;
    border-left-color: #3b82f6;
}

.nav-item.active {
    background: #eff6ff;
    color: #1d4ed8;
    border-left-color: #3b82f6;
    font-weight: 500;
}

.nav-icon {
    width: 24px;
    margin-right: 12px;
    text-align: center;
}

.nav-text {
    font-size: 0.95rem;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid #e2e8f0;
    font-size: 0.8rem;
    color: #94a3b8;
}

.app-version {
    font-weight: 600;
    color: #3b82f6;
}

.sidebar-overlay {
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 800;
    display: none;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-top: 64px;
    padding: 24px;
    min-height: calc(100vh - 64px);
}

.page {
    display: none;
    max-width: 1200px;
    margin: 0 auto;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-header {
    margin-bottom: 24px;
}

.page-header h2 {
    font-size: 1.8rem;
    color: #1e293b;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-subtitle {
    color: #64748b;
    font-size: 0.95rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.stat-card.mattina {
    border-top: 4px solid #f59e0b;
}

.stat-card.pomeriggio {
    border-top: 4px solid #3b82f6;
}

.stat-card.sera {
    border-top: 4px solid #8b5cf6;
}

.stat-header {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
}

.stat-header i {
    font-size: 1.5rem;
    margin-right: 12px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
}

.stat-card.mattina .stat-header i {
    background: #fef3c7;
    color: #92400e;
}

.stat-card.pomeriggio .stat-header i {
    background: #dbeafe;
    color: #1e40af;
}

.stat-card.sera .stat-header i {
    background: #f3e8ff;
    color: #5b21b6;
}

.stat-header h3 {
    font-size: 1.1rem;
    color: #1e293b;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 12px;
}

.stat-details {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label {
    color: #64748b;
    font-size: 0.85rem;
    margin-bottom: 2px;
}

.stat-amount {
    font-weight: 600;
    color: #1e293b;
}

/* Forms */
.form-container {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
}

.incasso-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #475569;
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s;
    background: white;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2);
}

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

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

.btn-danger {
    background: #ef4444;
    color: white;
}

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

/* Stato attivo per filtri e bottoni secondari */
.btn.active,
.btn.btn-secondary.active {
    background: #3b82f6 !important;
    color: #ffffff !important;
}

/* Righe della sezione riepilogo analisi */
.analisi-summary .summary-row {
    padding: 8px 12px;
    font-size: 0.95rem;
}
.analisi-summary .summary-row:nth-child(odd) {
    background-color: #ffffff;
}
.analisi-summary .summary-row:nth-child(even) {
    background-color: #f8fafc;
}
.analisi-summary .summary-row strong {
    font-weight: 600;
}

/* Responsive tables per dispositivi mobili */
@media (max-width: 600px) {
    /* Nascondi l'intestazione delle tabelle e rendi ogni riga un blocco */
    .table-responsive table {
        min-width: unset;
        width: 100%;
        display: block;
    }
    .table-responsive thead {
        display: none;
    }
    .table-responsive tr {
        display: block;
        margin-bottom: 16px;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        background: #ffffff;
    }
    .table-responsive td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 12px;
        font-size: 0.9rem;
        border-bottom: 1px solid #e2e8f0;
    }
    .table-responsive td:last-child {
        border-bottom: none;
    }
    .table-responsive td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #64748b;
        margin-right: 12px;
        flex: 1;
    }
}

/* Ridimensiona i grafici per schermi stretti */
@media (max-width: 600px) {
    #operatoriChart,
    #graficiGeneraliChart {
        max-width: 100% !important;
        height: auto !important;
    }
}

/* Link secondario in dimensioni ridotte (ad es. "Gestisci operatori") */
.small-link {
    display: inline-block;
    margin-top: 4px;
    font-size: 0.8rem;
    color: #3b82f6;
    text-decoration: none;
    cursor: pointer;
}
.small-link i {
    margin-right: 4px;
}
.small-link:hover {
    text-decoration: underline;
}

/* Pulsante eliminazione operatore */
.delete-operator {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 0.85rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}
.delete-operator:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Modale ticket */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}
.modal-content {
    position: relative;
    background: white;
    padding: 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 1;
}
.modal-content h3 {
    margin-bottom: 16px;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}
.ticket-form .form-group {
    margin-bottom: 12px;
}
.ticket-form textarea {
    resize: vertical;
}

/* Incasso form button */
.incasso-form .btn {
    /* Pulsanti incasso più compatti ed eleganti */
    padding: 8px 14px;
    font-size: 0.9rem;
    margin-top: 12px;
    width: auto;
    align-self: flex-start;
    border-radius: 6px;
}

/* ------------------------------------------------------------------ */
/* Mobile specific adjustments */
/* These rules enhance the app's usability on smartphones by reducing 
   element sizes, converting the sidebar into a drawer, and hiding 
   non‑essential controls. They are applied when the viewport width 
   is 600px or less. */
@media (max-width: 600px) {
    /* Compress the topbar height and padding */
    .topbar {
        height: 56px;
        padding: 0 12px;
    }
    /* Shrink the logo for smaller screens */
    .header-logo {
        height: 20px;
    }
    /* Hide the sync button on mobile to avoid overlap */
    .topbar-controls .sync-btn {
        display: none;
    }
    /* Sidebar drawer style: occupy 70% of the screen and slide in/out */
    .sidebar {
        width: 70%;
        left: -70%;
    }
    .sidebar.open {
        left: 0;
    }
    /* Display the close button in the sidebar on mobile */
    .sidebar-close {
        display: block;
    }
    .sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    /* Adjust stats grid for mobile: smaller cards and tighter gaps */
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 12px;
    }
    .stat-card {
        padding: 16px;
    }
    /* Stack form fields vertically on mobile */
    .form-row {
        grid-template-columns: 1fr;
    }
    /* Reduce general button sizes on mobile */
    .btn {
        font-size: 0.85rem;
        padding: 8px 14px;
    }
}

/* Tables */
.table-container {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
}

/* Alternanza righe per tabella analisi operatori */
#analisiTable tbody tr:nth-child(odd) {
    background-color: #ffffff;
}
#analisiTable tbody tr:nth-child(even) {
    background-color: #f8fafc;
}
#analisiTable td {
    padding: 8px 12px;
    border-bottom: 1px solid #e2e8f0;
}
#analisiTable th {
    background-color: #f1f5f9;
    padding: 8px 12px;
    text-align: left;
}

/* Filter Group */
.filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.date-filter {
    padding: 8px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
}

/* Chart container */
.chart-container {
    width: 100%;
    overflow-x: auto;
}

/* Ensure charts do not overwhelm the viewport by constraining their height and width */
.chart-container canvas {
    width: 100% !important;
    height: auto !important;
    max-height: 360px;
}

/* On very small screens, reduce the maximum height of charts further to
   prevent them from dominating the view. */
@media (max-width: 600px) {
    .chart-container canvas {
        max-height: 280px;
    }
}

/* Calendar */
.calendar-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
}

#calendarMonthYear {
    font-size: 1.2rem;
    font-weight: 600;
    color: #1e293b;
}

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

.calendar-cell {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.calendar-cell:hover:not(.disabled) {
    background: #eff6ff;
    transform: translateY(-2px);
}

.calendar-cell.disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: default;
}

.calendar-date {
    font-weight: 600;
    font-size: 0.9rem;
    color: #1e293b;
}

.calendar-incasso {
    font-size: 0.75rem;
    color: #475569;
}

/* Evidenzia l'incasso di un solo turno (ad esempio solo mattina o solo sera) in calendario */
.calendar-incasso.single {
    font-weight: 600;
}

.table-container h3 {
    padding: 20px 20px 12px;
    color: #1e293b;
    font-size: 1.2rem;
}

.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

thead {
    background: #f8fafc;
}

th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.85rem;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #e2e8f0;
}

td {
    padding: 12px 16px;
    font-size: 0.95rem;
    color: #475569;
    border-bottom: 1px solid #f1f5f9;
}

tbody tr:hover {
    background: #f8fafc;
}

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

.table-summary {
    font-size: 0.95rem;
    color: #475569;
}

.table-summary strong {
    color: #1e293b;
}

.link-calendar {
    color: #3b82f6;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    background: #eff6ff;
    transition: all 0.2s;
}

.link-calendar:hover {
    background: #dbeafe;
    text-decoration: none;
}

/* Info Box */
.info-box {
    background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
    border: 1px solid #bfdbfe;
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.info-icon {
    color: #3b82f6;
    font-size: 1.5rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.info-content h4 {
    color: #1e40af;
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.info-content p {
    color: #475569;
    line-height: 1.5;
    margin-bottom: 4px;
    font-size: 0.95rem;
}

.info-content p:last-child {
    margin-bottom: 0;
}

/* Settings */
.settings-section {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
}

.settings-section h3 {
    color: #1e293b;
    margin-bottom: 20px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.shift-settings {
    margin-bottom: 20px;
}

.shift-item {
    background: #f8fafc;
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid #e2e8f0;
}

.shift-item:last-child {
    margin-bottom: 0;
}

.shift-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.form-check label {
    font-weight: 500;
    color: #1e293b;
    cursor: pointer;
}

.shift-header i {
    color: #64748b;
    font-size: 1.2rem;
}

.shift-times {
    display: flex;
    gap: 24px;
}

.time-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.time-group label {
    font-size: 0.85rem;
    color: #64748b;
    font-weight: 500;
}

.time-group input {
    padding: 8px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.95rem;
    width: 120px;
}

.data-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: auto;
    animation: modalSlide 0.3s ease;
}

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

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

.modal-header h3 {
    color: #1e293b;
    font-size: 1.3rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #64748b;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.2s;
}

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

.modal-body {
    padding: 20px;
}

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

/* Responsive */
@media (max-width: 768px) {
    .main-content {
        padding: 16px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .table-footer {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    
    .shift-times {
        flex-direction: column;
        gap: 12px;
    }
    
    .data-actions {
        flex-direction: column;
    }
    
    .data-actions .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .page-header h2 {
        font-size: 1.5rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .form-container {
        padding: 16px;
    }

    /* Ajust header for mobile devices */
    .topbar {
        height: 56px;
        padding: 0 12px;
    }
    .header-logo {
        height: 24px;
    }
    /* Nascondi il pulsante di sincronizzazione su schermi molto piccoli per evitare sovrapposizioni */
    .topbar-controls .sync-btn {
        display: none;
    }
}