:root {
    --bg-base: #0b1329;
    --bg-surface: rgba(30, 41, 59, 0.65);
    --bg-elevated: rgba(40, 56, 80, 0.75);
    --border: rgba(255, 255, 255, 0.1);
    --border-hover: rgba(255, 255, 255, 0.2);
    --glass-bg: rgba(15, 23, 42, 0.65);
    --glass-card: rgba(30, 41, 59, 0.55);
    --accent: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.35);
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --purple: #8b5cf6;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --sidebar-width: 240px;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background: radial-gradient(circle at 15% 15%, #1e1b4b 0%, transparent 45%),
                radial-gradient(circle at 85% 85%, #0f2b48 0%, transparent 45%),
                radial-gradient(circle at 50% 50%, #0d1527 0%, #070a12 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: 600;
}

h2 {
    font-size: 16px;
}

h3 {
    font-size: 15px;
}

hr, .divider {
    height: 1px;
    background: var(--border);
    border: none;
    margin: 16px 0;
}

/* Layout */
.layout {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Sidebar */
.sidebar-brand {
    padding: 20px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.brand-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--accent), #06b6d4);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 4px 14px rgba(6, 182, 212, 0.3);
}

.brand-name {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.01em;
}

.brand-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    margin-bottom: 3px;
    position: relative;
    border: 1px solid transparent;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    transform: translateX(4px);
    border-color: rgba(255, 255, 255, 0.08);
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.25), rgba(59, 130, 246, 0.1));
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.3);
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.15);
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.badge {
    background: var(--danger);
    color: white;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 700;
    margin-left: auto;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

/* Pulse animation */
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }
    50% {
        opacity: 0.8;
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
    }
}

/* Header */
.header {
    padding: 14px 24px;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
    z-index: 9;
}

.header-search {
    flex: 1;
    max-width: 480px;
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 14px;
    transition: all 0.2s ease;
}

.header-search:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 16px var(--accent-glow);
    background: rgba(15, 23, 42, 0.85);
}

.header-search input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 14px;
    flex: 1;
    font-family: inherit;
}

.header-search input::placeholder {
    color: var(--text-muted);
}

.search-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 12px;
    z-index: 100;
    overflow: hidden;
    display: none;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.5);
}

.search-dropdown.open {
    display: block;
}

.search-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s, transform 0.15s;
}

.search-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(3px);
}

.header-actions {
    margin-left: auto;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-outline {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.28);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.25);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 13px;
    border-radius: 8px;
}

/* Tab Panes */
.tab-pane {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.tab-pane.active {
    display: block;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
}

.page-header p {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: rgba(30, 41, 59, 0.45);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    user-select: none;
}

.stat-card:hover {
    transform: translateY(-4px) scale(1.01);
    border-color: var(--border-hover);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35), 0 0 20px rgba(255, 255, 255, 0.05);
}

.stat-card.green {
    border-color: rgba(16, 185, 129, 0.25);
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.5), rgba(16, 185, 129, 0.08));
}

.stat-card.green:hover {
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35), 0 0 20px rgba(16, 185, 129, 0.2);
}

.stat-card.red {
    border-color: rgba(239, 68, 68, 0.25);
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.5), rgba(239, 68, 68, 0.08));
}

.stat-card.red:hover {
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35), 0 0 20px rgba(239, 68, 68, 0.2);
}

.stat-card.purple {
    border-color: rgba(139, 92, 246, 0.25);
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.5), rgba(139, 92, 246, 0.08));
}

.stat-card.purple:hover {
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35), 0 0 20px rgba(139, 92, 246, 0.2);
}

.stat-card.yellow {
    border-color: rgba(245, 158, 11, 0.25);
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.5), rgba(245, 158, 11, 0.08));
}

.stat-card.yellow:hover {
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35), 0 0 20px rgba(245, 158, 11, 0.2);
}

.stat-icon {
    font-size: 22px;
    margin-bottom: 10px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
}

/* Section */
.section {
    background: rgba(30, 41, 59, 0.45);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.section-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.section-header h2 {
    font-size: 15px;
    font-weight: 600;
}

/* Table */
.table-wrap {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.table tbody tr {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.table tbody tr:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(3px);
    cursor: pointer;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 32px !important;
}

/* Status badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-up {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-down {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.status-unreachable {
    background: rgba(139, 92, 246, 0.15);
    color: var(--purple);
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.status-unknown {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
    border: 1px solid rgba(100, 116, 139, 0.3);
}

.muted-badge {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Filters */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filter-input {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 14px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    flex: 1;
    min-width: 200px;
    transition: all 0.2s ease;
}

.filter-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
    background: rgba(15, 23, 42, 0.85);
}

.filter-buttons {
    display: flex;
    gap: 6px;
}

.filter-btn {
    background: rgba(30, 41, 59, 0.45);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 7px 14px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
}

.filter-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-1px);
}

.filter-btn.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent);
    color: #60a5fa;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

/* Topology */
.topology-legend {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot.green {
    background: var(--success);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.dot.red {
    background: var(--danger);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.dot.purple {
    background: var(--purple);
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.5);
}

.topology-container {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid var(--border);
    border-radius: 16px;
    height: calc(100vh - 240px);
    min-height: 400px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    position: relative;
    touch-action: none;
    user-select: none;
    will-change: transform;
}

/* Tree view styling */
.tree-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tree-node {
    display: flex;
    flex-direction: column;
}

.tree-row {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: fit-content;
    max-width: 100%;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.02);
}

.tree-row:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateX(4px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.tree-prefix {
    font-family: monospace;
    font-size: 13px;
    color: var(--text-muted);
    letter-spacing: -1px;
    opacity: 0.75;
    white-space: pre;
}

.tree-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tree-row:hover .tree-dot {
    transform: scale(1.25);
}

.tree-dot.status-up {
    background: var(--success);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.tree-dot.status-down {
    background: var(--danger);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
    animation: pulse 1.5s infinite;
}

.tree-dot.status-unreachable {
    background: var(--purple);
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.6);
}

.tree-dot.status-unknown {
    background: var(--text-muted);
}

.tree-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.tree-label-name {
    font-weight: 600;
    color: var(--text-primary);
}

.tree-label-ip {
    font-size: 12px;
    color: var(--text-muted);
    font-family: monospace;
    background: rgba(15, 23, 42, 0.6);
    padding: 2px 6px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.tree-children {
    padding-left: 26px;
    margin-left: 12px;
    border-left: 1px dashed rgba(255, 255, 255, 0.15);
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 4px;
    margin-bottom: 4px;
    transition: border-color 0.25s ease;
}

.tree-node:hover > .tree-children {
    border-left-color: var(--accent);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: rgba(24, 34, 53, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6), 0 0 30px rgba(59, 130, 246, 0.1);
    transform: scale(0.95);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.modal-overlay.open .modal {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.15s;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Device card inside modal */
.device-info-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin-bottom: 16px;
    align-items: flex-start;
}

.info-item {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: none;
}

.info-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
    white-space: nowrap;
}

.info-value {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.info-value.model-value {
    white-space: normal;
    word-break: break-word;
    font-size: 12px;
    max-width: none;
    max-height: 60px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.info-value code {
    background: rgba(15, 23, 42, 0.6);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 13px;
    border: 1px solid var(--border);
}

.services-list {
    margin-top: 16px;
}

.service-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 6px;
    font-size: 13px;
}

.children-list {
    margin-top: 10px;
}

.child-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.child-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(4px);
}

/* Upstream block & Port tag */
.upstream-block {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 16px;
    margin-top: 8px;
}

.tag-port {
    display: inline-flex;
    align-items: center;
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    font-family: monospace;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Form */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.form-input {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: all 0.2s ease;
}

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
    background: rgba(15, 23, 42, 0.85);
}

.period-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.period-btn {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    text-align: center;
}

.period-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-1px);
}

.period-btn.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent);
    color: #60a5fa;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
}

.checkbox-label input {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* Pagination */
.pagination {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 16px;
}

.page-btn {
    background: rgba(30, 41, 59, 0.45);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
}

.page-btn:hover, .page-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    box-shadow: 0 4px 12px var(--accent-glow);
    transform: translateY(-1px);
}

/* Empty states */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.3);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    transition: background 0.2s;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.5);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

/* Modal Large */
.modal-lg {
    max-width: 900px;
}

/* Speed badges */
.speed-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
}

.speed-badge.speed-1g {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.4);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

.speed-badge.speed-100m {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.4);
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.2);
}

.speed-badge.speed-other {
    background: rgba(100, 116, 139, 0.2);
    color: var(--text-muted);
    border: 1px solid rgba(100, 116, 139, 0.4);
}

/* Switch Info Panel (Grid Cards) */
.switch-info {
    margin-bottom: 20px;
}

.switch-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.switch-info-card {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s;
}

.switch-info-card:hover {
    background: rgba(30, 41, 59, 0.7);
    border-color: rgba(255, 255, 255, 0.15);
}

.switch-info-card .info-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.switch-info-card .info-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    word-break: break-word;
}

.switch-info-card .info-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Modal Tabs */
.modal-tabs {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    padding-bottom: 8px;
}

.modal-tabs .tab-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.modal-tabs .tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.modal-tabs .tab-btn.active {
    color: #ffffff;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
    font-weight: 600;
}

/* Diagnostic Modal Styles */
.diag-section {
    background: rgba(15, 23, 42, 0.4);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

.diag-section h3 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.diag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.diag-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.diag-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.diag-val {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
    word-break: break-word;
}

.diag-val.bad {
    color: var(--danger);
}

.diag-val.good {
    color: var(--success);
}


/* Mobile Responsiveness */
@media (max-width: 768px) {
    .layout {
        flex-direction: column-reverse;
    }

    .sidebar {
        width: 100%;
        height: 60px;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border);
        padding: 0;
        z-index: 100;
        overflow: hidden;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(10, 15, 30, 0.97);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    .sidebar-brand {
        display: none;
    }

    .sidebar-nav {
        display: flex;
        flex-direction: row;
        width: 100%;
        padding: 0;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .sidebar-nav::-webkit-scrollbar { display: none; }

    /* Each tab: icon only. Active tab gets label. */
    .nav-link {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 6px 4px;
        margin: 0;
        border: none;
        border-radius: 0;
        flex: 0 0 auto;
        width: 52px;
        min-width: 52px;
        gap: 2px;
    }

    .nav-link:hover { transform: none; }

    /* Hide text labels by default on mobile */
    .nav-link span:not(.nav-icon) {
        display: none;
    }

    /* Show label only on active tab */
    .nav-link.active span:not(.nav-icon) {
        display: block;
        font-size: 9px;
        margin-top: 2px;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 52px;
    }

    .nav-link.active {
        width: 64px;
        min-width: 64px;
    }

    .nav-link .nav-icon {
        font-size: 20px;
        margin: 0;
    }

    /* Mutes badge on mobile */
    .nav-link .badge {
        position: absolute;
        top: 4px;
        right: 4px;
        font-size: 9px;
        padding: 1px 4px;
    }

    .sidebar-footer {
        display: none;
    }

    /* Main content: leave room for fixed bottom nav */
    .main {
        flex: 1;
        padding-bottom: 60px;
    }

    /* Show refresh button on mobile (was hidden) */
    .header-actions {
        display: flex;
    }
    .header-actions .btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    /* Compact header on mobile */
    .header {
        padding: 8px 12px;
        gap: 8px;
    }
    .header-search {
        flex: 1;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 14px 10px;
    }

    .stat-value {
        font-size: 24px;
    }

    .modal {
        width: 96vw;
        max-height: 90vh;
        border-radius: 14px;
    }

    .modal-body {
        padding: 16px;
    }

    .switch-info-grid {
        grid-template-columns: 1fr;
    }

    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Full-width page sections */
    .tab-pane {
        padding: 12px;
    }

    .page-header {
        margin-bottom: 12px;
    }
    .page-header h1 { font-size: 18px; }
    .page-header p { font-size: 12px; }

    /* Filters bar stacks vertically */
    .filters-bar {
        flex-direction: column;
        gap: 8px;
    }
    .filter-input { width: 100%; }
    .filter-buttons { flex-wrap: wrap; gap: 4px; }
    .filter-btn { font-size: 12px; padding: 5px 10px; }
}


.clickable-link {
    color: var(--accent);
    cursor: pointer;
    text-decoration: underline dotted;
    transition: color 0.15s;
}
.clickable-link:hover {
    color: #ffffff;
    text-decoration: underline;
}

@media (max-width: 768px) {
    /* Скрытие лишнего интерфейса: убираем заголовок и кнопку обновления, но ОСТАВЛЯЕМ поиск */
    body.topology-active .header .header-actions {
        display: none !important;
    }
    body.topology-active #tab-topology .page-header {
        display: none !important;
    }

    /* Контейнер топологии должен занимать весь экран (за вычетом меню, шапки и легенды) */
    #tab-topology {
        padding: 0 !important;
    }
    #tab-topology .page-header {
        padding: 12px 16px;
        margin-bottom: 0;
    }
    /* Канвас */
    #topologyNetwork, .topology-container, #topologyContainer {
        height: calc(100vh - 140px) !important;
        border-radius: 0 !important;
        touch-action: none !important;
    }
}

/* Sortable headers */
th[data-sort] {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s, color 0.2s;
}

th[data-sort]:hover {
    background-color: var(--border-color);
}



/* Light Theme */
body.light-theme {
    --bg-base: #f8fafc;
    --bg-surface: rgba(255, 255, 255, 0.85);
    --bg-elevated: rgba(255, 255, 255, 0.95);
    --border: rgba(0, 0, 0, 0.1);
    --border-hover: rgba(0, 0, 0, 0.2);
    --glass-bg: rgba(248, 250, 252, 0.9);
    --glass-card: rgba(255, 255, 255, 0.8);
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --accent-glow: rgba(59, 130, 246, 0.15);
    
    background: radial-gradient(circle at 15% 15%, #e0e7ff 0%, transparent 45%),
                radial-gradient(circle at 85% 85%, #dbeafe 0%, transparent 45%),
                #f8fafc;
    background-attachment: fixed;
}

body.light-theme .stat-card {
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}
body.light-theme .stat-card.green {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(16, 185, 129, 0.15));
}
body.light-theme .stat-card.red {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(239, 68, 68, 0.15));
}
body.light-theme .stat-card.yellow {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(245, 158, 11, 0.15));
}
body.light-theme .stat-card.purple {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(139, 92, 246, 0.15));
}

body.light-theme .table th {
    background: rgba(241, 245, 249, 0.8);
}
body.light-theme .table tr:hover {
    background: rgba(241, 245, 249, 0.6);
}
body.light-theme .filter-btn {
    background: rgba(255, 255, 255, 0.5);
    color: var(--text-secondary);
}
body.light-theme .filter-btn:hover {
    background: rgba(255, 255, 255, 0.8);
}
body.light-theme .filter-btn.active {
    background: var(--accent);
    color: white;
}
body.light-theme .modal {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
}
body.light-theme .btn-outline {
    border-color: rgba(0, 0, 0, 0.2);
    color: var(--text-primary);
}
body.light-theme .btn-outline:hover {
    background: rgba(0, 0, 0, 0.05);
}
body.light-theme .sidebar-nav .nav-link:hover {
    background: rgba(0, 0, 0, 0.05);
}
body.light-theme .sidebar-nav .nav-link.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent);
}
body.light-theme #globalSearch {
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-primary);
    border-color: rgba(0, 0, 0, 0.1);
}
body.light-theme #globalSearch:focus {
    background: #fff;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.stat-card.active-card {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 2px var(--accent), 0 8px 24px var(--accent-glow) !important;
    transform: translateY(-2px);
}

/* --- Task 1: Hostgroup Dropdown Filter --- */
.filter-select {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 14px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    min-width: 240px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.filter-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
    background: rgba(15, 23, 42, 0.85);
}
.filter-select option {
    background: #1e293b;
    color: #f8fafc;
}
body.light-theme .filter-select {
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-primary);
    border-color: rgba(0, 0, 0, 0.15);
}
body.light-theme .filter-select option {
    background: #ffffff;
    color: #0f172a;
}

/* Sidebar */
body.light-theme .sidebar {
    background: rgba(248, 250, 252, 0.95);
    border-right: 1px solid rgba(0,0,0,0.08);
    backdrop-filter: blur(20px);
}
body.light-theme .sidebar-brand {
    color: #0f172a;
    border-bottom-color: rgba(0,0,0,0.08);
}
body.light-theme .sidebar-brand .brand-sub {
    color: #64748b;
}
body.light-theme .sidebar-footer {
    border-top-color: rgba(0,0,0,0.08);
    color: #64748b;
}

/* Header / top bar */
body.light-theme .header {
    background: rgba(248, 250, 252, 0.95);
    border-bottom: 1px solid rgba(0,0,0,0.08);
}
body.light-theme .header-search {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(0, 0, 0, 0.12);
}
body.light-theme .header-search:focus-within {
    background: #ffffff;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
body.light-theme .header-search input {
    color: #0f172a;
}
body.light-theme .header-search input::placeholder {
    color: #94a3b8;
}
body.light-theme .search-dropdown {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}
body.light-theme .search-result-item {
    color: #0f172a;
}
body.light-theme .search-result-item:hover {
    background: rgba(241, 245, 249, 0.8);
}
body.light-theme .search-result-type {
    color: #64748b;
}

/* Nav links */
body.light-theme .nav-link {
    color: #475569;
}
body.light-theme .nav-link:hover {
    background: rgba(0,0,0,0.05);
    color: #0f172a;
}
body.light-theme .nav-link.active {
    background: rgba(59,130,246,0.12);
    color: #2563eb;
}

/* Main content area */
body.light-theme .main {
    background: transparent;
}
body.light-theme .tab-pane {
    color: #0f172a;
}

/* Cards / surfaces (glass-card, glass-bg) */
body.light-theme .card,
body.light-theme .glass-card {
    background: rgba(255,255,255,0.85);
    border: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* Tables */
body.light-theme .table {
    color: #0f172a;
}
body.light-theme .table td {
    border-bottom-color: rgba(0,0,0,0.06);
    color: #1e293b;
}
body.light-theme .table th {
    background: rgba(241,245,249,0.9);
    color: #475569;
    border-bottom-color: rgba(0,0,0,0.1);
}
body.light-theme .table tr:hover td {
    background: rgba(241,245,249,0.7);
}
body.light-theme code {
    background: transparent;
    color: #1e293b;
    border-color: transparent;
    font-weight: 500;
}

/* Filter inputs and selects */
body.light-theme .filter-input,
body.light-theme input[type="text"],
body.light-theme input[type="search"] {
    background: rgba(255,255,255,0.9);
    color: #0f172a;
    border-color: rgba(0,0,0,0.15);
}
body.light-theme .filter-input::placeholder {
    color: #94a3b8;
}
body.light-theme .filter-input:focus {
    background: #ffffff;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

/* Buttons */
body.light-theme .btn-secondary {
    background: rgba(0,0,0,0.06);
    color: #334155;
    border-color: rgba(0,0,0,0.1);
}
body.light-theme .btn-secondary:hover {
    background: rgba(0,0,0,0.1);
}

/* Status badges */
body.light-theme .status-badge.status-up {
    background: rgba(16,185,129,0.15);
    color: #059669;
    border-color: rgba(16,185,129,0.3);
}
body.light-theme .status-badge.status-down {
    background: rgba(239,68,68,0.12);
    color: #dc2626;
    border-color: rgba(239,68,68,0.25);
}
body.light-theme .status-badge.status-unreachable {
    background: rgba(139,92,246,0.12);
    color: #7c3aed;
    border-color: rgba(139,92,246,0.25);
}

/* Modal and dividers */
body.light-theme .modal {
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.08);
}
body.light-theme .modal-header {
    border-bottom-color: rgba(0,0,0,0.08);
    color: #0f172a;
}
body.light-theme .modal-footer {
    border-top-color: rgba(0,0,0,0.08);
}
body.light-theme .divider {
    border-color: rgba(0,0,0,0.08);
}
body.light-theme .info-label {
    color: #64748b;
}
body.light-theme .info-value {
    color: #0f172a;
}

/* Speed/type badges in clients table */
body.light-theme .speed-badge {
    filter: brightness(0.85) saturate(1.2);
}

/* Page header text */
body.light-theme .page-header h1 {
    color: #0f172a;
}
body.light-theme .page-header p {
    color: #64748b;
}

/* service-item, child-item, comment-card */
body.light-theme .service-item {
    background: rgba(241,245,249,0.7);
    border-color: rgba(0,0,0,0.08);
    color: #1e293b;
}
body.light-theme .child-item {
    background: rgba(241,245,249,0.5);
    border-color: rgba(0,0,0,0.08);
    color: #1e293b;
}
body.light-theme .comment-card {
    background: rgba(241,245,249,0.7);
    border-color: rgba(0,0,0,0.08);
}
body.light-theme .comment-author {
    color: #1e293b;
}
body.light-theme .comment-time {
    color: #64748b;
}
body.light-theme .comment-body {
    color: #334155;
}

/* Port matrix and LLDP tables */
body.light-theme .lldp-table-wrap,
body.light-theme .port-matrix-wrap {
    background: rgba(241, 245, 249, 0.5);
    border-color: rgba(0, 0, 0, 0.08);
}
body.light-theme .lldp-table th,
body.light-theme .port-matrix-table th {
    background: rgba(241,245,249,0.9);
    color: #475569;
}
body.light-theme .lldp-table td,
body.light-theme .port-matrix-table td {
    border-color: rgba(0,0,0,0.06);
    color: #1e293b;
}
body.light-theme .port-tag {
    background: rgba(0,0,0,0.07);
    color: #334155;
    border-color: rgba(0,0,0,0.1);
}
body.light-theme .port-vlan-badge {
    background: rgba(59,130,246,0.12);
    color: #2563eb;
}

/* Pagination */
body.light-theme .page-btn {
    background: rgba(255,255,255,0.8);
    color: #334155;
    border-color: rgba(0,0,0,0.1);
}
body.light-theme .page-btn:hover {
    background: rgba(0,0,0,0.05);
}
body.light-theme .page-btn.active {
    background: #3b82f6;
    color: white;
}

/* Section cards (Mutes, Devices panels) */
body.light-theme .section {
    background: rgba(255, 255, 255, 0.85);
    border-color: rgba(0, 0, 0, 0.08);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}
body.light-theme .section-header {
    border-bottom-color: rgba(0, 0, 0, 0.08);
}
body.light-theme .section-header h2 {
    color: #1e293b;
}

/* Switch Info Card in Modal */
body.light-theme .switch-info-card {
    background: rgba(241, 245, 249, 0.7);
    border-color: rgba(0, 0, 0, 0.08);
}
body.light-theme .switch-info-card:hover {
    background: rgba(241, 245, 249, 0.9);
    border-color: rgba(0, 0, 0, 0.15);
}

/* Client diagnostic modal */
body.light-theme .diag-section {
    background: rgba(241, 245, 249, 0.7);
    border-color: rgba(0, 0, 0, 0.08);
    color: #0f172a;
}
body.light-theme .diag-label {
    color: #64748b;
}
body.light-theme .diag-val {
    color: #0f172a;
}
body.light-theme .diag-section h4,
body.light-theme .diag-section .section-title {
    color: #1e293b;
}
body.light-theme .diag-tab {
    background: rgba(241, 245, 249, 0.6);
    color: #475569;
    border-color: rgba(0, 0, 0, 0.08);
}
body.light-theme .diag-tab.active,
body.light-theme .diag-tab:hover,
body.light-theme .modal-tabs .tab-btn:hover {
    background: rgba(59, 130, 246, 0.12);
    color: #2563eb;
}
body.light-theme .modal-tabs .tab-btn.active {
    background: var(--accent);
    color: #ffffff;
}
body.light-theme .diag-tabs {
    border-bottom-color: rgba(0, 0, 0, 0.08);
}
body.light-theme .tab-content-section {
    background: rgba(248, 250, 252, 0.5);
    border-color: rgba(0, 0, 0, 0.06);
}

/* --- Task 3: Active Downtimes Banner --- */
.downtimes-container {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(217, 119, 6, 0.06));
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: 14px;
    padding: 16px 20px;
    box-shadow: 0 4px 20px rgba(245, 158, 11, 0.08);
}
.downtimes-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    color: #fbbf24;
    margin-bottom: 10px;
}
.downtimes-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.downtime-card {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: 10px;
    padding: 10px 14px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}
.downtime-host {
    font-weight: 600;
    color: var(--text-primary);
}
.downtime-time {
    color: var(--text-muted);
    font-size: 12px;
}
.downtime-comment {
    color: var(--text-secondary);
    flex: 1;
    min-width: 180px;
}
.downtime-author {
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 8px;
    border-radius: 6px;
}

/* --- Task 2: Engineer Comments Section --- */
.comments-section {
    margin-top: 14px;
}
.comment-card {
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-left: 3px solid var(--accent);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 8px;
    font-size: 13px;
}
.comment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    font-size: 12px;
}
.comment-author {
    font-weight: 600;
    color: #60a5fa;
}
.comment-time {
    color: var(--text-muted);
    font-size: 11px;
}
.comment-body {
    color: var(--text-primary);
    line-height: 1.4;
    white-space: pre-wrap;
}
.comment-service-tag {
    display: inline-block;
    margin-top: 5px;
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 1px 6px;
    border-radius: 4px;
}

/* --- Task 4 & 5: Hardware & LLDP & Port Matrix Tables --- */
.lldp-table-wrap, .port-matrix-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.35);
    margin-top: 8px;
}
.port-matrix-wrap {
    max-height: 380px;
    overflow-y: auto;
}
.lldp-table, .port-matrix-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.lldp-table th, .lldp-table td,
.port-matrix-table th, .port-matrix-table td {
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.lldp-table th, .port-matrix-table th {
    background: rgba(15, 23, 42, 0.7);
    color: var(--text-muted);
    font-weight: 600;
}
.port-matrix-table th {
    position: sticky;
    top: 0;
    z-index: 2;
}
.lldp-table tr:hover, .port-matrix-table tr:hover {
    background: rgba(255, 255, 255, 0.04);
}
.port-client-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: #60a5fa;
    padding: 2px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.15s;
}
.port-client-btn:hover {
    background: rgba(59, 130, 246, 0.25);
    border-color: #60a5fa;
    transform: translateY(-1px);
}
.port-tag {
    display: inline-block;
    font-family: monospace;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
}
.port-vlan-badge {
    display: inline-block;
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
    border: 1px solid rgba(139, 92, 246, 0.3);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 10px;
    margin: 1px;
}

/* ==========================================================================
   Mobile Responsive Adjustments (< 768px)
   ========================================================================== */

@media (max-width: 767px) {
    /* Prevent horizontal page overflow */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }

    .layout, .main {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* B. Navigation / Tab bar */
    .sidebar {
        width: 100% !important;
        height: 54px !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 100 !important;
        border-top: 1px solid var(--border) !important;
        border-right: none !important;
        background: rgba(10, 15, 30, 0.98) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

    .sidebar-brand, .sidebar-footer {
        display: none !important;
    }

    .sidebar-nav, .top-nav {
        display: flex !important;
        flex-direction: row !important;
        width: 100% !important;
        height: 100% !important;
        padding: 4px 6px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 6px !important;
        align-items: center !important;
        justify-content: space-around !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
    }
    .sidebar-nav::-webkit-scrollbar, .top-nav::-webkit-scrollbar {
        display: none !important;
    }

    .nav-link {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        padding: 6px 10px !important;
        font-size: 12px !important;
        font-weight: 500 !important;
        border-radius: 8px !important;
        color: var(--text-secondary) !important;
        text-decoration: none !important;
        white-space: nowrap !important;
        flex: 1 1 auto !important;
        min-width: fit-content !important;
        width: auto !important;
        margin: 0 !important;
        border: 1px solid transparent !important;
        transition: all 0.2s ease !important;
    }

    .nav-link span:not(.nav-icon) {
        display: inline-block !important;
        font-size: 12px !important;
        max-width: none !important;
        opacity: 1 !important;
    }

    .nav-link .nav-icon {
        font-size: 15px !important;
        width: auto !important;
        margin: 0 !important;
    }

    .nav-link.active {
        background: linear-gradient(135deg, rgba(59, 130, 246, 0.35), rgba(59, 130, 246, 0.15)) !important;
        color: #60a5fa !important;
        border: 1px solid rgba(59, 130, 246, 0.4) !important;
        box-shadow: 0 2px 10px rgba(59, 130, 246, 0.25) !important;
        font-weight: 600 !important;
        width: auto !important;
        min-width: fit-content !important;
    }

    .nav-link:hover {
        transform: none !important;
    }

    .nav-link .badge {
        position: static !important;
        font-size: 10px !important;
        padding: 1px 5px !important;
        margin-left: 4px !important;
    }

    .main {
        padding-bottom: 58px !important;
    }

    /* C. Stat cards on dashboard */
    .stats-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        margin-bottom: 16px !important;
        width: 100% !important;
    }

    .stat-card {
        padding: 12px 10px !important;
        border-radius: 12px !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    .stat-icon {
        font-size: 18px !important;
        margin-bottom: 4px !important;
    }

    .stat-value {
        font-size: 20px !important;
        font-weight: 700 !important;
        margin-bottom: 2px !important;
    }

    .stat-label {
        font-size: 11px !important;
        line-height: 1.2 !important;
    }

    /* D. Tables */
    .table-wrap {
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        margin-bottom: 12px !important;
    }

    .table {
        min-width: 560px !important;
        width: 100% !important;
        font-size: 12px !important;
    }

    .table th, .table td {
        padding: 6px 8px !important;
        font-size: 12px !important;
    }

    .table th {
        font-size: 11px !important;
        letter-spacing: 0.03em !important;
    }

    .status-badge {
        padding: 2px 6px !important;
        font-size: 11px !important;
    }

    .speed-badge {
        padding: 2px 6px !important;
        font-size: 11px !important;
    }

    /* E. Filters bar */
    .filters-bar {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
        width: 100% !important;
        margin-bottom: 12px !important;
    }

    .filter-input,
    .filter-select,
    .filters-bar .filter-input,
    .filters-bar .filter-select {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        font-size: 13px !important;
        padding: 8px 12px !important;
    }

    .filter-buttons {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 4px !important;
        width: 100% !important;
    }

    .filter-btn {
        flex: 1 1 auto !important;
        font-size: 12px !important;
        padding: 6px 10px !important;
        text-align: center !important;
    }

    #clientsSearchLoading {
        width: 100% !important;
        margin-top: 4px !important;
        font-size: 12px !important;
    }

    .header {
        padding: 8px 12px !important;
        gap: 8px !important;
    }

    .header-search {
        flex: 1 !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 6px 12px !important;
    }

    .header-search input {
        font-size: 13px !important;
    }

    /* F. Modals */
    .modal, .modal-lg {
        width: 95vw !important;
        max-width: 95vw !important;
        max-height: 90vh !important;
        border-radius: 14px !important;
        margin: auto !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    .modal-header {
        padding: 12px 16px !important;
    }

    .modal-header h2, .modal-header h3 {
        font-size: 15px !important;
    }

    .modal-close {
        min-width: 44px !important;
        min-height: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 20px !important;
        padding: 0 !important;
        cursor: pointer !important;
        touch-action: manipulation !important;
    }

    .modal-body {
        padding: 16px !important;
        max-height: calc(90vh - 110px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        flex: 1 1 auto !important;
    }

    .modal-footer {
        padding: 12px 16px !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    /* G. Pagination */
    .pagination {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 4px !important;
        justify-content: center !important;
        align-items: center !important;
        margin-top: 12px !important;
    }

    .page-btn {
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 6px 8px !important;
        font-size: 12px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-sizing: border-box !important;
        border-radius: 6px !important;
    }

    /* I. Device modal info grid on mobile */
    .device-info-grid {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px 12px !important;
        width: 100% !important;
        margin-bottom: 12px !important;
    }

    .device-info-grid .info-item {
        flex: 1 1 calc(50% - 12px) !important;
        max-width: calc(50% - 6px) !important;
        min-width: 120px !important;
        box-sizing: border-box !important;
    }

    .info-label {
        font-size: 10px !important;
    }

    .info-value {
        font-size: 12px !important;
    }

    .switch-info-grid {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    /* J. Client diagnostic modal */
    .diag-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    .diag-section {
        padding: 12px !important;
        margin-bottom: 12px !important;
    }

    .diag-val {
        font-size: 13px !important;
    }

    .diag-section .table-wrap,
    .modal-body .table-wrap,
    .lldp-table-wrap,
    .port-matrix-wrap {
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .lldp-table, .port-matrix-table {
        min-width: 480px !important;
        font-size: 11px !important;
    }

    .lldp-table th, .lldp-table td,
    .port-matrix-table th, .port-matrix-table td {
        padding: 5px 6px !important;
        font-size: 11px !important;
    }

    #switchIpoeTable, #switchPppTable {
        min-width: 500px !important;
        font-size: 12px !important;
    }

    #switchIpoeTable th, #switchIpoeTable td,
    #switchPppTable th, #switchPppTable td {
        padding: 6px 8px !important;
        font-size: 12px !important;
    }

    /* Additional Mobile Polish */
    .tab-pane {
        padding: 12px 10px !important;
    }

    .page-header {
        margin-bottom: 12px !important;
    }

    .page-header h1 {
        font-size: 18px !important;
    }

    .page-header p {
        font-size: 12px !important;
    }

    .period-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
    }

    .period-btn {
        padding: 8px 6px !important;
        font-size: 12px !important;
        min-height: 38px !important;
    }

    .downtimes-container {
        padding: 12px !important;
    }

    .downtime-card {
        padding: 8px 10px !important;
        font-size: 12px !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 4px !important;
    }

    .comments-section {
        margin-top: 10px !important;
    }

    .comment-card {
        padding: 8px 10px !important;
        font-size: 12px !important;
    }

    .topology-legend {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .topology-container, #topologyContainer {
        height: calc(100vh - 170px) !important;
        min-height: 280px !important;
    }
}

/* ==========================================================================
   H. Landscape Phone Orientation (< 500px height)
   ========================================================================== */

@media screen and (orientation: landscape) and (max-height: 500px) {
    /* landscape phone - reduce header height, make topology shorter */
    .header {
        padding: 4px 12px !important;
    }

    .top-nav {
        padding: 6px 12px !important;
    }

    .sidebar {
        height: 44px !important;
    }

    .main {
        padding-bottom: 46px !important;
    }

    .nav-link {
        padding: 4px 8px !important;
        font-size: 11px !important;
    }

    #topologyContainer, #topologyNetwork, .topology-container {
        height: calc(100vh - 110px) !important;
        min-height: 200px !important;
    }

    .tab-pane {
        padding: 8px 12px !important;
    }

    .page-header {
        margin-bottom: 8px !important;
    }

    .page-header h1 {
        font-size: 16px !important;
    }

    .page-header p {
        font-size: 11px !important;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 6px !important;
        margin-bottom: 10px !important;
    }

    .stat-card {
        padding: 8px 6px !important;
    }

    .stat-value {
        font-size: 16px !important;
    }

    .stat-icon {
        font-size: 14px !important;
        margin-bottom: 2px !important;
    }

    .stat-label {
        font-size: 10px !important;
    }

    .modal {
        max-height: 96vh !important;
    }

    .modal-body {
        padding: 10px 14px !important;
        max-height: calc(96vh - 80px) !important;
    }

    .modal-header {
        padding: 8px 14px !important;
    }

    .modal-footer {
        padding: 8px 14px !important;
    }
}
