:root {
    /* Colors */
    --bg-dark: #12141d;
    --bg-sidebar: #1a1d26;
    /* Slightly lighter than main bg for contrast */
    --bg-card: #20232e;

    --accent-primary: #00FF94;
    /* Green accent */
    --accent-secondary: #00E0FF;
    /* Cyan accent */
    --accent-gradient: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));

    --text-main: #ffffff;
    --text-muted: #a0a3bd;

    --border-color: rgba(255, 255, 255, 0.1);

    /* Spacing & Layout */
    --sidebar-width: 260px;
    --header-height: 70px;

    /* Typography */
    --font-family: 'Inter', sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Layout Container */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
}

.logo-icon {
    color: var(--accent-primary);
    margin-right: 12px;
    display: flex;
    align-items: center;
}

.app-name {
    font-weight: 700;
    font-size: 1.1rem;
    background: var(--accent-gradient);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.2s ease;
    font-size: 0.95rem;
    font-weight: 500;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.nav-item.active {
    background: rgba(0, 255, 148, 0.1);
    color: var(--accent-primary);
}

.nav-icon {
    margin-right: 12px;
    opacity: 0.8;
}

.nav-item.active .nav-icon {
    opacity: 1;
}

/* User Profile in Sidebar */
.user-profile-container {
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.user-profile-trigger {
    background: transparent;
    border: none;
    width: 100%;
    cursor: pointer;
    border-radius: 12px;
    padding: 12px;
    transition: all 0.2s ease;
    text-align: left;
    border: 1px solid transparent;
    /* Prevent jump on hover */
}

.user-profile-trigger:hover {
    background-color: rgba(255, 255, 255, 0.03);
    border-color: var(--border-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, rgba(0, 255, 148, 0.2), rgba(0, 224, 255, 0.2));
    border: 1px solid rgba(0, 255, 148, 0.1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-primary);
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.username {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.role {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.logout-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logout-btn:hover {
    color: #ff4d4d;
    background-color: rgba(255, 77, 77, 0.1);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    width: calc(100% - var(--sidebar-width));
}

.top-bar {
    margin-bottom: 32px;
}

#page-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Dynamic Container & Cards */
.content-container {
    animation: fadeIn 0.4s ease-out;
}

.welcome-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 40px;
    text-align: center;
}

.welcome-card h2 {
    margin-bottom: 12px;
    color: var(--text-main);
}

.welcome-card p {
    color: var(--text-muted);
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Styles */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 20px;
    }

    /* We would add a hamburger menu toggle here effectively */
}

/* Component Styles: Buttons */
.btn-primary {
    background: var(--accent-gradient);
    color: #000;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    font-size: 0.9rem;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
    background: rgba(255, 77, 77, 0.2);
    color: #ff4d4d;
    border: 1px solid rgba(255, 77, 77, 0.3);
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
}

.btn-danger:hover {
    background: rgba(255, 77, 77, 0.3);
    border-color: #ff4d4d;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
}

.btn-icon:hover {
    color: var(--text-main);
}

.btn-icon.danger:hover {
    color: #ff4d4d;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-secondary);
}

.full-width {
    width: 100%;
}

/* Select Styling */
select.form-control {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a0a3bd' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
    cursor: pointer;
}

select.form-control option,
.filter-select option {
    background-color: var(--bg-card);
    color: var(--text-main);
    padding: 8px;
}

.filter-select {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* Light Mode Select Override */
body.light-mode select.form-control option,
body.light-mode .filter-select option {
    background-color: #ffffff;
    color: #12141d;
}

/* Tables */
.table-container {
    overflow-x: auto;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 16px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    /* Fix column widths */
}

/* Explicit Column Widths */
.col-id {
    width: 6%;
    min-width: 60px;
}

.col-client {
    width: 25%;
    min-width: 180px;
}

.col-ip {
    width: 11%;
    min-width: 110px;
}

.col-internet,
.col-catv {
    width: 9%;
    min-width: 100px;
}

.col-innova,
.col-mikrotik {
    width: 15%;
    min-width: 150px;
    /* Ensure space for text + icon */
}

/* Potencias Table Columns */
.col-tx,
.col-rx {
    width: 12%;
}

.col-signal {
    width: 15%;
}

/* Truncate long content in cells */
.data-table td,
.data-table th {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-table th,
.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.9rem;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
}

.badge-admin,
.badge-super_admin {
    background: rgba(0, 224, 255, 0.2);
    color: var(--accent-secondary);
}

.badge-operator {
    background: rgba(0, 255, 148, 0.2);
    color: var(--accent-primary);
}

.badge-view_only {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
}

/* Generic status badges (para datos de auditoría) */
.badge-ok {
    background: rgba(0, 255, 148, 0.18);
    color: var(--accent-primary);
}

.badge-danger {
    background: rgba(255, 77, 77, 0.18);
    color: #ff4d4d;
}

.badge-warn {
    background: rgba(255, 206, 86, 0.18);
    color: #ffcd56;
}

.badge-muted {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
}

.badge-mini {
    padding: 2px 6px;
    font-size: 0.75rem;
    border-radius: 6px;
    line-height: 1.2;
}

/* Card */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
}

.card h3 {
    margin-bottom: 8px;
    font-size: 1.1rem;
    color: var(--text-main);
}

.card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.module-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.module-header h2 {
    font-size: 1.5rem;
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #12141d;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

#particles-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.login-card {
    position: relative;
    z-index: 1;
    background: rgba(32, 35, 46, 0.95);
    border: 1px solid var(--border-color);
    padding: 40px;
    border-radius: 20px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header .logo-icon.big {
    margin: 0 auto 16px auto;
    color: var(--accent-primary);
    background: rgba(0, 255, 148, 0.1);
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-footer {
    margin-top: 24px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--bg-card);
    padding: 30px;
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    border: 1px solid var(--border-color);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

/* Dashboard Styles */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 20px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
}

.stat-card.error {
    border-color: rgba(255, 77, 77, 0.3);
    background: linear-gradient(135deg, rgba(255, 77, 77, 0.05), transparent);
}

.stat-card.warning {
    border-color: rgba(255, 206, 86, 0.3);
    background: linear-gradient(135deg, rgba(255, 206, 86, 0.05), transparent);
}

.stat-card.good {
    border-color: rgba(0, 255, 148, 0.3);
    background: linear-gradient(135deg, rgba(0, 255, 148, 0.05), transparent);
}

.stat-title {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-card.error .stat-value {
    color: #ff4d4d;
}

.stat-card.warning .stat-value {
    color: #ffcd56;
}

.stat-card.good .stat-value {
    color: var(--accent-primary);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
}

.chart-card {
    height: 400px;
    /* Fixed height for consistency */
    display: flex;
    flex-direction: column;
}

.chart-container {
    flex: 1;
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-top: 10px;
    font-size: 0.9rem;
}

.alert.warning {
    background: rgba(255, 206, 86, 0.1);
    color: #ffcd56;
    border: 1px solid rgba(255, 206, 86, 0.2);
}

@media (max-width: 768px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

/* Utility */
.hidden {
    display: none !important;
}

/* Light Mode Overrides */
body.light-mode {
    --bg-dark: #f5f7fa;
    /* Light grey/white background */
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;

    --text-main: #12141d;
    --text-muted: #6b7280;

    --border-color: #e5e7eb;
}

/* Light mode specific adjustments */
body.light-mode .app-name {
    /* Ensure visibility on light bg */
    background: none;
    -webkit-text-fill-color: var(--text-main);
    color: var(--text-main);
}

body.light-mode .form-control {
    background-color: #f9fafb;
    border-color: #d1d5db;
    color: #12141d;
}

/* User Profile Refactor */
.user-profile-container {
    position: relative;
    border-top: 1px solid var(--border-color);
    padding: 16px;
}

.user-profile-trigger {
    background: none;
    border: none;
    width: 100%;
    cursor: pointer;
    border-radius: 12px;
    padding: 8px;
    transition: background-color 0.2s;
    text-align: left;
}

.user-profile-trigger:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

body.light-mode .user-profile-trigger:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.user-popover {
    position: absolute;
    bottom: 100%;
    /* Shows above the trigger */
    left: 16px;
    right: 16px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
    margin-bottom: 8px;
    padding: 4px;
    z-index: 200;
    overflow: hidden;
    animation: slideUp 0.2s ease-out;
}

body.light-mode .user-popover {
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.popover-section {
    padding: 4px;
}

.popover-section.border-top {
    border-top: 1px solid var(--border-color);
    margin-top: 4px;
    padding-top: 4px;
}

.popover-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.9rem;
    background: none;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.popover-item svg {
    margin-right: 10px;
    opacity: 0.7;
}

.popover-item:hover {
    background-color: rgba(0, 255, 148, 0.1);
    color: var(--accent-primary);
}

.popover-item:hover svg {
    opacity: 1;
}

.popover-item.danger:hover {
    background-color: rgba(255, 77, 77, 0.1);
    color: #ff4d4d;
}

/* Sections */
.dashboard-section {
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.dashboard-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Signal Cards */
.signal-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.signal-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.signal-card.good {
    border-left: 4px solid #00c853;
}

.signal-card.warning {
    border-left: 4px solid #ffab00;
}

.signal-card.critical {
    border-left: 4px solid #ff1744;
}

.signal-card .card-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.signal-card .card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Signal Badges */
.signal-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: monospace;
    /* For alignment */
}

.signal-badge.good {
    background: rgba(0, 200, 83, 0.1);
    color: #00c853;
}

.signal-badge.warning {
    background: rgba(255, 171, 0, 0.1);
    color: #ffab00;
}

.signal-badge.critical {
    background: rgba(255, 23, 68, 0.1);
    color: #ff1744;
}

/* Tooltip Styling */
.stat-card {
    position: relative;
    /* Needed for absolute positioning of tooltip */
}

.tooltip-text {
    visibility: hidden;
    width: 220px;
    background-color: var(--bg-card);
    color: var(--text-main);
    text-align: center;
    border-radius: 8px;
    padding: 12px;
    position: absolute;
    z-index: 1000;
    bottom: 110%;
    /* Place above the card */
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s ease, bottom 0.3s ease;
    font-size: 0.85rem;
    line-height: 1.4;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    /* Prevent flickering on hover */
    font-weight: 500;
    backdrop-filter: blur(5px);
}

.stat-card:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
    bottom: 105%;
    /* Slight movement effect */
}

/* Tooltip Arrow */
.tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: var(--bg-card) transparent transparent transparent;
}

.filter-active {
    color: var(--accent-primary) !important;
    opacity: 1 !important;
    filter: drop-shadow(0 0 5px rgba(0, 255, 148, 0.6));
}