/* UI */
:root {
    --bg: #f6f7f6;
    --card: #ffffff;
    --ink: #1b1d1b;
    --muted: #667085;
    --accent: #b24629;
    --accent-2: #14532d;
    --ring: #e6e6e6;
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, system-ui, Segoe UI, Roboto, Ubuntu, 'Helvetica Neue', Arial
}

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--ring)
}

.topbar .wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center
}

.brand {
    font-weight: 700
}

.admin-link {
    text-decoration: none;
    padding: 8px 12px;
    border: 1px solid var(--ring);
    border-radius: 8px;
    color: var(--ink)
}

.wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px
}

.hero {
    text-align: center;
    padding: 12px 0 8px
}

.logo {
    width: 250px;
}

h1 {
    margin: 8px 0 0;
    font-size: 28px
}

.muted {
    color: var(--muted)
}

.rooms-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 18px 0
}

.room-card {
    background: #fff;
    border: 1px solid var(--ring);
    border-radius: 14px;
    padding: 14px
}

.room-title {
    font-weight: 700;
    margin-bottom: 6px
}

.room-sub {
    font-size: 14px;
    color: var(--muted)
}

.card {
    background: var(--card);
    border: 1px solid var(--ring);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .03)
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.grid-2 .full {
    grid-column: 1 / -1;
}

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

.grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 16px
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px
}

input,
select,
textarea {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--ring);
    font: inherit;
    background: #fff
}

.btn {
    padding: 10px 16px;
    border-radius: 12px;
    background: linear-gradient(135deg, #4f46e5, #2563eb)
    color: white;
    border: none;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
}

.btn.primary {
    background: linear-gradient(135deg, #4f46e5, #2563eb)
}

.table {
    width: 100%;
    border-collapse: collapse
}

.table th,
.table td {
    border: 1px solid var(--ring);
    padding: 8px;
    text-align: left
}

.stat {
    background: #fff;
    border: 1px solid var(--ring);
    border-radius: 14px;
    padding: 12px
}

.stat-title {
    font-size: 14px;
    color: var(--muted)
}

.stat-value {
    font-size: 20px;
    font-weight: 700
}

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

.cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 16px
}

.bar {
    margin: 8px 0
}

.bar-label {
    font-size: 13px;
    margin-bottom: 4px
}

.bar-track {
    height: 10px;
    background: #eee;
    border-radius: 999px;
    overflow: hidden
}

.bar-fill {
    height: 10px;
    background: var(--accent-2)
}

.result {
    margin-top: 10px;
    font-size: 14px
}

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

.cal-title {
    font-weight: 700
}

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

.dow {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase
}

.day {
    background: #fff;
    border: 1px solid var(--ring);
    border-radius: 12px;
    min-height: 80px;
    padding: 8px;
    text-align: left;
    cursor: pointer
}

.day.empty {
    background: transparent;
    border: none;
    pointer-events: none
}

.day .daynum {
    font-weight: 700;
    font-size: 14px
}

.day .pct {
    font-size: 12px;
    color: var(--muted)
}

.day.c-low {
    background: #f3faf2
}

.day.c-mid {
    background: #fff7ea
}

.day.c-high {
    background: #fff0e8
}

.day.c-full {
    background: #ffe8e8
}

.legend {
    margin-top: 8px;
    display: flex;
    gap: 8px;
    align-items: center
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border: 1px solid var(--ring);
    border-radius: 999px;
    font-size: 12px
}

.b-low {
    background: #f3faf2
}

.b-mid {
    background: #fff7ea
}

.b-high {
    background: #fff0e8
}

.b-full {
    background: #ffe8e8
}

@media (max-width:800px) {
    .rooms-grid {
        grid-template-columns: 1fr
    }

    .grid {
        grid-template-columns: 1fr
    }

    .grid-2 {
        grid-template-columns: 1fr
    }

    .cards {
        grid-template-columns: 1fr
    }
}

#calendar .day.is-selected {
    outline: 2px solid #b24629;
    /* terracotta */
    box-shadow: 0 0 0 2px rgba(178, 70, 41, .15) inset;
}

#calendar .day.is-selected .daynum {
    font-weight: 700;
}

#calendar .day.is-selected .pct {
    opacity: .9;
}

/* ========================================
   SIDEBAR NAVIGATION
   ======================================== */

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for mobile */
    width: 250px;
    background: #fff;
    border-right: 1px solid var(--ring);
    transition: width 0.3s ease, transform 0.3s ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* iOS Safari fixes */
    -webkit-overflow-scrolling: touch;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    /* Force visibility on Safari */
    visibility: visible !important;
    opacity: 1 !important;
}

.sidebar.collapsed {
    width: 60px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--ring);
    min-height: 60px;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    color: var(--ink);
    transition: background 0.2s;
    border-radius: 6px;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: var(--bg);
}

.sidebar-brand {
    margin-left: 12px;
    font-weight: 700;
    font-size: 18px;
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.2s;
}

.sidebar.collapsed .sidebar-brand {
    opacity: 0;
    pointer-events: none;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: var(--ink);
    text-decoration: none;
    transition: background 0.2s;
    white-space: nowrap;
}

.sidebar-nav-item:hover {
    background: var(--bg);
}

.sidebar-nav-item:hover .nav-icon svg {
    fill: #2563eb;
}

.sidebar-nav-item.active {
    background: #e3f2fd;
    color: #2196f3;
    font-weight: 600;
}

.sidebar-nav-item.has-submenu {
    align-items: center;
}

.submenu-arrow {
    margin-left: auto;
    font-size: 0.85rem;
    color: #666;
    transition: transform 0.2s;
}

.sidebar-nav-item.has-submenu.expanded .submenu-arrow {
    transform: rotate(90deg);
}

.sidebar.collapsed .submenu-arrow {
    display: none;
}

.sidebar-nav-submenu {
    display: none;
    flex-direction: column;
    padding-left: 28px;
    background: #fafafa;
}

.sidebar-nav-item.has-submenu.expanded+.sidebar-nav-submenu {
    display: flex;
}

.sidebar-nav-submenu .sidebar-nav-item {
    padding: 10px 16px;
    font-size: 0.9rem;
}

.sidebar.collapsed .sidebar-nav-submenu {
    display: none;
}

.nav-icon {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-icon svg {
    width: 18px;
    height: 18px;
    fill: #9aa4b2;
    transition: fill 0.2s ease;
}

.sidebar-nav-item.active .nav-icon svg {
    fill: #2563eb;
}

.nav-label {
    margin-left: 12px;
    opacity: 1;
    transition: opacity 0.2s;
}

.sidebar.collapsed .nav-label {
    opacity: 0;
    pointer-events: none;
}

.sidebar-footer {
    border-top: 1px solid var(--ring);
    padding: 8px 0;
}

/* Sidebar Overlay (Mobile) - Solo quando sidebar è espansa */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
}

@media (max-width: 768px) {
    .sidebar-overlay {
        display: block;
        opacity: 0;
        pointer-events: none;
    }

    .sidebar.mobile-open~.sidebar-overlay,
    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ========================================
   HERO HEADER
   ======================================== */

.hero-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 32px 20px;
    margin-left: 250px;
    transition: margin-left 0.3s ease;
}

.sidebar.collapsed~.hero-header {
    margin-left: 60px;
}

.hero-content {
    max-width: 1100px;
    margin: 0 auto;
}

.hero-title {
    margin: 0;
    font-size: 32px;
    font-weight: 700;
}

/* ========================================
   MAIN CONTENT WITH SIDEBAR
   ======================================== */

.main-with-sidebar {
    margin-left: 250px;
    margin-right: 0;
    transition: margin-left 0.3s ease;
    padding-left: 20px;
    padding-right: 20px;
    max-width: none !important;
}

.sidebar.collapsed~* .main-with-sidebar,
.sidebar.collapsed~.main-with-sidebar {
    margin-left: 60px;
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(0);
        width: 60px;
        /* Force hardware acceleration on iOS */
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        /* Ensure it's always on top */
        z-index: 9999;
        /* Safari iOS specific */
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        display: flex !important;
        visibility: visible !important;
    }

    .sidebar.mobile-open {
        width: 250px;
    }

    .sidebar.collapsed {
        width: 60px;
    }

    .hero-header {
        margin-left: 60px;
    }

    .main-with-sidebar {
        margin-left: 0px;
        padding-left: 0;
        /*dino*/
    }

    .sidebar.mobile-open~.hero-header,
    .sidebar.mobile-open~* .main-with-sidebar,
    .sidebar.mobile-open~.main-with-sidebar {
        margin-left: 250px;
    }

    .sidebar.collapsed~.hero-header,
    .sidebar.collapsed~* .main-with-sidebar,
    .sidebar.collapsed~.main-with-sidebar {
        margin-left: 60px;
    }
}

/* ========================================
   MODAL
   ======================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: #fff;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--ring);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f9fafb;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--ink);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #374151;
}

.modal-section {
    margin-bottom: 20px;
}

.modal-section:last-child {
    margin-bottom: 0;
}

.modal-section-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 10px;
    border-bottom: 1px solid #f3f4f6;
    padding-bottom: 5px;
}

.modal-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.modal-stat-item {
    background: #f9fafb;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #f3f4f6;
}

.modal-stat-label {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 2px;
}

.modal-stat-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ink);
}

.modal-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.modal-list-item {
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    justify-content: space-between;
}

.modal-list-item:last-child {
    border-bottom: none;
}

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

.btn-link {
    font-size: 0.85rem;
    color: #1b5e20;
    text-decoration: none;
    font-weight: 600;
}

.news-widget-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.news-widget-list li a {
    color: #1b1d1b;
    text-decoration: none;
    font-weight: 600;
    display: block;
}

.news-widget-list li .meta {
    font-size: 0.8rem;
    color: #777;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--ring);
    background: #f9fafb;
    display: flex;
    justify-content: flex-end;
}

.ui-icon-heart {
    mask-image: url('data:image/svg+xml,%3Csvg xmlns=' 'http://www.w3.org/2000/svg' ' viewBox=' '0 0 24 24' '%3E%3Cpath fill=' 'white' ' d=' 'M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z' '/%3E%3C/svg%3E');
    -webkit-mask-image: url('data:image/svg+xml,%3Csvg xmlns=' 'http://www.w3.org/2000/svg' ' viewBox=' '0 0 24 24' '%3E%3Cpath fill=' 'white' ' d=' 'M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z' '/%3E%3C/svg%3E');
    background-color: currentColor;
}

/* Scrollbar personalizzata - sottile e in linea con i colori del tema (azzurro) */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(79, 70, 229, 0.5) transparent;
}

/* Webkit scrollbar (Chrome, Safari, Edge) */
*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(79, 70, 229, 0.6), rgba(37, 99, 235, 0.6));
    border-radius: 10px;
    transition: background 0.2s ease;
}

*::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(79, 70, 229, 0.8), rgba(37, 99, 235, 0.8));
}