/* Stili specifici per il ribbon di Excel */
#ribbon-container {
    background: linear-gradient(to bottom, #ffffff, #f8f8f8);
    border-bottom: 1px solid #d0d0d0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    position: relative;
    z-index: 999;
}

#menu-bar {
    display: flex;
    background: #ffffff;
    border-bottom: 1px solid #d6d6d6;
    height: 28px;
    font-size: 12px;
    padding: 0 8px;
    align-items: center;
    position: relative;
    z-index: 1000;
    gap: 2px;
}

.menu-item {
    padding: 4px 14px;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    user-select: none;
    border: 1px solid transparent;
    border-radius: 2px;
    margin: 0;
    font-weight: 400;
    color: #333;
    transition: all 0.15s ease;
    height: 24px;
    line-height: 24px;
}

.menu-item:hover {
    background: #f3f3f3;
    border: 1px solid #e1e1e1;
}

.menu-item.active {
    background: #ffffff;
    border-bottom: 2px solid #217346;
    border-top: 1px solid transparent;
    border-left: 1px solid transparent;
    border-right: 1px solid transparent;
    color: #217346;
    font-weight: 500;
}

#ribbon-content {
    background: #ffffff;
    padding: 6px 12px 4px 12px;
    min-height: 92px;
    max-height: 92px;
    border-bottom: 1px solid #d6d6d6;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    align-items: flex-start;
}

.ribbon-tab {
    display: none;
    gap: 2px;
    align-items: flex-start;
    height: 100%;
    flex-wrap: nowrap;
}

.ribbon-tab.active {
    display: flex;
}

.ribbon-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: fit-content;
    padding: 2px 8px 0 8px;
    border-right: 1px solid #e1e1e1;
    height: 100%;
}

.ribbon-group:last-child {
    border-right: none;
}

.group-title {
    font-size: 11px;
    color: #666;
    text-align: center;
    margin-top: auto;
    padding-top: 4px;
    font-weight: 400;
    order: 2;
}

.group-controls {
    display: flex;
    gap: 2px;
    align-items: flex-start;
    flex-wrap: wrap;
    max-height: 64px;
    order: 1;
}

.ribbon-button {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 2px;
    padding: 3px 5px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 32px;
    min-height: 48px;
    font-size: 11px;
    transition: all 0.1s ease;
    position: relative;
}

.ribbon-button:hover {
    background: #f3f3f3;
    border-color: #d6d6d6;
}

.ribbon-button:active {
    background: #e1e1e1;
    border-color: #c7c7c7;
}

.ribbon-button.large {
    min-width: 48px;
    padding: 4px 6px;
    min-height: 56px;
}

.button-group {
    display: flex;
    flex-direction: column;
    border: 1px solid transparent;
    border-radius: 2px;
    overflow: visible;
    background: transparent;
    gap: 1px;
}

.button-group .ribbon-button {
    border: 1px solid transparent;
    border-radius: 2px;
    margin: 0;
    min-height: 20px;
    flex-direction: row;
    gap: 4px;
    padding: 2px 6px;
    min-width: 24px;
}

.button-group .ribbon-button:hover {
    background: #f3f3f3;
    border-color: #d6d6d6;
}

.button-group.vertical {
    flex-direction: column;
    gap: 0;
}

.button-group.vertical .ribbon-button {
    flex-direction: row;
    justify-content: flex-start;
    min-width: 120px;
    padding: 3px 8px;
}

.ribbon-combo {
    border: 1px solid #d6d6d6;
    border-radius: 2px;
    padding: 2px 4px;
    font-size: 11px;
    background: white;
    min-width: 80px;
    height: 20px;
    color: #333;
}

.ribbon-combo:hover {
    border-color: #c7c7c7;
}

.ribbon-combo:focus {
    border-color: #217346;
    outline: none;
}

.button-icon {
    font-size: 16px;
    font-weight: normal;
    color: #333;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.button-text {
    font-size: 11px;
    color: #333;
    text-align: center;
    line-height: 1.2;
    white-space: nowrap;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.button-group .button-text {
    font-size: 11px;
    text-align: left;
}

/* Barra del titolo migliorata */
#title-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #217346;
    color: white;
    padding: 4px 8px;
    height: 32px;
    font-size: 12px;
}

.title-action-btn {
    background: none;
    border: none;
    color: white;
    font-size: 12px;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
    padding: 0;
}
.title-action-btn:hover {
    background: rgba(255,255,255,0.15);
    opacity: 1;
}
.title-action-btn:active {
    background: rgba(255,255,255,0.25);
}

.app-title-input {
    font-size: 13px;
    padding: 3px 8px;
    border: none;
    outline: none;
    border-radius: 3px;
    background: transparent;
    color: white;
    font-weight: 400;
    font-family: inherit;
    max-width: 200px;
    min-width: 60px;
}
.app-title-input:hover {
    background: rgba(255,255,255,0.15);
}
.app-title-input:focus {
    background: rgba(255,255,255,0.25);
    outline: 1px solid rgba(255,255,255,0.4);
}

.title-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    justify-content: flex-end;
    margin-right: 10px;
}

.search-box {
    flex: 1;
    max-width: 400px;
}

.search-box input {
    width: 100%;
    padding: 3px 8px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 2px;
    background: rgba(255,255,255,0.15);
    font-size: 11px;
    color: white;
}

.search-box input::placeholder {
    color: rgba(255,255,255,0.7);
}

.search-box input:focus {
    outline: none;
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.5);
}

.microsoft-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ms-action {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 2px;
    padding: 3px 10px;
    color: white;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s ease;
    height: 24px;
}

.ms-action:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.3);
}

#btn-buy-ms365 {
    background: #ff8c00;
    border: 1px solid #e67e00;
    font-weight: 500;
}

#btn-buy-ms365:hover {
    background: #ff9c20;
}

.window-controls {
    display: flex;
    gap: 0;
}

.control-btn {
    background: none;
    border: none;
    color: white;
    width: 46px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    transition: background-color 0.15s ease;
    font-family: 'Segoe MDL2 Assets', 'Segoe UI Symbol';
}

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

.control-btn.close:hover {
    background-color: #e81123;
    color: white;
}

/* Barra di stato migliorata */
#status-bar {
    display: flex;
    justify-content: space-between;
    background: #f3f3f3;
    border-top: 1px solid #d6d6d6;
    padding: 2px 12px;
    height: 22px;
    font-size: 11px;
    align-items: center;
    position: relative;
    z-index: 10;
}

.status-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.status-center {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    justify-content: center;
}

.status-stat {
    color: #444;
    font-size: 11px;
    white-space: nowrap;
}

.status-stat b {
    color: #217346;
    font-weight: 600;
}

.status-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-button.active {
    background: #d4e8d4;
    border-color: #217346;
}

.status-button {
    background: transparent;
    border: 1px solid transparent;
    padding: 2px 8px;
    font-size: 11px;
    cursor: pointer;
    border-radius: 2px;
    color: #333;
    transition: all 0.15s ease;
    height: 18px;
    line-height: 14px;
}

.status-button:hover {
    background-color: #e1e1e1;
}

.status-button.active {
    background-color: #d4e8d4;
    border-color: #217346;
    color: #217346;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 4px;
}

/* Slider dello zoom in verde Excel (cursore e barra) */
#zoom-slider-bar {
    accent-color: #217346;
}

.zoom-button {
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 14px;
    width: 20px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    transition: all 0.15s ease;
    border-radius: 2px;
}

.zoom-button:hover {
    background: #e1e1e1;
}

.zoom-level {
    font-size: 11px;
    min-width: 35px;
    text-align: center;
    color: #333;
    font-weight: 400;
}

/* Scrollbar personalizzata per il ribbon */
#ribbon-content::-webkit-scrollbar {
    height: 12px;
}

#ribbon-content::-webkit-scrollbar-track {
    background: #f3f3f3;
}

#ribbon-content::-webkit-scrollbar-thumb {
    background: #c7c7c7;
    border-radius: 6px;
    border: 3px solid #f3f3f3;
}

#ribbon-content::-webkit-scrollbar-thumb:hover {
    background: #a6a6a6;
}

/* Menu dropdown File */
.menu-dropdown {
    z-index: 1001 !important;
    background: white;
    border: 1px solid #d6d6d6;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    border-radius: 2px;
    min-width: 200px;
}

.menu-option {
    padding: 6px 32px 6px 12px;
    font-size: 12px;
    color: #333;
}

.menu-option:hover {
    background-color: #f3f3f3;
    color: #333;
}

/* Barra della formula */
#formula-bar {
    display: flex;
    background-color: #ffffff;
    border-bottom: 1px solid #d6d6d6;
    height: 24px;
    align-items: center;
}

.cell-reference {
    width: 80px;
    padding: 2px 8px;
    border-right: 1px solid #d6d6d6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    background-color: #f3f3f3;
    font-weight: 400;
    color: #333;
}

.formula-container {
    flex: 1;
    display: flex;
    background: white;
}

#formula-input {
    flex: 1;
    border: none;
    padding: 2px 8px;
    font-size: 12px;
    outline: none;
    background-color: white;
    color: #333;
}

#formula-input:focus {
    outline: 1px solid #217346;
    outline-offset: -1px;
}

/* Stili per la formattazione condizionale */
.data-bar {
    transition: width 0.3s ease;
}

.comment-indicator {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Stili per i grafici */
.chart-container {
    font-family: 'Segoe UI', sans-serif;
}

.chart-container svg {
    font-size: 10px;
}

/* Stili per le tabelle */
.table-header {
    font-weight: bold;
    text-align: center;
}

/* Stili per i filtri */
.filter-icon:hover {
    color: #217346;
}

/* Modal per grafici */
.modal {
    animation: fadeIn 0.2s ease;
}

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

/* Stili per la visualizzazione */
.zoom-controls {
    user-select: none;
}

/* Stili per la protezione */
.protected-cell {
    background-color: #f3f3f3 !important;
    color: #666 !important;
    cursor: not-allowed;
}

/* Barra fogli */
#sheet-tabs-bar {
    display: flex;
    align-items: center;
    height: 26px;
    background: #f3f3f3;
    border-top: 1px solid #d6d6d6;
    padding: 0 4px;
    flex-shrink: 0;
    gap: 2px;
    position: relative;
    z-index: 10;
}

.sheet-tab-btn {
    width: 24px;
    height: 20px;
    background: none;
    border: 1px solid #d6d6d6;
    border-radius: 3px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    flex-shrink: 0;
}
.sheet-tab-btn:hover { background: #e1e1e1; color: #333; }

.sheet-tabs-scroll {
    display: flex;
    overflow-x: auto;
    gap: 1px;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}
.sheet-tabs-scroll::-webkit-scrollbar { display: none; }

.sheet-tab {
    padding: 3px 16px;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 3px 3px 0 0;
    background: transparent;
    color: #666;
    user-select: none;
    position: relative;
    flex-shrink: 0;
}
.sheet-tab:hover { background: #e8e8e8; color: #333; }
.sheet-tab.active {
    background: white;
    color: #333;
    font-weight: 500;
    border-color: #d6d6d6;
}
.sheet-tab .close-tab {
    display: none;
    margin-left: 6px;
    font-size: 10px;
    color: #999;
    cursor: pointer;
}
.sheet-tab:hover .close-tab { display: inline; }
.sheet-tab .close-tab:hover { color: #d32f2f; }

/* Titolo cliccabile per rinomina */
.app-title {
    cursor: pointer;
}
.app-title:hover {
    text-decoration: underline;
    text-decoration-style: dotted;
}

/* ==================== RESPONSIVE MOBILE ==================== */
@media (max-width: 768px) {
    #title-bar {
        height: 36px;
        padding: 2px 6px;
    }
    .app-title {
        font-size: 11px;
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        cursor: pointer;
    }
    .search-box { display: none; }
    .microsoft-actions { display: none; }
    .window-controls { display: none; }

    #menu-bar {
        height: 28px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        gap: 0;
        padding: 0 2px;
        flex-shrink: 0;
    }
    #menu-bar::-webkit-scrollbar { display: none; }
    .menu-item {
        padding: 2px 8px;
        font-size: 11px;
        white-space: nowrap;
        flex-shrink: 0;
        height: 24px;
        line-height: 20px;
    }

    /* Menu dropdown File - full screen su mobile */
    .menu-dropdown {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: none !important;
        min-width: auto !important;
        border-radius: 0 !important;
        z-index: 10001 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding: 8px 0 !important;
    }
    .menu-dropdown .menu-option {
        padding: 14px 20px;
        font-size: 15px;
    }
    .menu-dropdown .menu-shortcut { display: none; }
    .menu-dropdown .menu-separator { margin: 6px 16px; }

    #ribbon-content {
        min-height: 66px;
        max-height: 66px;
        padding: 2px 4px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        flex-shrink: 0;
    }
    #ribbon-content::-webkit-scrollbar { display: none; }
    .ribbon-group {
        padding: 0 3px;
    }
    .group-title { display: none; }
    .group-controls {
        max-height: 62px;
        align-items: center;
    }
    .ribbon-button {
        min-width: 28px;
        min-height: 34px;
        padding: 2px 3px;
    }
    .ribbon-button.large {
        min-width: 32px;
        min-height: 36px;
    }
    .button-text { display: none; }
    .button-icon { font-size: 14px; }
    .ribbon-combo {
        min-width: 55px;
        font-size: 10px;
        height: 18px;
    }
    .button-group .ribbon-button {
        min-height: 16px;
        padding: 1px 3px;
    }

    #formula-bar {
        height: 26px;
        flex-shrink: 0;
    }
    .cell-reference { width: 45px; font-size: 10px; padding: 2px 4px; }
    #formula-input { font-size: 12px; }

    #status-bar {
        height: 26px;
        padding: 2px 6px;
        flex-shrink: 0;
    }
    .status-button { font-size: 9px; padding: 1px 3px; }
    .zoom-level { font-size: 10px; }
    .zoom-button { width: 24px; height: 24px; font-size: 16px; }

    /* Touch-friendly cells */
    #corner-header { width: 36px; }
    #row-headers { width: 36px; }
    .row-header { width: 36px; font-size: 9px; }

    /* Sheet area deve usare lo spazio restante */
    #sheet-area { flex: 1; min-height: 0; }

    /* Waffle button */
    .waffle-btn { width: 32px; height: 32px; }

    /* Sheet tabs mobile */
    #sheet-tabs-bar { height: 28px; }
    .sheet-tab { padding: 3px 10px; font-size: 10px; }
    .sheet-tab-btn { width: 28px; height: 22px; font-size: 16px; }
}

/* Stili per il dialog dei bordi */
.border-preset:hover {
    background-color: #f3f3f3 !important;
}

.border-preset.selected {
    background-color: #e1f0ff !important;
    border-color: #217346 !important;
}

.border-side-btn:hover {
    background-color: #f3f3f3 !important;
}

.border-side-btn.active {
    background-color: #e1f0ff !important;
    border-color: #217346 !important;
}

/* Migliora la visualizzazione delle celle con bordi */
.cell {
    box-sizing: border-box;
}

/* Assicurati che i bordi personalizzati siano visibili */
.cell[style*="border"] {
    z-index: 2;
}

/* Mantieni i bordi della griglia di base */
.cell:not([style*="border-top"]) {
    border-top: 1px solid #d6d6d6;
}

.cell:not([style*="border-right"]) {
    border-right: 1px solid #d6d6d6;
}

.cell:not([style*="border-bottom"]) {
    border-bottom: 1px solid #d6d6d6;
}

.cell:not([style*="border-left"]) {
    border-left: 1px solid #d6d6d6;
}


/* ======================================================================
   Home tab — maggiore fedeltà grafica all'originale di Excel
   ====================================================================== */
/* Grassetto/Corsivo/Sottolineato in fila (come Excel), non impilati */
#home-tab .button-group:has(#btn-bold) { flex-direction: row; gap: 0; }
#home-tab .button-group:has(#btn-bold) .ribbon-button { min-width: 26px; justify-content: center; padding: 2px 6px; }
#btn-bold .button-icon { font-weight: 700; }
#btn-italic .button-icon { font-style: italic; font-family: Georgia, 'Times New Roman', serif; }
#btn-underline .button-icon { text-decoration: underline; }

/* Colore carattere: "A" con barra rossa sotto (come Excel) */
#home-tab .ribbon-button[title*="Colore carattere"] .button-icon {
    font-weight: 700; line-height: 1; padding-bottom: 2px;
    border-bottom: 3px solid #d83b01;
}
/* Colore riempimento: barra gialla sotto l'icona (come Excel) */
#home-tab .ribbon-button[title*="Colore riempimento"] .button-icon {
    padding-bottom: 2px; border-bottom: 3px solid #ffc000;
}

/* Separatori di gruppo un filo più visibili, come la griglia del ribbon Excel */
.ribbon-group { border-right-color: #d4d4d4; }

/* Pulsanti formato numero (€ % , e decimali) con tinta verde Excel */
#btn-fmt-currency .button-icon,
#btn-fmt-percent .button-icon { color: #1f7244; font-weight: 600; }

/* Il ribbon non deve mai generare scorrimento orizzontale di pagina:
   i gruppi restano su una riga e, se serve, lo scroll resta interno al ribbon. */
#ribbon-content { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
.ribbon-tab.active { flex-wrap: nowrap; }

/* Allineamento: i tre orizzontali sopra, i tre verticali sotto (3 + 3) */
.align-stack { display: flex; flex-direction: column; gap: 2px; }
.align-stack .button-group { flex-direction: row; gap: 0; }
.align-stack .button-group .ribbon-button {
    flex-direction: row; min-width: 24px; min-height: 20px;
    justify-content: center; padding: 2px 6px;
}
.align-stack .button-icon { font-size: 14px; }
