* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;

    width: 100%;
    height: 100%;

    overflow: hidden;

    font-family:
        Arial,
        Helvetica,
        sans-serif;

    background: #111827;

    color: #ffffff;
}

#app {
    display: flex;

    width: 100vw;
    height: 100vh;
}

#sidebar {
    width: 300px;

    height: 100vh;

    padding: 24px;

    background: #111827;

    border-right:
        1px solid #374151;

    overflow-y: auto;

    z-index: 20;
}

#sidebar h1 {
    margin: 0;

    font-size: 26px;

    color: #60a5fa;
}

.subtitle {
    margin-top: 6px;

    margin-bottom: 30px;

    color: #9ca3af;

    font-size: 14px;
}

.panel-section {
    padding-bottom: 24px;

    margin-bottom: 24px;

    border-bottom:
        1px solid #374151;
}

.panel-section h2 {
    margin-top: 0;

    margin-bottom: 14px;

    font-size: 14px;

    text-transform: uppercase;

    letter-spacing: 1px;

    color: #9ca3af;
}

#stlFile {
    display: none;
}

#fileButton {
    display: block;

    width: 100%;

    padding: 12px;

    text-align: center;

    background: #2563eb;

    border-radius: 8px;

    cursor: pointer;

    font-weight: bold;

    transition:
        background 0.2s,
        transform 0.1s;
}

#fileButton:hover {
    background: #3b82f6;
}

#fileButton:active {
    transform: scale(0.98);
}

.drop-zone {
    margin-top: 12px;

    padding: 20px 10px;

    text-align: center;

    border:
        2px dashed #4b5563;

    border-radius: 8px;

    color: #9ca3af;

    font-size: 13px;

    transition:
        border-color 0.2s,
        background 0.2s,
        color 0.2s;
}

.drop-zone.dragover {
    border-color: #60a5fa;

    background: #1e3a5f;

    color: #ffffff;
}

#fileName {
    margin-top: 12px;

    color: #d1d5db;

    font-size: 13px;

    word-break: break-word;
}

button {
    display: block;

    width: 100%;

    margin-bottom: 10px;

    padding: 11px;

    border: none;

    border-radius: 7px;

    background: #374151;

    color: white;

    cursor: pointer;

    font-size: 14px;

    transition:
        background 0.2s;
}

button:hover {
    background: #4b5563;
}

button:active {
    background: #2563eb;
}

.status {
    display: flex;

    align-items: center;

    gap: 10px;

    color: #d1d5db;

    font-size: 14px;
}

.status-dot {
    width: 10px;
    height: 10px;

    border-radius: 50%;

    background: #6b7280;
}

.status-dot.active {
    background: #22c55e;

    box-shadow:
        0 0 8px #22c55e;
}

.info > div {
    display: flex;

    justify-content: space-between;

    margin-bottom: 10px;

    font-size: 13px;

    color: #9ca3af;
}

.info strong {
    color: #ffffff;

    max-width: 130px;

    overflow: hidden;

    text-overflow: ellipsis;

    white-space: nowrap;
}

.help {
    margin-top: 10px;

    color: #6b7280;

    font-size: 12px;
}

.help strong {
    color: #9ca3af;
}

.help p {
    margin: 8px 0;
}

#viewer {
    position: relative;

    flex: 1;

    min-width: 0;

    height: 100vh;

    overflow: hidden;

    background:
        radial-gradient(
            circle at center,
            #293548 0%,
            #111827 70%
        );
}

#viewer canvas {
    display: block;

    width: 100%;

    height: 100%;
}

.empty-message {
    position: absolute;

    top: 50%;
    left: 50%;

    transform:
        translate(-50%, -50%);

    text-align: center;

    color: #9ca3af;

    pointer-events: none;
}

.empty-icon {
    font-size: 70px;

    color: #374151;
}

.empty-message h2 {
    margin:
        10px 0;

    color: #d1d5db;
}

.empty-message p {
    margin: 0;

    font-size: 14px;
}

@media (max-width: 700px) {

    #sidebar {
        width: 240px;

        padding: 16px;
    }

    #sidebar h1 {
        font-size: 21px;
    }

}

#viewCube {
    position: absolute;
    top: 60px;
    left: 20px;

    width: 140px;
    height: 140px;

    z-index: 100;

    pointer-events: auto;

    background: rgba(17, 24, 39, 0.25);

    border-radius: 12px;
}

#cubeCanvas {
    display: block;

    width: 140px;
    height: 140px;

    cursor: pointer;
}

.camera-grid {
    display: grid;

    grid-template-columns:
        1fr 1fr;

    gap: 8px;

    margin-top: 10px;
}

.camera-grid button {
    margin-bottom: 0;

    padding: 9px 6px;

    font-size: 13px;
}

.camera-grid button:hover {
    background: #4b5563;
}

.camera-grid button:active {
    background: #2563eb;
}

.material-control {
    margin-bottom: 16px;
}

.material-control > label {
    display: block;

    margin-bottom: 8px;

    color: #d1d5db;

    font-size: 13px;
}

#materialColor {
    width: 100%;

    height: 40px;

    padding: 3px;

    border: 1px solid #4b5563;

    border-radius: 7px;

    background: #1f2937;

    cursor: pointer;
}

.range-row {
    display: flex;

    align-items: center;

    gap: 10px;
}

.range-row input[type="range"] {
    flex: 1;

    accent-color: #3b82f6;

    cursor: pointer;
}

.range-row span {
    width: 38px;

    text-align: right;

    color: #9ca3af;

    font-size: 12px;
}

.checkbox-control {
    display: flex;

    align-items: center;

    gap: 9px;

    color: #d1d5db;

    font-size: 13px;

    cursor: pointer;
}

.checkbox-control input {
    width: 16px;
    height: 16px;

    accent-color: #2563eb;

    cursor: pointer;
}

#rotationControls {
    position: absolute;

    top: 20px;
    left: 40px;

    z-index: 101;

    display: flex;

    gap: 8px;
}

#rotationControls button {
    width: 46px;
    height: 42px;

    margin: 0;

    padding: 0;

    border: 1px solid #4b5563;

    border-radius: 8px;

    background: rgba(17, 24, 39, 0.9);

    color: #ffffff;

    font-size: 24px;
    line-height: 1;

    cursor: pointer;

    transition:
        background 0.2s,
        transform 0.1s;
}

#rotationControls button:hover {
    background: #2563eb;
}

#rotationControls button:active {
    transform: scale(0.92);
}

#orientationCube {
    position: absolute;

    inset: 0;

    z-index: 50;

    pointer-events: none;

    display: none;
}

#orientationCube.active {
    display: block;
}

.cube-label {
    position: absolute;

    padding: 6px 10px;

    background: rgba(37, 99, 235, 0.8);

    border: 1px solid rgba(255, 255, 255, 0.35);

    border-radius: 5px;

    color: white;

    font-size: 11px;

    pointer-events: auto;

    cursor: pointer;
}

::-webkit-scrollbar {
  width: 10px;
}

::-webkit-scrollbar-track {
  background: #92888896;
}

::-webkit-scrollbar-thumb {
  background: #4a95eb;
}

::-webkit-scrollbar-thumb:hover {
  background: #1a6dd8;
}

/* =========================================================
   MOBILE / RESPONSIVE DRAWER
   ========================================================= */

.sidebar-mobile-header {
    display: none;
}

#sidebarBackdrop {
    display: none;
}

.mobile-menu-button {
    display: none;
}


/* =========================================================
   TOUCH
   ========================================================= */

/* Główny canvas Three.js */
#viewer > canvas {
    touch-action: none;
}


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 700px) {

    html,
    body {
        width: 100%;
        height: 100%;

        overflow: hidden;
    }

    #app {
        width: 100vw;

        height: 100vh;
        height: 100dvh;

        display: block;

        position: relative;
    }


    /* -----------------------------------------------------
       SIDEBAR — wysuwany panel
       ----------------------------------------------------- */

    #sidebar {

        position: fixed;

        top: 0;
        left: 0;

        width: min(86vw, 320px);

        height: 100vh;
        height: 100dvh;

        padding:
            calc(16px + env(safe-area-inset-top))
            18px
            calc(18px + env(safe-area-inset-bottom))
            18px;

        margin: 0;

        z-index: 1000;

        overflow-x: hidden;
        overflow-y: auto;

        background: #111827;

        border-right:
            1px solid #374151;

        box-shadow:
            12px 0 40px rgba(0, 0, 0, 0.45);

        transform:
            translateX(-105%);

        transition:
            transform 0.28s cubic-bezier(
                0.4,
                0,
                0.2,
                1
            );

        -webkit-overflow-scrolling: touch;
    }


    #sidebar.open {
        transform: translateX(0);
    }


    /* -----------------------------------------------------
       NAGŁÓWEK PANELU
       ----------------------------------------------------- */

    .sidebar-mobile-header {

        display: flex;

        align-items: center;

        justify-content: space-between;

        min-height: 44px;

        margin-bottom: 12px;

        color: #9ca3af;

        font-size: 12px;

        font-weight: bold;

        text-transform: uppercase;

        letter-spacing: 1px;
    }


    #sidebarClose {

        display: flex;

        align-items: center;
        justify-content: center;

        width: 42px;
        height: 42px;

        margin: 0;

        padding: 0;

        border:
            1px solid #4b5563;

        border-radius: 9px;

        background: #1f2937;

        color: #ffffff;

        font-size: 28px;

        line-height: 1;

        flex-shrink: 0;
    }


    #sidebarClose:hover {
        background: #374151;
    }


    #sidebar h1 {
        font-size: 23px;
    }


    .subtitle {
        margin-bottom: 22px;
    }


    /* -----------------------------------------------------
       TŁO POD MENU
       ----------------------------------------------------- */

    #sidebarBackdrop {

        display: block;

        position: fixed;

        inset: 0;

        z-index: 900;

        background:
            rgba(0, 0, 0, 0.58);

        opacity: 0;

        visibility: hidden;

        pointer-events: none;

        transition:
            opacity 0.25s ease,
            visibility 0.25s ease;

        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }


    body.sidebar-open {
        overflow: hidden;
    }


    body.sidebar-open #sidebarBackdrop {

        opacity: 1;

        visibility: visible;

        pointer-events: auto;
    }


    /* -----------------------------------------------------
       VIEWER
       ----------------------------------------------------- */

    #viewer {

        position: relative;

        width: 100%;

        height: 100vh;
        height: 100dvh;

        min-width: 0;

        overflow: hidden;
    }


    /* -----------------------------------------------------
       HAMBURGER
       ----------------------------------------------------- */

    .mobile-menu-button {

        display: flex;

        align-items: center;
        justify-content: center;

        position: absolute;

        top:
            calc(
                12px +
                env(safe-area-inset-top)
            );

        right:
            calc(
                12px +
                env(safe-area-inset-right)
            );

        z-index: 950;

        width: 46px;
        height: 46px;

        margin: 0;

        padding: 0;

        border:
            1px solid #4b5563;

        border-radius: 10px;

        background:
            rgba(17, 24, 39, 0.92);

        color: #ffffff;

        font-size: 25px;

        line-height: 1;

        box-shadow:
            0 6px 20px rgba(0, 0, 0, 0.3);

        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }


    .mobile-menu-button:hover {
        background: #2563eb;
    }


    .mobile-menu-button:active {
        transform: scale(0.94);
    }


    /* -----------------------------------------------------
       ROTACJA 90°
       ----------------------------------------------------- */

    #rotationControls {

        top:
            calc(
                12px +
                env(safe-area-inset-top)
            );

        left:
            calc(
                12px +
                env(safe-area-inset-left)
            );

        gap: 7px;
    }


    #rotationControls button {

        width: 44px;
        height: 42px;

        margin: 0;

        border-radius: 9px;

        font-size: 23px;
    }


    /* -----------------------------------------------------
       VIEW CUBE
       ----------------------------------------------------- */

    #viewCube {

        top: 68px;

        left:
            calc(
                10px +
                env(safe-area-inset-left)
            );

        width: 112px;
        height: 112px;

        border-radius: 10px;

        background:
            rgba(17, 24, 39, 0.15);
    }


    #cubeCanvas {

        width: 112px;
        height: 112px;
    }


    /* -----------------------------------------------------
       EMPTY MESSAGE
       ----------------------------------------------------- */

    .empty-message {

        width: calc(100% - 40px);

        max-width: 320px;
    }


    .empty-icon {
        font-size: 54px;
    }


    .empty-message h2 {

        margin:
            8px 0;

        font-size: 20px;
    }


    .empty-message p {

        font-size: 13px;

        line-height: 1.5;
    }


    /* -----------------------------------------------------
       PRZYCISKI W PANELU
       ----------------------------------------------------- */

    #sidebar button {

        min-height: 44px;
    }


    #fileButton {

        min-height: 44px;

        display: flex;

        align-items: center;

        justify-content: center;
    }


    #materialColor {

        height: 44px;
    }


    .camera-grid {

        gap: 7px;
    }


    .camera-grid button {

        min-height: 44px;

        padding:
            8px 5px;
    }


    /* -----------------------------------------------------
       INFORMACJE
       ----------------------------------------------------- */

    .info > div {

        gap: 12px;

        font-size: 12px;
    }


    .info strong {

        max-width: 150px;
    }


    /* -----------------------------------------------------
       DROP ZONE
       ----------------------------------------------------- */

    .drop-zone {

        min-height: 82px;

        display: flex;

        align-items: center;

        justify-content: center;

        line-height: 1.5;
    }


    /* -----------------------------------------------------
       SEKCJE
       ----------------------------------------------------- */

    .panel-section {

        padding-bottom: 20px;

        margin-bottom: 20px;
    }


    /* -----------------------------------------------------
       LEPSZE SUWAKI NA TELEFONIE
       ----------------------------------------------------- */

    .range-row input[type="range"] {

        height: 28px;
    }

}


/* =========================================================
   BARDZO MAŁE TELEFONY
   ========================================================= */

@media (max-width: 380px) {

    #sidebar {

        width: 88vw;

        padding-left: 15px;
        padding-right: 15px;
    }


    #sidebar h1 {
        font-size: 21px;
    }


    .camera-grid button {

        font-size: 12px;
    }


    #viewCube {

        transform: scale(0.9);

        transform-origin: top left;
    }

}

.cube-toggle-button {
    margin-top: 10px;
}