@import url('theme.css');
@import url('dark-mode.css');

/*=========================================================
RESET E LAYOUT BASE
=========================================================*/
*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: var(--wb-bg);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: var(--wb-text);
}

/*=========================================================
TOP BAR (Barra Superiore Gialla)
=========================================================*/
.topbar {
    background: #FFCC00;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    gap: 8px;
    z-index: 110;
    position: relative;
    overflow: visible;
}

.topbar .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
    font-size: 18px;
    color: #333;
    width: 220px;
}

.topbar .search {
    flex: 1;
    max-width: 500px;
    position: relative;
    margin-left: 20px;
}

.topbar .search input {
    width: 100%;
    padding: 10px 15px 10px 40px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}

.topbar .search .search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #888;
    z-index: 1;
    pointer-events: none;
}

.search-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: 360px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 200;
}

.search-dropdown-loading,
.search-dropdown-empty {
    padding: 14px 16px;
    font-size: 13px;
    color: #64748b;
}

.search-result {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-bottom: 1px solid #f1f5f9;
    background: #fff;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s;
}

.search-result:last-child {
    border-bottom: none;
}

.search-result:hover,
.search-result:focus-visible {
    background: #f0f7ff;
    outline: none;
}

.search-result-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: #e8f4fd;
    color: #0084ff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.search-result-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.search-result-label {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-meta {
    font-size: 11px;
    color: #64748b;
}

.topbar .lang-btn {
    border-color: rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.7);
    color: #333;
}

.topbar .theme-toggle {
    color: #1a1a1a;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.7);
    color: #1a1a1a;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.15s;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.95);
    transform: scale(1.04);
}

.theme-toggle i {
    font-size: 15px;
    color: currentColor;
}

.wb-toast-root {
    position: fixed;
    top: 72px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(360px, calc(100vw - 32px));
    pointer-events: none;
}

.wb-toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    font-size: 0.88rem;
    line-height: 1.4;
    pointer-events: auto;
    animation: wb-toast-in 0.2s ease;
}

.wb-toast-success { border-left: 4px solid #22c55e; }
.wb-toast-error { border-left: 4px solid #ef4444; }
.wb-toast-info { border-left: 4px solid #0084ff; }
.wb-toast-warn { border-left: 4px solid #f59e0b; }

.wb-toast-close {
    border: none;
    background: none;
    color: #94a3b8;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.wb-toast-out { opacity: 0; transform: translateX(12px); transition: 0.2s ease; }

@keyframes wb-toast-in {
    from { opacity: 0; transform: translateX(12px); }
    to { opacity: 1; transform: translateX(0); }
}

.profile-switcher {
    position: relative;
    flex-shrink: 0;
}

.profile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    max-width: 200px;
    min-height: 44px;
}

.profile-btn span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-chevron {
    font-size: 10px;
    opacity: 0.6;
}

.profile-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 240px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 200;
    overflow: hidden;
    border: 1px solid #e8e8e8;
}

.profile-dropdown.open {
    display: block;
}

.profile-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    padding: 12px 14px;
    border: none;
    background: #fff;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    color: #333;
}

.profile-option small {
    font-size: 11px;
    color: #888;
    font-weight: normal;
}

.profile-option:hover {
    background: #f5f8fc;
}

.profile-option.active {
    background: #e8f4ff;
    color: #0084ff;
}

.profile-manage {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid #eee;
    color: #555;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}

.profile-manage:hover {
    background: #f8f9fa;
}

.topbar .btn-blue {
    background: #00A8FF;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/*=========================================================
STRUTTURA SCHERMATA INTERNA (Sidebar + Menu)
=========================================================*/
.layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar Grigia Scura Verticale */
.sidebar {
    width: 75px;
    background: var(--wb-surface);
    border-right: 1px solid var(--wb-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 10px;
}

.sidebar .icon {
    width: 100%;
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--wb-text-secondary);
    font-size: 11px;
    cursor: pointer;
    text-align: center;
}

.sidebar .icon i {
    font-size: 18px;
    margin-bottom: 5px;
}

.sidebar .icon.active {
    background: var(--wb-sidebar-active-bg);
    color: #FFCC00;
    border-left: 4px solid #FFCC00;
    font-weight: bold;
}

/* Leftmenu Bianco Testuale */
.leftmenu {
    width: 250px;
    background: var(--wb-surface-2);
    border-right: 1px solid var(--wb-border);
    padding: 20px 0;
    overflow-y: auto;
}

.leftmenu h2 {
    font-size: 16px;
    font-weight: 600;
    padding: 0 20px 15px 20px;
    color: #0b7ef3;
    display: flex;
    align-items: center;
    gap: 10px;
}

.leftmenu ul {
    list-style: none;
}

.leftmenu ul li {
    padding: 10px 20px;
    font-size: 14px;
    color: #555;
    cursor: pointer;
}

.leftmenu ul li:hover:not(.group) {
    background: #eef2f7;
}

.leftmenu ul li.group {
    font-weight: bold;
    color: #222;
    padding-top: 20px;
    padding-bottom: 8px;
    cursor: default;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.leftmenu ul li.active-item {
    background: #e8f0fe;
    color: #0b7ef3;
    font-weight: 500;
}

/*=========================================================
GESTIONE SOTTOMENU IMPOSTAZIONI NASCONDI/MOSTRA
=========================================================*/
.hidden-menu {
    display: none;
    background: #f1f3f5;
    margin-top: 10px;
    border-top: 1px dashed #ccc;
}

.hidden-menu.show {
    display: block;
}

/*=========================================================
AREA CONTENUTO E GRIGLIA DASHBOARD
=========================================================*/
.content {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    background: var(--wb-bg);
}

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

.content h1 {
    font-size: 32px;
    font-weight: 500;
    color: var(--wb-text);
}

.dashboard {
    display: grid;
    grid-template-columns: 240px 1fr 240px;
    gap: 18px;
    grid-template-areas:
    "arrivi        pagamenti   fatturato"
    "partenze      pagamenti   presenze"
    "cancellazioni canale      sconti"
    "occupazione   canale      carrello"
    "grafico1      grafico2    grafico2";
}

.arrivi        { grid-area: arrivi; }
.partenze      { grid-area: partenze; }
.cancellazioni { grid-area: cancellazioni; }
.occupazione   { grid-area: occupazione; }
.pagamenti     { grid-area: pagamenti; }
.canale        { grid-area: canale; }
.fatturato     { grid-area: fatturato; }
.presenze      { grid-area: presenze; }
.sconti        { grid-area: sconti; }
.carrello      { grid-area: carrello; }
.grafico1      { grid-area: grafico1; }
.grafico2      { grid-area: grafico2; }

/*=========================================================
STILE DELLE CARD E DEI NUMERI
=========================================================*/
.card {
    background: var(--wb-surface);
    border-radius: 14px;
    box-shadow: 0 3px 10px var(--wb-shadow-sm);
    border: 1px solid var(--wb-border-light);
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: .25s;
    position: relative;
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 22px rgba(0,0,0,.08);
}

.card h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--wb-text);
    margin-bottom: 10px;
}

.card a {
    color: #0b7ef3;
    text-decoration: none;
    font-size: 14px;
    align-self: flex-end;
}

.number {
    font-size: 46px;
    font-weight: 300;
    color: var(--wb-text);
}

.number-inline {
    display: flex;
    align-items: baseline;
    gap: 2px;
}

.number-inline .subtext {
    font-size: 20px;
    color: #888;
    font-weight: 400;
}

.number-inline .currency {
    font-size: 32px;
    font-weight: 300;
    color: #222;
}

.eye-icon {
    margin-left: auto;
    color: #00A8FF;
    cursor: pointer;
    font-size: 16px;
}

.arrivi, .partenze, .cancellazioni, .occupazione,
.fatturato, .presenze, .sconti, .carrello {
    min-height: 140px;
}

.pagamenti, .canale {
    min-height: 310px;
}

.chart-container {
    flex: 1;
    position: relative;
    width: 100%;
    height: 180px;
}

.view-detail {
    position: absolute;
    bottom: 20px;
    right: 20px;
}

.grafico1, .grafico2 {
    min-height: 360px;
}

.line-chart-container {
    width: 100%;
    height: 260px;
}

.date-button {
    background: #ffffff;
    border: 1px solid #d7d7d7;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #555;
}

/*=========================================================
STILE DEL FRAME PER LE PROCEDURE DINAMICHE
=========================================================*/
.procedure-iframe {
    width: 100%;
    height: calc(100vh - 110px);
    border: none;
    background: var(--wb-bg);
    border-radius: 12px;
    box-shadow: 0 4px 12px var(--wb-shadow-sm);
}

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

.menu-toggle {
    display: none;
    background: transparent;
    border: none;
    font-size: 20px;
    color: #333;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 8px;
}

.menu-toggle:hover {
    background: rgba(0, 0, 0, 0.06);
}

.menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 90;
}

.menu-overlay.show {
    display: block;
}

body.menu-lock {
    overflow: hidden;
}

/*=========================================================
AUTENTICACIÓN / SOLA LECTURA
=========================================================*/
.user-auth {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.user-label {
    font-size: 12px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 8px;
    white-space: nowrap;
}

.user-label.guest {
    background: rgba(0,0,0,0.06);
    color: #555;
}

.user-label.authenticated {
    background: rgba(0, 132, 255, 0.12);
    color: #0066cc;
}

.btn-auth {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: 8px;
    background: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    min-height: 40px;
}

.btn-auth-out {
    background: transparent;
}

.read-only-banner {
    background: #fff8e6;
    color: #7a5b00;
    text-align: center;
    padding: 8px 12px;
    font-size: 13px;
    border-bottom: 1px solid #ffe08a;
    z-index: 9;
}

.read-only-banner a {
    color: #0084ff;
    font-weight: 600;
}

body.dashboard-read-only .topbar .btn-blue,
body.read-only #btn-nuovo,
body.read-only .toolbar .btn-success,
body.read-only .toolbar .btn-primary:not(.btn-secondary) {
    display: none !important;
}

/*=========================================================
RESPONSIVE — Tablet y móvil
=========================================================*/

/* Tablet landscape / small desktop */
@media (max-width: 1200px) {
    .dashboard {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "arrivi fatturato"
            "partenze presenze"
            "cancellazioni sconti"
            "occupazione carrello"
            "pagamenti canale"
            "grafico1 grafico1"
            "grafico2 grafico2";
    }

    .leftmenu {
        width: 220px;
    }
}

/* Tablet portrait */
@media (max-width: 1024px) {
    .topbar .logo {
        width: auto;
    }

    .topbar .search {
        max-width: 320px;
        margin-left: 10px;
    }

    .leftmenu {
        position: fixed;
        top: 60px;
        left: 0;
        bottom: 0;
        width: min(280px, 85vw);
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.12);
    }

    .layout.menu-open .leftmenu {
        transform: translateX(0);
    }

    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .content {
        padding: 16px;
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }

    .procedure-iframe {
        height: calc(100dvh - 60px - 72px - env(safe-area-inset-bottom, 0px));
        border-radius: 8px;
    }

    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        flex-direction: row;
        justify-content: flex-start;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid #e0e0e0;
        border-right: none;
        z-index: 80;
        background: #fff;
        gap: 2px;
        scrollbar-width: none;
    }

    .sidebar::-webkit-scrollbar {
        display: none;
    }

    .sidebar .icon {
        flex: 0 0 auto;
        min-width: 64px;
        padding: 8px 6px;
        border-left: none;
        border-radius: 8px;
    }

    .sidebar .icon.active {
        border-left: none;
        background: #FFF9E6;
        box-shadow: inset 0 -3px 0 #FFCC00;
    }

    .sidebar .icon span {
        font-size: 10px;
        white-space: nowrap;
    }

    .layout {
        flex-direction: column;
    }
}

/* Móvil */
@media (max-width: 768px) {
    .topbar {
        height: auto;
        min-height: 56px;
        flex-wrap: wrap;
        padding: 8px 12px;
        gap: 8px;
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
    }

    .topbar-utils {
        order: 2;
        margin-left: auto;
    }

    .profile-switcher {
        order: 3;
        flex: 1 1 100%;
    }

    .profile-btn {
        max-width: none;
        width: 100%;
    }

    .profile-dropdown {
        left: 0;
        right: 0;
        min-width: 0;
    }

    .topbar .search {
        order: 4;
        flex: 1 1 100%;
        max-width: none;
        margin-left: 0;
    }

    .topbar .toolbar {
        margin-left: auto;
    }

    .user-auth {
        order: 4;
        flex: 1 1 100%;
        justify-content: flex-end;
    }

    .user-label {
        font-size: 11px;
    }

    .topbar .btn-blue .btn-label {
        display: none;
    }

    .topbar .btn-blue {
        padding: 10px 14px;
        min-width: 44px;
        min-height: 44px;
    }

    .content h1 {
        font-size: 1.5rem;
    }

    .content-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .dashboard {
        grid-template-columns: 1fr;
        grid-template-areas: none;
        gap: 12px;
    }

    .card {
        grid-area: auto !important;
        padding: 16px;
        min-height: auto !important;
    }

    .number {
        font-size: 2rem;
    }

    .pagamenti,
    .canale {
        min-height: 260px;
    }

    .grafico1,
    .grafico2 {
        min-height: 280px;
    }

    .line-chart-container {
        height: 200px;
    }

    .chart-container {
        height: 160px;
    }

    .date-button {
        font-size: 12px;
        padding: 8px 10px;
    }
}

/* Móvil pequeño */
@media (max-width: 480px) {
    .logo-text {
        font-size: 15px;
    }

    .sidebar .icon {
        min-width: 56px;
    }

    .sidebar .icon i {
        font-size: 16px;
    }

    .content {
        padding: 12px;
    }
}