/* Import Local Fonts */
@import url('../fonts/fonts.css');

:root {
    /* Color Palette - Dark Mode Default */
    --bg-body: #0f172a;
    --bg-body-gradient: radial-gradient(at 0% 0%, rgba(56, 189, 248, 0.15) 0px, transparent 50%), 
                        radial-gradient(at 100% 0%, rgba(236, 72, 153, 0.15) 0px, transparent 50%), 
                        radial-gradient(at 100% 100%, rgba(14, 165, 233, 0.15) 0px, transparent 50%), 
                        radial-gradient(at 0% 100%, rgba(232, 121, 249, 0.15) 0px, transparent 50%);
    
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-card-hover: rgba(30, 41, 59, 0.85);
    --bg-input: rgba(15, 23, 42, 0.6);
    
    --border-color: rgba(148, 163, 184, 0.1);
    --border-color-hover: rgba(148, 163, 184, 0.2);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.5);
    
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.2);
    
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.2);
    
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-bg: rgba(239, 68, 68, 0.2);
    
    /* Spacing & Layout */
    --container-width: 1400px;
    --header-height: 70px;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 24px;
    
    /* Effects */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);
    
    --blur-sm: blur(8px);
    --blur-md: blur(12px);
    
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Font */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Monaco', 'Courier New', monospace;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    background-image: var(--bg-body-gradient);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

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

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

code, pre {
    font-family: var(--font-mono);
}

/* Layout */
.container {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 24px;
}

.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: var(--blur-md);
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-content {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-primary);
    text-decoration: none;
}

.logo-icon {
    font-size: 1.5rem;
}

.logo span:last-child {
    background: linear-gradient(to right, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Components: Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.875rem;
    transition: var(--transition);
    cursor: pointer;
    border: 1px solid transparent;
    gap: 0.5rem;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 0 25px rgba(37, 99, 235, 0.4);
}

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border-color: var(--border-color);
}

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

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.3);
    border-color: var(--danger);
    color: #fecaca;
}

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

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

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
}

.btn-icon {
    padding: 0.5rem;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border-color: var(--primary);
}

/* Components: Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    backdrop-filter: var(--blur-sm);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.card:hover {
    border-color: var(--border-color-hover);
    background: var(--bg-card-hover);
    box-shadow: var(--shadow-lg);
}

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

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Components: Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    backdrop-filter: var(--blur-sm);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: rgba(59, 130, 246, 0.3);
    box-shadow: var(--shadow-glow);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    background: linear-gradient(to right, #f8fafc, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-card.warning .stat-value {
    background: linear-gradient(to right, #fbbf24, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Components: Tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th {
    text-align: left;
    padding: 1rem 1.5rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
    background: rgba(15, 23, 42, 0.3);
}

td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-primary);
}

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

/* Components: Forms */
.form-group {
    margin-bottom: 1.25rem;
}

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

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
    background: rgba(15, 23, 42, 0.8);
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
}

/* Components: Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

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

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.badge-neutral {
    background: rgba(148, 163, 184, 0.1);
    color: #cbd5e1;
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.badge-superadmin {
    background: linear-gradient(135deg, #ec4899, #ef4444);
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
    border: none;
    padding: 0.35rem 0.85rem;
}

/* Components: Code & API Keys */
.code-block {
    background: #0f172a;
    padding: 1.25rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: #e2e8f0;
    border: 1px solid var(--border-color);
    margin-bottom: 1rem;
    white-space: pre-wrap;
    word-break: break-all;
}

.api-key-display {
    font-family: var(--font-mono);
    background: rgba(0, 0, 0, 0.3);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.2);
    display: inline-block;
    max-width: 100%;
    white-space: nowrap;
}

/* Utility */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.mr-2 { margin-right: 0.5rem; }
.gap-2 { gap: 0.5rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* Animation */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.modal-footer {
    padding: 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    padding: 0.25rem;
    border-radius: 4px;
}

.modal-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    overflow-x: auto;
}

.tab-btn {
    padding: 0.75rem 1.25rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    white-space: nowrap;
}

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

.tab-btn.active {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-danger {
    background: var(--danger-bg);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.alert-success {
    background: var(--success-bg);
    border-color: rgba(16, 185, 129, 0.3);
    color: #6ee7b7;
}

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

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
    display: block;
}

/* Avatar Styles */
.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
    transition: var(--transition);
    background: var(--bg-card);
}

.user-avatar:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
    transform: scale(1.05);
}

.user-avatar-fallback {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
    border: 2px solid var(--border-color);
    transition: var(--transition);
    text-transform: uppercase;
}

.user-avatar-fallback:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
    transform: scale(1.05);
}

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

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 0 12px;
    }
    
    .header-content {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.75rem 0;
    }
    
    .header {
        height: auto;
        position: sticky;
        top: 0;
    }
    
    .logo {
        font-size: 1rem;
    }
    
    .logo-icon {
        font-size: 1.25rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .stat-card {
        padding: 1rem;
    }
    
    .stat-label {
        font-size: 0.7rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    /* Buttons - keep natural width by default on mobile */
    .btn {
        width: auto;
    }
    
    /* Only full-width buttons when explicitly needed */
    .btn-full-mobile {
        width: 100%;
    }
    
    .btn-icon {
        width: 32px;
        height: 32px;
        flex: 0 0 32px;
        padding: 0.25rem;
    }
    
    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .table-responsive .btn {
        width: auto;
    }
    
    /* Header specific fixes */
    .header-content .flex.items-center.gap-2 {
        gap: 0.35rem;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .nav-actions {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.35rem;
    }
    
    .user-avatar,
    .user-avatar-fallback {
        width: 28px;
        height: 28px;
        font-size: 0.7rem;
    }

    /* Utility classes for mobile */
    .hidden-mobile {
        display: none !important;
    }
    
    /* show-mobile is hidden by default, shown only on mobile */
    
    /* Form adjustments */
    .form-control {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    #searchInput,
    #kvSearchInput,
    #eventSearchInput {
        width: 100% !important;
        min-width: 0;
        margin-bottom: 0;
    }
    
    /* Card adjustments */
    .card {
        padding: 1rem;
        margin-bottom: 1rem;
        border-radius: var(--radius-sm);
    }
    
    /* Card header adjustments for search input */
    .card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding-bottom: 0.75rem;
        margin-bottom: 1rem;
    }
    
    .card-header .card-title {
        font-size: 1rem;
    }
    
    .card-header .flex {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .card-header .flex.items-center {
        flex-direction: row;
    }
    
    /* Modal adjustments */
    .modal-content {
        max-height: 90vh;
        width: 95%;
        margin: 10px;
        max-width: none;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-wrap: wrap;
    }

    /* Tabs scrolling */
    .tabs {
        padding-bottom: 0.5rem;
        margin-bottom: 0.75rem;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        gap: 0.25rem;
    }
    
    .tabs::-webkit-scrollbar {
        display: none;
    }
    
    .tab-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
        flex-shrink: 0;
    }

    /* Mobile Responsive Table Cards */
    .responsive-table thead {
        display: none;
    }

    .responsive-table tbody tr {
        display: block;
        background: rgba(255, 255, 255, 0.02);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        margin-bottom: 0.75rem;
        padding: 0.75rem;
    }

    .responsive-table tbody tr:hover {
        background: rgba(255, 255, 255, 0.03);
    }

    .responsive-table tbody td {
        display: block;
        padding: 0.35rem 0;
        border-bottom: none;
        text-align: left;
        word-break: break-word;
    }

    .responsive-table tbody td::before {
        content: attr(data-label) ": ";
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.03em;
    }

    .responsive-table tbody td:last-child {
        padding-top: 0.5rem;
        margin-top: 0.35rem;
        border-top: 1px solid rgba(148, 163, 184, 0.1);
    }

    .responsive-table tbody td[data-label="Actions"]::before {
        display: none;
    }

    .responsive-table tbody td[data-label="Actions"] {
        display: flex;
        justify-content: flex-start;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .responsive-table .api-key-display {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.8rem;
    }
    
    .responsive-table .badge {
        display: inline-flex;
    }
    
    .responsive-table code {
        word-break: break-all;
    }
    
    /* Code blocks on mobile */
    .code-block {
        padding: 0.75rem;
        font-size: 0.75rem;
        overflow-x: auto;
    }
    
    /* Alerts */
    .alert {
        padding: 0.75rem;
        font-size: 0.875rem;
    }
    
    /* Badges */
    .badge {
        padding: 0.2rem 0.5rem;
        font-size: 0.65rem;
    }
    
    /* Empty state */
    .empty-state {
        padding: 2rem 1rem;
    }
    
    .empty-icon {
        font-size: 2rem;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .container {
        padding: 0 8px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .stat-card {
        padding: 0.75rem;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
    
    .stat-label {
        margin-bottom: 0;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
    
    .header-content {
        padding: 0.5rem 0;
    }
    
    .logo span:last-child {
        display: none;
    }
    
    .tab-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.7rem;
    }
    
    .card {
        padding: 0.75rem;
    }
    
    .card-header {
        gap: 0.5rem;
    }
    
    .responsive-table tbody tr {
        padding: 0.5rem;
    }
    
    .responsive-table tbody td {
        padding: 0.25rem 0;
    }
    
    /* Show mobile-only elements on very small screens */
    .show-mobile {
        display: inline-block !important;
    }
    
    .hidden-mobile {
        display: none !important;
    }
}

/* ============================================
   Footer
   ============================================ */

.site-footer {
    text-align: center;
    padding: 1.5rem 1rem;
    margin-top: 2rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border-color);
}

.site-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.site-footer a:hover {
    color: var(--primary);
}

.site-footer .version {
    display: inline-block;
    background: rgba(59, 130, 246, 0.15);
    color: var(--primary);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 0.8rem;
    margin-left: 0.5rem;
}

.site-footer .separator {
    margin: 0 0.75rem;
    opacity: 0.5;
}
