:root {
    --primary: #5865f2;
    --primary-glow: rgba(88, 101, 242, 0.35);
    --bg-dark: #313338;
    --card-bg: rgba(43, 45, 49, 0.95);
    --sidebar-bg: #2b2d31;
    --text-main: #dbdee1;
    --text-dim: #949ba4;
    --glass-border: rgba(255, 255, 255, 0.06);
    --success: #23a55a;
    --danger: #f23f42;
    --input-bg: #1e1f22;
}

[data-theme="light"] {
    --primary: #5865f2;
    --primary-glow: rgba(88, 101, 242, 0.25);
    --bg-dark: #f2f3f5;
    --card-bg: rgba(255, 255, 255, 0.95);
    --sidebar-bg: #e3e5e8;
    --text-main: #2e3338;
    --text-dim: #5c6068;
    --glass-border: rgba(0, 0, 0, 0.1);
    --success: #1e8a49;
    --danger: #da373c;
    --input-bg: #e8eaed;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

body::before {
    content: ''; position: fixed; inset: -50%;
    background: radial-gradient(circle at center, rgba(88,101,242,0.08) 0%, transparent 60%);
    opacity: 1; z-index: -1;
}

@keyframes pulse { 0% { transform: scale(1); } 100% { transform: scale(1.1); } }

.hidden { display: none !important; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */

header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px 40px; border-bottom: 1px solid var(--glass-border);
    background: var(--sidebar-bg); backdrop-filter: blur(10px);
    position: sticky; top: 0; z-index: 100;
}
.search-container { flex: 1; margin: 0 40px; max-width: 600px; }
#global-search {
    width: 100%; background: var(--input-bg); border: 1px solid var(--glass-border);
    padding: 10px 20px; border-radius: 12px; color: var(--text-main); outline: none;
    transition: all 0.2s; font-family: 'Outfit', sans-serif;
}
#global-search:focus { border-color: var(--primary); background: rgba(255, 255, 255, 0.08); box-shadow: 0 0 15px var(--primary-glow); }

.main-nav { display: flex; gap: 10px; }
.nav-item {
    background: transparent; color: var(--text-dim); border: none;
    padding: 8px 20px; cursor: pointer; border-radius: 8px;
    font-weight: 500; transition: all 0.2s;
}
.nav-item.active { background: rgba(255,255,255,0.05); color: white; }
.nav-item:hover:not(.active) { color: white; }

main { padding: 40px; max-width: 1400px; margin: 0 auto; }

.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }

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

/* ─── Components ─────────────────────────────────────────────────────────── */

.glass-card {
    background: var(--card-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border); border-radius: 20px; padding: 24px;
}

.btn-primary {
    background: var(--primary); color: white; border: none; padding: 10px 24px;
    border-radius: 10px; font-weight: 600; cursor: pointer; transition: all 0.2s;
    text-decoration: none;
    display: flex; align-items: center; justify-content: center;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 4px 15px var(--primary-glow); }

.btn-secondary {
    background: rgba(255,255,255,0.05); color: white; border: 1px solid var(--glass-border);
    padding: 8px 16px; border-radius: 8px; cursor: pointer;
    text-decoration: none;
    display: flex; align-items: center; justify-content: center;
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); }

.btn-ghost { background: transparent; color: var(--text-dim); border: none; cursor: pointer; }
.btn-ghost:hover { color: white; }
.btn-ghost.danger:hover { color: var(--danger); }

/* ─── Devices Grid ───────────────────────────────────────────────────────── */

.device-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px; margin-top: 24px;
}

.device-card { position: relative; transition: all 0.3s; cursor: default; }
.device-card:hover { border-color: var(--primary); transform: translateY(-3px); }

.device-status {
    position: absolute; top: 20px; right: 20px; width: 10px; height: 10px;
    border-radius: 50%; background: #333;
}
.device-status.online { 
    background: var(--success); 
    box-shadow: 0 0 15px var(--success); 
    animation: status-pulse 2s infinite;
}

@keyframes status-pulse {
    0% { opacity: 1; box-shadow: 0 0 10px var(--success); }
    50% { opacity: 0.8; box-shadow: 0 0 20px var(--success); }
    100% { opacity: 1; box-shadow: 0 0 10px var(--success); }
}

.device-icon { font-size: 2.2rem; margin-bottom: 20px; display: block; }
.device-info h3 { font-size: 1.2rem; margin-bottom: 5px; }

.id-badge {
    font-family: underline; color: var(--primary); cursor: pointer; font-size: 0.85rem;
}

.device-meta { margin: 15px 0; color: var(--text-dim); font-size: 0.85rem; display: grid; gap: 5px; }
.device-meta b { color: white; font-weight: 400; font-size: 0.75rem; text-transform: uppercase; background: rgba(255,255,255,0.05); padding: 2px 5px; border-radius: 4px; }

.device-actions { display: flex; gap: 10px; margin-top: 20px; }
.device-actions .btn-primary, 
.device-actions .btn-secondary {
    flex: 1;
    font-size: 0.9rem;
}

/* ─── Tables ─────────────────────────────────────────────────────────────── */

.modern-table { width: 100%; border-collapse: collapse; text-align: left; margin-top: 10px; }
.modern-table th { padding: 15px 20px; color: var(--text-dim); border-bottom: 1px solid var(--glass-border); font-size: 0.85rem; font-weight: 500; }
.modern-table td { padding: 15px 20px; border-bottom: 1px solid rgba(255,255,255,0.03); }

/* ─── Modals ─────────────────────────────────────────────────────────────── */

.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center; z-index: 1000;
    backdrop-filter: blur(4px);
}
.modal-content { width: 90%; max-width: 450px; }
.modal-content h3 { margin-bottom: 25px; }

.input-group { margin-bottom: 15px; }
.input-group label { display: block; margin-bottom: 5px; color: var(--text-dim); font-size: 0.85rem; }
.input-group input {
    width: 100%; background: var(--input-bg); border: 1px solid var(--glass-border);
    padding: 10px 15px; border-radius: 8px; color: var(--text-main); outline: none;
}
.input-group input:focus { border-color: var(--primary); }

#edit-id-visible {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #eab308; /* Yellow/Gold for new entries */
    color: #4ade80; 
    font-weight: 600;
}

#edit-id-static {
    padding: 12px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    color: var(--primary);
    font-weight: 600;
}

.checkbox-group { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 15px; margin-top: 25px; }
.flex-spacer { flex: 1; }

/* ─── Header & Filters ───────────────────────────────────────────────────── */

.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; }
.welcome-section { margin-bottom: 30px; }
.form-select { background: var(--input-bg); color: var(--text-main); border: 1px solid var(--glass-border); padding: 8px 15px; border-radius: 8px; }

/* ─── Tables ────────────────────────────────────────────────────────────── */
.table-container { padding: 20px; overflow-x: auto; margin-top: 20px; }
.modern-table { width: 100%; border-collapse: collapse; text-align: left; min-width: 600px; }
.modern-table th, .modern-table td { padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.modern-table th { font-weight: 600; color: var(--secondary); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 1px; }
.modern-table tr:hover { background: rgba(255,255,255,0.02); }
.modern-table td code { background: rgba(0,0,0,0.3); padding: 4px 8px; border-radius: 4px; font-family: monospace; font-size: 0.9rem; }

select.form-select, select[multiple] {
    background: var(--input-bg) !important;
    border: 1px solid var(--glass-border);
    color: var(--text-main) !important;
    padding: 10px !important;
    border-radius: 8px;
    width: 100%;
}

select.form-select option, select[multiple] option {
    background-color: var(--input-bg) !important;
    color: var(--text-main) !important;
    padding: 8px;
}

select[multiple] option:checked { 
    background: var(--primary) !important; 
    color: white !important; 
}

.btn-ghost.danger:hover { color: #ff5555; background: rgba(255,85,85,0.1); }
.flex-spacer { flex: 1; }

/* ─── Tree View ─────────────────────────────────────────────────────────── */

.tree-container {
    padding: 30px;
    min-height: 500px;
}

.tree-node {
    margin-left: 15px;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    padding-left: 5px;
    position: relative;
}

.tree-children {
    display: none; /* Colapsado por padrão */
}

.tree-node.expanded > .tree-children {
    display: block;
}

.tree-item {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    margin-bottom: 2px;
}

.tree-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.tree-item.folder {
    color: #4ade80;
    font-weight: 500;
}

.tree-item.folder[draggable="true"] { cursor: grab; }
.tree-item.folder[draggable="true"]:active { cursor: grabbing; }

.tree-item.dragging {
    opacity: 0.4;
}

.tree-item.drag-over {
    background: rgba(99, 102, 241, 0.25) !important;
    outline: 2px dashed rgba(99, 102, 241, 0.7);
    outline-offset: -2px;
    border-radius: 8px;
}

.tree-item.drag-before {
    border-top: 2px solid var(--primary);
    border-radius: 0;
}

.tree-item.drag-after {
    border-bottom: 2px solid var(--primary);
    border-radius: 0;
}

.tree-item.folder.level-0 { color: #818cf8; font-weight: 600; font-size: 1.05rem; }

.tree-toggle {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    transition: transform 0.2s;
    color: var(--text-dim);
}

.tree-node.expanded > .tree-item .tree-toggle {
    transform: rotate(90deg);
}

.tree-icon {
    margin-right: 8px;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
}

.tree-actions {
    display: none;
    gap: 8px;
    margin-left: auto;
    padding-left: 10px;
}

.tree-item:hover .tree-actions {
    display: flex;
}

.btn-tree {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
}

.btn-tree:hover {
    background: var(--primary);
}

.peer-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 10px;
    background: #444;
}

.peer-status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.peer-alias { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-id-tiny { font-size: 0.7rem; color: var(--text-dim); margin-left: 8px; font-family: monospace; }
.actions-left { display: flex; gap: 10px; }

/* Role Badges */
.role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.role-pdv { background: rgba(59,130,246,0.2); color: #60a5fa; border: 1px solid rgba(59,130,246,0.3); }
.role-concentrador { background: rgba(245,158,11,0.2); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3); }
.role-servidor { background: rgba(139,92,246,0.2); color: #a78bfa; border: 1px solid rgba(139,92,246,0.3); }

.badge-admin { background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.3); padding: 2px 10px; border-radius: 10px; font-size: 0.75rem; font-weight: 600; }
.badge-profile { background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3); padding: 2px 10px; border-radius: 10px; font-size: 0.75rem; font-weight: 600; }
.badge-yes { background: rgba(16,185,129,0.15); color: #34d399; padding: 2px 8px; border-radius: 8px; font-size: 0.75rem; }
.badge-no { background: rgba(107,114,128,0.15); color: #9ca3af; padding: 2px 8px; border-radius: 8px; font-size: 0.75rem; }

/* Role checkboxes in modals */
.role-checkboxes { display: flex; gap: 16px; flex-wrap: wrap; }
.check-item { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 0.9rem; }
.check-item input { width: auto; }
