:root{
  --bg:#121212;
  --panel:#1e1e1e;
  --accent:#4dabf7;
  --card:#1b1b1b;
}

/* Base */
html, body {
  height: 100%;
  margin: 0;
}
body{
  margin:0;
  font-family:Arial, Helvetica, sans-serif;
  background:var(--bg);
  color:#eee;
  display:flex;
  height:100vh;
  flex-direction:column;
  overflow: hidden;
}
.app-wrap{ 
  display:flex; 
  flex:1; 
  align-items:stretch; 
  min-height: 0; 
  min-width: 0; 
  height:100%;
}

/* Sidebar & content */
#sidebar{
  display:flex; 
  flex-direction: column;
  width:360px;
  background:var(--panel);
  padding:12px;
  overflow-y:hidden;
  border-right:1px solid #222;
  box-sizing:border-box;
  align-self:stretch;
  min-height: 0;
  height:100%;
}
#content{ 
  display:flex; 
  flex-direction: column;
  flex: 1;
  box-sizing:border-box; 
  min-width: 0; 
  min-height: 0; 
  height:100%;
  overflow-y:hidden; 
}

/* Headings */
h2,h3{ margin:6px 0; color:#fff; }

/* Form controls */
input,select,textarea,button{
  background:#262626;
  color:#eee;
  border:1px solid #333;
  padding:6px;
  border-radius:4px;
  box-sizing:border-box;
}

/* Buttons */
.btn{
  background:var(--accent);
  color:#fff;
  border:none;
  padding:7px 10px;
  border-radius:6px;
  cursor:pointer;
}
.btn-danger{
  background:#c0392b;
  color:#fff;
  border:none;
  padding:7px 10px;
  border-radius:6px;
}

/* Utility */
.small{ font-size:12px; color:#aaa; margin-left:6px; }
.admin-box{ background:#151515; padding:10px; border:1px solid #333; border-radius:6px; margin:8px 0; }

/* Lists & tree */
ul{ list-style:none; padding-left:14px; margin:6px 0; }
li{ margin:4px 0; }

/* Tree row layout */
.tree-row{ display:flex; align-items:center; gap:6px; position:relative; z-index:1; }

.tree-toogle:hover{ background: rgba(77,171,247,0.06); }
.tree-toogle.placeholder { visibility:hidden; width:18px; display:inline-block; }

/* When expanded */
li.expanded > .children { display:block !important; }
li.expanded > .tree-row > .tree-toogle {
  background: rgba(159,211,255,0.06);
  color:#9fd3ff;
}

/* Hide children by default, JS controls showing */
#categoryTree ul.children,
#projectTree ul.children,
#componentsTree ul.children,
#categoryTree .children,
#projectTree .children,
#componentsTree .children {
  display:none;
  margin:4px 0 0 12px;
  padding-left:12px;
}

/* Names (clickable) */
.category-name, .projekt-name, .raport-name, .tree-group-name {
  cursor:pointer;
  user-select:none;
  padding:4px 6px;
  border-radius:6px;
  transition: background .12s ease;
}
.category-name:hover, .projekt-name:hover, .raport-name:hover, .tree-group-name:hover {
  background: rgba(159,211,255,0.03);
}

/* Checked visual */
#categoryTree .tree-check:checked + .category-name,
#projectTree .tree-check:checked + .projekt-name {
  background: rgba(77,171,247,0.04);
}

/* Tree containers */
#categoryTree, #projectTree, #componentsTree {
  list-style:none;
  margin:0;
  padding-left:8px;
  max-height: calc(60vh - 120px);
  overflow:auto;
}

/* Project-specific tree tweaks */
#projectTree.project-tree { list-style:none; margin:0; padding-left:14px; box-sizing:border-box; max-height: calc(60vh - 120px); overflow:auto; }
#projectTree.project-tree > li, #projectTree.project-tree li { display:block; margin:4px 0; }
#projectTree .tree-toogle { width:22px; flex:0 0 22px; text-align:center; color:var(--accent); }
#projectTree ul.children { margin:4px 0 0 18px; padding-left:12px; }

/* Search inputs */
.search-input,
#categorySearch,
#projectSearch,
#projectProductSearch,
#productSearchInput,
#project_product_search,
#project_product_search_results {
  width:100%;
  box-sizing:border-box;
  padding:7px 8px;
  border-radius:6px;
  border:1px solid #333;
  background:#262626;
  color:#eee;
  font-size:13px;
}

/* Small search row helper */
.search-row { display:flex; gap:8px; align-items:center; }
.search-result.empty, .search-result .empty { color:#999; font-size:13px; padding:6px 4px; }

/* Projects area layout */
#projectsArea { 
  display:flex; 
  flex: 1; 
  flex-direction:column; 
  gap:8px; 
  padding-bottom:6px; 
  min-height: 0;
  overflow: hidden;
}
.projects-search-row, .projects-actions-row { width:100%; box-sizing:border-box; }

/* Tables */
table{ 
  width:100%; 
  border-collapse:collapse; 
  margin-top:12px; 
  max-width: 100%;
}
th,td{ 
  border:1px solid #333; 
  padding:8px; 
  text-align:left; 
  vertical-align:top; 
}
th{ 
  background:#171717; 
  cursor:pointer; 
  position: relative; 
  top: 0; 
  z-index: 50; 
  box-shadow: 0 4px 0 #171717;
}
thead tr:first-child th{ 
  position: sticky; 
  top: 0; 
  z-index: 50; 
  background:#171717;
  box-shadow: 0 4px 0 #171717;
}
thead tr.filters-row th{ 
  position: sticky; 
  top: var(--thead-offset, 0px); /* dynamiczne */
  z-index: 49; 
  background:#171717;
  box-shadow: 0 4px 0 #171717;
}

/* Thumbnail */
img.thumb{ width:100px; height:70px; object-fit:contain; object-position:center; border-radius:4px; }

/* Muted text */
.muted{ color:#999; font-size:13px; }

/* Toast notifications */
#toast{ position:fixed; right:20px; bottom:20px; z-index:9999; }
.toast{ background:#222; color:#fff; padding:10px 14px; margin-top:8px; border-radius:6px; box-shadow:0 2px 6px rgba(0,0,0,0.6); border-left:4px solid var(--accent); }
.toast.error{ border-left-color:#e74c3c; }

/* History list */
.history-list{ max-height:40vh; overflow:auto; border-top:1px solid #333; margin-top:12px; padding-top:8px; }
.history-item{ border-bottom:1px dashed #2a2a2a; padding:6px 0; font-size:13px; color:#ccc; }

/* Param item (drag & drop) */
.param-item { display:flex; gap:8px; align-items:center; padding:6px; border-bottom:1px solid #222; background:transparent; }
.param-item .drag-handle { cursor:grab; padding:6px 8px; color:#9fd3ff; user-select:none; }
.param-item.dragging { opacity:0.5; }
.param-item.placeholder { background: rgba(255,255,255,0.02); border:1px dashed #444; }

.param-list {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #333;
  padding: 10px 12px;
  margin-bottom: 5px;

  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 0px;
  align-items: center;
}
/* Modals */
.modal{
  display:none;
  position:fixed;
  left:0; top:0;
  width:100%; height:100%;
  background:rgba(0,0,0,0.6);
  z-index:200000; /* above most content */
  pointer-events:auto;
}
.modal .box{
  background:var(--card);
  width:760px;
  margin:4% auto;
  padding:16px;
  border-radius:8px;
  border:1px solid #333;
  color:#eee;
  max-width:95%;
  max-height:85vh;
  overflow:auto;
  position:relative;
  z-index:200001;
}

/* Modal close */
.modal .close{ float:right; cursor:pointer; padding:6px; border-radius:6px; }

/* Detail panel (bottom sheet) */
#detailPanel{
  position:fixed;
  left:0; right:0;
  bottom:-60%;
  height:40%;
  background:var(--card);
  border-top:1px solid #333;
  padding:12px;
  box-shadow:0 -6px 30px rgba(0,0,0,0.6);
  z-index:1500;
  transition:bottom .28s ease-in-out;
  overflow:auto;
}
#detailPanel.open{ bottom:0; }
#detailPanel .close{ float:right; cursor:pointer; padding:6px; border-radius:6px; }

/* layout within detail panel: left narrow column and flexible right */
#detailPanel #detailContent > div:first-child,
#detailPanel #detailContent > div {
  display:flex !important;
  flex-direction:row !important;
  gap:12px !important;
  align-items:flex-start !important;
}
#detailPanel #detailContent .detail-left-col,
#detailPanel #detailContent > div > div[style*="flex:0 0"] {
  flex:0 0 160px !important;
  min-width:160px !important;
  max-width:160px !important;
  text-align:center !important;
  display:flex !important;
  flex-direction:column !important;
  justify-content:flex-start !important;
  align-items:center !important;
}
#detailPanel #detailContent > div > div[style*="flex:1"] { flex:1 1 auto !important; }
#detailPanel .detail-buttons-wrap, #detailPanel .detail-buttons-wrap button {
  pointer-events:auto !important;
  position:relative !important;
  z-index:200005 !important;
}

/* Helpers for search result highlighting (JS may toggle) */
.category-hidden { display:none !important; }
.category-match { background: rgba(159,211,255,0.06); border-radius:4px; }
.category-ancestor { background: rgba(159,211,255,0.03); }

/* Focus outlines for accessibility */
.tree-toogle:focus, .category-name:focus, .projekt-name:focus {
  outline:2px solid rgba(159,211,255,0.14);
  outline-offset:2px;
}

/* Checkbox spacing */
.tree-row input[type="checkbox"] { transform: scale(1.02); margin-right:6px; }

/* Small helper sizes */
.search-input { height:36px; }

/* Project modal / product search results & container */
#projectModal .box, #projectProductsContainer { max-width:1100px; overflow-x:hidden; }
#projectProductsContainer { padding:8px; min-height:60px; }

/* Product table in project modal (if used) */
#projectProductsPanel .prod-table, .proj-prod-table-wrap .prod-table { width:100%; border-collapse:collapse; margin-top:8px; }
#projectProductsPanel .prod-table th, #projectProductsPanel .prod-table td { padding:6px 8px; border:1px solid #ddd; text-align:left; font-size:13px; }
#projectProductsPanel .prod-table input[type="number"]{ width:70px; padding:4px; }
#projectProductsPanel .prod-row-remove { color:#c00; background:transparent; border:none; cursor:pointer; }
#projectProductsPanel .prod-sum { font-weight:600; }

/* Responsive adjustments */
@media (max-width:900px){
  #sidebar{ width:280px; }
  .modal .box{ width:95%; }
}
@media (max-width:720px){
  .app-wrap{ flex-direction:column; }
  #sidebar{ width:100%; height:auto; border-right:none; border-bottom:1px solid #222; order:0; display:block; padding:10px; }
  #content{ order:1; padding:12px; }
  #sidebar.collapsed{ display:none; }
  .tree-row{ flex-wrap:wrap; }
  img.thumb{ width:80px; height:60px; }
  .modal .box{ width:95%; margin:6% auto; }
  #categoryTree, #projectTree { max-height:42vh; }
  #interfaceSwitcher { margin-top:36px; } /* safeguard if you later include switcher markup */
}

/* Safety: ensure modal sits above detail panel */
.modal { z-index:200000; pointer-events:auto; }
#detailPanel { z-index:1500; }

/* Ensure sidebar toggle visible on small screens */
#sidebarToggle { display:none; position:fixed; left:10px; top:10px; z-index:2200; padding:6px 8px; border-radius:6px; font-size:18px; }
@media (max-width:720px){ #sidebarToggle{ display:block; } }

/* Keep some legacy-safe selectors for server-rendered HTML */
#categoryModal, #paramModal, #productModal, #projectModal { /* modals already styled via .modal */ }

/* End of cleaned CSS for components.php + projects.php */
/* ---------- Interface switcher: button styles + mode-aware highlight ---------- */
/* Basic look for switcher buttons (keeps them subtle when inactive) */
#interfaceSwitcher {
  display:flex;
  gap:8px;
  margin-bottom:10px;
  align-items:center;
  flex-wrap:wrap;
}

#interfaceSwitcher .iface-btn {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(0,0,0,0.03));
  color: #e6eef8;
  border: 1px solid rgba(132,142,188,0.12);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight:700;
  font-size:13px;
  letter-spacing: .2px;
  transition: transform .08s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
  box-shadow: 0 1px 0 rgba(0,0,0,0.25) inset;
  min-height:36px;
  display:inline-flex;
  align-items:center;
  gap:6px;
}

/* active appearance used as fallback */
#interfaceSwitcher .iface-btn.active {
  background: linear-gradient(180deg, var(--accent), rgba(0,0,0,0.06));
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 8px 18px rgba(10,30,60,0.28);
}

/* Mode-aware highlight: when body[data-interface-mode="X"] is set,
   highlight the button that has matching data-mode attribute. */
body[data-interface-mode="komponenty"] #interfaceSwitcher .iface-btn[data-mode="komponenty"],
body[data-interface-mode="projekty"]   #interfaceSwitcher .iface-btn[data-mode="projekty"],
body[data-interface-mode="raporty"]    #interfaceSwitcher .iface-btn[data-mode="raporty"] {
  /* highlighted look */
  background: linear-gradient(180deg, var(--accent), rgba(0,0,0,0.06));
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 8px 18px rgba(10,30,60,0.28);
  transform: translateY(-1px);
}

/* small / compact variant */
#interfaceSwitcher .iface-btn.small {
  padding:5px 8px;
  font-size:12px;
  min-height:30px;
  border-radius:6px;
}

/* focus outline for accessibility */
#interfaceSwitcher .iface-btn:focus {
  outline: 2px solid rgba(159,211,255,0.22);
  outline-offset: 2px;
  box-shadow: 0 6px 14px rgba(10,30,60,0.18);
}

/* responsive tweaks already present in your CSS will keep switcher usable */


/* Small styles for project modal items and small buttons */
.proj-item { display:flex; gap:12px; align-items:center; justify-content:space-between; padding:10px 12px; border-bottom:1px solid rgba(255,255,255,0.03); background:transparent; box-sizing:border-box; transition:background .12s ease; }
.proj-item:hover { background: rgba(159,211,255,0.02); }
.proj-item-left { flex:1 1 0%; min-width:0; }
.proj-item-left strong { color:#fff; display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; font-weight:700; }
.proj-item-left .small { color:#bbb; margin-top:4px; font-size:13px; }

.qty-wrap { margin:0 12px; display:flex; flex-direction:column; gap:6px; align-items:flex-start; }
.qty-wrap label.small { color:#bbb; margin:0; }
.qty-wrap input.proj-qty { width:90px; padding:6px; border-radius:6px; background:#262626; color:#eee; border:1px solid #333; box-sizing:border-box; }

.right-wrap { margin-left:12px; display:flex; gap:8px; align-items:center; }
.right-wrap .proj-price { min-width:70px; text-align:right; color:#9fd3ff; font-weight:600; display:inline-block; }
.remove-proj-item { padding:6px 8px; border-radius:6px; background:transparent; border:1px solid rgba(255,255,255,0.04); color:#fff; cursor:pointer; }

/* price-badge style (used in search and can be used in proj item) */
.price-badge {
  display:inline-block;
  background: rgba(159,211,255,0.04);
  padding:4px 8px;
  border-radius:6px;
  color:#9fd3ff;
  font-weight:700;
  font-size:13px;
}

/* search-result-item layout (kept consistent) */
.search-result-item { display:flex; justify-content:space-between; align-items:center; padding:8px; border-bottom:1px solid rgba(255,255,255,0.02); gap:12px; box-sizing:border-box; }
.search-left { min-width:0; display:block; }
.search-name { display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; font-weight:700; color:#fff; }
.search-meta { color:#bbb; margin-top:4px; font-size:13px; }

.search-centre { display:flex; flex-direction:column; align-items:flex-start; }
.search-qty { width:80px; padding:6px; border-radius:6px; }

.search-right { display:flex; align-items:center; gap:8px; }

.search-result-item .price-wrap { margin-top:6px; }
.price-wrap .price-badge { display:inline-block; }

/* ensure results box hidden by default; JS toggles display on the container element */
#project_product_search_results { display:none; border: 1px solid rgba(255,255,255,0.03); border-radius:6px; background: rgba(0,0,0,0.04); padding:6px; }

/* responsive */
@media (max-width:720px){
  .proj-item { flex-direction:column; align-items:flex-start; gap:8px; }
  .right-wrap { margin-left:0; align-self:flex-end; }
  .qty-wrap input { width:100%; }
}

/* ensure no accidental inline margins break layout for proj items */
.proj-item > div { margin:0; }

/* little helpers */
.muted { color:#999; font-size:13px; }
.small { font-size:12px; color:#aaa; }
.btn-small { padding:6px 8px; font-size:13px; border-radius:6px; }




/* Sidebar: układ kolumnowy, umożliwia "wypchnięcie" categoryTree do dołu 
#sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0; // ważne żeby elementy wewnątrz mogły się kurczyć 
  box-sizing: border-box;
}*/

/* Obszar kategorii zajmuje pozostałą przestrzeń */
#categoriesArea, #aportsArea {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0; 
  overflow: hidden;
}

/* Formularz wewnątrz categoriesArea też rozciąga się (jeśli istnieje) */
#categoriesArea form#categoryForm,
#categoriesArea > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* Wyszukiwarka i przyciski pozostają o stałej wysokości */
#categoriesArea > input,
#categoriesArea > div,
#categoriesArea .search-row,
#categoriesArea .projects-actions-row {
  flex: 0 0 auto;
}

/* MAIN: categoryTree rozciąga się do końca sidebar i jest przewijalne */
#sidebar #categoryTree,
#sidebar #projectTree,
#sidebar #raportTree  {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  height: auto;
  overflow: auto;
  box-sizing: border-box;
  padding-right: 6px; 
  overflow: auto;
}
#content #productsContent,
#content #projectsContent,
#content #raportContent  {
  flex: 1;
  min-width: 0;
  min-height: 0;
  max-height: none;
  height: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
}


/* Mały tweak UI: upewnij się, że tytuł i drobne elementy nie przyklejają się do góry */
#sidebarTitle { margin-top:8px; margin-bottom:8px; }

/* Responsywne dopasowanie (wyłącznie na wąskich ekranach) */
@media (max-width:720px){
  #sidebar { flex: 0 0 auto; } /* w trybie kolumnowym możesz chcieć inne zachowanie */
}

:root{
  --suggest-bg: #ffffff;
  --suggest-border: #e6e6e6;
  --suggest-shadow: 0 6px 18px rgba(0,0,0,0.06);
  --text: #222;
  --subtext: #666;
  --item-hover: #f5f7fb;
  --btn-bg: #0b74d1;
  --btn-bg-hover: #095ca8;
  --btn-color: #fff;
  --muted-border: #e9e9e9;
}

/* SUGGESTIONS - pokazywać ~5 elementów, przewijać listę */
.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  max-height: calc(5 * 44px); /* ~5 itemów po 44px */
  overflow-y: auto;
  border: 1px solid var(--suggest-border);
  background: var(--suggest-bg);
  box-shadow: var(--suggest-shadow);
  display: none;
  margin-top: 6px;
  border-radius: 6px;
  z-index: 1200;
}

/* pojedynczy element w liście */
.suggestions .item {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:8px 10px;
  height:44px;
  line-height:1;
  border-bottom:1px solid var(--muted-border);
  cursor:default;

  background-color: #262626;
}

.suggestions .item:last-child { border-bottom: none; }



.suggestions .item .meta {
  display:flex;
  flex-direction:column;
  min-width:0;
  overflow:hidden;
}

.suggestions .item .meta .title {
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  font-weight:500;
  color: var(--text);
}

.suggestions .item .meta .sub {
  font-size:12px;
  color: var(--subtext);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

/* Add button (jednolity styl) */
.suggestions .add-btn {
  flex: 0 0 auto;
  border: none;
  background-color: var(--btn-bg);
  color: var(--btn-color);
  padding:6px 8px;
  border-radius:4px;
  font-size:13px;
  cursor:pointer;
}
.suggestions .add-btn:hover { background-color: var(--btn-bg-hover); }


.tree-row{ display:flex; align-items:center; gap:6px; position:relative; z-index:1; }
/* używamy klasy 'tree-toogle' aby dopasować do CSS który podałeś */
.tree-toogle {
    cursor: pointer;
    user-select: none;
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    min-width: 22px;
    text-align: center;
    font-weight: 700;
}
.tree-toogle:hover{ background: rgba(77,171,247,0.06); }
.tree-toogle.placeholder { visibility:hidden; width:18px; display:inline-block; }
/*
#categoryTree, #projectTree, #componentsTree { list-style: none; margin: 0; padding-left: 8px; max-height: calc(60vh - 120px); overflow: auto; }
*/
ul { list-style: none; padding-left: 14px; margin: 6px 0; }

/* Focus outlines for accessibility */
.tree-toogle:focus, .category-name:focus, .projekt-name:focus {
  outline:2px solid rgba(159,211,255,0.14);
  outline-offset:2px;
}

/* wygląd nazwy i mutedu */
.projekt-name{ padding:4px 6px; border-radius:4px; }
.projekt-name.muted { color:var(--muted-text, #6b7280); font-size:0.95em; }
.projekt-name.selected { background: rgba(77,171,247,0.08); }
.qty.muted { color:var(--muted-text, #6b7280); margin-left:6px; }

/* children list visibility when expanded */
li.expanded > .children { display:block !important; }

/* proste formatowanie drzewa */
#projectTree ul { list-style:none; margin:0; padding-left:20px; }
#projectTree li { margin:2px 0; }

/* checkbox styling minimal */
.tree-check { margin-right:8px; }
/* End of file */
.hidden-by-search {
  display: none !important;
}

