/* GŁÓWNY UKŁAD I STRUKTURA STRONY */
body { margin: 0; padding: 0; font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif; background-color: #f3f2f1; color: #323130; height: 100vh; overflow: hidden; }
.wrapper { display: flex; width: 100vw; height: 100vh; overflow: hidden; }
.excel-column { flex: 1; display: flex; flex-direction: column; height: 100%; overflow: hidden; background: #fff; }

/* REWOLUCYJNY PASEK NARZĘDZI (RIBBON) */
.excel-ribbon { display: flex; align-items: center; background-color: #f3f2f1; padding: 6px 12px; border-bottom: 1px solid #e1dfdd; gap: 10px; flex-shrink: 0; user-select: none; }
.ribbon-group { display: flex; align-items: center; gap: 4px; border-right: 1px solid #ced4da; padding-right: 10px; }
.ribbon-group:last-child { border-right: none; }
.ribbon-btn { background: transparent; border: 1px solid transparent; height: 28px; padding: 0 8px; font-size: 13px; border-radius: 4px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #323130; font-weight: 500; }
.ribbon-btn:hover { background-color: #edebe9; }
.ribbon-select { height: 28px; border: 1px solid #d2d0ce; border-radius: 4px; background: white; font-size: 13px; padding: 0 4px; outline: none; }
.custom-picker-trigger { cursor: pointer; font-size: 15px; padding: 2px 4px; border-radius: 3px; }
.custom-picker-trigger:hover { background: #edebe9; }

/* PRZEŁĄCZNIK TRYBÓW */
.switch-container { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.toggle-switch { position: relative; display: inline-block; width: 34px; height: 20px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .3s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: #107c41; }
input:checked + .slider:before { transform: translateX(14px); }

/* PASEK FORMUŁY (FORMULA BAR) */
.formula-bar { display: flex; align-items: center; background: #fff; border-bottom: 1px solid #e1dfdd; padding: 4px 12px; gap: 8px; flex-shrink: 0; }
.cell-address { width: 50px; height: 24px; text-align: center; font-weight: 600; border: 1px solid #d2d0ce; background: #f3f2f1; border-radius: 4px; font-size: 12px; color: #323130; outline: none; }
.fx-symbol { font-style: italic; font-weight: bold; color: #107c41; font-size: 15px; cursor: pointer; width: 20px; text-align: center; user-select: none; }
#formula-input { flex: 1; height: 24px; border: 1px solid #d2d0ce; border-radius: 4px; padding: 0 8px; font-size: 13px; outline: none; }
#formula-input:focus { border-color: #107c41; }

/* OBSZAR TABELI (GRID LAYOUT) */
.grid-layout-container { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.grid-main-row { display: flex; flex: 1; overflow: hidden; }
.grid-viewport { flex: 1; overflow: auto; position: relative; background: #f3f2f1; }

/* STYLIZACJA SIATKI ARKUSZA (DOKŁADNY WYGLĄD EXCELA) */
.excel-table { border-collapse: collapse; table-layout: fixed; background: white; position: relative; }
.excel-table th { background: #f3f2f1; color: #323130; font-size: 11px; font-weight: normal; border-right: 1px solid #c8c6c4; border-bottom: 1px solid #c8c6c4; text-align: center; user-select: none; position: relative; height: 22px; cursor: pointer; }
.excel-table th:hover { background: #edebe9; font-weight: bold; }
.excel-table th.selected-header { background: #bbb; font-weight: bold; color: #000; }
.excel-table td { border-right: 1px solid #e1dfdd; border-bottom: 1px solid #e1dfdd; padding: 0; margin: 0; position: relative; vertical-align: top; }

/* KOMÓRKI WEJŚCIOWE ARKUSZA */
.grid-cell { width: 100%; height: 100%; border: none; padding: 0 4px; margin: 0; box-sizing: border-box; font-size: 13px; font-family: Arial, sans-serif; color: #000; background: transparent; outline: none; }
.grid-cell:focus { background: #fff !important; box-shadow: inset 0 0 0 2px #107c41; position: relative; z-index: 10; }
.grid-cell.in-range { background-color: rgba(16, 124, 65, 0.08) !important; }

/* POPUPY I MENU KONTEKSTOWE */
.floating-popup { position: absolute; background: white; border: 1px solid #b8b8b8; box-shadow: 0 4px 12px rgba(0,0,0,0.15); border-radius: 4px; padding: 6px; z-index: 2000; display: none; }
.floating-popup-list { max-height: 220px; overflow-y: auto; }
.floating-item { padding: 6px 10px; cursor: pointer; border-radius: 3px; font-size: 12px; border-bottom: 1px solid #f3f3f3; }
.floating-item:hover { background: #f3f3f3; color: #107c41; }
.expanded-color-grid { display: grid; grid-template-columns: repeat(5, 20px); gap: 4px; padding: 4px; }
.grid-color-btn { width: 20px; height: 20px; border: 1px solid #ccc; border-radius: 2px; cursor: pointer; }

.context-menu { position: absolute; background: #ffffff; border: 1px solid #b8b8b8; box-shadow: 0 2px 8px rgba(0,0,0,0.15); border-radius: 4px; padding: 4px 0; z-index: 1000; display: none; min-width: 150px; font-size: 13px; }
.context-item { padding: 6px 14px; cursor: pointer; }
.context-item:hover { background: #f3f3f3; color: #107c41; }

/* PASEK STANU (STATUS BAR) */
.status-bar { display: flex; align-items: center; background-color: #107c41; color: white; padding: 4px 15px; font-size: 12px; gap: 20px; flex-shrink: 0; user-select: none; height: 22px; }
.status-bar-group { display: flex; align-items: center; gap: 6px; }
.status-control-btn { background: rgba(255,255,255,0.2); border: none; color: white; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; font-weight: bold; border-radius: 3px; cursor: pointer; font-size: 12px; }
.status-control-btn:hover { background: rgba(255,255,255,0.4); }
.size-slider-group { display: flex; align-items: center; }
.size-slider { -webkit-appearance: none; width: 70px; height: 4px; background: rgba(255,255,255,0.3); border-radius: 2px; outline: none; }
.size-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 10px; height: 10px; background: white; border-radius: 50%; cursor: pointer; }

/* PRAWY PANEL BOCZNY (ZADANIA I GRYWALIZACJA) */
.right-column { width: 420px; background: #ffffff; padding: 20px; overflow-y: auto; box-shadow: -2px 0 8px rgba(0,0,0,0.08); border-left: 1px solid #d3d3d3; display: flex; flex-direction: column; gap: 15px; flex-shrink: 0; box-sizing: border-box; }
.box { border: 1px solid #e1dfdd; padding: 15px; border-radius: 6px; background: #fafafa; color: #333; }
.game-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 5px; }
.stat-card { background: #e8f5e9; padding: 10px; border-radius: 4px; text-align: center; border: 1px solid #c8e6c9; color: #2e7d32; }
.stat-card.time { background: #fff3e0; border-color: #ffe0b2; color: #ef6c00; }
.stat-val { font-size: 20px; font-weight: bold; }
.stat-lbl { font-size: 10px; text-transform: uppercase; color: #666; font-weight: 600; }

.btn { display: block; width: 100%; height: 36px !important; padding: 0 15px; margin: 8px 0 0 0; cursor: pointer; border: none; border-radius: 4px; font-weight: bold; font-size: 13px; text-align: center; line-height: 36px; box-sizing: border-box; }
.btn-success { background-color: #107c41; color: white; }
.btn-success:hover { background-color: #0b592e; }
.btn-secondary { background-color: #6c757d; color: white; }
.btn-secondary:hover { background-color: #5a6268; }

.hint-box { background-color: #fff3cd; color: #856404; padding: 12px; margin-top: 8px; border-left: 5px solid #ffeeba; display: none; border-radius: 4px; font-size: 13px; }
.status { font-weight: bold; margin-top: 15px; padding: 10px; border-radius: 4px; display: none; text-align: center; font-size: 13px; }
.success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; display: block; }
.error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; display: block; }
.summary-list { font-size: 13px; margin: 10px 0; padding: 0; list-style: none; }
.summary-list li { padding: 6px 0; border-bottom: 1px dashed #ddd; display: flex; justify-content: space-between; }

/* UCHWYT WYPEŁNIANIA DANYCH (AUTOFILL HANDLE) */
#excel-fill-handle { position: absolute; width: 6px; height: 6px; background-color: #107c41; border: 1px solid white; cursor: crosshair; z-index: 1500; display: none; box-sizing: border-box; }

/* NOWY UKŁAD PRZYCISKÓW W PANELU */
.task-actions-row { display: flex; gap: 8px; margin-top: 8px; }
.task-actions-row .btn { flex: 1; margin: 0 !important; }
.btn:disabled { background-color: #a0a0a0 !important; cursor: not-allowed; opacity: 0.6; }

/* NAKŁADKA BLOCKERA Z LOGIEM SPINNERA */
.loading-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(255, 255, 255, 0.75); z-index: 9999; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.spinner { width: 40px; height: 40px; border: 4px solid #f3f3f3; border-top: 4px solid #107c41; border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 12px; }
.loading-text { font-size: 15px; font-weight: 600; color: #107c41; font-family: sans-serif; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* TRÓJSTANOWY PRZEŁĄCZNIK TRYBÓW */
.mode-selector { display: flex; background: #edebe9; padding: 4px; border-radius: 6px; gap: 4px; border: 1px solid #d2d0ce; margin-bottom: 5px; }
.mode-tab { flex: 1; text-align: center; padding: 6px 0; font-size: 12px; font-weight: 600; color: #323130; cursor: pointer; border-radius: 4px; transition: background 0.2s; }
.mode-tab:hover { background: #f3f2f1; }
.mode-tab.active { background: #107c41; color: white; }

/* PODZIAŁ PRZYCISKÓW AKCJI I REORGANIZACJA BOXÓW */
.task-actions-row { display: flex; gap: 8px; margin-top: 8px; }
.task-actions-row .btn { flex: 1; margin: 0 !important; }
.btn:disabled { background-color: #a0a0a0 !important; cursor: not-allowed; opacity: 0.6; }
.box-hidden { display: none !important; }

/* REGÓŁY CAŁKOWITEGO UKRYWANIA DLA TRYBÓW I PANELI */
.box-hidden { display: none !important; }
.right-column-hidden { display: none !important; }

/* PODŚWIETLENIE AKTYWNEGO CELU W SAMOUCZKU */
.tutorial-target-highlight { background-color: #fff9c4 !important; box-shadow: inset 0 0 0 2px #fbc02d !important; animation: tutorial-pulse 2s infinite; }
@keyframes tutorial-pulse { 0% { opacity: 1; } 50% { opacity: 0.7; } 100% { opacity: 1; } }


/* ====================================================================
   DOMYŚLNE USTAWIENIA DLA DESKTOPU (UKRYWANIE ELEMENTÓW MOBILNYCH)
   ==================================================================== */
#mobile-task-bar {
    display: none !important; /* Ukryte na komputerze */
}
#mobile-collapsible-panels {
    display: block !important; /* Zawsze widoczne na komputerze */
}

/* ====================================================================
   PANCERNY INTERFEJS RESPENSYWNY (SMARTFONY I TABLETY < 768px)
   ==================================================================== */
@media screen and (max-width: 768px) {
    /* 1. GWARANCJA PIONOWEGO UKŁADU STRONY */
    body, .wrapper, .main-layout {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* 2. PASKA NARZĘDZI (RIBBON) - PODZIAŁ NA WIERSZE I HAMBURGER */
    .excel-ribbon {
        display: flex !important;
        flex-wrap: wrap !important; /* Pozwala grupom przechodzić do nowych linii */
        gap: 6px 10px !important;    /* Odstępy między rzędami menu */
        height: auto !important;
        padding: 6px !important;
    }

    #mobile-menu-burger {
        display: block !important; /* Pokazuje przycisk ☰ na telefonie */
    }

    /* Ukrywamy grupy przycisków na starcie smartfona */
    .excel-ribbon .ribbon-group {
        display: none !important;
    }

    /* Klasa dodawana przez JS - rozwija całe menu po kliknięciu ☰ */
    .excel-ribbon.mobile-open .ribbon-group {
        display: inline-flex !important;
    }

    /* 3. ROZSTAWIE KOLUMN: Zadanie na górę, Arkusz w centrum */
    .right-column {
        width: 100% !important;
        order: 1 !important; /* Wskakuje pod menu na samą górę */
        padding: 6px !important;
        box-sizing: border-box;
    }

    .excel-column {
        width: 100% !important;
        order: 2 !important; /* Arkusz trafia idealnie na środek ekranu */
    }

    /* 4. MOBILNY PASEK STANU (ZADANIA, PUNKTY, CZAS) */
    #mobile-task-bar {
        display: block !important; /* Pokazuje wąski pasek na smartfonie */
    }

    #desktop-stats-grid {
        display: none !important; /* Ukrywa duże kafelki punktów na telefonie */
    }

    /* Domyślnie zwijamy duże sekcje konfiguracji i pytań pod pasek */
    #mobile-collapsible-panels {
        display: none !important;
        background-color: #ffffff;
        border: 1px solid #edebe9;
        border-bottom: 3px solid #107c41;
        padding: 10px !important;
        border-radius: 0 0 4px 4px;
        margin-top: -6px;
    }

    /* Klasa dodawana przez JS - płynnie wysuwa pełną instrukcję */
    #mobile-collapsible-panels.panels-open {
        display: block !important;
    }

    /* 5. ELASTYCZNA SIATKA I SUWAKI NA SAMYM DOLE */
    .table-responsive-wrapper {
        width: 100% !important;
        overflow: auto !important; /* Poziome i pionowe przesuwanie tabeli palcem */
        -webkit-overflow-scrolling: touch;
        border: 1px solid #edebe9;
    }

    .grid-cell {
        font-size: 14px !important;
        padding: 5px !important;
        min-width: 80px !important; /* Zabezpieczenie przed ściskaniem kolumn */
    }

    /* Belka skalowania i przyciski + / - lądują na samym spodzie ekranu */
    .status-bar {
        order: 3 !important; 
        width: 100% !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        background: #f3f2f1 !important;
        padding: 8px !important;
    }
}


  /* Klasa nakładana na komórkę, dla której otwarte jest okno właściwości */
  .active-context-cell {
    outline: 2px solid #107c41 !important;
    background-color: #f2f9f5 !important;
    z-index: 10;
  }

/* Aktywny nagłówek kolumny i wiersza dla aktualnie zaznaczonej komórki */
.selected-header.active-header {
    background-color: #d0e7d2 !important; /* Pastelowy szaro-zielonkawy odcień Excela */
    color: #107c41 !important;            /* Charakterystyczna zieleń czcionki nagłówka */
    font-weight: bold !important;
}
