:root {
    --bg-color: #fafafa;
    --sidebar-bg: #ffffff;
    --text-primary: #111;
    --text-secondary: #666;
    --border-color: #eaeaea;
    --accent-color: #000;
    --active-color: #0070f3;
    --center-point-color: #3b82f6;
    --radius: 12px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    
    --texture-url: url('images/oak_planks.png');
}

body {
    margin: 0; padding: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 360px;
    min-width: 280px;
    max-width: 600px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex; 
    flex-direction: column; 
    flex-shrink: 0;
    z-index: 100;
    position: relative;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    border-right: none;
    overflow: hidden;
}

.sidebar.collapsed > * {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

/* --- SIDEBAR RESIZER --- */
.sidebar-resizer {
    width: 12px;
    margin-left: -6px;
    background: transparent;
    cursor: col-resize;
    z-index: 101;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sidebar-resizer::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 0; bottom: 0;
    width: 1px;
    background: transparent;
}
.sidebar-resizer:hover::after, .sidebar-resizer.resizing::after {
    background: var(--active-color);
    width: 2px;
}

/* PRZYCISK ZWIJANIA (Strzałka) */
.sidebar-toggle-btn {
    width: 24px; height: 24px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    color: var(--text-secondary);
    transition: all 0.2s;
    z-index: 102;
}
.sidebar-toggle-btn:hover {
    background: var(--active-color);
    color: white;
    transform: scale(1.1);
}
.sidebar-toggle-btn svg {
    transition: transform 0.3s;
}
.sidebar.collapsed + .sidebar-resizer .sidebar-toggle-btn svg {
    transform: rotate(180deg);
}

b{ background-color: rgb(255, 67, 67); font-size: 10px; padding: 2px 6px; border-radius: 4px; ;}
.brand { padding: 24px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; gap: 10px; }
.brand h1 { font-family: 'BBH Hegarty', serif; font-size: 24px; margin: 0; }
.badge { background: #000; color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 600; }
.scroll-content { 
    flex: 1; 
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px; 
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}

.scroll-content::-webkit-scrollbar {
    width: 6px;
}
.scroll-content::-webkit-scrollbar-track {
    background: transparent;
}
.scroll-content::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 3px;
}
.section { margin-bottom: 24px; }
h2 { font-size: 12px; text-transform: uppercase; color: var(--text-secondary); letter-spacing: 1px; margin-bottom: 16px; margin-top: 0; }
.divider { height: 1px; background: var(--border-color); margin: 24px 0; }

/* INPUTS UI */
.control-group { margin-bottom: 16px; }
.control-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 8px; }
.control-group.row { display: flex; justify-content: space-between; align-items: center; }
.label-row { display: flex; justify-content: space-between; margin-bottom: 8px; }
.value-display { font-size: 12px; color: var(--text-secondary); background: #f0f0f0; padding: 2px 6px; border-radius: 4px; }
.input-wrapper { position: relative; }
input[type="number"] { width: 100%; padding: 10px 12px; border: 1px solid var(--border-color); border-radius: 8px; font-family: inherit; font-size: 14px; }
input[type="number"]:focus { outline: none; border-color: var(--active-color); }
.unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); font-size: 12px; pointer-events: none; }

/* SLIDERS & SWITCH */
input[type=range] { width: 100%; background: transparent; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; height: 16px; width: 16px; border-radius: 50%; background: #fff; border: 2px solid var(--text-primary); cursor: pointer; margin-top: -6px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 4px; background: var(--border-color); border-radius: 2px; }
.switch { position: relative; display: inline-block; width: 40px; height: 24px; }
.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: .4s; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 4px; bottom: 4px; background-color: white; transition: .4s; }
input:checked + .slider { background-color: var(--text-primary); }
input:checked + .slider:before { transform: translateX(16px); }
.slider.round { border-radius: 34px; } .slider.round:before { border-radius: 50%; }

/* MATERIAL GRID */
.material-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.material-item { cursor: pointer; border: 2px solid transparent; border-radius: 8px; overflow: hidden; transition: all 0.2s; background: #fff; }
.material-item:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
.material-item.selected { border-color: var(--active-color); box-shadow: 0 0 0 2px rgba(0, 112, 243, 0.1); }
.mat-preview { width: 100%; height: 40px; background-size: cover; background-position: center; background-repeat: no-repeat; background-color: #eee; }
.mat-name { display: block; font-size: 10px; text-align: center; padding: 6px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-secondary); background: #fff; }

/* CUSTOM UPLOAD */
.custom-upload-area { text-align: center; }
.divider-text { font-size: 10px; color: var(--text-secondary); margin: 10px 0; text-transform: uppercase; letter-spacing: 1px; position: relative; }
.divider-text::before, .divider-text::after { content: ''; position: absolute; top: 50%; width: 40%; height: 1px; background: var(--border-color); }
.divider-text::before { left: 0; }
.divider-text::after { right: 0; }
.btn-upload { width: 100%; padding: 10px; background: var(--text-primary); color: #fff; border: none; border-radius: 8px; font-size: 12px; font-weight: 500; cursor: pointer; transition: opacity 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-upload:hover { opacity: 0.9; }
.file-name-display { display: block; font-size: 11px; color: var(--active-color); margin-top: 6px; min-height: 14px; }

/* --- VIEWPORT --- */
.viewport {
    flex: 1; 
    background: var(--bg-color);
    background-image: radial-gradient(#e1e1e1 1px, transparent 1px);
    background-size: 20px 20px;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#grid-content-area {
    width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center; padding: 40px;
}

#grid-wrapper {
    position: relative;
    background: #fff;
    box-shadow: var(--shadow);
    border-radius: 4px;
    flex-shrink: 0; 
}

#grid {
    display: grid;
    gap: 0; 
    border-top: 1px solid #ccc;
    border-left: 1px solid #ccc;
    background-color: #fff;
    user-select: none;
}

/* --- CELL & BLOCKS --- */
.cell {
    width: 30px; height: 30px;
    min-width: 30px; min-height: 30px;
    background: #fff;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    padding: 0;
    position: relative;
    border-right: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    box-sizing: border-box; 
}

/* Sub-blocks (Tekstury) */
.sub-block { 
    width: 100%; height: 100%; 
    background-image: var(--texture-url); 
    background-size: 30px 30px; 
    opacity: 0; 
    z-index: 1;
}
.sub-block.filled { opacity: 1; }
.sub-block:nth-child(1) { background-position: 0 0; }
.sub-block:nth-child(2) { background-position: -15px 0; }
.sub-block:nth-child(3) { background-position: 0 -15px; }
.sub-block:nth-child(4) { background-position: -15px -15px; }

/* HOVER EFFECT */
.cell:hover::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 1px solid #aaa;
    background-color: rgba(247, 247, 247, 0.5);
    z-index: 100;
    pointer-events: none;
}
.cell:hover { cursor: crosshair; }

.cell.active-point::after {
    content: '';
    position: absolute;
    inset: 0;
    box-shadow: inset 0 0 0 2px red;
    z-index: 50;
    pointer-events: none;
}

.cell.manual-peak::after {
    content: '';
    position: absolute;
    inset: 0;
    box-shadow: inset 0 0 0 2px #00cc00;
    z-index: 51;
    pointer-events: none;
}

.cell.center-point::before {
    content: ''; position: absolute; top: 50%; left: 50%;
    width: 6px; height: 6px; background: var(--center-point-color); border-radius: 50%;
    transform: translate(-50%, -50%); 
    opacity: 0.8;
    z-index: 10;
}

/* --- MIRROR EFFECT (Biała nakładka) --- */
.sub-block.mirror-block {
    position: relative;
}
.sub-block.mirror-block::after {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(151, 125, 255, 0.5);
    pointer-events: none;
    z-index: 2;
}

/* --- RESIZE HANDLES --- */
.resize-handle {
    position: absolute; background: #fff; border: 1px solid var(--border-color);
    color: var(--text-primary); display: flex; justify-content: center; align-items: center;
    cursor: pointer; border-radius: 50%; width: 24px; height: 24px;
    font-size: 10px; z-index: 30; box-shadow: 0 2px 4px rgba(0,0,0,0.1); transition: transform 0.2s;
}
.resize-handle:hover { transform: scale(1.1); border-color: var(--active-color); }
.resize-handle.top { top: -12px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.resize-handle.top::after { content: '↕'; }
.resize-handle.right { right: -12px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.resize-handle.right::after { content: '↔'; }

/* --- HELP UI --- */
.help-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 40px; height: 40px;
    background: #000; color: #fff;
    border-radius: 50%;
    font-size: 20px; font-weight: bold;
    border: none; cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s;
    z-index: 1000;
}
.help-btn:hover {
    transform: scale(1.1);
    background: #333;
}

.btn-reset { width: 100%; padding: 10px; background: var(--text-primary); color: #fff; border: none; border-radius: 8px; font-size: 12px; font-weight: 500; cursor: pointer; transition: opacity 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; }

.btn-reset:hover { opacity: 0.9; }

.btn-reset:active {
    transform: translateY(0);
}

.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(2px);
    z-index: 2000; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal-content {
    background: white; padding: 30px; border-radius: 12px;
    max-width: 500px; width: 90%; box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    position: relative; font-family: 'Inter', sans-serif;
}
.modal-content h3 { margin-top: 0; border-bottom: 1px solid #eee; padding-bottom: 10px; }
.modal-content ul { line-height: 1.6; padding-left: 20px; color: #444; }
.modal-content li { margin-bottom: 8px; }

.close-modal {
    position: absolute; top: 15px; right: 20px; font-size: 24px;
    cursor: pointer; color: #888;
}
.close-modal:hover { color: #000; }

@media (max-width: 768px) {
    .app-container { flex-direction: column; }
    .sidebar { width: 100%; height: 40%; order: 2; border-right: none; border-top: 1px solid var(--border-color); }
    .viewport { height: 60%; order: 1; }
    .material-grid { grid-template-columns: repeat(5, 1fr); }
}

/* --- PRAWY PASEK REKLAMOWY (Ad Rail) --- */
.ad-rail {
    width: 160px;
    min-width: 160px;
    background: #f8f8f8;
    border-left: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    z-index: 90;
    padding: 10px;
    overflow: hidden;
}

.ad-placeholder-vertical {
    width: 160px; height: 600px;
    background: #e0e0e0; border: 1px dashed #aaa;
    display: flex; align-items: center; justify-content: center;
    text-align: center; font-size: 12px; color: #666;
}

.ad-box-modal {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    display: flex; justify-content: center;
}
.ad-placeholder-rect {
    width: 300px; height: 250px;
    background: #e0e0e0; border: 1px dashed #aaa;
    display: flex; align-items: center; justify-content: center;
    text-align: center; font-size: 12px; color: #666;
}