/* 1. Imports */
@import url('/assets/tokens.css');
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

/* 2. CSS Custom Properties (:root) */
:root {
    /* Palette */
    --bg: #0a0a0f;
    --surface: #111827;
    --surface-hover: #1e293b;
    --text-primary: #f0f0f5;
    --text-secondary: #8b95a5;
    --text-muted: #505868;
    
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-subtle: rgba(59, 130, 246, 0.12);
    
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);

    /* Spacing & Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-8: 48px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
    --ring-accent: 0 0 0 3px rgba(59, 130, 246, 0.15);

    /* Transitions */
    --transition-base: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

    /* Legacy aliases — backward compat for pages using old token names */
    --primary: var(--accent);
    --accent-light: var(--accent-subtle);
    --text: var(--text-primary);
    --muted: var(--text-muted);
    --border-color: var(--border);
    --border-strong: var(--border-hover);
    --bg-main: var(--bg);
    --font-header: var(--font-sans, 'Inter', sans-serif);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --neon-cyan-dim: rgba(59, 130, 246, 0.2);
}

/* 3. Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    background-color: var(--bg);
    background-image: radial-gradient(ellipse at top, #111827 0%, #0a0a0f 70%);
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 4. Typography */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: var(--space-4);
}

p {
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: var(--transition-base);
}

a:hover {
    color: var(--accent-hover);
}

code, pre {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

/* 5. Layout */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-4);
}

.page-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    padding: var(--space-8) 0;
}

/* 6. Navigation */
.navbar, .public-nav {
    background: rgba(17, 24, 39, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: var(--space-4) 0;
    position: sticky;
    top: 0;
    z-index: 50;
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.nav-links {
    display: flex;
    gap: var(--space-5);
    align-items: center;
}

.nav-link {
    color: var(--text-secondary);
    font-weight: 500;
}

.nav-link:hover, .nav-link.active {
    color: var(--text-primary);
}

/* 7. Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-family: inherit;
    text-align: center;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition-base);
    background: transparent;
    color: var(--text-primary);
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--ring-accent);
}

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

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: var(--ring-accent);
}

.btn-secondary {
    background: var(--surface-hover);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
    border-color: var(--border-hover);
    background: rgba(255,255,255,0.05);
}

.btn-outline {
    border-color: var(--border);
    color: var(--text-primary);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

/* 8. Forms & Inputs */
.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    margin-bottom: var(--space-2);
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    transition: var(--transition-base);
}

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

.form-control::placeholder {
    color: var(--text-muted);
}

/* 9. Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    transition: var(--transition-base);
}

.card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
}

/* 10. Challenge Grid & Cards */
.challenge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-5);
}

.challenge-card {
    display: flex;
    flex-direction: column;
}

.challenge-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
}

.challenge-title {
    font-size: 1.125rem;
    margin: 0;
}

.challenge-points {
    font-weight: 600;
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
}

/* 11. Auth Pages */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.auth-card {
    width: 100%;
    max-width: 400px;
}

.auth-header {
    text-align: center;
    margin-bottom: var(--space-6);
}

/* 12. Scoreboard */
.scoreboard-container {
    margin-top: var(--space-6);
}

/* 13. Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.stat-card {
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
    font-family: 'JetBrains Mono', monospace;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* 14. Feed/Post */
.feed-container {
    max-width: 800px;
    margin: 0 auto;
}

.feed-item {
    margin-bottom: var(--space-4);
}

/* 15. Tables */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th, .table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
    background: rgba(255,255,255,0.02);
}

.table tbody tr {
    transition: var(--transition-base);
}

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

/* 16. Profile Page */
.profile-header {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    margin-bottom: var(--space-6);
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-sm);
    background: var(--surface-hover);
    border: 1px solid var(--border);
}

/* 17. Admin Page */
.admin-toolbar {
    display: flex;
    justify-content: space-between;
    margin-bottom: var(--space-5);
}

/* 18. Alerts */
.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-4);
    border: 1px solid transparent;
}

.alert-success {
    background: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.alert-danger {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

/* 19. Badges & Tags */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--surface-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.badge-accent {
    background: var(--accent-subtle);
    color: var(--accent-hover);
    border-color: rgba(59, 130, 246, 0.2);
}

/* 20. Utility Classes */
.text-center { text-align: center; }
.mt-4 { margin-top: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none; }

/* 21. Skeleton/Loading States */
.skeleton {
    background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hover) 50%, var(--surface) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* 22. Responsive Breakpoints */
@media (max-width: 768px) {
    .challenge-grid {
        grid-template-columns: 1fr;
    }

    .nav-links {
        display: none;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

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

/* ───────────────────────────────────────────────────────────
   Extended Component Library
   (Backward-compatible selectors for existing PHP pages)
   ─────────────────────────────────────────────────────────── */

/* Button Sizes */
.btn-sm {
    padding: 6px 12px;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 10px 20px;
    font-size: 1rem;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

/* Button gap helper */
.btn i,
.btn svg {
    margin-right: 6px;
}

/* Form compat — legacy selectors */
.form-input,
.auth-input,
input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    transition: var(--transition-base);
}

.form-input:focus,
.auth-input:focus,
input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring-accent);
}

.form-input::placeholder,
input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

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

.form-actions {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-5);
}

/* Auth page compat */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
}

.auth-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.auth-logo p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.auth-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-header h2 { font-size: 1.25rem; margin-bottom: 0.25rem; }
.auth-header p { font-size: 0.875rem; }

.auth-footer {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.auth-footer a { font-weight: 500; }

/* Challenge card extended */
.challenge-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    cursor: pointer;
    transition: var(--transition-base);
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.challenge-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
    color: inherit;
}

.challenge-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.challenge-category {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
    background: var(--accent-subtle);
    padding: 2px 8px;
    border-radius: var(--radius-full, 9999px);
}

.challenge-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.challenge-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.solved-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--success);
    font-weight: 500;
}

.challenge-progress {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* Scoreboard extended */
.scoreboard-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.scoreboard-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border);
}

.scoreboard-table td {
    padding: 12px 16px;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

.scoreboard-table tr:last-child td { border-bottom: none; }
.scoreboard-table tr:hover td { background: rgba(255, 255, 255, 0.02); }

.scoreboard-rank {
    font-weight: 700;
    width: 3rem;
}

.scoreboard-rank.top-3 { color: var(--accent); }

.scoreboard-username {
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.scoreboard-you-badge {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-full, 9999px);
}

.scoreboard-score {
    font-weight: 600;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono, monospace);
}

/* Stat card compat */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    transition: var(--transition-base);
}

.stat-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
}

.stat-card-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}

/* Feed compat */
.feed-post {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    transition: var(--transition-base);
}

.feed-post:hover { box-shadow: var(--shadow-md); }

.feed-post-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.feed-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-subtle);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}

.feed-author { font-weight: 600; font-size: 0.875rem; }
.feed-time { font-size: 0.8125rem; color: var(--text-muted); }
.feed-content { font-size: 0.9375rem; color: var(--text-secondary); line-height: 1.6; }

.feed-actions {
    display: flex;
    gap: 1.5rem;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.feed-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition-base);
}

.feed-action:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
}

/* Profile page extended */
.profile-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.profile-head {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 3rem 2rem;
    margin-bottom: 2rem;
}

.profile-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--accent-subtle);
    border: 3px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    margin-bottom: 1.5rem;
    color: var(--accent);
}

.profile-name {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    letter-spacing: -0.03em;
}

.profile-sub {
    font-size: 0.875rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    margin-bottom: 1rem;
}

.profile-bio {
    color: var(--text-secondary);
    max-width: 600px;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.profile-social {
    display: flex;
    gap: 1rem;
}

.badge-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 1rem;
}

/* Admin page extended */
.admin-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.admin-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 2rem;
    letter-spacing: -0.03em;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.admin-card,
.admin-stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.admin-stat-grid,
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.admin-btn,
.tab-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    background: var(--surface-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    transition: var(--transition-base);
}

.admin-btn:hover,
.tab-btn:hover {
    background: var(--accent);
    color: #fff;
}

.admin-btn.active,
.tab-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.admin-input,
.admin-file-input {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    width: 100%;
    margin-bottom: 1rem;
    font-family: inherit;
    font-size: 0.875rem;
}

.admin-table,
.chall-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.8125rem;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

.admin-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

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

.tab-nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.admin-form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 1.5rem;
}

.admin-form-group label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
    letter-spacing: 0.02em;
}

.span-2 { grid-column: span 2; }

@media (max-width: 768px) {
    .span-2 { grid-column: span 1; }
}

.asc-num {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
}

.asc-label {
    font-size: 0.8125rem;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Role badges */
.role-badge {
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    border: 1px solid transparent;
}

.badge-admin { background: rgba(239, 68, 68, 0.1); color: var(--danger); border-color: rgba(239, 68, 68, 0.2); }
.badge-user { background: var(--accent-subtle); color: var(--accent); border-color: rgba(59, 130, 246, 0.2); }
.badge-banned { background: rgba(245, 158, 11, 0.1); color: var(--warning); border-color: rgba(245, 158, 11, 0.2); }

/* Notification items */
.notif-item {
    padding: 1rem;
    background: var(--surface);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
}

.notif-msg { color: var(--text-primary); margin-bottom: 4px; }
.notif-time { font-size: 0.8rem; color: var(--text-muted); }

/* Severity variants */
.sev-critical { border-left-color: var(--danger); background: rgba(239, 68, 68, 0.05); }
.sev-warning { border-left-color: var(--warning); background: rgba(245, 158, 11, 0.05); }
.sev-info { border-left-color: var(--accent); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state-icon { font-size: 2.5rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state-title { font-size: 1rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }

/* Grid utility */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

/* Node card compat */
.node-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: var(--transition-base);
}

.node-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
}

/* Misc compat */
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-right { text-align: right; }
.font-mono { font-family: 'JetBrains Mono', monospace; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-6 { margin-top: 1.5rem; }
.mb-6 { margin-bottom: 1.5rem; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.flex-col { flex-direction: column; }

/* Skip link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--accent);
    color: #fff;
    padding: 8px 16px;
    z-index: 100;
    border-radius: 0 0 var(--radius-sm) 0;
}

.skip-link:focus { top: 0; }

/* Wargame compat */
.campaign-card, .team-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
}

.progress-wrapper {
    background: var(--surface-hover);
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 12px;
}

.progress-bar {
    background: var(--accent);
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: right;
    font-family: 'JetBrains Mono', monospace;
}

.level-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    background: var(--surface);
    overflow: hidden;
}

.level-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.level-body { padding: 1rem; color: var(--text-secondary); }

.level-action {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.level-action input { flex: 1; }

.status-completed { color: var(--success); }
.status-current { color: var(--accent); }
.status-locked { color: var(--text-muted); }

/* Hero section compat */
.hero-section {
    text-align: center;
    margin-bottom: 3rem;
}

.hero-section h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 0.5rem;
}

.hero-section p {
    color: var(--text-muted);
    font-size: 1.05rem;
}

/* Ticket / chat / labs / achievements compat */
.ticket-container,
.achievements-container,
.chat-container,
.labs-hero {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.ticket-card,
.chart-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.row-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* Tooltip */
.tooltip { position: relative; }
.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: var(--text-primary);
    color: var(--bg);
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}
.tooltip:hover::after { opacity: 1; }

/* Neon text compat (subtle version) */
.neon-text-blue,
.neon-text-cyan {
    color: var(--accent);
}

/* Alert compat for dark mode */
.alert-info {
    background: rgba(6, 182, 212, 0.1);
    color: #06b6d4;
    border: 1px solid rgba(6, 182, 212, 0.2);
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-success {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.2);
}

/* Member list */
.member-list { list-style: none; padding: 0; margin: 1rem 0; }
.member-list li {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.member-list li:last-child { border-bottom: none; }

/* Score display */
.score {
    text-align: right;
    color: var(--accent);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-family: 'JetBrains Mono', monospace;
}

/* Stat num compat */
.stat-num {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    letter-spacing: -0.02em;
}


/* Fix Mobile Tables Overflow */
.table-wrapper, .sb-table-wrapper, .admin-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.sb-table, .admin-table, .scoreboard-table, .table {
    width: 100%;
    min-width: 600px; /* Force scrolling on small devices instead of squishing */
    border-collapse: collapse;
}

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

.sb-table th {
    background: rgba(255, 255, 255, 0.02);
    font-weight: 600;
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    /* Make sure all grids collapse gracefully on tablet/mobile */
    .sb-grid, .profile-grid, .admin-grid {
        display: grid;
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
}

.btn-danger {
    background: #ef4444;
    color: #ffffff;
    border: 1px solid #dc2626;
}
.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    border-color: #b91c1c;
}
.btn-del {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0 4px;
}
.btn-del:hover {
    color: #dc2626;
    transform: scale(1.1);
}
.alert:empty { display: none; }
.alert:not(.show) { display: none !important; }

/* MODAL / OVERLAY CSS */
.edit-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}
.edit-overlay.open {
    display: flex;
}
.edit-overlay-bg {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}
.edit-modal {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    padding: var(--space-6);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    z-index: 10000;
}

/* TABLE CONTROLS */
.table-controls {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}
.table-controls .search-input {
    flex-grow: 1;
    min-width: 200px;
}

/* FORM GRID */
.form-grid, .settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}
@media (max-width: 768px) {
    .form-grid, .settings-grid {
        grid-template-columns: 1fr;
    }
}

.form-wrapper-flex {
    display: flex;
    gap: var(--space-4);
    align-items: flex-end;
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}
.form-flex-child {
    flex-grow: 1;
}

.switch-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    margin-top: var(--space-2);
    padding: var(--space-2) 0;
}
.switch-row input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
    accent-color: var(--primary);
}
.sw-label {
    font-weight: 500;
    color: var(--text);
}

/* HEALTH SYSTEM */
.health-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}
.health-item {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--surface-hover);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--border);
    align-items: center;
}
.health-item.lvl-ok { border-left-color: var(--success); }
.health-item.lvl-warn { border-left-color: var(--warning); }
.health-item.lvl-error { border-left-color: var(--danger); }
.h-title {
    font-weight: bold;
    color: var(--text);
}
.h-detail {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: var(--space-1);
}

/* HINT TEXT */
.hint-text {
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: normal;
}

.notif-history-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: var(--space-4);
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding-bottom: var(--space-2);
}
.empty-solves {
    color: var(--muted);
    font-style: italic;
    text-align: center;
    padding: var(--space-4);
}

hr.divider {
    border: 0;
    height: 1px;
    background: var(--border);
    margin: var(--space-6) 0;
}

.table-empty-msg, .table-loading-msg {
    text-align: center;
    padding: var(--space-6) !important;
    color: var(--muted);
    font-style: italic;
}

.sev-danger { border-left-color: var(--danger); background: rgba(239, 68, 68, 0.05); }
.sev-success { border-left-color: var(--success); background: rgba(34, 197, 94, 0.05); }

.notif-loading-msg {
    text-align: center;
    padding: var(--space-6);
    color: var(--muted);
    font-style: italic;
}

.margin-top-8 { margin-top: 8px !important; }

.col-player { font-weight: 500; }
.col-challenge { font-weight: bold; color: var(--accent); }
.col-pts { text-align: right; color: var(--success); font-family: monospace; }
.col-time { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.col-rating { white-space: nowrap; }
.col-feedback { max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.first-blood-tag {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: bold;
    margin-left: 6px;
    vertical-align: middle;
}

.input-disabled {
    background: var(--surface-hover);
    color: var(--muted);
    cursor: not-allowed;
    border-color: var(--border);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.badge-category {
    background: rgba(168, 85, 247, 0.1);
    color: #c084fc;
    border-color: rgba(168, 85, 247, 0.2);
}

/* Fade in animation for tab panels */
@keyframes fadeInScale {
    0% { opacity: 0; transform: translateY(5px); }
    100% { opacity: 1; transform: translateY(0); }
}
.tab-panel.active {
    display: block;
    animation: fadeInScale 0.3s ease-out forwards;
}

/* Stat card hover effect */
.admin-stat-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.admin-stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.4);
}

.admin-file-input-full {
    width: 100%;
    padding: var(--space-3);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-hover);
    color: var(--text);
    cursor: pointer;
}

.textarea-large {
    min-height: 200px;
    resize: vertical;
}

.req {
    color: var(--danger);
    font-weight: bold;
    margin-left: 2px;
}

/* EasyMDE Dark Theme */
.editor-toolbar { border-color: var(--border) !important; background: var(--surface) !important; opacity: 1 !important;}
.editor-toolbar a { color: var(--text) !important; }
.editor-toolbar a.active, .editor-toolbar a:hover { background: var(--border-strong) !important; border-color: var(--border) !important;}
.CodeMirror { border-color: var(--border) !important; background: var(--bg) !important; color: var(--text) !important; font-family: monospace !important;}
.CodeMirror-cursor { border-left-color: var(--text) !important; }
.editor-statusbar { color: var(--muted) !important; }
.editor-preview { background: var(--bg) !important; color: var(--text) !important; }

.editor-toolbar.fullscreen,
.CodeMirror-fullscreen {
    z-index: 100000 !important;
}

/* ====== GLOBAL RESPONSIVE REFACTORING (Aug 29) ====== */

/* 1. Global Flex/Grid Container Fixes */
body {
    overflow-x: hidden; /* Prevent horizontal scroll on body */
    width: 100%;
}

.container, .main-wrapper, .admin-container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    box-sizing: border-box;
}

/* Ensure grids are responsive */
.admin-stat-grid, .badge-grid, .chall-grid, .posts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    width: 100%;
}

/* 2. Tables wrapping */
.table-wrapper, .table-responsive, table.admin-table, table.sb-table, table.chall-table {
    width: 100%;
    overflow-x: auto;
    display: block;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap; /* Prevent table content from squishing too much */
}

/* 3. Cards, Form, & Modal */
.admin-card {
    width: 100%;
    box-sizing: border-box;
    max-width: 100%;
}

.admin-input, .lc-input, input[type="text"], input[type="password"], input[type="email"], select, textarea { width: 100%; }

.admin-input, .lc-input, input, select, textarea, button, .btn {
    max-width: 100%;
    box-sizing: border-box;
}

/* Specific Modal Fix */
.modal-content, #edit-profile-modal .admin-card {
    width: 100%;
    max-width: 95%; /* Better padding on mobile */
    margin: 0 auto;
}

/* Fix navbar icon and text overlap on mobile */
@media (max-width: 480px) {
    .lc-nav-logo { font-size: 0.9rem !important; }
    
}

@media (max-width: 768px) {
    .admin-stat-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
    }
}
@media (max-width: 480px) {
    .btn, .lc-btn, .admin-btn { width: 100%; justify-content: center; margin-bottom: 8px; }
    .form-actions { flex-direction: column; }
}

/* ====== FEED LAYOUT (3-column responsive) ====== */
.feed-container {
    display: grid;
    grid-template-columns: 240px 1fr 240px;
    gap: 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
    align-items: start;
}

.feed-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.feed-sidebar .sidebar-title,
.feed-card h3 {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.stat-row:last-child { border-bottom: none; }
.stat-row .accent { color: var(--accent); font-weight: 700; }
.stat-row .cyan { color: var(--info, #06b6d4); font-weight: 700; }

.post-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.post-tag {
    font-size: 0.75rem;
    padding: 4px 10px;
    background: var(--accent-subtle);
    color: var(--accent);
    border-radius: var(--radius-full, 9999px);
    cursor: pointer;
}

.feed-post-form textarea,
.feed-post-form input[type="text"],
.feed-post-form select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
}

.feed-post-form textarea { min-height: 100px; resize: vertical; }

.feed-post-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

@media (max-width: 1024px) {
    .feed-container { grid-template-columns: 1fr; }
    .feed-sidebar { display: none; }
    .feed-container > aside:first-child { display: block; order: 2; }
    .feed-container > main { order: 1; }
}

/* ====== TEAMS PAGE ====== */
.team-container { max-width: 1000px; margin: 0 auto; }
.team-container h2 { color: var(--text-primary); }
.team-container h3 { color: var(--text-primary) !important; }
.team-container table { width: 100%; border-collapse: collapse; }
.team-container th, .team-container td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    color: var(--text-secondary);
}
.team-container th { color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; }
.team-container .score { text-align: right; color: var(--accent); font-family: monospace; font-weight: 700; }
.member-list { list-style: none; }
.member-list li {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    color: var(--text-primary);
}

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

/* ====== CTF MESSAGES (DM) — WhatsApp-style responsive ====== */
.ctf-chat-app {
    display: flex;
    gap: 1rem;
    height: calc(100vh - 140px);
    min-height: 500px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

.ctf-chat-sb {
    width: 300px;
    min-width: 260px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.ctf-chat-sb-hdr {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ctf-chat-sb-hdr h2 { margin: 0; font-size: 1.1rem; color: var(--accent); }

.ctf-convo-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    margin: 0;
    padding: 0;
}

.ctf-convo-item {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}

.ctf-convo-item:hover,
.ctf-convo-item.active { background: var(--accent-subtle); }

.ctf-convo-name { font-weight: 600; color: var(--text-primary); margin-bottom: 0.2rem; display: block; }
.ctf-convo-last { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ctf-chat-panel {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    position: relative;
}

.ctf-chat-hdr {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ctf-chat-hdr h2 { margin: 0; font-size: 1.1rem; color: var(--text-primary); }

.ctf-chat-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ctf-msg {
    max-width: 75%;
    padding: 0.65rem 0.9rem;
    border-radius: 12px;
    position: relative;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.ctf-msg-sent {
    background: var(--accent);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.ctf-msg-received {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.ctf-msg-time { font-size: 0.68rem; opacity: 0.7; margin-top: 4px; display: block; text-align: right; }

.ctf-chat-input {
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    background: var(--surface);
    flex-wrap: wrap;
    align-items: flex-end;
}

.ctf-chat-input textarea {
    flex: 1;
    min-width: 160px;
    padding: 0.65rem 0.875rem;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 20px;
    font-family: inherit;
    resize: none;
    min-height: 42px;
    max-height: 120px;
}

.ctf-chat-input .file-label {
    padding: 0.65rem 1rem;
    background: var(--surface-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
}

.ctf-drop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(59, 130, 246, 0.08);
    border: 2px dashed var(--accent);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
    border-radius: var(--radius-md);
    color: var(--accent);
    font-weight: 600;
}

.ctf-drop-overlay.show { display: flex; }

.ctf-chat-back { display: none; }

@media (max-width: 768px) {
    .ctf-chat-app {
        flex-direction: column;
        height: calc(100dvh - 100px);
        padding: 0.5rem;
        position: relative;
    }

    .ctf-chat-sb {
        width: 100%;
        min-width: 100%;
        flex: 1;
    }

    .ctf-chat-panel {
        display: none;
        position: absolute;
        inset: 0.5rem;
        z-index: 20;
    }

    .ctf-chat-app.chat-open .ctf-chat-sb { display: none; }
    .ctf-chat-app.chat-open .ctf-chat-panel { display: flex; }
    .ctf-chat-back { display: inline-flex !important; }
    .ctf-msg { max-width: 88%; }
}

/* Tickets page dark theme fix */
.ticket-card h2, .ticket-title, .form-group input,
.form-group textarea, .form-group select,
.ticket-list li, #dt-creator {
    color: var(--text-primary) !important;
}

.form-group input, .form-group textarea, .form-group select,
#filter-status {
    background: var(--bg) !important;
    border-color: var(--border) !important;
    color: var(--text-primary) !important;
}
