/* ==========================================================================
   5. LAYOUT.CSS
   Style specyficzne dla aplikacji "CRM:TONdance".
   Definiuje layout, układ paneli, menu i elementy UI specyficzne dla tej appki.
   ========================================================================== */

/* --- ZMIENNE LAYOUTU --- */
:root {
    --panel-width: 22.5rem; 
    --visible-panels: 1; /* Domyślnie 1 (mobile) */
}

/* --- GLOBALNE USTAWIENIA SVG --- */
svg {
    width: 1em;
    height: 1em;
    fill: currentColor;
    display: inline-block;
    vertical-align: middle;
    margin-top: -0.125em; 
}

/* --- LOGIKA SKALOWANIA I RESPNSYWNOŚĆ --- */
html {
    font-size: calc(100dvw / (var(--visible-panels) * 22.5));
}

/* 1. Zabezpieczenie dla orientacji poziomej (Landscape) */
@media (orientation: landscape) { 
    :root { --visible-panels: 2; } 
}

/* 2. Breakpointy szerokości */
@media (min-width: 45rem) { :root { --visible-panels: 2; } }
@media (min-width: 67.5rem) { :root { --visible-panels: 3; } }
@media (min-width: 90rem) { :root { --visible-panels: 4; } }
@media (min-width: 112.5rem) { :root { --visible-panels: 5; } }

/* --- GLOBALNE USTAWIENIA STRUKTURALNE --- */
body {
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden; 
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

/* --- APP BAR (GÓRNY PASEK) --- */
.app-bar {
    flex: 0 0 4rem; 
    background-color: var(--bg-appbar);
    border-bottom: 0.0625em solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 10;
    position: relative; 
}

.app-menu {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	flex: 1;
	justify-content: center;
}

/* HAMBURGER BUTTON */
.hamburger-btn {
    display: none; 
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 2.5rem;
    height: 2.5rem;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

/* --- SIDEBAR (BOCZNE MENU - MOBILNE) --- */
.app-sidebar-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    z-index: 998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.app-sidebar-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.app-sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 18rem;
    max-width: 85vw;
    height: 100%;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.app-sidebar.active {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}
.sidebar-header .logo { margin: 0; }
.sidebar-close {
    background: transparent; border: none; font-size: 1rem; color: var(--text-secondary); cursor: pointer;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    color: var(--text-main);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
    background-color: transparent;
    border: none;
    width: 100%;
    text-align: left;
    transition: background-color 0.2s;
    cursor: pointer;
}
.sidebar-link:hover {
    background-color: var(--bg-surface-2);
}

/* Ikona w kolorze tekstu */
.sidebar-link iconify-icon {
    font-size: 1.4rem;
    color: currentColor; 
}

/* --- LOGIKA WYŚWIETLANIA MENU --- */
body[data-nav-mode="compact"] .app-menu { display: none; }
body[data-nav-mode="compact"] .hamburger-btn { display: flex; order: 1; }
body[data-nav-mode="compact"] .logo { position: absolute; left: 50%; transform: translateX(-50%); margin: 0; order: 2; }
body[data-nav-mode="compact"] .user-actions { order: 3; margin-left: auto; }
body[data-nav-mode="compact"] .app-bar { padding: 0 1rem; }


/* --- LOGO --- */
.logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    z-index: 2;
    color: var(--text-main); 
    transition: color 0.3s;
}

.logo svg {
    width: auto;
    height: 2.5rem; 
    display: block;
    margin-top: 0; 
}

/* --- USER ACTIONS --- */
.user-actions { 
    display: flex; 
    align-items: center; 
    gap: 1rem; 
    margin-left: auto;
    z-index: 2;
    position: relative; 
	width: auto;
	justify-content: right;
}

.avatar {
    width: 3rem; height: 3rem;
    border-radius: 50%;
    background-color: var(--bg-surface-2);
    border: 0.125em solid var(--primary-main);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
}
.avatar:hover { transform: scale(1.05); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* User Dropdown */
.user-dropdown {
    position: absolute; top: 100%; right: 0; margin-top: 0.5rem;
    width: 16rem; background-color: var(--bg-surface);
    border: 0.0625em solid var(--border-color);
    border-radius: 0.5rem; box-shadow: var(--shadow-md);
    display: none; flex-direction: column; overflow: hidden; z-index: 100;
}
.user-dropdown.active { display: flex; animation: fadeIn 0.2s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

.user-dropdown-header { padding: 1rem; border-bottom: 0.0625em solid var(--border-color); background-color: var(--bg-surface-2); }
.user-name { font-weight: 800; font-size: 1.1em; display: block; color: var(--text-main); }
.user-role { font-size: 0.85em; color: var(--text-secondary); }
.user-dropdown-content { padding: 0.5rem; }

.dropdown-item {
    display: flex; align-items: center; gap: 0.75rem; width: 100%; padding: 0.75rem 1rem;
    color: var(--text-main); background: transparent; border: none; cursor: pointer;
    text-align: left; border-radius: 0.25rem; transition: background-color 0.2s;
    font-weight: 600; font-size: 0.95em; text-decoration: none;
}
.dropdown-item:hover { background-color: var(--bg-surface-2); color: var(--primary-main); }
.dropdown-divider { height: 0.0625em; background-color: var(--border-color); margin: 0.5rem 0; }


/* --- VIEWPORT & FILMSTRIP --- */
.viewport {
    flex: 1; position: relative; overflow: hidden; background-color: var(--bg-surface-2); cursor: grab;
    transition: filter 0.3s ease-in-out; 
}
.viewport:active { cursor: grabbing; }

body.user-menu-open .viewport {
    filter: blur(0.25rem) brightness(0.6);
    pointer-events: none;
    user-select: none;
}

#filmstrip {
    display: flex; height: 100%;
    transform: translateX(0); 
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform; padding-left: 0; 
}


/* --- PANELE --- */
.panel {
    width: var(--panel-width); 
    height: 100%; 
    flex-shrink: 0;
    border-right: 0.0625em solid var(--border-color); 
    background-color: var(--bg-surface);
    display: flex; 
    flex-direction: column;
    
    position: relative;
    overflow: hidden; 

    /* Domyślnie panel jest widoczny */
    opacity: 1;
    transform: translateX(0);
	transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                        margin 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                        opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                        transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                        border-width 0.35s ease;
    overflow: hidden; /* Kluczowe przy zwijaniu width */
}

/* --- ANIMACJA WEJŚCIA NOWEGO PANELU --- */
.panel.anim-enter {
    animation: 
        /* 1. Rozsuwanie sąsiadów (szybsze: 0.4s) */
        makeSpace 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards,
        
        /* 2. Wsuwanie się panelu (wolniejsze: 0.6s) */
        slideContent 0.6s cubic-bezier(0.25, 1, 0.5, 1) forwards;
        
    /* Panel startuje niewidoczny, żeby nie mignął przed animacją */
    opacity: 0; 
    
    /* Ukrywamy nadmiar podczas animacji szerokości */
    overflow: hidden;
}

/* Animacja 1: Rozszerzanie szerokości od 0 do pełnej */
@keyframes makeSpace {
    0% {
        width: 0;
        min-width: 0;
        border-right-width: 0;
    }
    100% {
        width: var(--panel-width);
        min-width: var(--panel-width);
        border-right-width: 0.0625em;
    }
}

/* Animacja 2: Wsuwanie treści z lewej strony (spod poprzedniego panelu) */
@keyframes slideContent {
    0% {
        opacity: 0; /* Na starcie niewidoczny */
        transform: translateX(-50%); /* Startuje "pod" lewym sąsiadem */
    }
    40% {
        opacity: 1; /* Szybko staje się widoczny */
    }
    100% {
        opacity: 1;
        transform: translateX(0); /* Ląduje na miejscu */
    }
}


/* NOWOŚĆ: Uchwyt w postaci 4 kropek */
.panel-drag-handle {
    width: 4em;
    height: 1.5rem; /* Większa strefa kliknięcia dla wygody */
    margin: 0 auto; /* Wyśrodkowanie */
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.4;
    transition: opacity 0.2s, transform 0.2s;
}

.panel-drag-handle:hover {
    opacity: 1;
    transform: scale(1.1);
}

.panel-drag-handle:active {
    cursor: grabbing;
}

/* Rysowanie 4 kropek za pomocą jednego elementu i cieni (shadow clone technique) */
.panel-drag-handle::before {
    content: '';
    display: block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: var(--text-secondary);
    /* Cienie tworzą kolejne 3 kropki po prawej */
    box-shadow: 
        10px 0 0 var(--text-secondary),
        20px 0 0 var(--text-secondary),
        30px 0 0 var(--text-secondary);
    /* Przesunięcie w lewo o połowę szerokości całego układu kropek, żeby były idealnie na środku */
    transform: translateX(-15px);
}

/* Style dla panelu podczas sortowania */
.panel.is-sorting {
    position: absolute; /* Wyjęcie z normalnego przepływu */
    z-index: 1000 !important;
    box-shadow: 0 0.5rem 1.5rem rgba(0,0,0,0.25);
    opacity: 0.95;
    transform: scale(1.02) translateY(0.7em);; 
    border-radius: 0.5rem;
    border: 1px solid var(--primary-main);
    
    /* Wyłączamy animacje wejścia podczas dragowania */
    animation: none !important; 
    transition: none !important;
}

/* Placeholder */
.panel-placeholder {
    width: var(--panel-width);
    height: 100%;
    flex-shrink: 0;
    background-color: rgba(0,0,0,0.03);
    border: 0.35em dashed var(--border-color);
    border-radius: 0.5rem;
    margin-right: 0,0625em;
    /* Dodajemy transition dla szerokości na wypadek dynamicznych zmian */
    transition: width 0.2s;
}


/* Zabezpieczenie szerokości dzieci panelu */
.panel > * {
    min-width: var(--panel-width);
}

.panel-header { 
    padding: 0em 1em 1em 1em; /* Zmniejszony padding-top bo jest handle */
	min-height:7em;
    border-bottom: 0.0625em solid var(--border-color); 
    background-color: var(--bg-surface); 
    position: sticky; top: 0; z-index: 2; 
}
.panel-top-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0; margin-top: 0em;}
.panel-actions { display: flex; gap: 0.5em; }
.panel-content { flex: 1; overflow-y: auto; padding: 0rem /* było: 1.5em */; scrollbar-width: thin; scrollbar-color: var(--text-muted) transparent;
 	/* Ukrywanie paska przewijania (Firefox) */
	scrollbar-width: none; 
	/* Ukrywanie paska przewijania (IE/Edge stare) */
	-ms-overflow-style: none;  }
/* Ukrywanie paska przewijania (Chrome/Safari/Webkit) */
.panel-content::-webkit-scrollbar {
	display: none;
}

/* Linki w panelach */
.panel-link {
    display: block; padding: 1rem; margin-bottom: 0.5rem; background-color: var(--bg-surface-2);
    border-radius: 0.5rem; cursor: pointer; transition: all 0.2s; border-left: 0.25rem solid transparent;
}
.panel-link:hover { background-color: var(--secondary-brand-bg); border-left-color: var(--secondary-brand); }
.panel-link h4 { font-weight: 600; margin-bottom: 0.2em; display: flex; align-items: center; gap: 0.5em; }
.panel-link h4 svg { color: var(--primary-main); font-size: 0.9em; }
.panel-link p { font-size: 0.85em; color: var(--text-secondary); margin: 0; }
.panel-link.active { background-color: var(--secondary-brand-bg); border-left-color: var(--secondary-brand); }

/* --- PANEL TOOLBAR --- */
.panel-toolbar {
	display: flex;
	gap: 0.5rem;
	padding-top: 0.8em;
    margin-top: 0.5em;
    border-top: solid 0.0625em var(--border-color);
}
.toolbar-btn {
    background: transparent; border: 0.0625em solid var(--border-color); border-radius: 0.25rem;
    color: var(--text-muted); cursor: pointer; padding: 0.4em 0.8em; font-size: 1.2rem;
    font-weight: 600; display: flex; align-items: center; gap: 0.4em; transition: all 0.2s; flex: 1; justify-content: center;
}
.toolbar-btn:hover { border-color: var(--primary-main); color: var(--primary-main); background-color: rgba(255, 204, 0, 0.05); }
.toolbar-btn svg { font-size: 1.1em; }

/* --- UI HELPERS --- */
.btn-icon {
    background: transparent; border: none; cursor: pointer; color: var(--text-muted);
    font-size: 1.1em; width: 2em; height: 2em; display: flex; align-items: center; justify-content: center;
    border-radius: 50%; transition: all 0.2s;
}
.btn-icon:hover { color: var(--primary-main); background-color: var(--bg-surface-2); }
.btn-icon:active { transform: scale(0.9); }

.nav-controls { position: absolute; bottom: 2rem; right: 2rem; display: flex; gap: 1rem; z-index: 20; }
.nav-btn {
    width: 3rem; height: 3rem; border-radius: 50%; background-color: var(--primary-main); color: var(--primary-content);
    display: flex; align-items: center; justify-content: center; font-size: 1.2rem; box-shadow: var(--shadow-md); border: none;
    cursor: pointer; transition: transform 0.2s;
}
.nav-btn:hover { transform: scale(1.1); }
.nav-btn:active { transform: scale(0.9); }
.nav-btn:disabled { background-color: var(--text-muted); opacity: 0.5; cursor: not-allowed; }

.debug-info { position: absolute; bottom: 0.5rem; left: 0.5rem; font-size: 0.7rem; color: var(--text-muted); pointer-events: none; }


/* --- ORIENTATION LOCK --- */
#orientation-lock {
    display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background-color: var(--bg-body); color: var(--text-main); z-index: 99999;
    flex-direction: column; justify-content: center; align-items: center; gap: 1.5rem; text-align: center;
}
#orientation-lock svg { font-size: 3rem; color: var(--primary-main); animation: rotate-device 3s infinite ease-in-out; }
#orientation-lock span { font-family: 'Dosis', sans-serif; font-size: 1.5rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; }
@keyframes rotate-device { 0%, 20% { transform: rotate(0deg); } 40%, 60% { transform: rotate(-90deg); } 80%, 100% { transform: rotate(0deg); } }
@media screen and (orientation: landscape) and (max-height: 500px) {
    #orientation-lock { display: flex; }
    .app-container { filter: blur(5px); }
}


/* Domyślny styl ikon */
iconify-icon { display: inline-block; vertical-align: middle; font-size: 1.5em;}

.btn-toolbar iconify-icon { font-size: 1.5em; margin-bottom: 0.1em; transition: color 0.2s, transform 0.2s; }
.panel-link h4 iconify-icon { color: var(--primary-main); font-size: 1.1em; margin-right: 0.4em; }
.toolbar-btn iconify-icon { font-size: 1.1em; }
.nav-btn iconify-icon { font-size: 1.5rem; }
.btn-icon iconify-icon { font-size: 1.25em; }
.theme-btn iconify-icon { font-size: 1.2em; }
.dropdown-item iconify-icon { font-size: 1.2em; }
#orientation-lock iconify-icon { font-size: 3rem; color: var(--primary-main); animation: rotate-device 3s infinite ease-in-out; }


.sidebar-link iconify-icon {
	color: currentColor; 
	font-size: 1.4rem;
}

.hamburger-btn iconify-icon {
	font-size: 1.8rem;
}

.btn-toolbar iconify-icon { font-size: 1.5em; margin-bottom: 0.1em; transition: color 0.2s, transform 0.2s; }
.logo iconify-icon { font-size: 2.5rem; }
.panel-link h4 iconify-icon { color: var(--primary-main); font-size: 1.1em; margin-right: 0.4em; }
.toolbar-btn iconify-icon { font-size: 1.1em; }
.nav-btn iconify-icon { font-size: 1.5rem; }
.btn-icon iconify-icon { font-size: 1.25em; }
.theme-btn iconify-icon { font-size: 1.2em; }
.dropdown-item iconify-icon { font-size: 1.2em; }
#orientation-lock iconify-icon { font-size: 3rem; color: var(--primary-main); animation: rotate-device 3s infinite ease-in-out; }

/* Ukrywanie uchwytu, gdy jest tylko jeden panel */
.panel:only-child .panel-drag-handle {
	display: none !important;
}

/* Absolutne centrowanie menu w trybie "full" (desktop) */
body[data-nav-mode="full"] .app-menu {
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	width: auto;
	margin: 0;
}

/* --- NOWE STYLE DLA SCROLLA I CIENI --- */

/* Wrapper potrzebny do pozycjonowania cieni względem obszaru treści */
.panel-content-wrapper {
	flex: 1;
	position: relative;
	overflow: hidden; /* Cienie nie mogą wystawać */
	display: flex;
	flex-direction: column;
}




/* Elementy cienia */
.scroll-shadow {
	position: absolute;
	left: 0;
	right: 0;
	height: 1rem; /* Wysokość cienia */
	z-index: 10;
	pointer-events: none; /* Kliknięcia przechodzą przez cień */
	opacity: 0; /* Domyślnie ukryty */
	transition: opacity 0.3s ease;
}

.scroll-shadow.top {
	top: 0;
	background: linear-gradient(to bottom, rgba(0, 0, 0, 0.15), transparent);
}

.scroll-shadow.bottom {
	bottom: 0;
	background: linear-gradient(to top, rgba(0, 0, 0, 0.15), transparent);
}

/* W trybie ciemnym cienie mogą być nieco mocniejsze lub inne */
[data-theme="dark"] .scroll-shadow.top {
	background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent);
}
[data-theme="dark"] .scroll-shadow.bottom {
	background: linear-gradient(to top, rgba(0, 0, 0, 0.5), transparent);
}