*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
    background: radial-gradient(circle at top, #020617 0, #020617 40%, #000 100%);
    color: #e5e7eb;
}
.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 16px;
}
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 12px;
}

/* --- NAGŁÓWEK APLIKACJI --- */
.app-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.03em;
    display: flex;
    align-items: center;
    gap: 12px;
}

.title-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.1;
}

.app-title span {
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: #9ca3af;
}
.badge {
    border-radius: 999px;
    border: 1px solid #22c55e44;
    background: #16a34a22;
    color: #bbf7d0;
    padding: 2px 8px;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
}
.btn {
    border-radius: 999px;
    border: 1px solid #1f2937;
    background: #020617;
    color: #e5e7eb;
    padding: 6px 10px;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}
.btn-icon {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: radial-gradient(circle at 30% 30%, #22c55e, #16a34a);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}
.btn:hover {
    border-color: #3b82f6;
    background: #111827;
}
.btn-primary {
    background: linear-gradient(135deg, #2563eb, #4f46e5);
    border-color: #1d4ed8;
    color: #fff;
}
.btn-primary:hover {
    background: linear-gradient(135deg, #1d4ed8, #4338ca);
}
.btn.btn-xs {
    padding: 2px 8px;
    font-size: 11px;
    margin-left: 8px;
    vertical-align: middle;
}
.btn.btn-xs.active {
    border-color: #22c55e;
    color: #bbf7d0;
    box-shadow: 0 0 5px rgba(34, 197, 94, 0.5);
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #9ca3af;
    cursor: pointer;
}
.toggle input {
    width: 34px;
    height: 18px;
    cursor: pointer;
}

.main {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    max-width: 100%;
}

.card {
    border-radius: 16px;
    border: 1px solid #111827;
    background: radial-gradient(circle at top left, #020617 0, #020617 40%, #020617);
    box-shadow: 0 18px 40px rgba(0,0,0,0.8);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 100%;
    overflow: hidden;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-title {
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #9ca3af;
}
.card-subtitle {
    font-size: 11px;
    color: #6b7280;
}
.card-body {
    font-size: 13px;
}

/* --- TABELA --- */
.table-wrapper {
    border-radius: 12px;
    border: 1px solid #111827;
    /* WAŻNE: overflow visible pozwala menu wystawać poza tabelę */
    overflow: visible !important; 
    background: radial-gradient(circle at top left, #020617 0, #020617 35%, #020617);
    min-height: 400px; /* Zapewnia miejsce na scrollowanie i menu */
}
.table-scroll {
    /* WAŻNE: overflow-x visible wyłącza scrollowanie paska, ale pozwala menu działać. 
       Przy responsywności "Action Menu" jest lepsze niż poziomy pasek. */
    overflow: visible !important; 
}
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}
.table th,
.table td {
    padding: 6px 8px;
    border-bottom: 1px solid #111827;
    word-wrap: break-word;
    vertical-align: middle;
    text-align: left; /* Wyrównanie do lewej */
}

/* SZEROKOŚCI KOLUMN */
.table th:nth-child(1), .table td:nth-child(1) { width: 10%; } /* IP */
.table th:nth-child(2), .table td:nth-child(2) { width: 15%; } /* Nazwa */
.table th:nth-child(3), .table td:nth-child(3) { width: 9%;  } /* Grupa */
.table th:nth-child(4), .table td:nth-child(4) { width: 11%; } /* MAC */
.table th:nth-child(5), .table td:nth-child(5) { width: 12%; } /* Źródła */
.table th:nth-child(6), .table td:nth-child(6) { width: 7%;  } /* Status */
.table th:nth-child(7), .table td:nth-child(7) { width: 7%;  } /* Ping */
.table th:nth-child(8), .table td:nth-child(8) { width: 8%;  } /* DL */
.table th:nth-child(9), .table td:nth-child(9) { width: 8%;  } /* UL */
.table th:nth-child(10),.table td:nth-child(10){ width: 8%;  } /* Uptime */

/* KOLUMNA AKCJI - WĄSKA DLA DROPDOWNA */
.table th:nth-child(11),.table td:nth-child(11){ 
    width: 50px; 
    text-align: center; 
    overflow: visible; /* Kluczowe dla dropdowna */
}

.table th {
    position: sticky;
    top: 0;
    background: radial-gradient(circle at top, #020617 0, #020617 50%, #020617);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6b7280;
    cursor: pointer;
    user-select: none;
    z-index: 10;
}

/* --- SORTOWANIE --- */
.table th[data-sort] {
    cursor: pointer;
    position: relative; /* Ważne dla pozycjonowania */
    padding-right: 20px; /* Miejsce na strzałkę, żeby nie nachodziła na tekst */
}

.table th[data-sort]::after {
    content: '↕'; /* Domyślna ikona (góra/dół) - rezerwuje miejsce */
    position: absolute;
    right: 4px;   /* Przyklejona do prawej krawędzi nagłówka */
    top: 50%;
    transform: translateY(-50%); /* Idealnie wyśrodkowana w pionie */
    
    font-size: 10px;
    width: 12px;
    text-align: center;
    opacity: 0.2; /* Prawie niewidoczna domyślnie */
    transition: all 0.2s;
}

/* Po najechaniu myszką */
.table th[data-sort]:hover::after { 
    opacity: 0.5; 
    color: #e5e7eb;
}

/* Aktywne sortowanie rosnące */
.table th.sort-asc::after { 
    content: '▲'; 
    opacity: 1; 
    color: #38bdf8; /* Niebieski akcent */
}

/* Aktywne sortowanie malejące */
.table th.sort-desc::after { 
    content: '▼'; 
    opacity: 1; 
    color: #38bdf8; /* Niebieski akcent */
}
/* --- STYLIZACJA KOMÓREK --- */
.table td.ip-cell {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
}
.table td.mac-cell {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    color: #9ca3af;
}
.table td.hostname-cell {
    font-size: 13px;
    color: #e5e7eb;
}
.clickable-cell { cursor: pointer; color: #38bdf8; }
.clickable-cell:hover { text-decoration: underline; }
.row-offline .clickable-cell { color: #9ca3af; }

/* --- STATUS PILLS --- */
.status-pill {
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.status-online { background: #16a34a22; color: #bbf7d0; border: 1px solid #16a34a55; }
.status-offline { background: #111827; color: #6b7280; border: 1px solid #1f2937; }
.status-dot { width: 8px; height: 8px; border-radius: 999px; }
.status-dot-online { background: radial-gradient(circle at 30% 30%, #22c55e, #15803d); }
.status-dot-offline { background: radial-gradient(circle at 30% 30%, #4b5563, #111827); }

/* --- MENU AKCJI (DROPDOWN - NOWOŚĆ) --- */
.action-menu-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.action-toggle-btn {
    background: transparent;
    border: 1px solid transparent;
    color: #9ca3af;
    font-size: 18px;
    padding: 4px;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.action-toggle-btn:hover,
.action-toggle-btn.active {
    background: #1f2937;
    color: #e5e7eb;
    border-color: #374151;
}

.action-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 0;
    margin-top: 4px;
    background: #111827; /* Ciemne tło menu */
    border: 1px solid #374151;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.8);
    min-width: 170px;
    z-index: 1000;
    flex-direction: column;
    padding: 6px 0;
}

.action-dropdown.show {
    display: flex;
    animation: fadeIn 0.1s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.action-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: #e5e7eb;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}

.action-item:hover {
    background: #1f2937;
}

.action-item.danger { color: #fca5a5; }
.action-item.danger:hover { background: rgba(239, 68, 68, 0.15); }

.action-item.warning { color: #fcd34d; }
.action-item.warning:hover { background: rgba(245, 158, 11, 0.15); }

.action-icon {
    width: 16px;
    text-align: center;
    font-size: 14px;
    opacity: 0.8;
}

.action-divider {
    height: 1px;
    background: #1f2937;
    margin: 4px 0;
}

/* --- FOOTER & PAGINATION --- */
.footer-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    font-size: 11px;
    color: #6b7280;
}
.pagination {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}
.pagination button {
    border-radius: 999px;
    border: 1px solid #111827;
    background: #020617;
    color: #9ca3af;
    padding: 1px 6px;
    font-size: 11px;
    cursor: pointer;
}
.pagination button[disabled] { opacity: 0.4; cursor: default; }
.pagination button:hover:not([disabled]) {
    border-color: #3b82f6;
    color: #e5e7eb;
}

/* --- CHARTS --- */
.charts-grid {
    display: grid;
    grid-template-columns: 2fr 3fr;
    gap: 8px;
    max-width: 100%;
}
@media (max-width: 960px){
    .charts-grid { grid-template-columns: 1fr; }
}
.chart-box {
    border-radius: 12px;
    border: 1px solid #111827;
    background: radial-gradient(circle at top left, #020617 0, #020617 40%, #020617);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 100%;
}
.chart-header {
    font-size: 11px;
    color: #9ca3af;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chart-body {
    height: 200px;
    max-width: 100%;
    position: relative;
}
.chart-body canvas {
    width: 100% !important;
    max-width: 100%;
}
.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 10px;
    color: #6b7280;
}
.legend-item { display: inline-flex; align-items: center; gap: 4px; }
.legend-dot { width: 8px; height: 8px; border-radius: 999px; }
.legend-dot-online { background: radial-gradient(circle at 30% 30%, #22c55e, #15803d); }
.legend-dot-offline { background: radial-gradient(circle at 30% 30%, #4b5563, #111827); }
.legend-dot-up { background: radial-gradient(circle at 30% 30%, #38bdf8, #0369a1); }
.legend-dot-down { background: radial-gradient(circle at 30% 30%, #22c55e, #15803d); }

/* --- FORMULARZE --- */
.bottom-row {
    display: grid;
    grid-template-columns: minmax(0,3fr) minmax(0,2fr);
    gap: 12px;
    margin-top: 12px;
    max-width: 100%;
}
@media (max-width: 960px){
    .bottom-row { grid-template-columns: minmax(0,1fr); }
}
.form-card,
.ignored {
    border-radius: 16px;
    border: 1px solid #111827;
    background: radial-gradient(circle at top left, #020617 0, #020617 40%, #020617);
    box-shadow: 0 18px 40px rgba(0,0,0,0.8);
    padding: 10px;
    font-size: 12px;
    max-width: 100%;
}
.form-card h3, .ignored h3 {
    margin: 0 0 6px 0;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #9ca3af;
}
.form-row {
    display: grid;
    grid-template-columns: repeat(3,minmax(0,1fr));
    gap: 6px;
}
.form-row-full { grid-column: 1 / -1; }
.form-row-full input[type="text"] { width: 100%; }

.form-row label {
    display: block;
    font-size: 11px;
    color: #9ca3af;
    margin-bottom: 2px;
}
/* Naprawa Inputów */
.form-row input, 
select, 
textarea {
    width: 100%;
    border-radius: 8px;
    border: 1px solid #1f2937;
    background: #1f2937; /* Ciemne tło */
    color: #e5e7eb; /* Jasny tekst */
    padding: 4px 6px;
    font-size: 12px;
}
.form-row input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #2563eb;
    background: #020617;
}

.form-actions {
    margin-top: 8px;
    display: flex;
    gap: 6px;
    align-items: center;
}
.form-actions button { font-size: 12px; }
.hint { font-size: 11px; color: #6b7280; }
.error { font-size: 11px; color: #fca5a5; }
.success { font-size: 11px; color: #bbf7d0; }

.ignored-list {
    display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px;
}
.ignored-chip {
    border-radius: 999px; border: 1px solid #1f2937;
    background: #020617; padding: 2px 6px; font-size: 11px;
    display: inline-flex; align-items: center; gap: 4px; color: #9ca3af;
}
.ignored-chip button {
    border: none; background: transparent; color: #6b7280;
    cursor: pointer; font-size: 11px;
}
.ignored-chip button:hover { color: #f97316; }

.template-select {
    border-radius: 999px;
    border: 1px solid #1f2937;
    background: #020617;
    color: #9ca3af;
    padding: 4px 4px; /* Zmniejszony padding boczny */
    font-size: 11px;
    
    /* --- NOWE WŁAŚCIWOŚCI DLA RESPONSYWNOŚCI --- */
    max-width: 85px;         /* Bardzo wąska na telefonach */
    white-space: nowrap;     /* Nie zawijaj tekstu */
    overflow: hidden;        /* Ukryj nadmiar tekstu */
    text-overflow: ellipsis; /* Dodaj "..." jeśli tekst jest za długi */
    cursor: pointer;
}

/* Na większych ekranach (tablet/desktop) pozwalamy na szerszą listę */
@media (min-width: 768px) {
    .template-select {
        max-width: 160px;
        padding: 4px 8px;
    }
}
/* --- LOGOWANIE --- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, #020617 0, #000 60%);
}
.login-card {
    width: 320px;
    border-radius: 18px;
    border: 1px solid #111827;
    background: radial-gradient(circle at top left, #020617 0, #020617 40%, #020617);
    box-shadow: 0 24px 60px rgba(0,0,0,0.9);
    padding: 18px;
}
.login-card h1 { font-size: 16px; margin: 0 0 4px 0; }
.login-card p { font-size: 11px; color: #6b7280; margin: 0 0 10px 0; }
.login-form-row { margin-bottom: 8px; }
.login-form-row label { display: block; font-size: 11px; color: #9ca3af; margin-bottom: 2px; }
.login-form-row input {
    width: 100%; border-radius: 8px; border: 1px solid #1f2937;
    background: #020617; color: #e5e7eb; padding: 5px 8px; font-size: 12px;
}
.login-form-row input:focus { outline: none; border-color: #2563eb; }
.login-footer {
    display: flex; justify-content: space-between;
    align-items: center; margin-top: 8px; font-size: 10px; color: #6b7280;
}
.login-footer .btn { font-size: 12px; }

/* --- ŹRÓDŁA --- */
.source-legend {
    display: flex; flex-wrap: wrap; gap: 3px; align-items: center;
    padding: 6px 8px 4px 8px; font-size: 11px; color: #6b7280;
}
.source-legend .legend-title { font-weight: 500; color: #9ca3af; }
.source-legend .legend-pill {
    display: inline-flex; align-items: center; gap: 1px;
    padding: 3px 6px; background: #020617;
    border-radius: 4px; border: 1px solid #1f2937;
}
.source-legend .legend-pill::before {
    content: attr(data-letter);
    display: inline-block; width: 20px; height: 20px;
    line-height: 20px; text-align: center; font-size: 10px;
    font-weight: bold; border-radius: 3px; vertical-align: middle;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    background-color: var(--color); color: #fff; 
}

.source-pills-container {
    display: flex; flex-wrap: wrap; gap: 2px;
    align-items: center; justify-content: flex-start; /* Do lewej */
}
.source-pill {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 10px; font-weight: bold; width: 16px; height: 16px;
    line-height: 16px; text-align: center; border-radius: 4px;
    background: #111827; color: #4b5563; cursor: default; user-select: none;
}
.source-pill.active-dhcp { background: #3b82f6; color: #fff; }
.source-pill.active-hosts { background: #10b981; color: #fff; }
.source-pill.active-ethers { background: #8b5cf6; color: #fff; }
.source-pill.active-dns { background: #f59e0b; color: #fff; }
.source-pill.active-live { background: #ef4444; color: #fff; }

.info-pill {
    border-radius: 999px; border: 1px solid #1f2937;
    background: #020617; padding: 2px 8px; font-size: 10px;
    display: inline-flex; align-items: center; gap: 4px; color: #9ca3af;
}
.info-dot {
    width: 7px; height: 7px; border-radius: 999px;
    background: radial-gradient(circle at 30% 30%, #22c55e, #16a34a);
}
.src-ok { color: #bbf7d0; }
.src-warn { color: #facc15; }
.src-unreadable, .src-unavailable { color: #fca5a5; }

/* --- SIDE PANEL --- */
.side-tabs { display:flex; gap:4px; margin-bottom:6px; }
.side-tab {
    flex:1 1 0; border-radius:999px; border:1px solid #374151;
    background:#020617; color:#9ca3af; font-size:11px;
    padding:4px 6px; cursor:pointer;
}
.side-tab-active {
    background:#1d4ed8; border-color:#2563eb; color:#f9fafb;
}
.side-tab-panel h3 { margin:0 0 6px 0; font-size:13px; }
.config-form .form-row { display:flex; flex-wrap:wrap; gap:8px; }
.config-form label { font-size:11px; color:#9ca3af; display:block; }
.config-form input[type="number"], .config-form input[type="text"] {
    width:100%; background:#020617; border:1px solid #1f2937;
    color:#e5e7eb; border-radius:6px; padding:4px 6px; font-size:12px;
}
.config-form input[type="number"]:focus, .config-form input[type="text"]:focus {
    outline:none; border-color:#2563eb;
}
.checkbox-group {
    display: flex; flex-wrap: wrap; gap: 8px;
    background: #020617; border: 1px solid #1f2937;
    border-radius: 6px; padding: 6px;
}
.checkbox-group label {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 12px; color: #e5e7eb; margin-bottom: 0;
}
.checkbox-group input[type="checkbox"] { width: auto; }

/* --- CELL STYLES --- */
.ping-cell {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px; color: #e5e7eb;
}
.row-offline .ping-cell { color: #6b7280; }
.down-cell, .up-cell {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px; white-space: nowrap;
}
.traffic-offline { color:#6b7280; }
.traffic-down-online { color:#22c55e; }
.traffic-up-online { color:#38bdf8; }
.row-offline td { color:#6b7280; }
.row-offline td.hostname-cell { color:#9ca3af; }

/* --- MODALS --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75); z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(5px);
}
.modal-overlay.hidden { display: none; }
.modal-content {
    background: #030712; border: 1px solid #1f2937; border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8); width: 96%; max-width: 1400px;
    max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 20px; border-bottom: 1px solid #1f2937;
}
.modal-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-close-btn {
    background: none; border: none; font-size: 24px; color: #9ca3af;
    cursor: pointer; line-height: 1;
}
.modal-close-btn:hover { color: #e5e7eb; }
.modal-body {
    padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px;
}
.modal-info-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px;
}
.modal-info-box {
    background: #020617; border: 1px solid #111827; border-radius: 8px; padding: 10px 12px;
}
.modal-info-box strong {
    display: block; font-size: 11px; text-transform: uppercase;
    color: #6b7280; margin-bottom: 4px;
}
.modal-info-box span {
    font-size: 14px; font-weight: 500;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
#modal-ping { display: inline-block; min-width: 60px; }
.modal-button-group {
    display: inline-flex; gap: 0px; margin-left: -14px; vertical-align: middle;
}
.modal-charts-grid {
    display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 10px;
}
.modal-chart-container {
    background: #020617; border: 1px solid #111827; border-radius: 8px;
    padding: 22px; position: relative; height: 250px;
    display: flex; flex-direction: column; overflow: hidden;
}
.modal-chart-container h3 {
    margin: 0 0 10px 0; font-size: 13px; font-weight: 500; color: #9ca3af;
}
@media (min-width: 1000px) {
    .modal-charts-grid { grid-template-columns: 1fr 1fr; gap: 16px; }
    .modal-chart-container:nth-child(1) { grid-column: 1 / -1; height: 180px; }
    .modal-chart-container:nth-child(2), .modal-chart-container:nth-child(3) { height: 400px; }
}
.modal-footer {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 12px 20px; border-top: 1px solid #1f2937;
    background: #020617; border-radius: 0 0 16px 16px;
}

.table-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.table-scroll::-webkit-scrollbar-track { background: #020617; border-radius: 4px; }
.table-scroll::-webkit-scrollbar-thumb {
    background: #1f2937; border-radius: 4px; border: 1px solid #020617;
}
.table-scroll::-webkit-scrollbar-thumb:hover { background: #374151; }
.table-scroll { scrollbar-width: thin; scrollbar-color: #1f2937 #020617; }

#alert-modal, #confirm-modal { z-index: 2000 !important; }

/* --- GRUPY --- */
.group-pill {
    display: inline-block; padding: 2px 6px; border-radius: 8px;
    font-size: 10px; font-weight: 600; margin-right: 4px;
    white-space: nowrap; opacity: 0.9; border: 1px solid currentColor;
}
#devices-table td:nth-child(3) {
    max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.groups-list {
    display: flex; flex-direction: column; gap: 8px;
}
.group-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px; background-color: #1f2937; border-radius: 4px;
}
.group-item-info {
    display: flex; align-items: center; gap: 10px; flex-grow: 1;
}
.group-item-color {
    width: 16px; height: 16px; border-radius: 50%; border: 2px solid #374151;
}

/* --- STATYSTYKI SYSTEMOWE --- */
.system-stats {
    display: flex; gap: 20px; font-size: 12px; color: #9ca3af;
    flex-grow: 1; flex-wrap: wrap; align-items: center;
    padding: 0 10px; max-width: 700px; border-right: 1px solid #1e293b;
    margin-right: 20px;
}
.stat-item { white-space: nowrap; }
.stat-label { font-weight: 600; color: #f3f4f6; margin-right: 4px; }
#stat-cpu, #stat-mem, #stat-uptime, #stat-temp { font-weight: 700; color: #38bdf8; }

/* --- WERSJA APLIKACJI --- */
.version-box { display: block; margin-top: 0px; }
.version-box span { font-weight: normal; letter-spacing: 0.5px; }
.login-card h1 .version-box span {
    font-size: 0.55em; opacity: 0.4; display: block; margin-top: 0;
}
.app-title .version-box span {
    font-size: 10px; color: #6b7280; margin-left: 1px;
}
/* --- RESPOSYWNA TABELA (NAPRAWA WYŚWIETLANIA) --- */

/* 1. Kontener tabeli musi pozwalać na przewijanie */
.table-wrapper {
    width: 100%;
    overflow-x: auto !important; /* Wymuś pasek przewijania poziomego */
    overflow-y: visible !important; /* Pozwól menu wystawać w pionie */
    -webkit-overflow-scrolling: touch; /* Płynne przewijanie na iPhone */
    margin-bottom: 20px;
    border: 1px solid #1f2937;
    background: #020617; /* Tło pod spodem */
}

/* 2. Tabela musi mieć minimalną szerokość, żeby kolumny się nie zgniatały */
.table {
    width: 100%;
    min-width: 1100px; /* KLUCZOWE: Tabela zawsze ma min. 1100px szerokości */
    table-layout: fixed; /* Stała szerokość kolumn dla porządku */
    border-collapse: separate; /* Wymagane dla sticky columns */
    border-spacing: 0;
}

/* 3. Resetujemy szerokości kolumn, aby były czytelne */
.table th, .table td {
    white-space: nowrap; /* Nie łam tekstów (np. IP czy MAC) */
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 10px 12px; /* Większe odstępy dla dotyku */
}

/* Ustawienia szerokości dla konkretnych danych */
.table th:nth-child(1), .table td:nth-child(1) { width: 80px; } /* IP - sztywno */
.table th:nth-child(2), .table td:nth-child(2) { width: 120px; } /* Nazwa */
.table th:nth-child(11),.table td:nth-child(11){ width: 30px;  } /* Akcje */

/* --- STICKY COLUMNS (Przyklejone kolumny) --- */
/* To sprawia, że IP i Akcje "pływają" nad tabelą podczas przewijania */

/* Lewa strona: Adres IP zawsze widoczny */
.table th:first-child,
.table td:first-child {
    position: sticky;
    left: 0;
    z-index: 20;
    background-color: #020617; /* Musi mieć tło, żeby nie było przezroczyste */
    border-right: 1px solid #1f2937; /* Linia oddzielająca */
    box-shadow: 2px 0 5px rgba(0,0,0,0.5); /* Cień dla efektu głębi */
}

/* Prawa strona: Przycisk akcji (trzy kropki) zawsze widoczny */
.table th:last-child,
.table td:last-child {
    position: sticky;
    right: 0;
    z-index: 20;
    background-color: #020617;
    border-left: 1px solid #1f2937;
    box-shadow: -2px 0 5px rgba(0,0,0,0.5);
    overflow: visible !important; /* Ważne dla dropdowna! */
}

/* Nagłówki muszą być wyżej niż treść */
.table th:first-child, 
.table th:last-child {
    z-index: 30; /* Wyższy priorytet dla nagłówka */
    background-color: #0f172a; /* Nieco jaśniejsze tło nagłówka */
}

/* --- NAPRAWA DROPDOWNA W PRZEWIJANEJ TABELI --- */
/* Menu akcji musi się wyświetlać "nad" wszystkim */
.action-menu-container {
    position: static; /* Reset pozycjonowania */
}

.action-dropdown {
    position: absolute;
    right: 94px; /* Odsunięcie od prawej krawędzi */
    top: 0;
    margin-top: -10px; /* Lekka korekta */
    min-width: 160px;
    z-index: 9999 !important; /* Musi być najwyżej */
    background: #111827;
    border: 1px solid #374151;
    box-shadow: 0 0 20px rgba(0,0,0,0.9);
}

/* --- RESPONSYWNOŚĆ NA BARDZO MAŁYCH EKRANACH --- */
@media (max-width: 768px) {
    /* Zwiększamy czcionkę dla wygody palca */
    .table td {
        font-size: 13px;
        padding: 12px 8px;
    }
    
    /* Ukrywamy mniej ważne kolumny tylko jeśli naprawdę trzeba, 
       ale dzięki przewijaniu (scroll) nie musimy tego robić! 
       Zostawiamy użytkownikowi wybór przewijania. */
       
    .card-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    .card-header .btn {
        width: 100%; /* Przycisk odśwież na całą szerokość */
        justify-content: center;
    }
}
/* --- UKRYWANIE NAGŁÓWKA (HEADER TOGGLE) --- */

/* Płynna animacja ukrywania nagłówka */
.app-header {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 200px; /* Wystarczająco dużo, by pomieścić treść */
    overflow: visible;
    opacity: 1;
    transform: translateY(0);
}

/* Klasa dodawana gdy nagłówek jest ukryty */
.app-header.collapsed {
    max-height: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    overflow: hidden;
    transform: translateY(-20px);
    pointer-events: none; /* Kliknięcia przechodzą przez niewidoczny nagłówek */
}

/* Przycisk przywracania (pojawia się, gdy nagłówek jest ukryty) */
.header-restore-btn {
    position: fixed;
    top: 10px;
    right: 50%;
    transform: translateX(50%) translateY(-50px); /* Domyślnie schowany nad ekranem */
    z-index: 100;
    background: rgba(17, 24, 39, 0.9);
    backdrop-filter: blur(4px);
    border: 1px solid #374151;
    color: #e5e7eb;
    border-radius: 0 0 12px 12px;
    padding: 4px 16px;
    font-size: 11px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    transition: all 0.3s ease;
    opacity: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

/* Stan widoczny przycisku przywracania */
.header-restore-btn.visible {
    transform: translateX(50%) translateY(0);
    opacity: 1;
    top: 0;
    pointer-events: auto;
}

.header-restore-btn:hover {
    background: #1f2937;
    border-color: #3b82f6;
    color: #fff;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}
/* --- MOBILE HEADER CLOSE BUTTON --- */
.mobile-close-trigger {
    display: none; /* Domyślnie ukryty na Desktopie */
}

@media (max-width: 768px) {
    .mobile-close-trigger {
        display: block;
        width: 100%;
        text-align: center;
        background: #111827; /* Ciemne tło */
        color: #6b7280;
        font-size: 10px;
        font-weight: 700;
        letter-spacing: 1px;
        text-transform: uppercase;
        padding: 10px 0;
        margin-top: 10px;
        border-top: 1px solid #1f2937;
        cursor: pointer;
        user-select: none;
        transition: background 0.2s, color 0.2s;
        border-radius: 0 0 16px 16px; /* Zaokrąglenie zgodne z kartą */
    }

    .mobile-close-trigger:active {
        background: #1f2937;
        color: #e5e7eb;
    }
    
    /* Opcjonalnie: Zmniejszamy paddingi w nagłówku na mobile, żeby całość była mniejsza */
    .app-header {
        padding-bottom: 0 !important; /* Reset paddingu, bo przycisk go zastępuje */
    }
}

/* Styl dla zaznaczonego wiersza */
tr.row-selected td {
    background: rgba(59, 130, 246, 0.15) !important; /* Lekki niebieski z priorytetem */
    border-top: 1px solid rgba(59, 130, 246, 0.4) !important;
    border-bottom: 1px solid rgba(59, 130, 246, 0.4) !important;
    transition: background 0.3s ease;
}

/* Opcjonalnie: lekka poświata na tekście w zaznaczonym wierszu */
tr.row-selected .ip-cell {
    text-shadow: 0 0 5px rgba(59, 130, 246, 0.5);
    font-weight: 700;
}