/* === Rotazione Zone Dialisi — Tema Sanitario === */

:root {
    --medical-blue: #1a5276;
    --medical-dark: #0d3b56;
    --scrubs-teal: #117a65;
    --scrubs-green: #229954;
    --sterile-white: #fefefe;
    --gauze: #f4f6f8;
    --plaster: #e8ecf0;
    --bandage: #d5dbdb;
    --betadine: #c0392b;
    --saline: #2e86c1;
    --iodine: #f39c12;
    --oxygen: #27ae60;
    --text: #1c2833;
    --text-light: #5d6d7e;
    --radius: 10px;
    --shadow: 0 2px 12px rgba(26,82,118,0.08);
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: linear-gradient(135deg, #e8f0f8 0%, #f0f4f8 50%, #eaf2f8 100%);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === Pattern sottile di sfondo === */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image:
        radial-gradient(circle at 20% 50%, rgba(46,134,193,0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(17,122,101,0.03) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* === Header === */
header {
    background: linear-gradient(135deg, var(--medical-blue) 0%, var(--medical-dark) 100%);
    color: white;
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    position: relative;
    z-index: 1;
    box-shadow: 0 2px 16px rgba(13,59,86,0.15);
}
header h1 {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 10px;
}
header h1 .cross-icon {
    display: inline-block;
    width: 28px; height: 28px;
    background: var(--betadine);
    border-radius: 4px;
    position: relative;
}
header h1 .cross-icon::before,
header h1 .cross-icon::after {
    content: '';
    position: absolute;
    background: white;
}
header h1 .cross-icon::before {
    width: 4px; height: 18px;
    top: 5px; left: 12px;
}
header h1 .cross-icon::after {
    width: 18px; height: 4px;
    top: 12px; left: 5px;
}
.header-right { display: flex; align-items: center; gap: 12px; }
.status-dot { font-size: 1.3rem; }
.status-dot.online { color: #2ecc71; filter: drop-shadow(0 0 6px #2ecc7188); }
.status-dot.offline { color: #e74c3c; }

/* === Nav === */
nav {
    background: var(--medical-dark);
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0;
    border-bottom: 4px solid var(--scrubs-teal);
    position: relative;
    z-index: 1;
}
.nav-btn {
    background: none;
    border: none;
    color: #aab7c4;
    padding: 13px 18px;
    font-size: 0.87rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    font-family: var(--font);
    border-bottom: 3px solid transparent;
    margin-bottom: -4px;
}
.nav-btn:hover {
    color: white;
    background: rgba(255,255,255,0.06);
}
.nav-btn.active {
    color: white;
    background: rgba(255,255,255,0.12);
    border-bottom-color: var(--scrubs-teal);
    font-weight: 600;
}

/* === Main === */
main {
    flex: 1;
    padding: 20px;
    max-width: 1440px;
    margin: 0 auto;
    width: 100%;
    position: relative;
    z-index: 1;
}

.tab { display: none; }
.tab.active { display: block; animation: fadeSlide 0.3s ease; }

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

.card {
    background: var(--sterile-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 16px;
    border: 1px solid var(--plaster);
    border-left: 4px solid var(--medical-blue);
}
.card h2 {
    margin-bottom: 14px;
    font-size: 1.2rem;
    color: var(--medical-blue);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card h3 {
    margin: 16px 0 10px;
    font-size: 1rem;
    color: var(--medical-dark);
}
.card p { margin-bottom: 8px; color: var(--text-light); font-size: 0.9rem; }

/* === Statistiche card special === */
#tab-stats .card {
    border-left-color: var(--scrubs-teal);
    background: linear-gradient(white, #f9fdfb);
}

/* === Form elements === */
.form-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.form-row label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--medical-dark);
}
input[type="date"],
input[type="number"],
input[type="password"],
select {
    padding: 9px 14px;
    border: 1.5px solid var(--bandage);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: var(--font);
    background: var(--sterile-white);
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--saline);
    box-shadow: 0 0 0 3px rgba(46,134,193,0.12);
}

.btn {
    padding: 10px 20px;
    border: 1.5px solid var(--bandage);
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: var(--font);
    font-weight: 500;
    transition: all 0.18s;
    color: var(--text);
}
.btn:hover {
    background: var(--gauze);
    border-color: var(--saline);
}
.btn-primary {
    background: var(--medical-blue);
    color: white;
    border-color: var(--medical-blue);
    box-shadow: 0 2px 8px rgba(26,82,118,0.25);
}
.btn-primary:hover {
    background: var(--medical-dark);
    border-color: var(--medical-dark);
}
.btn-stats {
    background: var(--scrubs-teal);
    color: white;
    border-color: var(--scrubs-teal);
    box-shadow: 0 2px 8px rgba(17,122,101,0.25);
}
.btn-stats:hover {
    background: #0d5c4a;
}
.btn-group { display: flex; gap: 12px; flex-wrap: wrap; }
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

/* === Upload === */
.upload-area {
    border: 2.5px dashed var(--bandage);
    border-radius: var(--radius);
    padding: 36px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s;
    margin: 14px 0;
    background: var(--gauze);
}
.upload-area:hover, .upload-area.drag-over {
    border-color: var(--saline);
    background: #eaf2fc;
    box-shadow: 0 0 0 6px rgba(46,134,193,0.06);
}
.upload-icon { font-size: 3.2rem; display: block; margin-bottom: 10px; }
.upload-placeholder p { font-size: 1rem; margin-bottom: 5px; color: var(--text); }
.upload-placeholder small { color: var(--text-light); }
.upload-progress { display: flex; align-items: center; justify-content: center; gap: 12px; }

.spinner {
    width: 26px; height: 26px;
    border: 3px solid var(--plaster);
    border-top-color: var(--saline);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Tables === */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 62vh;
    overflow-y: auto;
    border: 1px solid var(--plaster);
    border-radius: 8px;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
    min-width: 700px;
}
th, td {
    padding: 7px 9px;
    border: 1px solid var(--plaster);
    text-align: center;
    white-space: nowrap;
}
th {
    background: var(--medical-blue);
    color: white;
    position: sticky;
    top: 0;
    z-index: 2;
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.3px;
}
tr:nth-child(even) { background: #f9fbfc; }
tr:hover { background: #eef4fa; }

.cell-assignable { background: #d5f5e3; }
.cell-velina { background: #fef5e7; }
.cell-excluded { background: #fadbd8; }
.cell-manual { border-left: 4px solid var(--iodine); }
.cell-locked { border-left: 4px solid var(--betadine); }
.cell-auto { border-left: 4px solid var(--oxygen); }

/* === Placeholder === */
.placeholder-text {
    color: var(--text-light);
    text-align: center;
    padding: 36px;
    font-style: italic;
}

/* === Anomalies === */
#anomalies-box {
    background: #fef9e7;
    border: 1.5px solid #f9e79f;
    border-radius: var(--radius);
    padding: 14px;
    margin-top: 14px;
    border-left: 4px solid var(--iodine);
}
#anomalies-box h3 { color: #7d6608; margin-bottom: 6px; }
#anomalies-list { list-style: none; padding: 0; }
#anomalies-list li {
    padding: 5px 0;
    border-bottom: 1px solid #fdebd0;
    font-size: 0.85rem;
}

/* === Warnings === */
.warning-text {
    color: var(--iodine);
    font-weight: 600;
    padding: 10px 14px;
    background: #fef9e7;
    border-radius: 6px;
    margin-bottom: 12px;
    border-left: 4px solid var(--iodine);
}
#generate-warnings {
    margin-top: 14px;
    padding: 12px;
    border-radius: 6px;
    border-left: 4px solid;
}
#generate-warnings.warn {
    background: #fef9e7;
    border-color: var(--iodine);
    color: #7d6608;
}
#generate-warnings.error {
    background: #fdedec;
    border-color: var(--betadine);
    color: #922b21;
}

/* === Password Modal === */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(13,59,86,0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
    background: white;
    border-radius: 16px;
    padding: 32px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    border-top: 5px solid var(--scrubs-teal);
}
.modal-box .modal-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}
.modal-box h2 {
    color: var(--medical-dark);
    margin-bottom: 8px;
    font-size: 1.3rem;
}
.modal-box p {
    color: var(--text-light);
    margin-bottom: 20px;
    font-size: 0.9rem;
}
.modal-box input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 14px;
    font-size: 1rem;
    text-align: center;
    letter-spacing: 4px;
}
.modal-box .modal-error {
    color: var(--betadine);
    font-size: 0.85rem;
    margin-bottom: 10px;
    min-height: 20px;
}
.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* === Toast === */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 22px;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    z-index: 9999;
    transition: all 0.3s;
    font-family: var(--font);
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}
.toast.success { background: var(--oxygen); }
.toast.error { background: var(--betadine); }
.toast.warning { background: var(--iodine); }

/* === Footer === */
footer {
    text-align: center;
    padding: 14px;
    color: var(--text-light);
    font-size: 0.82rem;
    background: var(--sterile-white);
    border-top: 1px solid var(--plaster);
    position: relative;
    z-index: 1;
}

/* === Legend === */
.legend-text {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 8px;
}
.legend-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-right: 4px;
    vertical-align: middle;
}

/* === Schedule Day Colors & Shift Badge === */
.shift-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}
.shift-mattina {
    background: #fef9e7;
    color: #b7950b;
    border: 1px solid #f9e79f;
}
.shift-pomeriggio {
    background: #eaf2f8;
    color: #2471a3;
    border: 1px solid #aed6f1;
}
td.schedule-cell {
    transition: background 0.15s;
}
td.schedule-cell:hover {
    filter: brightness(0.93);
    outline: 2px solid var(--saline);
    outline-offset: -1px;
    z-index: 1;
    position: relative;
}

/* === Stats === */
.stats-table { min-width: 800px; }
.stats-table th { font-size: 0.76rem; }
.stats-bar {
    height: 14px;
    border-radius: 7px;
    background: linear-gradient(90deg, var(--scrubs-teal), var(--oxygen));
    min-width: 4px;
    transition: width 0.4s ease;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

/* === Hidden === */
.hidden { display: none !important; }

/* === Quick Dropdown === */
.quick-dropdown {
    position: absolute;
    z-index: 10000;
    background: white;
    border: 2px solid var(--saline);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(26,82,118,0.2);
    max-height: 320px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.dropdown-search {
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-bottom: 1.5px solid var(--plaster);
    font-size: 0.88rem;
    font-family: var(--font);
    outline: none;
    background: var(--gauze);
}
.dropdown-search:focus {
    background: white;
}
.dropdown-items {
    overflow-y: auto;
    max-height: 260px;
}
.dropdown-item {
    padding: 8px 14px;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--gauze);
    transition: background 0.1s;
    display: flex;
    align-items: center;
    gap: 10px;
}
.dropdown-item:hover {
    background: #e8f0fa;
}
.dropdown-item .dd-code {
    font-weight: 700;
    color: var(--medical-blue);
    min-width: 40px;
    font-size: 0.9rem;
}
.dropdown-item .dd-desc {
    color: var(--text-light);
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === Login Screen === */
#login-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 99999;
    background: linear-gradient(135deg, #0d3b56 0%, #1a5276 40%, #154360 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}
.login-card {
    background: white;
    border-radius: 16px;
    padding: 36px 28px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-icon {
    margin-bottom: 16px;
}
.cross-icon-large {
    display: inline-block;
    width: 48px; height: 48px;
    background: var(--betadine);
    border-radius: 8px;
    position: relative;
}
.cross-icon-large::before,
.cross-icon-large::after {
    content: '';
    position: absolute;
    background: white;
}
.cross-icon-large::before {
    width: 6px; height: 28px;
    top: 10px; left: 21px;
}
.cross-icon-large::after {
    width: 28px; height: 6px;
    top: 21px; left: 10px;
}
.login-card h1 {
    color: var(--medical-dark);
    font-size: 1.3rem;
    margin-bottom: 6px;
}
.login-subtitle {
    color: var(--text-light);
    font-size: 0.85rem;
    margin-bottom: 22px;
}
.login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.login-form input[type="password"] {
    width: 100%;
    padding: 14px 18px;
    font-size: 1.1rem;
    text-align: center;
    letter-spacing: 6px;
    border: 2px solid var(--bandage);
    border-radius: 10px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.login-form input[type="password"]:focus {
    border-color: var(--medical-blue);
    box-shadow: 0 0 0 4px rgba(26,82,118,0.1);
    outline: none;
}
.login-error {
    color: var(--betadine);
    font-size: 0.85rem;
    min-height: 20px;
}
.login-btn {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
}

/* === Logout button === */
.btn-logout {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}
.btn-logout:hover {
    background: rgba(255,255,255,0.2);
}

/* === Reset Section === */
.reset-section {
    text-align: center;
    margin-top: 20px;
    padding: 14px;
    border-top: 1px solid var(--plaster);
}
.reset-section small {
    display: block;
    margin-top: 6px;
    color: var(--text-light);
    font-size: 0.78rem;
}
.btn-reset {
    background: transparent;
    color: var(--betadine);
    border: 1.5px solid var(--betadine);
    padding: 10px 20px;
    font-size: 0.85rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-reset:hover {
    background: var(--betadine);
    color: white;
}

/* === Camera Section === */
.camera-section {
    text-align: center;
    margin: 14px 0;
    padding: 16px;
    background: var(--gauze);
    border-radius: var(--radius);
    border: 1.5px dashed var(--bandage);
}
.camera-section small {
    display: block;
    margin-top: 8px;
    color: var(--text-light);
    font-size: 0.8rem;
}
.btn-camera {
    background: var(--scrubs-teal);
    color: white;
    border: none;
    padding: 14px 28px;
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 14px rgba(17,122,101,0.3);
    transition: all 0.2s;
    cursor: pointer;
}
.btn-camera:hover {
    background: #0d5c4a;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(17,122,101,0.4);
}
.btn-camera:active {
    transform: translateY(0);
}
.camera-icon {
    font-size: 1.4rem;
}

/* On desktop, show subtle hint that camera works on mobile */
@media (hover: hover) {
    .camera-section::after {
        content: '📱 Su smartphone apre la fotocamera';
        display: block;
        font-size: 0.72rem;
        color: var(--text-light);
        margin-top: 4px;
        opacity: 0.7;
    }
}

/* === Editable cells === */
td[contenteditable="true"]:focus {
    outline: 2.5px solid var(--saline);
    background: #fff;
    border-radius: 2px;
}
td.editable { cursor: text; background: #fefefe; }

/* === Responsive === */
@media (max-width: 768px) {
    main { padding: 10px; }
    .card { padding: 14px; }
    .nav-btn { padding: 11px 13px; font-size: 0.78rem; }
    header h1 { font-size: 1.15rem; }
    th, td { padding: 5px 6px; font-size: 0.72rem; }
}

@media (max-width: 480px) {
    nav { flex-wrap: wrap; }
    .nav-btn { flex: 1 0 auto; text-align: center; padding: 9px 7px; font-size: 0.7rem; }
    .upload-area { padding: 18px; }
    .modal-box { padding: 20px; }
}
