/* =========================================
   1. ZMIENNE I RESET (CORE)
   ========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Kolory neutralne */
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb; /* Używaj tej zmiennej zamiast #ddd */
  
  /* Kolory akcentów */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --chip-bg: #eef2ff;
  
  /* Paleta KPI / Statusów */
  --purple: #7c3aed; --purple-bg: #f3e8ff;
  --orange: #ea580c; --orange-bg: #fff1e6;
  --green:  #059669; --green-bg:  #ecfdf5;
  --red:    #ef4444; --red-bg:    #fee2e2;
  --blue:   #2563eb; --blue-bg:   #eff6ff;

  /* Efekty */
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.15);
  --radius: 14px;
}

html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* Płynne przejście marginesu przy zmianie widoku */
  transition: margin-left 0.3s ease; 
}

a { text-decoration: none; color: inherit; }

/* =========================================
   2. TOPBAR (Pasek górny)
   ========================================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #fff;
  border-bottom: 1px solid var(--line);
  height: 64px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  margin-left: 2px;
  white-space: nowrap;
}

/* Wyszukiwarka w topbarze */
.searchbar {
  flex: 1;
  max-width: 720px;
  position: relative;
}
.searchbar input {
  width: 100%;
  height: 42px;
  padding: 0 44px 0 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.2s;
}
.searchbar input:focus {
  outline: none;
  border-color: var(--primary);
}
.searchbar .search-ico {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #111827;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

/* =========================================
   3. BUTTONS (Przyciski)
   ========================================= */
.btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
  transition: all 0.2s ease;
}

/* Ikony */
.btn.icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.btn.icon:hover { background: #f2f4f7; color: var(--text); }

/* Ikony małe kolorowe */
.btn.icon.sm.orange {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--orange); color: #fff;
}
.btn.icon.sm.orange:hover { background: #d97706; }

/* Primary Button */
.btn.primary {
  background: var(--primary);
  color: #fff;
  padding: 9px 14px;
  border-radius: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.btn.primary:hover { background: var(--primary-hover); }

/* Chip Button */
.btn.chip {
  background: #f3f4f6;
  border-radius: 12px;
  padding: 9px 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #1f2937;
  font-size: 13px;
  font-weight: 500;
}

/* Pill Button */
.btn.pill {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: 30px; padding: 8px 16px;
  background: #fff; border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 14px; cursor: pointer;
}
.btn.pill i { color: var(--primary); }

/* Danger Button */
.btn.danger {
  background: #e53935; color: #fff;
  border: 1px solid #e53935; padding: 8px 16px;
  border-radius: 8px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn.danger:hover { background: #c62828; transform: translateY(-1px); }
.btn.danger:active { background: #b71c1c; transform: translateY(0); }

/* =========================================
   4. SIDEBAR (Panel Boczny)
   ========================================= */
.sidebar {
  position: fixed;
  top: 64px; /* Pod Topbarem */
  left: 0;
  bottom: 0;
  width: 260px;
  background: #fff;
  border-right: 1px solid var(--line);
  transform: translateX(-100%); /* Domyślnie ukryty (Mobile First) */
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 2000;
}

/* Otwieranie sidebara (klasa na body) */
body.sidebar-open .sidebar {
  transform: translateX(0);
}

/* Overlay (tło) dla mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 64px; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1999;
  cursor: pointer;
  backdrop-filter: blur(2px);
}

/* Pokaż overlay tylko na mobile, gdy sidebar otwarty */
@media (max-width: 1024px) {
  body.sidebar-open .sidebar-overlay { display: block; }
}

/* Elementy wewnątrz sidebara */
.side-scroll { height: 100%; overflow-y: auto; padding: 16px; }
.side-section { color: var(--muted); font-size: 12px; font-weight: 600; margin: 16px 6px 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.side-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }

.side-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: #374151; font-size: 14px; font-weight: 500;
  transition: background 0.2s;
}
.side-item:hover { background: #f3f4f6; color: var(--text); }
.side-item.active { background: var(--chip-bg); color: var(--primary); font-weight: 600; }

/* Submenu */
.side-item.has-sub { justify-content: space-between; cursor: pointer; }
.side-item.has-sub .chevron { transition: transform 0.2s ease; width: 16px; height: 16px; }
.side-item.has-sub.open .chevron { transform: rotate(180deg); }

.sub-menu {
  display: none;
  flex-direction: column;
  padding-left: 12px; /* Wcięcie */
  margin-top: 2px;
}
.sub-menu.open { display: flex; } /* Klasa JS do otwierania */

.side-sub-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px 8px 20px; /* Większy padding z lewej dla hierarchii */
  border-radius: 10px;
  color: #4b5563; font-size: 13px;
  border-left: 2px solid transparent;
}
.side-sub-item:hover { color: var(--text); }
.side-sub-item.active { color: var(--primary); border-left-color: var(--primary); background: #fff; }


/* =========================================
   5. CONTENT (Główna zawartość)
   ========================================= */
.content {
  /* ZMIANA: width: auto zamiast 100%, aby margines nie wypychał treści */
  width: auto; 
  /* ZMIANA: max-width: 100% jest bezpieczniejsze niż 100vw (unikasz scrolla paska) */
  max-width: 100%; 
  padding: 24px; 
  margin-left: 0;
  /* overflow-x: hidden; <- To często ukrywa problem zamiast go naprawić. 
     Przy poprawnym width:auto jest to zbędne, chyba że dla specyficznych animacji. */
  min-height: calc(100vh - 64px);
  transition: margin-left 0.3s ease;
}

/* --- RESPOSYWNOŚĆ DESKTOP (>= 1025px) --- */
@media (min-width: 1025px) {
  .sidebar {
    transform: translateX(0); /* Zawsze widoczny */
    box-shadow: none;
  }
  
  .content {
    /* Tutaj width: auto (z góry) automatycznie odejmie te 260px od szerokości */
    margin-left: 260px; 
  }
  
  /* Opcjonalnie: Klasa do chowania sidebara na desktopie */
  body.desktop-sidebar-closed .sidebar { transform: translateX(-100%); }
  body.desktop-sidebar-closed .content { margin-left: 0; }
}

/* Responsywność Mobile (< 768px) */
@media (max-width: 768px) {
  .content { padding: 16px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .brand { font-size: 16px; }
  .searchbar { display: none; }
}

/* =========================================
   6. KOMPONENTY (KPI, Karty, Tabele)
   ========================================= */
/* Karty i Grid */
.grid, .cards {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  position: relative;
}

/* KPI Widget */
.kpi { position: relative; }
.kpi .dots {
  position: absolute; top: 16px; right: 16px;
  color: var(--muted); cursor: pointer;
}
.kpi-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }

.icon-swatch {
  width: 48px; height: 48px; border-radius: 12px;
  display: grid; place-items: center; font-size: 24px;
  flex-shrink: 0;
}
/* Warianty kolorystyczne ikon */
.icon-swatch.purple { background: var(--purple-bg); color: var(--purple); }
.icon-swatch.orange { background: var(--orange-bg); color: var(--orange); }
.icon-swatch.green  { background: var(--green-bg);  color: var(--green); }
.icon-swatch.red    { background: var(--red-bg);    color: var(--red); }
.icon-swatch.blue   { background: var(--blue-bg);   color: var(--blue); }

.kpi-title { font-size: 14px; color: var(--muted); margin-top: 4px; font-weight: 500; }
.kpi-value { font-size: 24px; font-weight: 700; margin: 4px 0; color: var(--text); }
.kpi-sub { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.spark { height: 50px; margin-top: 12px; width: 100%; }

/* Tabele */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 650px; /* Zapobiega ściskaniu na mobile */
}
.table th, .table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap; /* Ważne dla czytelności */
}
.table th {
  background: #f9fafb;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f9fafb; }

/* Wyszukiwarka w treści (Search Bar Component) */
.search-bar {
  display: flex; gap: 12px; align-items: center; width: 100%; margin-bottom: 20px;
}
.search-input {
  display: flex; align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 50px;
  padding: 8px 16px;
  flex: 1;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
}
.search-input:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.search-input i { color: var(--muted); margin-right: 8px; width: 18px; }
.search-input input {
  border: none; outline: none; background: transparent;
  width: 100%; font-size: 14px;
}

/* =========================================
   7. MODALE I UTILS
   ========================================= */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(2px);
  align-items: center; justify-content: center;
  z-index: 3000;
}
.modal-overlay.show { display: flex; } /* Klasa JS do pokazywania */

.modal-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 24px;
  width: 100%; max-width: 500px;
  margin: 16px;
  animation: modalFadeIn 0.25s ease-out;
}

.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-form { display: flex; flex-direction: column; gap: 16px; }
.form-group label { font-size: 13px; font-weight: 600; margin-bottom: 6px; display: block; color: #374151; }
.form-group input, .form-group select {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Marginesy dla przycisków w modalu (zamiast globalnych) */
.modal-actions {
  display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px;
}
.modal-actions .btn { margin: 0; } /* Reset specyficzności */

/* Dropdown Menu (Zunifikowane) */
.dropdown { position: relative; display: inline-block; }

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%; right: 0; margin-top: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  padding: 6px;
  z-index: 2100;
  animation: fadeIn 0.2s ease;
}
.dropdown-menu.show { display: block; }

.dropdown-menu a, .dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  color: var(--text); text-decoration: none;
  font-size: 14px; border-radius: 6px;
  transition: background 0.15s;
}
.dropdown-menu a:hover, .dropdown-item:hover { background: #f3f4f6; }
.dropdown-menu i { width: 16px; height: 16px; color: var(--muted); }

/* Flash Messages */
.flash {
  position: fixed; top: 24px; right: 24px;
  padding: 14px 20px; border-radius: 10px;
  color: #fff; font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  display: flex; align-items: center; gap: 10px;
  animation: slideInRight 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.flash.success { background: #10b981; }
.flash.error { background: #ef4444; }

/* Animacje */
@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes modalFadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }



