/* ==========================================================================
   DESIGN SYSTEM & MODERN STYLING (DARK THEME & GLASSMORPHISM)
   ========================================================================== */

:root {
    /* Color Palette */
    --bg-main: #0f172a;        /* Deep Slate */
    --bg-sidebar: #1e293b;     /* Slate 800 */
    --bg-card: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --primary: #6366f1;        /* Indigo */
    --primary-hover: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.15);
    
    --success: #10b981;        /* Emerald (Ore Svolte) */
    --success-light: rgba(16, 185, 129, 0.15);
    
    --warning: #f59e0b;        /* Amber (Ore Preventivate) */
    --warning-light: rgba(245, 158, 11, 0.15);
    
    --danger: #ef4444;         /* Red */
    --danger-hover: #dc2626;
    
    --font-family: 'Outfit', sans-serif;
    
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 80px;
    --topbar-height: 70px;
    
    --transition-speed: 0.25s;
    --border-radius: 12px;
}

/* Light Theme Variables */
.light-theme {
    --bg-main: #f8fafc;
    --bg-sidebar: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.8);
    --border-color: rgba(0, 0, 0, 0.08);
    --text-main: #0f172a;
    --text-muted: #64748b;
    
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: rgba(79, 70, 229, 0.1);
    
    --border-color: #e2e8f0;
}

/* ==========================================================================
   BASE & LAYOUT STYLES
   ========================================================================== */

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: 14px;
    color: inherit;
}

/* Hide helper classes */
.hidden {
    display: none !important;
}

/* Glassmorphism card effect */
.glass {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
}

.glass-accent {
    background: var(--primary-light);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: var(--border-radius);
    padding: 15px;
}

/* ==========================================================================
   LOGIN VIEW
   ========================================================================== */

#login-view {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background: radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.15) 0%, transparent 40%),
                radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.1) 0%, transparent 40%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 40px 30px;
    border-radius: 16px;
    animation: fadeInUp 0.5s ease;
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
}

.logo-icon {
    font-size: 32px;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 14px;
}

.login-footer {
    text-align: center;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
}

.login-footer code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--primary);
}

/* ==========================================================================
   APP MAIN LAYOUT
   ========================================================================== */

#main-layout {
    display: flex;
    min-height: 100vh;
}

/* SIDEBAR STYLES */
.sidebar {
    width: var(--sidebar-width);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-left: none;
    display: flex;
    flex-direction: column;
    transition: width var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
    background-color: var(--bg-sidebar);
}

.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-title-text {
    font-size: 18px;
    font-weight: 600;
    white-space: nowrap;
    transition: opacity var(--transition-speed);
}

.btn-toggle-sidebar {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 5px;
    border-radius: 6px;
    transition: background 0.2s;
}

.btn-toggle-sidebar:hover {
    background: rgba(255, 255, 255, 0.08);
}

.sidebar-user {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary-light);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity var(--transition-speed);
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.user-role {
    font-size: 12px;
    color: var(--text-muted);
}

.sidebar-nav {
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-grow: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    background: none;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    position: relative;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.nav-btn.active {
    background: var(--primary);
    color: #ffffff;
    font-weight: 500;
}

.nav-icon {
    font-size: 18px;
    width: 24px;
    display: flex;
    justify-content: center;
}

.nav-text {
    font-size: 14px;
    white-space: nowrap;
    transition: opacity var(--transition-speed);
}

.sidebar-footer {
    padding: 15px 10px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-footer-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 15px;
    background: none;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}

.sidebar-footer-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.logout-btn:hover {
    background: var(--danger-hover) !important;
    color: #ffffff;
}

/* Collapsed Sidebar Logic */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .sidebar-title-text,
.sidebar.collapsed .user-info,
.sidebar.collapsed .nav-text {
    opacity: 0;
    pointer-events: none;
    width: 0;
}

.sidebar.collapsed .sidebar-user {
    justify-content: center;
}

/* MAIN CONTENT CONTAINER */
.main-content {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed + .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

/* TOP BAR */
.top-bar {
    height: var(--topbar-height);
    position: sticky;
    top: 0;
    right: 0;
    z-index: 99;
    display: flex;
    align-items: center;
    padding: 0 30px;
    border-radius: 0;
    border-top: none;
    border-right: none;
    border-left: none;
    background: rgba(15, 23, 42, 0.6);
}

.top-bar h2 {
    font-size: 18px;
    font-weight: 600;
}

#btn-sidebar-toggle {
    display: none; /* Visible only on mobile */
    margin-right: 15px;
}

/* CONTENT CONTAINER */
.content-container {
    padding: 30px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    flex-grow: 1;
}

/* ==========================================================================
   UI COMPONENTS (FORMS, BUTTONS, TABLES, CARDS)
   ========================================================================== */

/* CARDS */
.card {
    padding: 25px;
    margin-bottom: 25px;
    border-radius: var(--border-radius);
    animation: fadeInUp 0.4s ease;
}

.card h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 5px;
}

.card-desc {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 20px;
}

.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
}

.card-header-row h3 {
    margin-bottom: 0;
}

/* STAT CARDS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.stat-card {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    border-radius: var(--border-radius);
    animation: fadeInUp 0.4s ease;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-icon.green { background: var(--success-light); }
.stat-icon.blue { background: var(--primary-light); }
.stat-icon.yellow { background: var(--warning-light); }
.stat-icon.purple { background: rgba(168, 85, 247, 0.15); }

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

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
}

.stat-content h3 {
    font-size: 22px;
    font-weight: 700;
    margin-top: 2px;
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn-success {
    background: var(--success);
    color: #ffffff;
}

.btn-success:hover {
    background: #0d9488;
}

.btn-danger {
    background: var(--danger);
    color: #ffffff;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-icon {
    padding: 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
}

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

/* FORMS */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="time"],
select,
textarea {
    width: 100%;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-row {
    display: flex;
    gap: 15px;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.flex-3 { flex: 3; }

.inline-form {
    display: flex;
    gap: 15px;
    align-items: flex-end;
}

.inline-form .form-group {
    margin-bottom: 0;
}

/* TABLES */
.table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

.data-table th, .data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: rgba(255, 255, 255, 0.02);
    font-weight: 600;
    color: var(--text-muted);
}

.data-table tbody tr {
    transition: background 0.15s;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.text-center {
    text-align: center;
}

/* BADGES */
.badge {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.badge-preventivata {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-svolta {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-attiva {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-terminata {
    background: rgba(148, 163, 184, 0.15);
    color: var(--text-muted);
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.badge-container {
    display: flex;
    gap: 8px;
}

/* FILTER GRID */
.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    align-items: flex-end;
}

.filter-grid .form-group {
    margin-bottom: 0;
}

.filter-actions {
    display: flex;
    justify-content: flex-end;
}

/* GRID LAYOUTS */
.grid-2col {
    display: grid;
    grid-template-columns: 1.3fr 0.7fr;
    gap: 25px;
}

.planned-top10-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ==========================================================================
   VIEW SECTIONS (SPA STRUCTURE)
   ========================================================================== */

.view-section {
    display: none;
    animation: fadeIn 0.4s ease;
}

.view-section.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 30px;
}

.section-header h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.section-desc {
    color: var(--text-muted);
    font-size: 14px;
}

.action-row {
    display: flex;
    gap: 10px;
}

/* ==========================================================================
   CALENDAR VIEW STYLING
   ========================================================================== */

.calendar-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    padding: 15px 25px;
    margin-bottom: 20px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

#calendar-title {
    font-size: 18px;
    font-weight: 600;
    min-width: 140px;
    text-align: center;
}

.btn-toggle {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
}

.btn-toggle.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.input-small {
    padding: 6px 10px;
    font-size: 13px;
    border-radius: 6px;
    width: auto;
}

.calendar-container {
    padding: 20px;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 10px;
    font-size: 13px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: minmax(140px, auto);
    gap: 8px;
}

/* VISTA SETTIMANALE: ALLUNGA LE CASELLE IN ALTEZZA SENZA TAGLI */
.calendar-grid.week-view-container {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: minmax(160px, auto);
    gap: 10px;
}

.calendar-grid.week-view-container .calendar-day {
    height: auto;
    min-height: 160px;
    overflow: visible;
}

.calendar-grid.week-view-container .events-list {
    overflow-y: visible;
    max-height: none;
}

.calendar-grid.week-view-container .event-pill {
    white-space: normal;
    word-break: break-word;
}

/* VISTA MENSILE COME ELENCO (AGENDA LIST) */
.calendar-grid.month-list-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    grid-template-columns: none;
}

.month-list-day-card {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.03);
}

.month-list-day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.month-list-day-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--primary);
}

.month-list-day-hours {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.month-list-events {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.month-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.month-list-item:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
}

.month-list-item-main {
    display: flex;
    align-items: center;
    gap: 12px;
}

.month-list-icon {
    font-size: 20px;
}

.month-list-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.month-list-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.month-list-desc {
    font-size: 11px;
    opacity: 0.8;
    margin-top: 2px;
}

.month-list-item-side {
    display: flex;
    align-items: center;
    gap: 8px;
}

.empty-month-list {
    text-align: center;
    padding: 30px;
    color: var(--text-muted);
    font-style: italic;
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--border-radius);
    border: 1px dashed var(--border-color);
}

.calendar-day {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    flex-direction: column;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s;
    overflow: hidden;
}

.calendar-day:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(99, 102, 241, 0.3);
}

.calendar-day.prev-month {
    opacity: 0.3;
}

.calendar-day.today {
    border-color: var(--primary);
    background: var(--primary-light);
}

.day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.day-number {
    font-weight: 600;
    font-size: 13px;
}

.day-total-hours {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 10px;
}

.events-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    flex-grow: 1;
}

.event-pill {
    font-size: 10px;
    padding: 3px 6px;
    border-radius: 4px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    font-weight: 500;
    transition: transform 0.15s;
}

.event-pill:hover {
    transform: scale(1.02);
}

.event-preventivata {
    background: var(--warning-light);
    color: var(--warning);
    border-left: 3px solid var(--warning);
}

.event-svolta {
    background: var(--success-light);
    color: var(--success);
    border-left: 3px solid var(--success);
}

/* SETTIMANALE VISTA SPECIALE */
.calendar-grid.week-view-container {
    grid-auto-rows: 400px !important;
}

.calendar-grid.week-view-container .calendar-day {
    background: rgba(255, 255, 255, 0.03);
}

.calendar-grid.week-view-container .events-list {
    gap: 8px;
}

.calendar-grid.week-view-container .event-pill {
    font-size: 11px;
    padding: 8px;
    white-space: normal;
    word-break: break-word;
}

/* ==========================================================================
   SYNC VIEW TUTORIAL
   ========================================================================== */

.sync-status-box {
    margin-bottom: 25px;
}

.status-indicator {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 8px;
}

.sync-status-box p {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

.tutorial-steps {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.step-num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
}

.step p {
    font-size: 13px;
    line-height: 1.4;
}

/* ==========================================================================
   MODAL OVERLAY & CARD
   ========================================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.85);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.3s ease;
    overflow-y: auto;
}

.modal-card {
    width: 100%;
    max-width: 580px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    animation: scaleUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.2s;
}

.btn-close:hover {
    color: var(--text-main);
}

.modal-body {
    padding: 25px;
    overflow-y: auto;
    flex-grow: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.warning-box {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--border-radius);
    padding: 12px 15px;
    font-size: 13px;
    line-height: 1.4;
    margin-bottom: 20px;
}

.modal-warning {
    max-width: 480px;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ==========================================================================
   TOAST NOTIFICATION
   ========================================================================== */

.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--primary);
    color: #ffffff;
    padding: 12px 24px;
    border-radius: var(--border-radius);
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 1100;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform: translateY(100px);
    opacity: 0;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* ==========================================================================
   UX ENHANCEMENTS & COMPONENTI ASSISTITI PER ORE
   ========================================================================== */

/* Sezione Filtro Tabs per Pratiche */
.filter-tabs {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 4px;
    border: 1px solid var(--border-color);
}

.tab-btn {
    background: none;
    border: none;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    background: var(--bg-main);
    color: var(--text-main);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Input di ricerca rapida inline in cima ai select */
.input-search-inline {
    background: rgba(255, 255, 255, 0.03);
    font-size: 13px;
    padding: 8px 12px;
}

/* Pills grafici per le categorie (disposti in quadrato 2x2) */
.quick-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 4px;
}

.pill-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    padding: 8px 10px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}

.pill-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.pill-btn.active {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* Preset rapidi per la durata in minuti */
.quick-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.preset-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
}

.preset-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--text-muted);
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes scaleUp {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes spinRot {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spin-icon {
    display: inline-block;
    animation: spinRot 1.2s linear infinite;
}

/* ==========================================================================
   RESPONSIVE DESIGN (MOBILE & TABLET OPTIMIZATIONS)
   ========================================================================== */

@media (max-width: 1024px) {
    .grid-2col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    #main-layout {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* SideBar Collapsible on Mobile */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 10px 0 30px rgba(0,0,0,0.3);
    }
    
    .sidebar.mobile-active {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        overflow-x: hidden !important;
    }
    
    #btn-sidebar-toggle {
        display: block;
    }
    
    #btn-sidebar-collapse {
        display: none;
    }
    
    .top-bar {
        padding: 0 20px;
    }
    
    .content-container {
        padding: 15px;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Stats grid */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .stat-card {
        padding: 12px;
        gap: 12px;
    }
    
    .stat-icon {
        width: 38px;
        height: 38px;
        font-size: 18px;
    }
    
    .stat-content h3 {
        font-size: 18px;
    }
    
    /* Forms and Filters */
    .filter-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }
    
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    
    /* --- MOBILE CALENDAR UX --- */
    .calendar-weekdays {
        font-size: 11px;
    }
    
    /* Riduciamo l'altezza delle righe per far entrare la griglia nello schermo */
    .calendar-grid {
        grid-auto-rows: 55px !important;
        gap: 4px;
    }
    
    .calendar-day {
        padding: 4px;
        justify-content: flex-start;
        align-items: center;
        position: relative;
    }
    
    .day-header {
        width: 100%;
        justify-content: center;
    }
    
    .day-number {
        font-size: 14px;
    }
    
    /* Nascondiamo l'indicatore orario numerico sulle celle per non sovrapporsi */
    .day-total-hours {
        display: none;
    }
    
    /* Nascondiamo i pill di testo dei singoli eventi per non congestionare */
    .events-list {
        display: flex;
        flex-direction: row;
        justify-content: center;
        gap: 3px;
        flex-wrap: wrap;
        width: 100%;
        overflow: hidden;
        margin-top: 4px;
    }
    
    .event-pill {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        padding: 0;
        margin: 0;
        border: none;
        font-size: 0;
        text-indent: -9999px; /* Diventa un pallino colorato */
    }
    
    .event-preventivata {
        background: var(--warning) !important;
    }
    
    .event-svolta {
        background: var(--success) !important;
    }
    
    /* Cella giorno selezionato da mobile */
    .calendar-day.selected-day {
        border-color: var(--primary);
        background: rgba(99, 102, 241, 0.1);
        box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
    }
    
    /* Box dettagli eventi mobile */
    .mobile-details-card {
        margin-top: 15px;
        padding: 15px;
        border-radius: var(--border-radius);
        animation: fadeInUp 0.3s ease;
    }
    
    .mobile-details-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 12px;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 8px;
    }
    
    .mobile-details-header h3 {
        font-size: 15px;
        font-weight: 600;
    }
    
    .mobile-events-list {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    
    .mobile-event-item {
        padding: 12px;
        background: rgba(255, 255, 255, 0.03);
        border-radius: 8px;
        border: 1px solid var(--border-color);
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .mobile-event-info {
        display: flex;
        flex-direction: column;
        gap: 4px;
        flex-grow: 1;
        padding-right: 10px;
    }
    
    .mobile-event-title {
        font-size: 13px;
        font-weight: 600;
    }
    
    .mobile-event-meta {
        font-size: 11px;
        color: var(--text-muted);
    }
    
    .mobile-event-desc {
        font-size: 12px;
        font-style: italic;
        color: var(--text-muted);
        margin-top: 2px;
    }
    
    .border-preventivata {
        border-left: 4px solid var(--warning) !important;
    }
    
    .border-svolta {
        border-left: 4px solid var(--success) !important;
    }
    
    /* Mobile Form and Input Enhancements */
    input[type="text"],
    input[type="password"],
    input[type="date"],
    input[type="number"],
    input[type="time"],
    select,
    textarea {
        font-size: 16px !important; /* Previene lo zoom fastidioso di iOS Safari su focus */
        padding: 12px 14px; /* Tap targets più comodi */
        width: 100% !important;
        max-width: 100% !important; 
        min-width: 0 !important; /* Impedisce ai campi di allargare il layout oltre il contenitore */
        box-sizing: border-box !important;
    }
    
    .modal-overlay {
        padding: 10px; /* Più spazio per il modal su schermi piccoli */
    }
    
    .modal-card {
        max-height: 95vh;
        width: calc(100% - 20px) !important; /* Impedisce al modal di strabordare in larghezza */
        max-width: 580px !important;
        margin: 10px !important;
        border-radius: 12px;
        box-sizing: border-box !important;
    }
    
    .modal-body {
        padding: 15px; /* Spaziatura interna ridotta per massimizzare l'area visibile */
        box-sizing: border-box !important;
    }
    
    /* Forza i gruppi dei campi a comportarsi come normali blocchi verticali al 100% */
    .form-row > .form-group,
    .form-row > div {
        flex: none !important; /* Rimuove il flex: 1 che causava il bug di calcolo della larghezza */
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Ottimizzazione dei pills delle categorie per non andare a capo male */
    .quick-group {
        flex-wrap: wrap; /* Permette il wrap pulito su telefoni molto stretti */
        gap: 6px;
        width: 100% !important;
    }
    
    .pill-btn {
        padding: 10px 4px;
        font-size: 12px;
        flex: 1 1 calc(33.333% - 6px) !important; /* Si adatta perfettamente a 3 colonne */
        min-width: 0 !important; /* Rimosso il min-width che forzava l'allargamento del modal */
    }
    
    /* Preset durata */
    .quick-presets {
        gap: 5px;
    }
    
    .preset-btn {
        padding: 6px 10px;
        font-size: 11px;
    }
    
    /* Riduzione padding card su mobile */
    .card {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .stat-card {
        padding: 10px;
        gap: 10px;
    }
    
    .stat-content h3 {
        font-size: 16px;
    }
    
    /* Nasconde colonne secondarie in tabelle recenti per evitare scorrimento orizzontale esagerato */
    #recent-entries-table th:nth-child(6), /* Stato */
    #recent-entries-table td:nth-child(6),
    #recent-entries-table th:nth-child(7), /* Note */
    #recent-entries-table td:nth-child(7) {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-card {
        padding: 15px;
    }
    
    .modal-body {
        padding: 15px 5px;
    }
}

/* Fix dropdown select option colors for white-on-white text */
select option {
    background-color: var(--bg-sidebar);
    color: var(--text-main);
}

/* Landscape Mobile Layout: Optimization for small screen heights */
@media (max-height: 500px) {
    .modal-overlay {
        align-items: flex-start !important; /* Starts scrollable from the top */
        padding: 10px;
        overflow-y: auto;
    }
    
    .modal-card {
        max-height: none !important; /* Let it grow naturally so the whole card scrolls */
        margin-top: 10px;
        margin-bottom: 20px;
    }
    
    .modal-body {
        overflow-y: visible !important; /* Disable nested body scroll */
    }
}

/* ==========================================================================
   ATTIVITÀ PIANIFICATE & STAMPA PDF (LANDSCAPE 2 PAGINE)
   ========================================================================== */

/* Udienze Category Badge & Border */
.badge-udienze {
    background: rgba(139, 92, 246, 0.15) !important;
    color: #8b5cf6 !important;
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.border-udienze {
    border-left: 4px solid #8b5cf6 !important;
}

/* Colori Distinti per gli Avvocati (Palette per UI e Stampa) */
.lawyer-color-1 { background-color: rgba(79, 70, 229, 0.15); border-left: 4px solid #4f46e5 !important; color: #6366f1; }
.lawyer-color-2 { background-color: rgba(16, 185, 129, 0.15); border-left: 4px solid #10b981 !important; color: #10b981; }
.lawyer-color-3 { background-color: rgba(245, 158, 11, 0.15); border-left: 4px solid #f59e0b !important; color: #f59e0b; }
.lawyer-color-4 { background-color: rgba(236, 72, 153, 0.15); border-left: 4px solid #ec4899 !important; color: #ec4899; }
.lawyer-color-5 { background-color: rgba(6, 182, 212, 0.15); border-left: 4px solid #06b6d4 !important; color: #06b6d4; }

.lawyer-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-top: 4px;
}

.badge-postponed {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

/* Griglia Settimanale Orizzontale */
.planned-week-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 10px;
    min-height: 250px;
}

.planned-day-col {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.planned-day-header {
    font-weight: 600;
    font-size: 13px;
    text-align: center;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
}

.planned-item-card {
    padding: 8px;
    border-radius: 6px;
    font-size: 12px;
    background: var(--bg-card);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

@media (max-width: 1024px) {
    .planned-week-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   REGOLE DI STAMPA PDF (LANDSCAPE / ORIZZONTALE - 2 PAGINE)
   ========================================================================== */
@media print {
    @page {
        size: landscape;
        margin: 5mm;
    }
    
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    html, body {
        background: #ffffff !important;
        color: #000000 !important;
        font-size: 8.5pt !important;
        margin: 0 !important;
        padding: 0 !important;
        height: auto !important;
        overflow: visible !important;
    }
    
    .sidebar, .top-bar, .action-row, #btn-print-planned-pdf, .sidebar-nav, .sidebar-footer,
    #dash-add-entry-btn, .btn-close, .btn-secondary, .btn-primary, #theme-toggle,
    .filter-grid, .planned-filter-card, .section-header, #btn-sidebar-toggle, #planned-detail-table-card {
        display: none !important;
    }
    
    .main-content, .content-container, #planned-view {
        margin-left: 0 !important;
        padding-top: 0 !important;
        margin-top: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
    }
    
    .view-section {
        display: none !important;
    }
    
    #planned-view {
        display: block !important;
    }
    
    .card {
        background: #ffffff !important;
        border: 1px solid #ccc !important;
        color: #000000 !important;
        box-shadow: none !important;
        margin: 0 0 8px 0 !important;
        padding: 6px 8px !important;
    }

    .card h3 {
        font-size: 11pt !important;
        margin: 0 0 2px 0 !important;
        padding: 0 !important;
    }

    .card p {
        font-size: 8pt !important;
        margin: 0 0 6px 0 !important;
    }
    
    /* LAYOUT FLEX IN STAMPA PER EVITARE IL SALTO PAGINA ATOMICO DI CSS GRID */
    .planned-week-grid {
        display: flex !important;
        flex-direction: row !important;
        gap: 3px !important;
        width: 100% !important;
    }
    
    .planned-day-col {
        flex: 1 1 0 !important;
        width: 14% !important;
        min-width: 0 !important;
        border: 1px solid #999 !important;
        background: #fafafa !important;
        padding: 3px !important;
        box-sizing: border-box !important;
    }
    
    .planned-item-card {
        border: 1px solid #ddd !important;
        padding: 3px 4px !important;
        margin-bottom: 3px !important;
        font-size: 8pt !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
        -webkit-column-break-inside: avoid !important;
    }

    /* VIVID PRINT COLORS FOR LAWYERS & BADGES */
    .lawyer-color-1 {
        background-color: #eef2ff !important;
        border-left: 4px solid #4f46e5 !important;
        color: #312e81 !important;
    }
    .lawyer-color-2 {
        background-color: #ecfdf5 !important;
        border-left: 4px solid #10b981 !important;
        color: #065f46 !important;
    }
    .lawyer-color-3 {
        background-color: #fffbeb !important;
        border-left: 4px solid #f59e0b !important;
        color: #92400e !important;
    }
    .lawyer-color-4 {
        background-color: #fdf2f8 !important;
        border-left: 4px solid #ec4899 !important;
        color: #9d174d !important;
    }
    .lawyer-color-5 {
        background-color: #ecfeff !important;
        border-left: 4px solid #06b6d4 !important;
        color: #155e75 !important;
    }

    .lawyer-tag {
        display: inline-block !important;
        padding: 1px 4px !important;
        border-radius: 3px !important;
        font-weight: bold !important;
        border: 1px solid rgba(0,0,0,0.15) !important;
    }

    .event-pill {
        border-left: 3px solid #4f46e5 !important;
        background: #f1f5f9 !important;
        color: #0f172a !important;
    }

    .badge-postponed {
        background-color: #fee2e2 !important;
        color: #991b1b !important;
        border: 1px solid #fca5a5 !important;
    }
    
    .planned-top10-section {
        display: flex !important;
        flex-direction: row !important;
        gap: 12px !important;
        width: 100% !important;
    }

    .planned-top10-section .card {
        flex: 1 1 0 !important;
        width: 50% !important;
        margin: 0 !important;
    }
    
    .planned-top10-section .card,
    .month-list-item,
    .data-table tr,
    .data-table tbody tr {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
        -webkit-column-break-inside: avoid !important;
    }

    .data-table th {
        background: #e2e8f0 !important;
        color: #000000 !important;
        border: 1px solid #cbd5e1 !important;
        padding: 4px 6px !important;
    }
    
    .data-table td {
        border: 1px solid #cbd5e1 !important;
        color: #000000 !important;
        padding: 4px 6px !important;
    }
    
    .print-only-page-break {
        page-break-before: always !important;
        break-before: page !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
}
