@import url('https://fonts.googleapis.com/css2?family=Ubuntu:wght@300;400;500;700&display=swap');

:root {
    --bg-light: #f4f4f7;
    --card-bg: #ffffff;
    --nav-bg: #ffffff;
    --glass-border: rgba(0, 0, 0, 0.08);
    --accent-primary: #e31e24; /* Tikona red */
    --accent-secondary: #2d1e2f; /* Tikona Charcoal */
    --status-up: #10b981;
    --status-down: #ef4444;
    --text-main: #2d1e2f;
    --text-muted: #64748b;
    --card-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.05);
}

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

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

/* Glassmorphism Background Elements */
.bg-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.blob {
    position: absolute;
    width: 400px;
    height: 400px;
    background: linear-gradient(to right, var(--accent-primary), #fdba74);
    filter: blur(100px);
    border-radius: 50%;
    opacity: 0.05;
    animation: move 20s infinite alternate;
}

.blob:nth-child(2) {
    top: 40%;
    right: -100px;
    background: linear-gradient(to right, #ec4899, #8b5cf6);
    animation-delay: -5s;
}

@keyframes move {
    from {
        transform: translate(0, 0);
    }

    to {
        transform: translate(100px, 100px);
    }
}

.modal-content {
    background: var(--nav-bg);
    max-width: 1200px;
    width: 95%;
    max-height: 90vh;
    border-radius: 12px;
    position: relative;
    padding: 0;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--glass-border);
}

.modal-header {
    background: var(--accent-secondary);
    color: #fff;
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 800;
    margin: 0;
    letter-spacing: 0.5px;
    color: #ffffff;
}

.modal-body {
    padding: 2rem;
    overflow-y: auto;
    max-height: calc(90vh - 120px);
    background: #f8fafc;
}

.top-nav {
    position: sticky;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 70px;
    height: auto;
    background: var(--nav-bg);
    border-bottom: 3px solid var(--accent-primary);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    z-index: 1000;
    display: flex;
    align-items: center;
}

.nav-container {
    max-width: 98%;
    margin: 0 auto;
    width: 100%;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-logo h1 {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0;
    color: var(--accent-secondary);
}

.nav-logo p {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--accent-primary);
    margin: 0;
    font-weight: 700;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.cycle-selector {
    background: #f1f5f9;
    padding: 6px 12px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cycle-selector select {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
}

.cycle-selector select option {
    background: white;
    color: var(--text-main);
}

.nav-btn {
    padding: 8px 16px;
    border-radius: 10px;
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.nav-btn.export { background: rgba(34, 197, 94, 0.1); color: #22c55e; }
.nav-btn.bulk { background: rgba(99, 102, 241, 0.1); color: #6366f1; }
.nav-btn.add { background: var(--accent-primary); color: white; }
.nav-btn.logout { background: rgba(239, 68, 68, 0.1); color: #ef4444; padding: 8px 12px; }

.nav-btn:hover {
    transform: translateY(-2px);
    filter: contrast(1.2);
}

.container {
    max-width: 98%;
    margin: 0 auto;
    padding: 2rem;
}

.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    box-shadow: var(--card-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.glass-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

.link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 1.5rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.clickable-stat {
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.clickable-stat:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
}

.clickable-stat.active-filter {
    background: rgba(227, 30, 36, 0.05);
    border-color: var(--accent-primary);
}

.clickable-stat.active-filter::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--accent-primary);
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
}

.status-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
}

.status-up {
    background: var(--status-up);
    box-shadow: 0 0 10px var(--status-up);
}

.status-down {
    background: var(--status-down);
    box-shadow: 0 0 10px var(--status-down);
}

.link-card {
    min-height: auto;
    display: flex;
    flex-direction: column;
    padding: 1.2rem;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.link-header {
    margin-bottom: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.link-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
}

.link-name-title {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--text-main);
    margin-bottom: 5px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.traffic-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.bandwidth-chart {
    height: 120px;
    /* FIXED HEIGHT: Ensures alignment of footers */
    width: 100%;
    margin-bottom: 1rem;
}

.link-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 45px;
    /* FIXED HEIGHT: Ensures alignment of port section */
}

.badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-primary {
    background: rgba(79, 70, 229, 0.2);
    color: #818cf8;
    border: 1px solid rgba(79, 70, 229, 0.3);
}

.badge-failover {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.traffic-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.bandwidth-chart {
    height: 120px;
    width: 100%;
}

.btn {
    padding: 10px 20px;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background: #c11218;
    box-shadow: 0 4px 12px rgba(227, 30, 36, 0.2);
}

#addLinkBtn {
    padding: 12px 24px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(45, 30, 47, 0.4); /* Tikona charcoal soft overlay */
    backdrop-filter: blur(4px);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
}

.form-control {
    width: 100%;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    color: var(--text-main);
    outline: none;
    font-family: inherit;
}

.form-control option {
    background-color: #ffffff;
    color: var(--text-main);
}

.form-control:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(227, 30, 36, 0.1);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.link-card {
    animation: fadeIn 0.5s ease-out forwards;
}

/* Dashboard Loader */
.loader {
    width: 48px;
    height: 48px;
    border: 5px solid #FFF;
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Link Footer */
.link-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--glass-border);
    padding-top: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
    color: var(--text-main);
}

/* Tag Label */
.link-tag {
    display: inline-block;
    margin-top: 4px;
    padding: 2px 10px;
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* History Button */
.btn-history {
    padding: 5px 14px;
    border-radius: 10px;
    border: 1px solid rgba(227, 30, 36, 0.2);
    background: rgba(227, 30, 36, 0.05);
    color: var(--accent-primary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.btn-history:hover {
    background: rgba(227, 30, 36, 0.1);
    box-shadow: 0 2px 8px rgba(227, 30, 36, 0.15);
}

/* Tag Edit Button */
.btn-tag {
    padding: 5px 10px;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    background: #f1f5f9;
    color: var(--text-main);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-tag:hover {
    background: #e2e8f0;
}

.btn-refresh-ports {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--glass-border);
    background: #f1f5f9;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
}

.btn-refresh-ports:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--accent-secondary);
    border-color: var(--accent-secondary);
    transform: rotate(30deg);
}

.btn-refresh-ports:active {
    transform: scale(0.9);
}

/* Status Text */
.status-up-text {
    color: #10b981;
}

.status-down-text {
    color: #ef4444;
}

/* Card Header & Meta */
.link-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.meta-sep {
    opacity: 0.3;
}

.meta-tag-text {
    color: var(--accent-primary);
    font-weight: 600;
}

.header-edit-btn {
    margin-left: 1rem;
}

.close-modal {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.close-modal:hover {
    background: var(--accent-primary);
    transform: rotate(90deg);
}

.icon-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

/* Specific Card Layout Enhancements */
.card-separator {
    height: 1px;
    background: linear-gradient(to right, transparent, var(--glass-border), transparent);
    margin: 4px 0;
}

.status-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    padding: 6px 12px;
    border-radius: 12px;
}

.status-label-text {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.5px;
}

.action-box {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sla-text {
    font-size: 0.95rem;
    color: var(--text-muted);
}

.port-tag-name {
    flex: 1;
    color: var(--text-main);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.2s;
    font-weight: 500;
}

.port-tag-name:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--accent-secondary);
}

.uptime-badge {
    background: rgba(6, 182, 212, 0.1);
    border: 1px solid rgba(6, 182, 212, 0.3);
    border-radius: 8px;
    padding: 4px 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 0.75rem;
    color: var(--accent-secondary);
    font-weight: 700;
}

.uptime-badge i {
    color: var(--accent-secondary);
    font-size: 0.7rem;
    margin-right: 4px;
}

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

/* Port Status Section (per card) */
.port-status-section {
    border-top: 1px solid var(--glass-border);
    margin-top: 0.5rem;
}

.port-status-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 600;
}

.port-status-header:hover {
    color: #06b6d4;
}

.port-row {
    display: flex;
    align-items: center;
    padding: 6px 0;
    font-size: 0.92rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.port-index {
    width: 24px;
    color: var(--text-muted);
    font-weight: 600;
}

.port-status-badge {
    font-weight: 700;
    font-size: 0.85rem;
    min-width: 40px;
    text-align: right;
}

/* View Selector & List View */
.view-selector {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    padding: 2px 8px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.list-view {
    margin-top: 1.5rem;
    animation: fadeIn 0.4s ease-out;
}

.table-clean th {
    background: #f1f5f9 !important;
    color: var(--text-main) !important;
    border-bottom: 2px solid var(--accent-primary);
    position: sticky;
    top: 0;
    z-index: 10;
    font-size: 0.9rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 14px 15px;
}

/* Global font-size override for list-view table cells (overrides JS inline styles) */
.table-clean td {
    font-size: 0.9rem !important;
}

.table-clean td span {
    font-size: 0.88rem !important;
}

.table-clean td .btn {
    font-size: 0.85rem !important;
}

.table-clean tr:hover td {
    background: #f8fafc !important;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.list-view .glass-card {
    border-radius: 16px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
}

.list-view .btn {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.list-view .btn:hover {
    transform: scale(1.05);
    filter: brightness(1.2);
}

@media (max-width: 1000px) { 
    .list-view {
        overflow-x: auto;
    }
    .table-clean {
        min-width: 1000px;
    }
} 

/* Manual layout switch (header Desktop/Mobile selector) */
body.layout-mobile .container {
    padding: 10px 5px !important;
    max-width: 100% !important;
    margin-top: 10px !important;
    width: 100% !important;
}

body.layout-mobile .top-nav {
    position: relative; /* Prevent overlapping content when wrapped */
    height: auto;
    min-height: 70px;
    padding: 10px 0;
}

body.layout-mobile .table-clean {
    min-width: 100% !important; /* Override 1000px minimum width */
}

body.layout-mobile .nav-container {
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    padding: 0 10px;
    width: 100%;
}

body.layout-mobile .nav-actions {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

body.layout-mobile .nav-actions .btn,
body.layout-mobile .nav-actions .nav-btn,
body.layout-mobile .nav-actions select {
    font-size: 0.7rem !important;
    padding: 4px 8px !important;
}

body.layout-mobile .nav-logo {
    text-align: left;
    width: 100%;
}

body.layout-mobile .nav-links {
    flex-wrap: nowrap !important;
    justify-content: flex-start;
    overflow-x: auto;
    gap: 8px !important;
    margin-bottom: 5px !important;
    padding-bottom: 5px !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}

body.layout-mobile .nav-links::-webkit-scrollbar {
    display: none; /* Chrome/Safari/Edge */
}

body.layout-mobile .nav-links .nav-btn {
    font-size: 0.65rem;
    padding: 6px 12px;
    flex: 0 0 auto;
    text-align: center;
    justify-content: center;
    white-space: nowrap;
}

/* Reduce clutter on mobile layout */
body.layout-mobile .nav-btn.export,
body.layout-mobile .nav-btn.bulk,
body.layout-mobile #btnViewToggle {
    display: none !important;
}

/* Force List View and Hide Grid View on Mobile */
body.layout-mobile #linkGrid {
    display: none !important;
}
body.layout-mobile #listView {
    display: block !important;
}

/* Hide Unnecessary List Columns on Mobile */
/* Hide: ID (2), Address (3), IP (4), Group (5), Uptime (8), Primary (9), Secondary (10), Action (13) */
body.layout-mobile #listView table th:nth-child(2),
body.layout-mobile #listView table td:nth-child(2),
body.layout-mobile #listView table th:nth-child(3),
body.layout-mobile #listView table td:nth-child(3),
body.layout-mobile #listView table th:nth-child(4),
body.layout-mobile #listView table td:nth-child(4),
body.layout-mobile #listView table th:nth-child(5),
body.layout-mobile #listView table td:nth-child(5),
body.layout-mobile #listView table th:nth-child(8),
body.layout-mobile #listView table td:nth-child(8),
body.layout-mobile #listView table th:nth-child(9),
body.layout-mobile #listView table td:nth-child(9),
body.layout-mobile #listView table th:nth-child(10),
body.layout-mobile #listView table td:nth-child(10),
body.layout-mobile #listView table th:nth-child(13),
body.layout-mobile #listView table td:nth-child(13) {
    display: none !important;
}

body.layout-mobile .tikona-brand {
    /* Removed display: none to show logo */
}

/* Mobile View: Convert group filters to dropdown */
body.layout-mobile #groupFilters {
    display: none !important;
}

body.layout-mobile #groupFiltersMobile {
    display: block !important;
    width: 100% !important;
    max-width: 100%;
    box-sizing: border-box;
}

/* Mobile View: Fit stats overview side by side in a single grid */
body.layout-mobile .stats-overview {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

body.layout-mobile .stats-overview .glass-card {
    padding: 0.5rem 0.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

body.layout-mobile .stats-overview .stat-label {
    font-size: 0.55rem;
    line-height: 1.1;
    margin-bottom: 0.25rem;
}

body.layout-mobile .stats-overview .stat-value {
    font-size: 1.1rem;
}

body.layout-mobile .stats-overview span[style*="font-size: 0.75rem"] {
    font-size: 0.55rem !important;
    display: flex;
    flex-direction: column;
}

/* Mobile View: Link Grid & Cards Styling */
body.layout-mobile .link-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

body.layout-mobile .link-card {
    padding: 10px;
}

body.layout-mobile .link-name-title {
    font-size: 0.8rem;
    margin-bottom: 4px;
    line-height: 1.2;
}

body.layout-mobile .link-meta-row {
    font-size: 0.65rem;
    gap: 6px;
    margin-bottom: 6px;
}

body.layout-mobile .status-box {
    padding: 4px 8px;
    border-radius: 6px;
}

body.layout-mobile .status-label-text {
    font-size: 0.75rem;
}

body.layout-mobile .btn-history {
    padding: 3px 8px;
    font-size: 0.7rem;
}

body.layout-mobile .uptime-badge,
body.layout-mobile .badge,
body.layout-mobile .link-tag {
    font-size: 0.6rem;
    padding: 2px 6px;
}

body.layout-mobile .link-footer {
    padding-top: 8px;
    gap: 4px;
    flex-direction: column;
    align-items: flex-start;
}

body.layout-mobile .action-box {
    width: 100%;
    justify-content: space-between;
}

/* Bandwidth Tier Cards - Modern Redesign */
.bandwidth-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.bw-card {
    background: var(--card-bg);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    border: 1px solid var(--glass-border);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    display: flex;
    flex-direction: column;
}

.bw-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.12);
    border-color: rgba(227, 30, 36, 0.3);
}

.bw-card-header {
    padding: 12px 15px;
    color: #fff;
    font-weight: 800;
    font-size: 0.85rem;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    background: linear-gradient(135deg, var(--accent-primary), #f43f5e);
}

.bw-card-body {
    padding: 25px 15px;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: linear-gradient(to bottom, #ffffff, #f8fafc);
}

.bw-total {
    font-size: 3rem;
    font-weight: 900;
    color: var(--accent-secondary);
    line-height: 1;
    margin-bottom: 5px;
    background: linear-gradient(135deg, var(--accent-secondary), #4b5563);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.bw-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 700;
}

.bw-footer {
    display: flex;
    padding: 0;
    height: 45px;
    border-top: 1px solid var(--glass-border);
}

.bw-stat {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 800;
    color: #fff;
    gap: 8px;
    transition: all 0.3s;
}

.bw-up { 
    background: #10b981; 
    border-right: 1px solid rgba(255,255,255,0.1);
}
.bw-down { background: #ef4444; }

.bw-up:hover { background: #059669; }
.bw-down:hover { background: #dc2626; }

/* Bandwidth Bar Chart - Modern Redesign */
.bw-bar-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    height: 100%;
    justify-content: flex-end;
}

.bw-bar {
    width: 65px;
    border-radius: 12px 12px 0 0;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.03);
    transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.05);
}

.bw-bar:hover {
    filter: brightness(1.1);
    transform: scaleX(1.05);
}

.bw-bar-segment {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 900;
    color: #fff;
    transition: height 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.bw-bar-up { 
    background: linear-gradient(to top, #10b981, #34d399); 
}
.bw-bar-down { 
    background: linear-gradient(to top, #ef4444, #f87171); 
}

.bw-bar-label {
    font-size: 0.8rem;
    color: var(--accent-secondary);
    white-space: nowrap;
    font-weight: 800;
    margin-top: 5px;
    letter-spacing: 0.5px;
}

.nav-links {
    display: flex;
    gap: 10px;
}

.nav-btn {
    padding: 8px 18px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-btn i {
    font-size: 0.9rem;
}

.nav-btn:hover {
    background: rgba(255,255,255,0.05);
    color: #fff;
}

.nav-btn.active {
    background: rgba(227, 30, 36, 0.1);
    color: var(--accent-primary);
    position: relative;
}

.nav-btn.active::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--accent-primary);
    border-radius: 3px;
}

.filter-group-container { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 10px; 
    margin-bottom: 20px; 
    padding: 15px; 
    background: #0f172a; 
    border-radius: 12px; 
    border: 1px solid rgba(255,255,255,0.05); 
}

.filter-chip { 
    padding: 10px 22px; 
    background: #334155; 
    color: #f8fafc; 
    border: 1px solid rgba(255,255,255,0.1); 
    border-radius: 10px; 
    font-size: 0.9rem; 
    font-weight: 600; 
    cursor: pointer; 
    transition: all 0.2s ease; 
    white-space: nowrap; 
}

.filter-chip:hover { 
    background: #475569; 
    color: #ffffff; 
    border-color: rgba(255,255,255,0.3);
}

.filter-chip.active { 
    background: #00bcd4; 
    color: #0f172a; 
    border-color: #00bcd4; 
    box-shadow: 0 4px 15px rgba(0, 188, 212, 0.4); 
}

.status-bar-group {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.status-bar-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.status-bar-label {
    font-size: 1.1rem;
    color: #e2e8f0;
    font-weight: 500;
}

.status-bar-track {
    height: 35px;
    background: rgba(30, 41, 59, 0.7);
    border-radius: 20px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255,255,255,0.05);
}

.status-bar-fill {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 20px;
    transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.9rem;
    color: #fff;
    white-space: nowrap;
}

.primary-fill {
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
}

.secondary-fill {
    background: linear-gradient(90deg, #10b981, #34d399);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}

.isolated-fill {
    background: linear-gradient(90deg, #ef4444, #f87171);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
}

/* Compact Bandwidth Cards for Mobile */
body.layout-mobile .bw-card {
    border-radius: 8px;
}
body.layout-mobile .bw-card-header {
    padding: 4px 6px;
    font-size: 0.65rem;
    font-weight: 800;
}
body.layout-mobile .bw-card-body {
    padding: 6px 4px;
}
body.layout-mobile .bw-total {
    font-size: 1.4rem;
    margin-bottom: 0px;
    line-height: 1.1;
}
body.layout-mobile .bw-label {
    font-size: 0.5rem;
    letter-spacing: 0px;
    line-height: 1;
}
body.layout-mobile .bw-footer {
    height: 22px;
}
body.layout-mobile .bw-stat {
    font-size: 0.6rem;
    font-weight: 800;
}
body.layout-mobile .bw-stat i {
    font-size: 0.55rem !important;
}

/* Bandwidth Dashboard Responsive Grid */
#bwDashboardGrid {
    grid-template-columns: 1fr 2fr 1.2fr;
    min-height: 320px;
}

body.layout-mobile #bwDashboardGrid {
    grid-template-columns: 1.3fr 1fr !important;
    gap: 8px !important; /* Reduce gap between charts */
}

/* Extra-small phones: stack bandwidth dashboard to avoid horizontal clipping */
@media (max-width: 600px) {
    body.layout-mobile #bwDashboardGrid {
        grid-template-columns: 1fr !important;
    }
    body.layout-mobile #bwDashboardGrid > div {
        grid-column: 1 / -1 !important;
    }
}

/* Safety net: even without the manual "Mobile View" toggle, keep phone layouts from clipping */
@media (max-width: 600px) {
    #bwDashboardGrid {
        grid-template-columns: 1fr !important;
    }
    #bwDashboardGrid > div {
        grid-column: 1 / -1 !important;
    }
    .bw-bar {
        width: 34px;
    }
    #bwChart {
        justify-content: space-between;
    }
}

/* Make Bandwidth Filter side menu compact on mobile */
body.layout-mobile #bandwidthFiltersSide {
    gap: 4px !important;
}
body.layout-mobile #bandwidthFiltersSide .filter-chip {
    padding: 6px 8px !important;
    gap: 4px !important;
    border-radius: 6px !important;
    min-height: 36px;
}
body.layout-mobile #bandwidthFiltersSide .filter-chip span {
    font-size: 0.75rem !important;
}
body.layout-mobile #bandwidthFiltersSide .filter-chip .neon-up,
body.layout-mobile #bandwidthFiltersSide .filter-chip .neon-down {
    padding: 2px 0 !important;
    font-size: 0.65rem !important;
}
body.layout-mobile #bwDashboardGrid > div:first-child {
    grid-column: 1 / -1;
}

/* Make bar chart fit on narrow screens (avoid overflow from fixed bar widths) */
body.layout-mobile .bw-bar {
    width: 34px !important;
    border-radius: 10px 10px 0 0;
}
body.layout-mobile #bwChart {
    justify-content: space-between;
}

/* Tables: keep content readable without breaking layout on mobile */
body.layout-mobile .table-clean th,
body.layout-mobile .table-clean td {
    padding: 10px 8px !important;
}
body.layout-mobile .table-clean td {
    word-break: break-word;
}

/* Fix flex headers for SLA and Utilisation on mobile */
body.layout-mobile #slaView .glass-card > div:first-child,
body.layout-mobile #utilisationView .glass-card:first-child {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 15px;
}
body.layout-mobile #slaView .glass-card > div:first-child > div:last-child,
body.layout-mobile #utilisationView .glass-card:first-child > div:last-child {
    width: 100%;
    text-align: left !important;
    justify-content: flex-start !important;
}
body.layout-mobile #slaView h2,
body.layout-mobile #utilisationView h2 {
    font-size: 1.1rem !important;
}
body.layout-mobile #utilisationView #utilUpgradeCount {
    font-size: 1.8rem !important;
}

/* Neon Pulse Animations for Status Buttons */
@keyframes neonPulseGreen {
    0% { box-shadow: 0 0 4px rgba(34,197,94,0.4), inset 0 0 8px rgba(34,197,94,0.1); border-color: rgba(34,197,94,0.5); }
    50% { box-shadow: 0 0 10px rgba(34,197,94,0.8), inset 0 0 15px rgba(34,197,94,0.3); border-color: rgba(74,222,128,1); }
    100% { box-shadow: 0 0 4px rgba(34,197,94,0.4), inset 0 0 8px rgba(34,197,94,0.1); border-color: rgba(34,197,94,0.5); }
}
@keyframes neonPulseRed {
    0% { box-shadow: 0 0 4px rgba(239,68,68,0.4), inset 0 0 8px rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.5); }
    50% { box-shadow: 0 0 10px rgba(239,68,68,0.8), inset 0 0 15px rgba(239,68,68,0.3); border-color: rgba(248,113,113,1); }
    100% { box-shadow: 0 0 4px rgba(239,68,68,0.4), inset 0 0 8px rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.5); }
}

.neon-up {
    animation: neonPulseGreen 2s infinite;
    background: rgba(34,197,94,0.1) !important;
    border: 1px solid rgba(34,197,94,0.5);
    color: #4ade80 !important;
    transition: background 0.2s;
}
.neon-up:hover {
    background: rgba(34,197,94,0.25) !important;
}

.neon-down {
    animation: neonPulseRed 2s infinite;
    background: rgba(239,68,68,0.1) !important;
    border: 1px solid rgba(239,68,68,0.5);
    color: #f87171 !important;
    transition: background 0.2s;
}
.neon-down:hover {
    background: rgba(239,68,68,0.25) !important;
}

/* Responsive Charts */
.chart-card {
    padding: 1.5rem;
}
#bwChart {
    height: 250px;
    display: flex;
    align-items: flex-end;
    gap: 20px;
    padding-top: 20px;
    padding-bottom: 10px;
    position: relative;
    border-bottom: 1px solid var(--glass-border);
    margin-top: 20px;
    margin-bottom: 40px;
}
#availabilityChart {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
.donut-perc { font-size: 2.2rem; }
.donut-perc small { font-size: 1rem; }
.donut-label { font-size: 0.65rem; letter-spacing: 1px; }

body.layout-mobile .chart-card {
    padding: 15px 5px !important;
}
body.layout-mobile .chart-card .filter-section-title {
    font-size: 0.7rem !important;
    text-align: center;
    margin-bottom: 15px !important;
}
body.layout-mobile #bwChart {
    height: 140px !important;
    gap: 5px !important;
    margin-top: 10px !important;
    margin-bottom: 25px !important;
    padding-top: 10px !important;
}
body.layout-mobile .bw-bar-label {
    font-size: 0.55rem !important;
    transform: rotate(-35deg) translateX(-5px);
    white-space: nowrap;
}
body.layout-mobile #availabilityChart {
    width: 100px !important;
    height: 100px !important;
}
body.layout-mobile .donut-perc { font-size: 1.3rem !important; }
body.layout-mobile .donut-perc small { font-size: 0.7rem !important; }
body.layout-mobile .donut-label { font-size: 0.45rem !important; letter-spacing: 0; margin-top: 2px !important; }
body.layout-mobile .chart-legend {
    gap: 10px !important;
    font-size: 0.55rem !important;
}

/* Stats Filter Mobile Compact */
body.layout-mobile .dynamic-date-filter {
    display: none !important;
}
body.layout-mobile .modal-filter-row {
    padding: 8px 10px !important;
    border-radius: 8px !important;
}
body.layout-mobile .quick-filters {
    width: 100%;
    justify-content: space-between;
    gap: 6px !important;
}
body.layout-mobile .quick-filters .filter-label {
    display: none !important;
}
body.layout-mobile .quick-filters .quick-btn {
    flex: 1;
    padding: 6px 0 !important;
    text-align: center;
    font-size: 0.75rem !important;
}
body.layout-mobile #statsMonthSelect {
    flex: 1.5;
    width: 100% !important;
    text-align: center;
    font-size: 0.75rem !important;
}

/* Reduce gaps inside modal stats section for compact mobile view */
body.layout-mobile #modalStatsSection {
    gap: 0.5rem !important;
}
body.layout-mobile #modalIspCharts {
    gap: 0.5rem !important;
}
body.layout-mobile #modalStatsSection .glass-card {
    padding: 10px !important;
    margin-bottom: 0 !important;
}
body.layout-mobile #modalStatsSection .glass-card h4 {
    margin-bottom: 10px !important;
    font-size: 0.8rem !important;
}
body.layout-mobile .unprovisioned-note {
    padding: 8px !important;
}
body.layout-mobile .unprovisioned-note span {
    font-size: 0.75rem !important;
}

body.layout-mobile .sla-hide-mobile,
body.layout-mobile .util-hide-mobile {
    display: none !important;
}

body.layout-mobile .desktop-only {
    display: none !important;
}

body:not(.layout-mobile) .mobile-only {
    display: none !important;
}

.pills-container {
    display: flex;
    flex-direction: row;
    gap: 15px;
    margin: 0 auto 25px auto;
    max-width: 1000px;
    justify-content: space-between;
}

.pills-container > div {
    flex: 1;
}

body.layout-mobile .pills-container {
    flex-direction: column;
    max-width: 650px;
    gap: 10px;
}

/* Fix right-side cut on phones: the pill filter chips have fixed grid columns inline */
body.layout-mobile .pills-container .filter-chip {
    grid-template-columns: 20px 1fr 34px 44px 44px !important;
    gap: 6px !important;
    padding: 8px 10px !important;
}
body.layout-mobile .pills-container .filter-chip i {
    font-size: 1rem !important;
}
body.layout-mobile .pills-container .filter-chip span,
body.layout-mobile .pills-container .filter-chip .neon-up,
body.layout-mobile .pills-container .filter-chip .neon-down {
    font-size: 0.7rem !important;
}

/* Auto-responsive (no toggle needed): apply mobile-fit rules on small screens */
@media (max-width: 700px) {
    .container {
        padding: 10px 5px;
        max-width: 100%;
        width: 100%;
        margin-top: 10px;
    }
    .nav-container {
        flex-wrap: wrap;
        gap: 10px;
        justify-content: center;
        padding: 0 10px;
        width: 100%;
    }
    .nav-actions {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }
    .nav-logo {
        width: 100%;
        justify-content: space-between !important;
        flex-direction: row-reverse !important;
    }
    .nav-logo > div {
        text-align: left !important;
    }
    .nav-container {
        position: relative;
        width: 100%;
    }

    /* Utilisation Table Column Widths for Mobile */
    #utilisationView .table-clean th:nth-child(1),
    #utilisationView .table-clean td:nth-child(1) { width: 40%; }
    #utilisationView .table-clean th:nth-child(3),
    #utilisationView .table-clean td:nth-child(3) { width: 25%; white-space: nowrap !important; }
    #utilisationView .table-clean th:nth-child(5),
    #utilisationView .table-clean td:nth-child(5) { width: 25%; }
    #utilisationView .table-clean th:nth-child(6),
    #utilisationView .table-clean td:nth-child(6) { width: 10%; }
    .nav-links {
        flex-wrap: nowrap;
        justify-content: flex-start;
        overflow-x: auto;
        gap: 8px;
        margin-bottom: 5px;
        padding-bottom: 5px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .nav-links::-webkit-scrollbar {
        display: none;
    }
    .pills-container {
        flex-direction: column;
        max-width: 100%;
        gap: 4px;
        margin-bottom: 5px !important;
    }
    .pills-container .filter-chip {
        grid-template-columns: 20px 1fr 34px 44px 44px !important;
        gap: 6px !important;
        padding: 6px 10px !important;
    }
    .filter-container { margin-bottom: 0px !important; }
    .filter-group-container { margin-bottom: 0px !important; padding: 5px 10px !important; }
    #groupFiltersMobile { margin-bottom: 0px !important; margin-top: 5px !important; }

    /* Force main list table to fit within phone width (no horizontal scroll) */
    #listView .table-clean {
        width: 100% !important;
        table-layout: fixed;
    }
    #listView .table-clean th {
        font-size: 0.8rem !important;
    }
    #listView .table-clean th,
    #listView .table-clean td {
        white-space: normal !important;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    /* After mobile column-hiding, remaining visible columns are: 1 Link Name, 6 Plan BW, 7 Firewall, 11 SLA, 12 Stats */
    #listView .table-clean th:nth-child(1),
    #listView .table-clean td:nth-child(1) { width: 32%; }
    #listView .table-clean th:nth-child(6),
    #listView .table-clean td:nth-child(6) { width: 20%; white-space: nowrap !important; font-size: 0.55rem !important; }
    #listView .table-clean th:nth-child(7),
    #listView .table-clean td:nth-child(7) { width: 24%; }
    #listView .table-clean th:nth-child(11),
    #listView .table-clean td:nth-child(11) { width: 14%; white-space: nowrap !important; font-size: 0.55rem !important; }
    #listView .table-clean th:nth-child(12),
    #listView .table-clean td:nth-child(12) { width: 10%; }

    body.layout-mobile .nav-links {
        gap: 4px !important;
    }
    body.layout-mobile .nav-links .nav-btn {
        padding: 6px 10px !important;
        font-size: 0.75rem !important;
    }

    /* Stats button: icon-only on phones to prevent tall/wrapped cell */
    #listView td:nth-child(12) .btn {
        width: 32px !important;
        height: 32px !important;
        padding: 0 !important;
        border-radius: 10px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 0 !important; /* Hide text "Stats" */
        line-height: 1 !important;
    }
    #listView td:nth-child(12) .btn i {
        font-size: 14px !important;
        margin: 0 !important;
    }

    /* Prevent SLA % column from wrapping and breaking onto multiple lines */
    #slaView .table-clean th:last-child,
    #slaView .table-clean td:last-child {
        white-space: nowrap !important;
        word-break: normal !important;
        width: auto !important;
    }

    /* Reduce card padding on mobile so tables can stretch to fill the screen */
    body.layout-mobile .glass-card {
        padding: 0.5rem 0.25rem !important;
    }

    /* Fix modal chart widths and event tables for mobile */
    body.layout-mobile canvas#modalUptimeChart {
        min-width: 600px !important; /* Force horizontal scroll for readability */
    }

    body.layout-mobile #firewallEventsBody td, body.layout-mobile #firewallEventsBody th,
    body.layout-mobile #primaryEventsBody td, body.layout-mobile #primaryEventsBody th,
    body.layout-mobile #secondaryEventsBody td, body.layout-mobile #secondaryEventsBody th {
        white-space: nowrap !important;
        font-size: 0.65rem !important;
        padding: 6px 4px !important;
    }

    /* Force 3 ports side-by-side on mobile */
    body.layout-mobile #modalPortStatusList {
        display: grid !important;
        grid-template-columns: 1fr 1fr 1fr !important;
        gap: 0.25rem !important;
    }
    body.layout-mobile #modalPortStatusList > div {
        flex-direction: column !important;
        justify-content: center;
        text-align: center;
        padding: 4px 2px !important;
    }
    body.layout-mobile #modalPortStatusList > div span:nth-child(2) {
        font-size: 0.55rem !important;
        margin-bottom: 2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
        display: block;
    }
}
