
:root{
    --blue:#0054a6;
    --blue-dark:#003d7a;
    --blue-soft:#d8e7f6;
    --blue-soft-2:#eef5fb;
    --bg:#f3f6f9;
    --green:#2e7d32;
    --border:#d7e0e9;
    --text:#1f2937;
}

*{box-sizing:border-box}

html,body{
    margin:0;
    padding:0;
    font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif;
    background:var(--bg);
    color:var(--text);
}

body{
    padding-bottom:env(safe-area-inset-bottom);
}

a{color:inherit}

button,input,select,textarea{font:inherit}

.topbar{
    background:#fff;
    border-bottom:3px solid var(--blue);
    padding:11px max(12px,env(safe-area-inset-right)) 9px max(12px,env(safe-area-inset-left));
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    position:sticky;
    top:0;
    z-index:80;
}

.topbar h1{
    font-size:20px;
    line-height:1.1;
    color:var(--blue);
    margin:0;
}

.topbar nav{
    display:flex;
    align-items:center;
    gap:7px;
}

.topbar nav a,
.nav-button{
    border:0;
    background:var(--blue);
    color:#fff;
    text-decoration:none;
    padding:9px 11px;
    border-radius:8px;
    font-weight:800;
    font-size:12px;
    cursor:pointer;
}

.pdf-button{
    background:#2e7d32;
}

.userline{
    font-size:11px;
    margin-top:4px;
    color:#64748b;
}

.monthbar{
    display:flex;
    gap:7px;
    align-items:center;
    padding:9px 12px;
    overflow-x:auto;
    white-space:nowrap;
    background:#eaf1f8;
    position:sticky;
    top:56px;
    z-index:70;
    -webkit-overflow-scrolling:touch;
}

.monthbar a,
.monthbar select,
.month-create-button{
    border:1px solid #b8c8da;
    background:#fff;
    color:var(--blue);
    border-radius:9px;
    padding:8px 11px;
    font-weight:800;
    text-decoration:none;
    font-size:12px;
    min-height:38px;
}

.monthbar a.active,
.monthbar select:focus{
    border-color:var(--blue);
    box-shadow:0 0 0 2px rgba(0,84,166,.12);
}

.monthbar .month-current{
    display:flex;
    align-items:center;
    gap:8px;
    background:var(--blue);
    color:#fff;
    border-color:var(--blue-dark);
    padding:6px 12px;
}

.monthbar .month-current.active{
    background:#003f83;
    box-shadow:0 0 0 3px rgba(0,84,166,.18);
}

.month-current-label{
    display:inline-block;
    background:#fff;
    color:var(--blue);
    border-radius:999px;
    padding:2px 6px;
    font-size:8px;
    font-weight:900;
    letter-spacing:.35px;
}

.month-next.active{
    background:#dbeafe;
    color:#003f83;
}

.month-create-button{
    border:0;
    background:#2e7d32;
    color:#fff;
    cursor:pointer;
}

.month-create-button:active{
    transform:translateY(1px);
}

main{padding:12px}

.panel{
    background:#fff;
    border-radius:12px;
    box-shadow:0 3px 14px rgba(0,0,0,.08);
    padding:10px;
}

.panel-title{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
    margin-bottom:9px;
}

.panel-title h2{
    margin:0;
    color:var(--blue);
    font-size:21px;
}

.source-badge,
.viewer-badge,
.current-month-badge,
.future-month-badge{
    display:inline-block;
    margin-top:3px;
    border-radius:999px;
    padding:3px 7px;
    font-size:9px;
    font-weight:900;
    letter-spacing:.3px;
}

.source-badge{
    color:#155e75;
    background:#cffafe;
}

.viewer-badge{
    color:#334155;
    background:#e2e8f0;
}

.current-month-badge{
    color:#fff;
    background:#2e7d32;
}

.future-month-badge{
    color:#1e3a8a;
    background:#dbeafe;
}

.table-wrap{
    overflow:auto;
    max-height:calc(100vh - 176px);
    border:1px solid var(--border);
    border-radius:8px;
    -webkit-overflow-scrolling:touch;
    overscroll-behavior:contain;
}

.schedule{
    border-collapse:separate;
    border-spacing:0;
    width:max-content;
    min-width:100%;
    font-size:10px;
}

.schedule th{
    position:sticky;
    z-index:30;
    background:var(--blue);
    color:#fff;
    border-right:1px solid #003b73;
    border-bottom:1px solid #003b73;
    padding:8px 6px;
    min-width:116px;
    height:39px;
    text-align:center;
}

.schedule thead .group-row th{
    top:0;
    height:28px;
    padding:5px 6px;
}

.schedule thead tr:nth-child(2) th{
    top:28px;
}

.schedule .group-date{
    top:0!important;
}

.group-head{
    background:#003f83!important;
    letter-spacing:.3px;
}

.group-lat{
    background:#004ec2!important;
}

.group-magazzino{
    background:#0059a8!important;
}

.group-uff--commerciale{
    background:#0d5592!important;
}

.schedule td{
    position:relative;
    border-right:1px solid #d5dde5;
    border-bottom:1px solid #d5dde5;
    min-width:116px;
    max-width:158px;
    height:54px;
    padding:6px;
    text-align:center;
    vertical-align:middle;
    background:#fff;
    word-break:break-word;
}

.schedule td.col-alt{
    background:var(--blue-soft-2);
}

.schedule td.col-base{
    background:#fff;
}

.schedule .date-col{
    position:sticky;
    left:0;
    z-index:45;
    min-width:98px;
    max-width:98px;
    background:#f8fafc!important;
    color:var(--blue);
    font-weight:800;
    border-right:2px solid var(--blue);
}

.schedule thead .date-col{
    background:var(--blue)!important;
    color:#fff;
    z-index:60;
}

.schedule tr.saturday td{
    border-top:1px solid #c3ccd5;
}

.schedule tr.current-week td{
    background:#fffed7;
}

.schedule tr.sunday td{
    background:#d7d7d7!important;
    color:#374151;
}

.schedule tr.today td{
    background:#e9f7ed;
    box-shadow:
        inset 0 2px 0 var(--green),
        inset 0 -2px 0 var(--green);
}

.schedule tr.today .date-col{
    border-left:7px solid var(--green);
}

.today-tag{
    display:block;
    color:#fff;
    background:var(--green);
    border-radius:4px;
    font-size:8px;
    margin-top:3px;
    padding:2px;
}

.entry-cell.editable{
    cursor:pointer;
    touch-action:manipulation;
}

.entry-cell.editable:active{
    filter:brightness(.94);
}

.cell-text{
    font-weight:650;
    color:#064b90;
    white-space:pre-wrap;
    line-height:1.15;
}

.signature{
    position:absolute;
    right:3px;
    bottom:2px;
    background:#0f172a;
    color:#fff;
    border-radius:4px;
    padding:1px 4px;
    font-size:8px;
    font-weight:900;
    letter-spacing:.4px;
}

.reason-ferie{
    background:#ffd6dc!important;
}

.reason-ferie .cell-text{
    color:#a51428;
}

.reason-malattia{
    background:#ffe2b8!important;
    box-shadow:inset 0 0 0 2px #f59e0b;
}

.reason-malattia .cell-text{
    color:#934100;
}

.reason-permesso{
    background:#e8ddff!important;
}

.reason-permesso .cell-text{
    color:#5b21b6;
}

.reason-rol{
    background:#d8eefc!important;
}

.reason-rol .cell-text{
    color:#075985;
}

.reason-generic{
    background:#fff2b7!important;
}

.login-body{
    min-height:100vh;
    display:grid;
    place-items:center;
    padding:18px;
    background:linear-gradient(180deg,#eff6ff,#f8fafc);
}

.login-card{
    width:min(460px,100%);
    background:#fff;
    border-radius:18px;
    padding:22px;
    box-shadow:0 15px 40px rgba(0,0,0,.12);
}

.login-card.wide{
    width:min(620px,100%);
}

.login-card h1{
    color:var(--blue);
    text-align:center;
    font-size:23px;
}

form label,
.edit-sheet label{
    display:block;
    font-weight:750;
    font-size:13px;
    margin:10px 0;
}

input,
select,
textarea{
    width:100%;
    border:1px solid #b9c5d3;
    border-radius:9px;
    padding:10px;
    background:#fff;
    margin-top:5px;
}

textarea{resize:vertical}

.primary,
.secondary,
.small,
.quick,
.icon-btn{
    border:0;
    border-radius:9px;
    font-weight:800;
    cursor:pointer;
}

.primary{
    background:var(--blue);
    color:#fff;
    padding:10px 14px;
}

.secondary{
    background:#e2e8f0;
    color:#0f172a;
    padding:10px 14px;
}

.small{
    padding:7px 9px;
    background:#e2e8f0;
}

.full{width:100%}

.notice{
    padding:11px;
    border-radius:9px;
    margin:10px 0;
    background:#edf2f7;
}

.notice.error{
    background:#fee2e2;
    color:#991b1b;
}

.notice.ok{
    background:#dcfce7;
    color:#166534;
}

.sheet-backdrop{
    position:fixed;
    inset:0;
    background:rgba(15,23,42,.4);
    z-index:90;
    display:none;
}

.edit-sheet{
    position:fixed;
    z-index:100;
    background:#fff;
    left:50%;
    bottom:0;
    transform:translate(-50%,105%);
    width:min(640px,100%);
    max-height:90vh;
    overflow:auto;
    padding:10px 16px calc(16px + env(safe-area-inset-bottom));
    border-radius:18px 18px 0 0;
    box-shadow:0 -12px 40px rgba(0,0,0,.2);
    transition:transform .2s ease;
}

.edit-sheet.open{
    transform:translate(-50%,0);
}

.sheet-backdrop.open{
    display:block;
}

.sheet-handle{
    width:46px;
    height:5px;
    background:#cbd5e1;
    border-radius:5px;
    margin:0 auto 10px;
}

.sheet-head{
    display:flex;
    justify-content:space-between;
    align-items:center;
}

.icon-btn{
    width:38px;
    height:38px;
    font-size:25px;
    background:#e2e8f0;
}

.muted{
    color:#64748b;
    font-size:12px;
}

.quick-buttons{
    display:flex;
    gap:6px;
    overflow-x:auto;
    padding:8px 0;
    -webkit-overflow-scrolling:touch;
}

.quick{
    padding:8px 11px;
    white-space:nowrap;
    background:#eef2f7;
    color:#0f172a;
}

.quick.reason-ferie{color:#a51428}
.quick.reason-malattia{color:#934100}
.quick.reason-permesso{color:#5b21b6}
.quick.reason-rol{color:#075985}

.sheet-actions{
    display:flex;
    gap:10px;
    justify-content:flex-end;
    margin-top:12px;
}

.history-box{
    font-size:12px;
    margin-top:8px;
}

.history-item{
    padding:7px;
    border-bottom:1px solid #e2e8f0;
}

.autocomplete{
    position:relative;
}

.suggestions{
    display:none;
    position:absolute;
    left:0;
    right:0;
    top:100%;
    z-index:140;
    max-height:220px;
    overflow:auto;
    background:#fff;
    border:1px solid #b9c5d3;
    border-radius:8px;
    box-shadow:0 8px 24px rgba(0,0,0,.15);
}

.suggestions.open{
    display:block;
}

.suggestion{
    padding:9px 10px;
    border-bottom:1px solid #edf2f7;
    cursor:pointer;
}

.suggestion:last-child{
    border-bottom:0;
}

.suggestion small{
    display:block;
    color:#64748b;
    margin-top:2px;
}

.admin-main{
    padding:12px;
}

.admin-tabs{
    display:flex;
    gap:7px;
    overflow-x:auto;
    margin-bottom:10px;
    -webkit-overflow-scrolling:touch;
}

.admin-tabs a{
    text-decoration:none;
    color:var(--blue);
    background:#fff;
    border:1px solid #b8c8da;
    padding:9px 11px;
    border-radius:8px;
    white-space:nowrap;
    font-size:12px;
    font-weight:800;
}

.admin-tabs a.active{
    background:var(--blue);
    color:#fff;
}

.admin-card{
    background:#fff;
    padding:13px;
    border-radius:12px;
    box-shadow:0 3px 14px rgba(0,0,0,.07);
}

.full-width{
    width:100%;
}

.admin-card h2{
    color:var(--blue);
    margin:0 0 8px;
}

.admin-title-row{
    display:flex;
    gap:10px;
    justify-content:space-between;
    align-items:flex-start;
}

.search-form{
    display:flex;
    gap:6px;
    align-items:center;
}

.search-form input{
    margin:0;
}

.admin-edit{
    display:grid;
    grid-template-columns:minmax(180px,2.4fr) minmax(130px,1fr) 85px 96px 62px 82px;
    gap:7px;
    align-items:center;
    padding:7px 0;
    border-top:1px solid #edf2f7;
}

.admin-edit input,
.admin-edit select{
    margin:0;
}

.admin-edit.new-item{
    padding:10px;
    margin:8px 0 12px;
    border:1px solid #bad0e5;
    border-radius:9px;
    background:#f5faff;
}

.user-edit{
    grid-template-columns:
        minmax(160px,1.5fr)
        minmax(130px,1fr)
        85px
        minmax(145px,1fr)
        minmax(160px,1fr)
        90px
        82px;
}

.checkline{
    display:flex!important;
    align-items:center;
    gap:5px;
    margin:0!important;
    font-size:11px!important;
}

.checkline input{
    width:auto;
    margin:0;
}

.pdf-area{
    position:fixed;
    left:-12000px;
    top:0;
    width:210mm;
    background:#fff;
}

.pdf-area.pdf-rendering{
    position:static;
    left:auto;
    top:auto;
    width:210mm;
}

.pdf-page{
    width:210mm;
    height:297mm;
    padding:8mm 7mm 7mm;
    background:#fff;
    color:#111827;
    page-break-after:always;
    break-after:page;
    overflow:hidden;
    font-family:Arial,Helvetica,sans-serif;
}

.pdf-page:last-child{
    page-break-after:auto;
    break-after:auto;
}

.pdf-title{
    text-align:center;
    color:#0054a6;
    font-size:18pt;
    line-height:1;
    font-weight:800;
    margin:0 0 3.5mm;
    text-transform:uppercase;
}

.pdf-subtitle{
    text-align:center;
    color:#222;
    font-size:8.2pt;
    line-height:1.1;
    margin:0 0 3.2mm;
}

.pdf-table{
    border-collapse:collapse;
    table-layout:fixed;
    width:100%;
    font-size:6.15pt;
    color:#084f90;
}

.pdf-table th,
.pdf-table td{
    border:.35mm solid #8a8a8a;
    padding:.7mm .55mm;
    vertical-align:middle;
    text-align:center;
    line-height:1.08;
    overflow-wrap:anywhere;
    word-break:normal;
}

.pdf-table thead th,
.pdf-table tfoot th{
    height:5.1mm;
    background:#0054a6;
    color:#fff;
    font-size:6.2pt;
    font-weight:800;
    padding:.55mm .45mm;
}

.pdf-table tbody td{
    height:6.05mm;
    background:#fff;
    font-weight:650;
}

.pdf-table .pdf-date{
    width:24mm;
    color:#0054a6;
    font-weight:800;
    white-space:nowrap;
}

.pdf-table thead .pdf-date,
.pdf-table tfoot .pdf-date{
    color:#fff;
}

.pdf-table tbody tr.pdf-current-week td{
    background:#fffed7;
}

.pdf-table tbody tr.pdf-today td{
    background:#e9f7ed;
    border-top:.45mm solid #2e7d32;
    border-bottom:.45mm solid #2e7d32;
}

.pdf-table tbody tr.pdf-today td.pdf-date{
    border-left:1.7mm solid #2e7d32;
}

.pdf-table tbody tr.pdf-sunday td{
    background:#d5d5d5!important;
    color:#333;
}

.pdf-today-tag{
    display:inline-block;
    margin-top:.4mm;
    padding:.15mm .9mm;
    border-radius:1mm;
    background:#2e7d32;
    color:#fff;
    font-size:5.1pt;
    line-height:1.15;
    font-weight:900;
}

.pdf-table td.reason-ferie{
    background:#ffc9cc!important;
    color:#c21f24!important;
    font-weight:800;
}

.pdf-table td.reason-malattia{
    background:#ffe2a8!important;
    color:#9a4900!important;
    font-weight:800;
    box-shadow:inset 0 0 0 .35mm #df8a1b;
}

.pdf-table td.reason-permesso{
    background:#eadfff!important;
    color:#5b21b6!important;
    font-weight:800;
}

.pdf-table td.reason-rol{
    background:#d8eefc!important;
    color:#075985!important;
    font-weight:800;
}

.pdf-table td.reason-generic{
    background:#fff2b7!important;
    color:#6b5600!important;
    font-weight:800;
}

.pdf-empty{
    margin:20mm auto 0;
    width:80%;
    border:1px solid #d7e0e9;
    border-radius:10px;
    padding:10mm;
    text-align:center;
    color:#64748b;
}

.month-dialog-backdrop{
    position:fixed;
    inset:0;
    display:none;
    z-index:105;
    background:rgba(15,23,42,.42);
}

.month-dialog-backdrop.open{
    display:block;
}

.month-dialog{
    position:fixed;
    z-index:110;
    left:50%;
    top:50%;
    transform:translate(-50%,-46%) scale(.98);
    width:min(430px,calc(100% - 24px));
    background:#fff;
    border-radius:16px;
    padding:12px 16px 16px;
    box-shadow:0 18px 60px rgba(0,0,0,.25);
    opacity:0;
    visibility:hidden;
    transition:.16s ease;
}

.month-dialog.open{
    transform:translate(-50%,-50%) scale(1);
    opacity:1;
    visibility:visible;
}

@media(max-width:760px){
    .topbar h1{font-size:15px}
    .topbar{align-items:flex-start}
    .topbar nav{gap:4px}
    .topbar nav a,.nav-button{padding:8px 8px;font-size:10px}
    .monthbar{top:53px}
    .monthbar .month-current{
        padding:6px 9px;
    }
    .month-current-label{
        display:none;
    }
    .month-create-button{
        min-height:40px;
    }
    main{padding:7px}
    .panel{padding:6px}
    .panel-title h2{font-size:17px}
    .table-wrap{max-height:calc(100vh - 160px)}
    .schedule th,.schedule td{min-width:112px;max-width:142px}
    .schedule .date-col{min-width:92px;max-width:92px}
    .admin-title-row{flex-direction:column}
    .search-form{width:100%}
    .admin-edit,
    .user-edit{
        grid-template-columns:1fr;
        padding:10px 0;
    }
    .admin-edit.new-item{
        padding:10px;
    }
    .small,.primary,.secondary{
        min-height:42px;
    }
    input,select,textarea{
        min-height:44px;
        font-size:16px;
    }
}
