* { box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
body { margin: 0; padding: 0; background: #0f172a; color: #f8fafc; font-size: 14px; }

header {
    background: #1e293b;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #334155;
}

.logo { font-size: 18px; font-weight: bold; color: #fbbf24; display: flex; align-items: center; gap: 8px; }

.nav-links { display: flex; gap: 10px; align-items: center; }
.nav-links a, .nav-links button {
    color: #94a3b8;
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 6px;
    font-weight: bold;
    background: #334155;
    border: none;
    cursor: pointer;
}
.nav-links a.active, .nav-links button:hover, .nav-links a:hover { background: #475569; color: #fff; }

.app-layout { display: flex; height: calc(100vh - 58px); overflow: hidden; }

/* LEWY PANEL */
.sidebar-left { width: 340px; background: #1e293b; border-right: 1px solid #334155; display: flex; flex-direction: column; }
.sidebar-tabs { display: flex; border-bottom: 1px solid #334155; }
.tab-btn { flex: 1; padding: 10px; background: #0f172a; color: #94a3b8; border: none; cursor: pointer; font-weight: bold; }
.tab-btn.active { background: #1e293b; color: #fbbf24; border-bottom: 2px solid #fbbf24; }

.catalog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; overflow-y: auto; flex-grow: 1; }
.product-card {
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.product-card img { height: 85px; object-fit: contain; margin-bottom: 6px; }
.product-card .title { font-weight: bold; font-size: 12px; height: 30px; overflow: hidden; }
.product-card .price { color: #fbbf24; font-weight: bold; font-size: 13px; margin: 4px 0; }
.btn-add { background: #f59e0b; color: #000; border: none; padding: 6px; border-radius: 4px; font-weight: bold; cursor: pointer; }

/* CANVAS AREA */
.canvas-area { flex-grow: 1; background: #020617; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; }
.top-toolbar { position: absolute; top: 12px; display: flex; gap: 8px; background: #1e293b; padding: 8px 14px; border-radius: 8px; border: 1px solid #334155; z-index: 10; }

#canvas-board {
    width: 650px;
    height: 650px;
    background-color: #ffffff;
    background-size: cover;
    background-position: center;
    border-radius: 12px;
    position: relative;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

#canvas-board.show-grid {
    background-image: linear-gradient(to right, rgba(0,0,0,0.08) 1px, transparent 1px),
                      linear-gradient(to bottom, rgba(0,0,0,0.08) 1px, transparent 1px);
    background-size: 20px 20px;
}

/* KONTROLKI I NAPISY NA BALONIE */
.placed-item { position: absolute; cursor: move; user-select: none; display: inline-block; }
.placed-item.selected { outline: 2px dashed #f59e0b; }

.balloon-text-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    text-align: center;
    white-space: nowrap;
    font-weight: bold;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.item-tools {
    position: absolute;
    top: -48px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 6px;
    display: none;
    gap: 3px;
    padding: 4px;
    z-index: 9999;
}
.placed-item.selected .item-tools { display: flex; }
.tool-btn { background: #334155; color: white; border: none; padding: 4px 6px; border-radius: 4px; cursor: pointer; font-size: 11px; }
.tool-btn:hover { background: #475569; }
.tool-btn.danger { background: #ef4444; }

/* PRAWY PANEL */
.sidebar-right { width: 330px; background: #1e293b; border-left: 1px solid #334155; padding: 15px; display: flex; flex-direction: column; justify-content: space-between; }
.summary-box { background: #0f172a; padding: 12px; border-radius: 8px; border: 1px solid #334155; text-align: center; margin-bottom: 12px; }
.summary-box h2 { color: #22c55e; margin: 4px 0; }

.shopping-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; max-height: 280px; }
.shopping-list li { background: #0f172a; padding: 8px 10px; border-radius: 6px; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; border: 1px solid #334155; }

.btn-main { background: #22c55e; color: black; width: 100%; padding: 10px; border: none; border-radius: 6px; font-weight: bold; font-size: 14px; cursor: pointer; margin-top: 6px; }
.btn-main:hover { background: #16a34a; }

/* MODALE */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 1000; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-content { background: #1e293b; border: 1px solid #334155; padding: 20px; border-radius: 10px; width: 450px; max-width: 90%; }

/* ADMIN & LOGOWANIE */
.admin-container { max-width: 1100px; margin: 20px auto; padding: 20px; }
.admin-panel { background: #1e293b; padding: 18px; border-radius: 8px; border: 1px solid #334155; }
.form-group { margin-bottom: 10px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: bold; }
.form-group input, .form-group select { width: 100%; padding: 8px; background: #0f172a; border: 1px solid #334155; color: white; border-radius: 4px; }
.toggle-label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.toggle-label input { width: auto; }



/* ZOPTYMALIZOWANY LEWY PANEL Z BALONAMI */
.catalog-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    padding: 8px !important;
    overflow-y: auto !important;
}

.product-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    justify-content: space-between;
    height: 160px; /* Stała, zwarta wysokość boxa */
    box-sizing: border-box;
}

.product-card img {
    max-width: 100%;
    height: 65px;
    object-fit: contain;
    margin-bottom: 4px;
}

.product-card .title {
    font-size: 11px;
    font-weight: 600;
    color: #e2e8f0;
    line-height: 1.2;
    margin-bottom: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 26px;
}

.product-card .price {
    font-size: 12px;
    font-weight: bold;
    color: #22c55e;
    margin-bottom: 4px;
}

.product-card .btn-add {
    width: 100%;
    padding: 4px 6px;
    font-size: 11px;
    background: #22c55e;
    color: #000;
    font-weight: bold;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.product-card .btn-add:hover {
    background: #16a34a;
}

/* WARSTWA BALONÓW NA OBSZARZE ROBOCZYM (PŁYNNY DRAG) */
.placed-item {
    position: absolute;
    cursor: move;
    user-select: none;
    touch-action: none;
    transition: none !important; /* Usuwa opóźnienia przy przeciąganiu */
}

.placed-item.selected {
    outline: 2px dashed #fbbf24;
    outline-offset: 3px;
}

.item-tools {
    position: absolute;
    top: -42px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 3px 5px;
    gap: 4px;
    white-space: nowrap;
    z-index: 99999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.placed-item.selected .item-tools {
    display: flex;
}

.tool-btn {
    background: #334155;
    color: white;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-btn:hover {
    background: #475569;
}

.tool-btn.danger {
    background: #ef4444;
}

.balloon-text-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
    width: 85%;
    word-wrap: break-word;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    font-weight: bold;
}