/* ===== CSS VARIABLES ===== */
:root {
    --bg:           #0a0f1e;
    --bg-secondary: #111827;
    --sidebar:      #0d1117;
    --card:         #161d2e;
    --card-hover:   #1c2539;
    --border:       #1e293b;
    --border-light: #253047;
    --accent:       #3b82f6;
    --accent-hover: #2563eb;
    --success:      #22c55e;
    --danger:       #ef4444;
    --warning:      #f59e0b;
    --purple:       #a855f7;
    --text:         #e2e8f0;
    --muted:        #64748b;
    --muted-light:  #94a3b8;
    --radius:       10px;
    --sidebar-w:    240px;
    --sidebar-collapsed: 64px;
    --header-h:     68px;
    --card-shadow:  none;
    --theme-transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

/* ===== LIGHT MODE THEME ===== */
[data-theme="light"] {
    --bg:           #eef1f8;
    --bg-secondary: #ffffff;
    --sidebar:      #ffffff;
    --card:         #ffffff;
    --card-hover:   #f4f7ff;
    --border:       #e3e9f4;
    --border-light: #cdd6ea;
    --text:         #1a2138;
    --muted:        #8994a6;
    --muted-light:  #5e6e87;
    --card-shadow:  0 1px 3px rgba(99,115,165,0.10), 0 6px 24px rgba(99,115,165,0.07);
}
[data-theme="light"] .table tbody tr:hover td {
    background: rgba(59,130,246,0.04) !important;
}
[data-theme="light"] .loading-overlay {
    background: rgba(238,241,248,0.78);
}
[data-theme="light"] .modal-overlay {
    background: rgba(26,33,56,0.55);
}
[data-theme="light"] .sidebar {
    box-shadow: 2px 0 12px rgba(99,115,165,0.12);
}
[data-theme="light"] .topbar {
    box-shadow: 0 1px 6px rgba(99,115,165,0.09);
}
[data-theme="light"] .nav-item:hover {
    background: #eef1f8;
    color: var(--text);
}
[data-theme="light"] .nav-item.active {
    background: #eef4ff;
    color: var(--accent);
}
[data-theme="light"] .token-display {
    background: #f4f7ff;
}
[data-theme="light"] .toast {
    box-shadow: 0 4px 24px rgba(99,115,165,0.18);
}
[data-theme="light"] .btn-ghost {
    background: #eef1f8;
    border-color: var(--border);
}
[data-theme="light"] .btn-ghost:hover {
    background: var(--border);
    color: var(--text);
}
[data-theme="light"] .form-input,
[data-theme="light"] .form-select,
[data-theme="light"] .form-textarea {
    background: #f8faff;
    color: var(--text);
}
[data-theme="light"] .form-input::placeholder,
[data-theme="light"] .form-textarea::placeholder { color: var(--muted); }
[data-theme="light"] .modal { box-shadow: 0 8px 40px rgba(99,115,165,0.18); }
[data-theme="light"] body { color-scheme: light; }

/* ===== RESET ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
    transition: var(--theme-transition);
}

/* ===== LAYOUT ===== */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: width 0.25s ease;
    overflow: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    height: var(--header-h);
    flex-shrink: 0;
    transition: var(--theme-transition);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-logo img {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    flex-shrink: 0;
    object-fit: contain;
}

.logo-icon {
    font-size: 22px;
    color: var(--accent);
    flex-shrink: 0;
}

.logo-text {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}

.sidebar-toggle:hover {
    color: var(--text);
    background: var(--border);
}

/* ===== NAV ===== */
.sidebar-nav {
    flex: 1;
    padding: 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--muted-light);
    transition: all 0.15s ease;
    white-space: nowrap;
    position: relative;
}

.nav-item:hover {
    background: var(--border);
    color: var(--text);
}

.nav-item.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--accent);
    font-weight: 500;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.nav-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
}

.nav-label {
    font-size: 13.5px;
    transition: opacity 0.2s;
}

/* Collapsed sidebar labels */
.sidebar.collapsed .nav-label,
.sidebar.collapsed .logo-text,
.sidebar.collapsed .user-details {
    opacity: 0;
    pointer-events: none;
    width: 0;
}

/* ===== SIDEBAR FOOTER ===== */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    transition: justify-content 0.2s;
}

/* When sidebar is collapsed: center the logout button */
.sidebar.collapsed .sidebar-footer {
    justify-content: center;
    padding: 16px 8px;
}
.sidebar.collapsed .user-info { display: none; }

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    min-width: 0;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.user-details {
    overflow: hidden;
    transition: opacity 0.2s;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    transition: all 0.15s;
    flex-shrink: 0;
}

.logout-btn:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    transition: margin-left 0.25s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-content.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed);
}

/* ===== PAGE HEADER (inside content-area) ===== */
.page-header {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.page-header .page-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.4px;
}

.page-header .page-subtitle {
    font-size: 13px;
    color: var(--muted);
    margin-top: 3px;
}

/* ===== TOPBAR (now controls-only, no page title) ===== */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    min-height: var(--header-h);
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 50;
    flex-shrink: 0;
    gap: 12px;
    transition: var(--theme-transition);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Topbar brand: ONLY shown on mobile when sidebar is off-screen */
.topbar-brand {
    display: none;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}
.topbar-brand img {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    object-fit: contain;
}
/* Desktop collapsed: brand stays hidden (sidebar icon-only is still visible) */
.main-content.sidebar-collapsed .topbar-brand { display: none; }
/* Mobile only: sidebar slides off-screen, so show brand in topbar */
@media (max-width: 767px) {
    .main-content .topbar-brand { display: flex; }
    .main-content.sidebar-collapsed .topbar-brand { display: flex; }
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.page-subtitle {
    font-size: 13px;
    color: var(--muted);
    margin-top: 2px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--muted-light);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.6; }
}

/* ===== CONTENT AREA ===== */
.content-area {
    padding: 28px;
    flex: 1;
}

/* ===== CARD ===== */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--card-shadow);
    transition: var(--theme-transition);
}

.card:last-child {
    margin-bottom: 0;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.card-subtitle {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

/* ===== GRID SYSTEM ===== */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ===== STAT CARD ===== */
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: var(--card-shadow);
    transition: var(--theme-transition);
}

.stat-card:hover {
    border-color: var(--border-light);
    background: var(--card-hover);
}

.stat-label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.stat-meta {
    font-size: 12px;
    color: var(--muted);
}

/* ===== BADGES ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.badge-success  { background: rgba(34,197,94,0.15);  color: var(--success); }
.badge-danger   { background: rgba(239,68,68,0.15);  color: var(--danger); }
.badge-warning  { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-info     { background: rgba(59,130,246,0.15); color: var(--accent); }
.badge-purple   { background: rgba(168,85,247,0.15); color: var(--purple); }
.badge-neutral  { background: var(--border); color: var(--muted-light); }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary   { background: var(--accent); color: white; }
.btn-primary:hover  { background: var(--accent-hover); }
.btn-danger    { background: var(--danger); color: white; }
.btn-danger:hover   { opacity: 0.85; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--border-light); }
.btn-ghost     { background: transparent; color: var(--muted-light); border: 1px solid var(--border); }
.btn-ghost:hover    { color: var(--text); border-color: var(--border-light); }
.btn-success   { background: var(--success); color: white; }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* ===== LOADER ===== */
.btn .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: none;
}

.btn.loading .spinner { display: block; }
.btn.loading .btn-label { opacity: 0.7; }

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted-light);
    margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    transition: border-color 0.15s;
    outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.6;
}

.form-hint {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

.form-error {
    font-size: 11px;
    color: var(--danger);
    margin-top: 4px;
}

/* ===== TABLE ===== */
.table-wrapper {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    border-radius: var(--radius);
}

/* Styled scrollbar for table wrapper */
.table-wrapper::-webkit-scrollbar {
    height: 5px;
}
.table-wrapper::-webkit-scrollbar-track {
    background: var(--border);
    border-radius: 3px;
}
.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}
.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

.table tbody tr:hover td {
    background: rgba(255,255,255,0.02);
}

.table-empty {
    text-align: center;
    color: var(--muted);
    padding: 40px 20px !important;
    font-style: italic;
}

/* ===== PROGRESS BAR ===== */
.progress {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.progress-bar.success { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger  { background: var(--danger); }
.progress-bar.info    { background: var(--accent); }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 90%;
    max-width: 480px;
    padding: 28px;
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(-20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-title {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 4px;
    transition: color 0.15s;
}

.modal-close:hover { color: var(--text); }

/* ===== TOAST ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 280px;
    max-width: 360px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    animation: toastIn 0.3s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error   { border-left: 3px solid var(--danger); }
.toast.toast-info    { border-left: 3px solid var(--accent); }

.toast-icon { font-size: 16px; flex-shrink: 0; padding-top: 1px; }
.toast-body { flex: 1; }
.toast-title { font-size: 13px; font-weight: 600; }
.toast-message { font-size: 12px; color: var(--muted-light); margin-top: 2px; }

/* ===== LOGIN PAGE ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 36px;
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo .logo-icon {
    font-size: 36px;
    display: block;
    margin-bottom: 10px;
}

.login-logo h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.login-logo p {
    font-size: 13px;
    color: var(--muted);
    margin-top: 5px;
}

/* ===== TOKEN PAGE ===== */
.token-display {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 11px;
    word-break: break-all;
    color: var(--muted-light);
    background: var(--bg);
    padding: 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    max-height: 100px;
    overflow: hidden;
    position: relative;
}

.token-display::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(transparent, var(--bg));
}

/* ===== SERVER MONITORING ===== */
.metric-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--card-shadow);
    transition: var(--theme-transition);
}

.metric-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -1px;
}

.metric-unit {
    font-size: 14px;
    font-weight: 400;
    color: var(--muted);
    margin-left: 2px;
}

.metric-bar-wrapper {
    margin-top: 12px;
}

/* ===== PROCESS TABLE ===== */
.process-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
}

.process-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.process-dot.online  { background: var(--success); }
.process-dot.stopped { background: var(--danger); }
.process-dot.error   { background: var(--warning); }

/* ===== DATATABLES OVERRIDES ===== */
/* Match DataTables chrome to dashboard theme */
div.dataTables_wrapper {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 13px;
    color: var(--text);
}
div.dataTables_wrapper div.dataTables_length,
div.dataTables_wrapper div.dataTables_filter,
div.dataTables_wrapper div.dataTables_info,
div.dataTables_wrapper div.dataTables_paginate {
    padding: 10px 0;
    color: var(--muted-light);
}
div.dataTables_wrapper div.dataTables_length select,
div.dataTables_wrapper div.dataTables_filter input {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 5px 10px;
    font-family: inherit;
    font-size: 12px;
    outline: none;
    transition: border-color 0.15s;
}
div.dataTables_wrapper div.dataTables_length select:focus,
div.dataTables_wrapper div.dataTables_filter input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
div.dataTables_wrapper div.dataTables_filter {
    text-align: right;
}
div.dataTables_wrapper div.dataTables_length label,
div.dataTables_wrapper div.dataTables_filter label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}
div.dataTables_wrapper div.dataTables_paginate .paginate_button {
    padding: 4px 10px;
    border-radius: 6px;
    margin: 0 2px;
    cursor: pointer;
    font-size: 12px;
    border: 1px solid transparent;
    color: var(--muted-light) !important;
    background: transparent;
    transition: all 0.15s;
}
div.dataTables_wrapper div.dataTables_paginate .paginate_button:hover {
    background: var(--border) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}
div.dataTables_wrapper div.dataTables_paginate .paginate_button.current,
div.dataTables_wrapper div.dataTables_paginate .paginate_button.current:hover {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: #fff !important;
}
div.dataTables_wrapper div.dataTables_paginate .paginate_button.disabled,
div.dataTables_wrapper div.dataTables_paginate .paginate_button.disabled:hover {
    opacity: 0.35;
    cursor: default;
    color: var(--muted) !important;
}
div.dataTables_wrapper div.dataTables_info {
    padding-top: 12px;
}
table.dataTable thead th {
    border-bottom: 1px solid var(--border) !important;
    background: var(--bg-secondary) !important;
    color: var(--muted) !important;
}
table.dataTable thead th.sorting::before,
table.dataTable thead th.sorting::after,
table.dataTable thead th.sorting_asc::before,
table.dataTable thead th.sorting_desc::after {
    color: var(--muted) !important;
}
table.dataTable thead th.sorting_asc::before,
table.dataTable thead th.sorting_desc::after {
    color: var(--accent) !important;
}
table.dataTable.no-footer {
    border-bottom: none !important;
}
div.dataTables_wrapper div.dataTables_length,
div.dataTables_wrapper div.dataTables_filter {
    display: flex;
    align-items: center;
}

/* ===== FILTER BAR ===== */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-bar .form-select,
.filter-bar .form-input {
    width: auto;
    min-width: 160px;
}

/* ===== THEME TOGGLE ===== */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 7px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 5px 11px 5px 9px;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.2s, background 0.2s;
}
.theme-toggle:hover {
    border-color: var(--border-light);
    background: var(--card-hover);
}
.ti-moon, .ti-sun {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    transition: color 0.25s, opacity 0.25s;
}
/* Dark mode: moon active */
.ti-moon { color: var(--accent); opacity: 1; }
.ti-sun  { color: var(--muted);  opacity: 0.4; }
/* Light mode: sun active */
[data-theme="light"] .ti-moon { color: var(--muted); opacity: 0.4; }
[data-theme="light"] .ti-sun  { color: var(--warning); opacity: 1; }

.toggle-track {
    width: 36px;
    height: 20px;
    background: var(--border-light);
    border-radius: 10px;
    position: relative;
    flex-shrink: 0;
    transition: background 0.3s;
}
[data-theme="light"] .toggle-track { background: var(--accent); }

.toggle-thumb {
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
[data-theme="light"] .toggle-thumb { transform: translateX(16px); }

/* ===== MOBILE HAMBURGER ===== */
.mobile-hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--muted-light);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    margin-right: 2px;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}
.mobile-hamburger:hover { color: var(--text); background: var(--border); }

/* ===== SIDEBAR BACKDROP ===== */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.sidebar-backdrop.show {
    display: block;
    animation: backdropFadeIn 0.2s ease;
}
@keyframes backdropFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===== RESPONSIVE ===== */

/* Large tablet (1024px-1280px) */
@media (max-width: 1280px) and (min-width: 1025px) {
    :root { --sidebar-w: 220px; }
}

/* Tablet (768px-1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    :root {
        --sidebar-w: 200px;
    }
    .grid-3  { grid-template-columns: repeat(2, 1fr); }
    .grid-4  { grid-template-columns: repeat(2, 1fr); }
    .content-area { padding: 20px; }
    .topbar  { padding: 0 16px; }
    .filter-bar .form-select { min-width: 130px; }
    .topbar-brand { display: none !important; } /* brand shown only on mobile/collapsed see below */
    .main-content.sidebar-collapsed .topbar-brand { display: flex !important; }
}

/* Mobile (< 768px) */
@media (max-width: 767px) {
    /* Sidebar: hidden off-screen, slides in as overlay */
    .sidebar {
        transform: translateX(-100%);
        width: 260px !important;
        z-index: 200;
        transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    }
    .sidebar.collapsed { width: 260px !important; }
    .sidebar.mobile-open { transform: translateX(0); }
    /* Always show labels when mobile sidebar is open */
    .sidebar.mobile-open .nav-label,
    .sidebar.mobile-open .logo-text,
    .sidebar.mobile-open .user-details {
        opacity: 1 !important;
        width: auto !important;
        pointer-events: auto !important;
    }

    /* Main: full width, no offset */
    .main-content,
    .main-content.sidebar-collapsed {
        margin-left: 0 !important;
        min-width: 0;       /* prevent flex item from expanding beyond viewport */
        overflow-x: hidden; /* clip any rogue overflow at the page level */
    }

    /* Hamburger toggle: visible on mobile (it's the only way to open the sidebar) */
    .sidebar-toggle { display: flex !important; }

    /* Topbar */
    .topbar { padding: 0 14px; gap: 8px; }
    .page-subtitle { display: none; }
    .status-text { display: none; }
    .status-indicator { padding: 6px; border-radius: 50%; }

    /* Content */
    .content-area { padding: 14px; }
    .page-header { margin-bottom: 18px; padding-bottom: 14px; }
    .page-header .page-title { font-size: 18px; }

    /* All grids → single column */
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; }

    /* Filter bar: vertical stack */
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .form-select,
    .filter-bar .form-input { width: 100% !important; min-width: 0; }

    /* Card: prevent content from breaking card boundaries */
    .card { overflow: hidden; }
    /* Card header: wrap buttons on narrow screens */
    .card-header { flex-wrap: wrap; gap: 8px; }

    /* Tables: horizontal scroll */
    .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table { min-width: 540px; }
    /* DataTables wrapper: horizontal scroll for table content only */
    div.dataTables_wrapper { overflow-x: visible; }
    div.dataTables_wrapper div.dataTables_scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* DataTables — keep length + filter on ONE row, side by side */
    div.dataTables_wrapper div.dataTables_length {
        float: left !important;
        flex-direction: row;
        align-items: center;
        gap: 6px;
    }
    div.dataTables_wrapper div.dataTables_filter {
        float: right !important;
        flex-direction: row;
        align-items: center;
        text-align: right;
        gap: 6px;
    }
    div.dataTables_wrapper div.dataTables_filter input { max-width: 110px; }
    /* clearfix so info/paginate row renders below the floated controls */
    div.dataTables_wrapper div.dataTables_info,
    div.dataTables_wrapper div.dataTables_paginate { clear: both; }

    /* Toasts */
    .toast-container { left: 12px; right: 12px; bottom: 12px; }
    .toast { min-width: 0; max-width: 100%; }

    /* Modal */
    .modal { width: 95%; padding: 20px; }

    /* Stat cards */
    .stat-value { font-size: 20px; }
    .metric-value { font-size: 22px; }

    /* Login page: add horizontal padding so card doesn't touch screen edges */
    .login-page { padding: 24px 16px; align-items: flex-start; padding-top: 60px; }
    .login-card { border-radius: 14px; padding: 28px 20px; margin: auto;}

    /* Sidebar footer: push above browser bottom navigation bar */
    .sidebar-footer { padding-bottom: max(20px, env(safe-area-inset-bottom, 20px)); }
}

/* ===== UTILS ===== */
.grid-top   { align-items: start; }

.text-muted   { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-accent  { color: var(--accent); }
.text-sm      { font-size: 12px; }
.text-xs      { font-size: 11px; }

.text-center { text-align: center !important; }

.mt-auto { margin-top: auto; }
.d-flex  { display: flex; }
.align-center { align-items: center; }
.gap-8   { gap: 8px; }
.gap-12  { gap: 12px; }

.loading-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(10, 15, 30, 0.7);
    border-radius: var(--radius);
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.loading-overlay.show {
    display: flex;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
