:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --card-bg: #ffffff;
    --card-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --card-shadow-hover: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    --sidebar-bg: #2c3e50;
    --sidebar-text: #ecf0f1;
    --sidebar-hover: #34495e;
    --sidebar-active: #3498db;
    --input-bg: #ffffff;
    --input-border: #ced4da;
    --table-bg: #ffffff;
    --table-hover: #f8f9fa;
    --table-border: #dee2e6;
    --table-header-bg: #f8f9fa;
}

[data-theme="dark"] {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border-color: #30363d;
    --card-bg: #161b22;
    --card-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.5);
    --card-shadow-hover: 0 0.5rem 1rem rgba(0, 0, 0, 0.7);
    --sidebar-bg: #010409;
    --sidebar-text: #e6edf3;
    --sidebar-hover: #161b22;
    --sidebar-active: #1f6feb;
    --input-bg: #0d1117;
    --input-border: #30363d;
    --table-bg: #0d1117;
    --table-hover: #161b22;
    --table-border: #21262d;
    --table-header-bg: #161b22;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Layout with Sidebar */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Styles */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    transition: all 0.3s ease;
    z-index: 1000;
}

.sidebar-header {
    padding: 1.5rem 1.25rem;
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="light"] .sidebar-header {
    background: #ffffff;
    border-bottom: 1px solid #dee2e6;
}

.sidebar-header i {
    font-size: 1.5rem;
}

.sidebar-logo {
    width: 180px;
    max-width: 180px;
    min-width: 180px;
    height: auto;
    max-height: 80px;
    display: block;
    object-fit: contain;
    margin: 0 auto;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background-color: var(--sidebar-hover);
    color: #fff;
}

.sidebar-link.active {
    background-color: var(--sidebar-hover);
    border-left-color: var(--sidebar-active);
    color: #fff;
}

.sidebar-link i {
    font-size: 1.1rem;
    width: 20px;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-copyright {
    padding: 0.75rem 1.25rem;
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-copyright small {
    font-size: 0.75rem;
    opacity: 0.7;
}

.user-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-info i {
    font-size: 1.5rem;
}

.user-details {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 500;
}

.theme-toggle, .logout-btn {
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
    font-size: 1.1rem;
}

.theme-toggle:hover, .logout-btn:hover {
    background-color: var(--sidebar-hover);
    color: #fff;
}

/* Main Content Area */
.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 2rem;
    background-color: var(--bg-secondary);
    min-height: 100vh;
    transition: all 0.3s ease;
}

/* Cards */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    box-shadow: var(--card-shadow);
    margin-bottom: 1.5rem;
    transition: all 0.3s ease;
}

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

.card-header {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-weight: 600;
    padding: 1rem 1.5rem;
    border-radius: 0.75rem 0.75rem 0 0;
}

.card-body {
    padding: 1.5rem;
    background-color: var(--card-bg);
    color: var(--text-primary);
}

/* Table Container for Responsive Scroll */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

/* Tables - COMPLETE DARK MODE FIX */
.table {
    background-color: var(--table-bg) !important;
    color: var(--text-primary) !important;
    border-color: var(--table-border) !important;
    margin-bottom: 0;
    min-width: 100%;
    white-space: nowrap;
}

.table thead th {
    background-color: var(--table-header-bg) !important;
    color: var(--text-primary) !important;
    border-color: var(--table-border) !important;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    padding: 0.75rem 1rem;
}

.table tbody tr {
    background-color: var(--table-bg) !important;
    border-color: var(--table-border) !important;
    transition: background-color 0.2s ease;
}

.table tbody tr:hover {
    background-color: var(--table-hover) !important;
}

.table tbody td {
    background-color: transparent !important;
    color: var(--text-primary) !important;
    border-color: var(--table-border) !important;
    padding: 0.875rem 1rem;
    vertical-align: middle;
}

.table-striped tbody tr:nth-of-type(odd) {
    background-color: var(--table-bg) !important;
}

.table-striped tbody tr:nth-of-type(even) {
    background-color: var(--bg-secondary) !important;
}

/* Forms */
.form-control, .form-select {
    background-color: var(--input-bg) !important;
    border-color: var(--input-border) !important;
    color: var(--text-primary) !important;
    border-radius: 0.5rem;
    padding: 0.625rem 0.875rem;
    transition: all 0.2s ease;
}

.form-control:focus, .form-select:focus {
    background-color: var(--input-bg) !important;
    border-color: #0d6efd !important;
    color: var(--text-primary) !important;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.15) !important;
}

.form-label {
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.form-text {
    color: var(--text-secondary);
}

/* Buttons */
.btn {
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
}

/* Badges */
.badge {
    font-weight: 500;
    padding: 0.35rem 0.65rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    letter-spacing: 0.3px;
}

/* Alerts */
.alert {
    border: 1px solid transparent;
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
}

.alert-success {
    background-color: var(--bg-secondary);
    color: #198754;
    border-color: #198754;
}

.alert-danger {
    background-color: var(--bg-secondary);
    color: #dc3545;
    border-color: #dc3545;
}

.alert-warning {
    background-color: var(--bg-secondary);
    color: #ffc107;
    border-color: #ffc107;
}

.alert-info {
    background-color: var(--bg-secondary);
    color: #0dcaf0;
    border-color: #0dcaf0;
}

[data-theme="dark"] .alert-success {
    background-color: rgba(25, 135, 84, 0.1);
}

[data-theme="dark"] .alert-danger {
    background-color: rgba(220, 53, 69, 0.1);
}

[data-theme="dark"] .alert-warning {
    background-color: rgba(255, 193, 7, 0.1);
}

[data-theme="dark"] .alert-info {
    background-color: rgba(13, 202, 240, 0.1);
}

/* Dropdown */
.dropdown-menu {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow-hover);
    border-radius: 0.5rem;
}

.dropdown-item {
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.dropdown-item:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: 600;
}

h2 {
    margin-bottom: 1.5rem;
    font-size: 1.75rem;
}

h5 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.text-muted {
    color: var(--text-muted) !important;
}

small, .small {
    color: var(--text-secondary);
}

/* Code/Pre */
pre {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    padding: 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    max-height: 400px;
    overflow-y: auto;
}

/* Lists */
.list-group-item {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.list-group-item:hover {
    background-color: var(--bg-secondary);
}

/* Pagination */
.pagination .page-link {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.pagination .page-link:hover {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.pagination .page-item.active .page-link {
    background-color: #0d6efd;
    border-color: #0d6efd;
}

/* Modal */
.modal-content {
    background-color: var(--card-bg);
    border-color: var(--border-color);
}

.modal-header {
    border-bottom-color: var(--border-color);
    background-color: var(--bg-secondary);
}

.modal-body {
    background-color: var(--card-bg);
    color: var(--text-primary);
}

.modal-footer {
    border-top-color: var(--border-color);
    background-color: var(--bg-secondary);
}

.btn-close {
    filter: invert(0);
}

[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Dashboard Stats */
.stat-card {
    text-align: center;
    padding: 1.5rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0.5rem 0;
}

.stat-card .stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Server Info Cards */
.server-info-card {
    padding: 1rem;
    border-left: 4px solid #0d6efd;
    margin-bottom: 1rem;
}

.server-info-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.server-info-row:last-child {
    border-bottom: none;
}

.server-info-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.server-info-value {
    color: var(--text-primary);
}

hr {
    border-color: var(--border-color);
    opacity: 1;
}

/* Mobile Header Bar */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background-color: var(--sidebar-bg);
    z-index: 1100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    align-items: center;
    padding: 0 1rem;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    background-color: transparent;
    color: var(--sidebar-text);
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1100;
}

.mobile-menu-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 0.375rem;
}

.mobile-menu-toggle i {
    font-size: 1.5rem;
}

.mobile-header-title {
    flex: 1;
    text-align: center;
    color: var(--sidebar-text);
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0 1rem;
}

/* Mobile overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Responsive */
/* Desktop search input sizing */
.search-input-desktop {
    max-width: 400px;
    flex: 1;
}

/* Mobile collapsible filter icon - hidden on desktop */
.mobile-collapse-icon {
    display: none;
    transition: transform 0.3s ease;
}

.card-header[aria-expanded="true"] .mobile-collapse-icon {
    transform: rotate(180deg);
}

/* Desktop flex layout - keep horizontal */
@media (min-width: 993px) {
    .d-flex.gap-2 {
        flex-direction: row !important;
    }
    
    .d-flex.gap-2 > *,
    .d-flex.gap-2 .form-control,
    .d-flex.gap-2 .btn {
        width: auto !important;
        max-width: none !important;
    }
    
    .d-flex.gap-2 .search-input-desktop {
        max-width: 400px !important;
        width: auto !important;
    }
}

/* Smaller laptop screens (15.6 inch and below) */
@media (max-width: 1400px) {
    .sidebar {
        width: 220px;
    }
    
    .sidebar-logo {
        width: 150px !important;
        max-width: 150px !important;
        min-width: 150px !important;
    }
    
    .main-content {
        margin-left: 220px;
        padding: 1.5rem;
    }
    
    .card-body {
        padding: 1.25rem;
    }
    
    .table {
        font-size: 0.8125rem;
    }
    
    .table td, .table th {
        padding: 0.5rem 0.75rem;
    }
    
    /* Table responsive wrapper */
    .table-responsive {
        border: 1px solid var(--table-border);
        border-radius: 0.5rem;
    }
    
    /* Make action buttons more compact */
    .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.875rem;
    }
    
    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.8125rem;
    }
    
    /* Responsive form columns */
    .col-md-3, .col-md-4, .col-md-6 {
        margin-bottom: 0.75rem;
    }
    
    /* Server info rows more compact */
    .server-info-row {
        padding: 0.375rem 0;
    }
    
    .server-info-label {
        font-size: 0.8125rem;
    }
    
    .server-info-value {
        font-size: 0.875rem;
    }
    
    /* Compact headers */
    h2 {
        font-size: 1.5rem;
    }
    
    h5 {
        font-size: 1rem;
    }
}

/* Tablet and Mobile screens */
@media (max-width: 992px) {
    /* Prevent horizontal overflow on mobile */
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
        width: 100%;
    }
    
    /* Show mobile header */
    .mobile-header {
        display: flex;
    }
    
    /* Show hamburger menu */
    .mobile-menu-toggle {
        display: block;
    }
    
    .mobile-overlay {
        display: block;
    }
    
    /* Hide sidebar by default on mobile */
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        z-index: 1001;
        top: 0;
    }
    
    /* Show sidebar when active */
    .sidebar.active {
        transform: translateX(0);
    }
    
    /* Remove left margin from main content */
    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: 76px;
        max-width: 100vw;
        width: 100%;
        overflow-x: hidden;
    }
    
    /* Show full text in mobile sidebar */
    .sidebar-header span,
    .sidebar-link span,
    .user-details {
        display: flex;
    }
    
    /* Sidebar logo sizing for mobile */
    .sidebar-logo {
        width: 200px !important;
        max-width: 200px !important;
        min-width: 200px !important;
        height: auto !important;
        display: block;
        margin: 0 auto;
    }
    
    /* Dashboard cards - full width on mobile */
    .row > .col-md-3,
    .row > .col-md-4,
    .row > .col-md-6 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 1rem;
    }
    
    /* Adjust card spacing */
    .card-body {
        padding: 1rem;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Ensure cards don't overflow */
    .card {
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Reduce filter card padding on mobile */
    .card-body .row.g-3 {
        margin-bottom: 0;
    }
    
    .card-body .row.mt-3 {
        margin-top: 1rem !important;
    }
    
    /* Remove excessive spacing in forms */
    .card-body form {
        margin-bottom: 0;
    }
    
    /* Prevent excessive card height and whitespace */
    .card {
        min-height: auto !important;
        height: auto !important;
    }
    
    .card-body {
        min-height: auto !important;
        height: auto !important;
        padding-bottom: 1rem !important;
    }
    
    /* Remove excessive spacing after tables */
    .table-responsive {
        margin-bottom: 0 !important;
    }
    
    .card-body > .table-responsive:last-child,
    .card-body > .table:last-child,
    .card-body > *:last-child {
        margin-bottom: 0 !important;
    }
    
    /* Remove spacing from rows in cards */
    .card-body > .row:last-child {
        margin-bottom: 0 !important;
    }
    
    /* Ensure no min-height on any Bootstrap components */
    .card .table-responsive,
    .card .row,
    .card .col {
        min-height: auto !important;
    }
    
    /* Better table scrolling - wrap ALL tables */
    .table {
        font-size: 0.875rem;
        min-width: 500px;
        width: 100%;
    }
    
    .table td, .table th {
        padding: 0.5rem;
        white-space: nowrap;
        font-size: 0.8125rem;
    }
    
    /* Ensure tables without .table-responsive wrapper still scroll */
    .card-body > .table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        max-width: 100%;
    }
    
    /* Table responsive wrapper */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border: 1px solid var(--table-border);
        border-radius: 0.5rem;
        width: 100%;
        max-width: 100%;
    }
    
    /* Touch-friendly buttons - minimum 44px tap target */
    .btn {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    .btn-sm {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
        min-height: 38px;
    }
    
    /* Stack form controls on mobile ONLY */
    .d-flex.gap-2 {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    .d-flex.gap-2 > *,
    .d-flex.gap-2 .form-control,
    .d-flex.gap-2 .btn {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
    
    /* Mobile search input - full width */
    .d-flex.gap-2 .search-input-desktop {
        max-width: 100% !important;
        width: 100% !important;
    }
    
    /* Show collapse icon on mobile */
    .mobile-collapse-icon {
        display: inline-block !important;
    }
    
    /* Bulk actions toolbar - wrap buttons */
    .col-auto {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    .col-auto .btn,
    .col-auto .form-select {
        margin-bottom: 0.5rem;
        margin-right: 0.5rem;
    }
    
    /* Stack columns on mobile */
    .row > [class*='col-'] {
        margin-bottom: 0.75rem;
    }
    
    /* Reduce header sizes */
    h1 {
        font-size: 1.75rem;
    }
    
    h2 {
        font-size: 1.5rem;
        word-break: break-word;
    }
    
    h3 {
        font-size: 1.25rem;
    }
    
    h5.card-title {
        font-size: 1rem;
    }
    
    /* Form inputs touch-friendly */
    .form-control, .form-select {
        font-size: 16px;
        min-height: 44px;
        padding: 0.625rem 0.75rem;
    }
    
    /* Search input - shorter placeholder */
    .form-control::placeholder {
        font-size: 0.8125rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    /* Better modal sizing */
    .modal-dialog {
        margin: 0.5rem;
    }
    
    /* Compact pagination */
    .pagination {
        font-size: 0.875rem;
    }
    
    .page-link {
        padding: 0.5rem 0.75rem;
    }
    
    /* Server info responsive */
    .server-info-row {
        flex-direction: column;
        gap: 0.25rem;
        padding: 0.5rem 0;
    }
    
    .server-info-label {
        font-weight: 600;
        font-size: 0.75rem;
    }
    
    .server-info-value {
        font-size: 0.875rem;
    }
}

/* Small phone screens */
@media (max-width: 576px) {
    .main-content {
        padding: 0.75rem;
        padding-top: 76px;
    }
    
    .card {
        margin-bottom: 1rem;
        border-radius: 0.5rem;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    .card-header {
        padding: 0.75rem;
        font-size: 1rem;
    }
    
    /* Full width buttons on very small screens */
    .btn-group {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .btn-group .btn {
        width: 100%;
    }
    
    /* Stack action buttons */
    .d-flex.gap-2 {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .d-flex.gap-2 .btn {
        width: 100%;
    }
    
    /* Smaller table font */
    .table {
        font-size: 0.8125rem;
    }
    
    /* Reduce padding everywhere */
    h1 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }
    
    h2 {
        font-size: 1.25rem;
        margin-bottom: 0.75rem;
    }
    
    /* Compact badges */
    .badge {
        font-size: 0.75rem;
        padding: 0.35em 0.6em;
    }
    
    /* Better form layout */
    .row.g-3 {
        --bs-gutter-x: 0.5rem;
        --bs-gutter-y: 0.5rem;
    }
    
    /* Prevent horizontal overflow */
    .card, .card-body, .row {
        overflow-x: hidden;
    }
    
    /* Adjust sidebar for very small screens */
    .sidebar {
        width: 85%;
        max-width: 300px;
    }
    
    .sidebar-logo {
        width: 140px !important;
        max-width: 140px !important;
        min-width: 140px !important;
    }
}

/* Login Page - Full Width */
body:not(:has(.layout-wrapper)) {
    background-color: var(--bg-secondary);
}
