/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #0078d4;
    --primary-dark: #005a9e;
    --primary-light: #deecf9;
    --success: #107c10;
    --warning: #ffb900;
    --danger: #d13438;
    --bg: #f3f2f1;
    --surface: #ffffff;
    --text: #323130;
    --text-secondary: #605e5c;
    --border: #edebe9;
    --border-dark: #c8c6c4;
    --radius: 6px;
    --shadow: 0 2px 4px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* === Screens === */
.screen { display: none; }
.screen.active { display: block; }

/* === Login === */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0078d4 0%, #005a9e 100%);
}

.login-card {
    background: var(--surface);
    padding: 48px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    max-width: 420px;
    width: 90%;
}

.login-card h1 {
    font-size: 28px;
    margin-bottom: 8px;
    color: var(--text);
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px solid var(--border-dark);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn:hover { background: var(--bg); }

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-large { padding: 12px 24px; font-size: 16px; }

.btn-sm { padding: 4px 12px; font-size: 13px; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* === Header === */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--primary);
    color: white;
}

.app-header h1 { font-size: 20px; font-weight: 600; }

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info { font-size: 14px; opacity: 0.9; }

#btn-logout {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.3);
    color: white;
}

#btn-logout:hover { background: rgba(255,255,255,0.25); }

/* === Tab Navigation === */
.tab-nav {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
}

.tab-btn {
    padding: 14px 20px;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.15s;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content { display: none; padding: 24px; }
.tab-content.active { display: block; }

/* === Cards === */
.section-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.section-card h2 {
    font-size: 18px;
    margin-bottom: 12px;
    color: var(--text);
}

.hint {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* === Forms === */
.form-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

select, input[type="text"], input[type="number"] {
    padding: 8px 12px;
    border: 1px solid var(--border-dark);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
}

select:focus, input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

/* === Upload Area === */
.upload-area {
    position: relative;
    border: 2px dashed var(--border-dark);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    transition: all 0.2s;
}

.upload-area.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-area.uploaded {
    border-color: var(--success);
    border-style: solid;
}

.upload-area input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    pointer-events: none;
}

.upload-icon { font-size: 32px; }

.upload-status {
    margin-top: 12px;
    font-size: 13px;
    font-weight: 600;
}

.upload-status.success { color: var(--success); }
.upload-status.error { color: var(--danger); }

/* === Table Wrapper === */
.table-container { padding: 0; overflow: hidden; }

#table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 65vh;
    position: relative;
}

.empty-state {
    padding: 48px;
    text-align: center;
    color: var(--text-secondary);
}

/* === Pivot Table === */
.pivot-table {
    border-collapse: collapse;
    font-size: 12px;
    white-space: nowrap;
    min-width: 100%;
    table-layout: fixed;
}

/* Header sticky in alto */
.pivot-table thead tr {
    position: sticky;
    top: 0;
    z-index: 3;
}

.pivot-table th {
    background: var(--primary);
    color: white;
    padding: 5px 3px;
    text-align: center;
    font-weight: 600;
    border: 1px solid rgba(255,255,255,0.15);
    line-height: 1.3;
}

.pivot-table th small { font-size: 10px; font-weight: 400; opacity: 0.9; }

.pivot-table td {
    border: 1px solid #ddd;
    text-align: center;
    padding: 2px 2px;
    height: 34px;
    vertical-align: middle;
    font-size: 11px;
}

/* Colonne fisse a sinistra */
.col-matr {
    width: 50px;
    min-width: 50px;
    max-width: 50px;
}

.col-nome {
    width: 130px;
    min-width: 130px;
    max-width: 130px;
    text-align: left !important;
    padding-left: 8px !important;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sticky: prima colonna */
th.sticky-col1,
td.sticky-col1 {
    position: sticky;
    left: 0;
    z-index: 2;
}

/* Sticky: seconda colonna */
th.sticky-col2,
td.sticky-col2 {
    position: sticky;
    left: 50px;
    z-index: 2;
}

/* Z-index extra per header sticky */
thead th.sticky-col1,
thead th.sticky-col2 {
    z-index: 4;
}

td.sticky-col1,
td.sticky-col2 {
    background: #fff;
    box-shadow: 2px 0 4px rgba(0,0,0,0.06);
}

/* Colonne giorno */
.col-day {
    width: 38px;
    min-width: 38px;
    max-width: 46px;
}

/* Header weekend */
.col-we-hdr { background: #4a6fa5 !important; }

/* Colonna totale */
.col-tot {
    width: 58px;
    min-width: 58px;
    font-weight: 700;
    background: var(--primary-light) !important;
    font-size: 12px;
}

/* === Colori celle === */
.cell-ordi      { background: #ffffff; }
.cell-smart     { background: #d4edda; }
.cell-fuori-sede{ background: #fff8e1; border-left: 3px solid #ffc107; }
.cell-smart-fs  { background: #d4edda; border-left: 3px solid #ffc107; } /* Smart + Fuori Sede */
.cell-ferie     { background: #fff3cd; }
.cell-malattia{ background: #f8d7da; }
.cell-riposo  { background: #fde8d1; }
.cell-weekend { background: #e5e5e5; color: #aaa; }
.cell-empty   { background: #fafafa; }
.cell-assenza { background: #e2d9f3; }

/* Testo nelle celle */
.cell-ore {
    display: block;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.3;
    color: #222;
}

.cell-init {
    display: block;
    font-size: 10px;
    color: #666;
    line-height: 1.1;
}

.cell-stra {
    display: block;
    color: var(--danger);
    font-size: 9px;
    font-weight: 600;
    line-height: 1.1;
}

.cell-tkt {
    display: inline-block;
    color: #2e7d32;
    font-size: 10px;
    line-height: 1;
    margin-top: 1px;
}

.cell-rimb {
    display: inline-block;
    color: #e65100;
    font-size: 10px;
    line-height: 1;
    margin-top: 1px;
}

.cell-bonus {
    display: inline-block;
    color: #1565c0;
    font-size: 10px;
    line-height: 1;
    margin-top: 1px;
    margin-left: 2px;
}

.cell-bonus-inline {
    color: #1565c0;
    font-weight: 600;
    font-size: 0.85em;
    margin-left: 1px;
    white-space: nowrap;
}

.col-straord { color: var(--danger); }
.col-ticket  { color: #2e7d32; }
.col-bonus   { color: #1565c0; }
.col-magg    { color: #4527a0; }

/* === Riepilogo Stat Card === */
.stat-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    text-align: center;
    font-size: 13px;
}

.stat-card strong {
    display: block;
    font-size: 20px;
    color: var(--primary);
    margin-bottom: 2px;
}

/* === Legenda === */
.legenda {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    font-size: 13px;
}

.leg-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.leg-box {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid var(--border-dark);
    flex-shrink: 0;
}

.leg-box.ordi     { background: #ffffff; }
.leg-box.smart      { background: #d4edda; }
.leg-box.fuori-sede { background: #fff8e1; border-left: 3px solid #ffc107; }
.leg-box.smart-fs   { background: #d4edda; border-left: 3px solid #ffc107; } /* Smart + Fuori Sede */
.leg-box.visita     { background: #cce5ff; }
.leg-box.ferie    { background: #fff3cd; }
.leg-box.malattia { background: #f8d7da; }
.leg-box.riposo   { background: #fde8d1; }
.leg-box.weekend  { background: #e5e5e5; }

.legenda-card { padding: 12px 24px !important; }

/* === Toolbar === */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* === Export === */
.export-options {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    margin: 24px 0;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius);
}

/* === Toast === */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius);
    color: white;
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-box {
    background: var(--surface);
    border-radius: 10px;
    padding: 32px 36px;
    max-width: 420px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    text-align: center;
    animation: modal-in 0.18s ease;
}

@keyframes modal-in {
    from { transform: scale(0.92); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

.modal-icon {
    font-size: 36px;
    margin-bottom: 12px;
    color: var(--warning);
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text);
}

.modal-msg {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 24px;
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover { background: #b52d31; }

.btn-secondary {
    background: #6c757d;
    color: white;
    border-color: #6c757d;
}

.btn-secondary:hover { background: #545b62; }

/* Spinner import in corso */
.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.75;
}

/* === Responsive === */
@media (max-width: 768px) {
    .form-row { flex-direction: column; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-actions { flex-direction: column; }
    .tab-nav { overflow-x: auto; }
    .app-header { padding: 12px 16px; }
    .tab-content { padding: 16px; }
}
