:root {
    --bg-color: #0f172a;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #0ea5e9;
    --accent-hover: #0284c7;
    --danger: #ef4444;
    --success: #22c55e;
    
    --glass-bg: rgba(30, 41, 59, 0.4);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --glass-blur: blur(12px);
    
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* Background Blobs */
.background-blobs {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    overflow: hidden;
    filter: blur(100px);
}

.blob {
    position: absolute;
    border-radius: 50%;
    animation: float 20s infinite alternate;
}

.blob-1 {
    width: 400px; height: 400px;
    background: rgba(14, 165, 233, 0.3);
    top: -10%; left: -10%;
}

.blob-2 {
    width: 600px; height: 600px;
    background: rgba(139, 92, 246, 0.2);
    bottom: -20%; right: -10%;
    animation-delay: -5s;
}

.blob-3 {
    width: 300px; height: 300px;
    background: rgba(236, 72, 153, 0.2);
    top: 40%; left: 50%;
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) rotate(0deg); }
    100% { transform: translate(100px, 100px) rotate(90deg); }
}

/* Typography */
h1, h2, h3 { font-weight: 600; line-height: 1.2; }
.subtitle { color: var(--text-secondary); margin-bottom: 2rem; font-size: 1.1rem; }

/* Utilities */
.hidden { display: none !important; }
.view {
    min-height: 100vh;
    display: none;
    flex-direction: column;
    animation: fadeIn 0.4s ease-out;
}
.view.active { display: flex; }
.full-width { width: 100%; }

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

/* Glassmorphism Classes */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
    padding: 2.5rem;
}

.glass-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-links {
    display: flex;
    gap: 1rem;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition-fast);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.primary-btn {
    background: var(--accent);
    color: white;
}
.primary-btn:hover { background: var(--accent-hover); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4); }

.outline-btn {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}
.outline-btn:hover { background: rgba(255,255,255,0.05); }

/* Specific Button Colors */
.btn-telegram { background: #0088cc; color: white; }
.btn-telegram:hover { background: #0077b3; color: white; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 136, 204, 0.4); border: none; }
.btn-download { background: #28a745; color: white; }
.btn-download:hover { background: #218838; color: white; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4); border: none; }
.btn-extend { background: #ffc107; color: black; }
.btn-extend:hover { background: #e0a800; color: black; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(255, 193, 7, 0.4); border: none; }
.btn-revoke { background: #dc3545; color: white; }
.btn-revoke:hover { background: #c82333; color: white; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(220, 53, 69, 0.4); border: none; }
.btn-restore { background: #17a2b8; color: white; }
.btn-restore:hover { background: #138496; color: white; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(23, 162, 184, 0.4); border: none; }

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
    font-size: 1rem;
    font-family: inherit;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.nav-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.05); }
.nav-btn.active { color: var(--accent); background: rgba(14, 165, 233, 0.1); }
.nav-btn.outline { border: 1px solid var(--glass-border); color: var(--text-primary); }
.nav-btn.outline:hover { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.5); color: var(--danger); }

/* Forms & Inputs */
.input-group {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.input-group input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition-fast);
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
    background: rgba(0, 0, 0, 0.3);
}

.input-group small {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* Login View Layout */
#login-view {
    justify-content: center;
    align-items: center;
}

.login-card {
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-card .logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.login-card form {
    text-align: left;
}

.error-text {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* Dashboard Layout */
.dashboard-content {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 2rem;
}

.section-header p {
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Tables */
.table-card { padding: 0; overflow: hidden; min-height: 100px; }
.table-responsive { width: 100%; overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

/* Fixed column widths prevent row-shift when data loads */
.keys-table, #server-table, #folder-table, #submissions-table, #users-table, #history-table {
    table-layout: fixed;
}

th, td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--glass-border);
}

th {
    background: rgba(255, 255, 255, 0.02);
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tbody tr {
    transition: var(--transition-fast);
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

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

/* Status Badges */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

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

/* Actions */
.action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}
.action-btn:hover { color: var(--danger); background: rgba(239, 68, 68, 0.1); }

/* States */
.loading-state, .empty-state {
    padding: 3rem;
    text-align: center;
    color: var(--text-secondary);
}

.spinner {
    width: 20px; height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Modals */
.glass-modal {
    margin: auto;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    color: var(--text-primary);
    padding: 2rem;
    width: 100%;
    max-width: 500px;
}

.glass-modal::backdrop {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content h3 { margin-bottom: 1.5rem; }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    body {
        padding-bottom: 80px; /* Space for bottom nav */
    }

    .glass-nav {
        padding: 1rem;
        /* Keep brand and logout horizontally aligned */
    }
    
    .nav-brand h2 {
        font-size: 1.25rem;
    }
    
    .nav-links {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        background: rgba(15, 23, 42, 0.85);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid var(--glass-border);
        padding: 0.5rem;
        z-index: 1000;
        gap: 0;
    }
    
    .nav-btn {
        flex-direction: column;
        gap: 0.25rem;
        padding: 0.5rem;
        font-size: 0.7rem;
        flex: 1;
        border-radius: var(--radius-sm);
    }

    .nav-btn svg {
        width: 20px;
        height: 20px;
    }
    
    .dashboard-content {
        padding: 1rem 0.5rem;
    }
    
    .glass-card {
        padding: 1rem;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .section-header > div:last-child {
        width: 100%;
        justify-content: space-between;
    }

    /* Action Buttons */
    .btn {
        padding: 0.75rem 1rem;
        min-height: 44px;
    }

    /* Table to Card Conversion */
    table, thead, tbody, th, td, tr {
        display: block;
    }

    thead tr {
        display: none;
    }

    tr {
        background: rgba(255, 255, 255, 0.02);
        border: 1px solid var(--glass-border);
        border-radius: var(--radius-md);
        margin-bottom: 1rem;
        padding: 1rem;
    }

    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: none;
        padding: 0.5rem 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        text-align: right;
    }

    td:last-child {
        border-bottom: none;
        padding-bottom: 0;
        justify-content: flex-end;
        gap: 0.5rem;
        margin-top: 0.5rem;
    }

    td::before {
        content: attr(data-label);
        font-weight: 500;
        color: var(--text-secondary);
        font-size: 0.85rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        padding-right: 1rem;
        text-align: left;
    }
    
    .stats-container {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
}

/* Table */
.keys-table {
    width: 100%;
    border-collapse: collapse;
    background: #1a1a2e;
    border-radius: 12px;
    overflow: hidden;
}

.keys-table thead {
    background: #16213e;
}

.keys-table th {
    padding: 14px 16px;
    text-align: left;
    color: #8892b0;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.keys-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #233554;
    color: #ccd6f6;
}

/* Only truncate text cells, not the action cell */
.keys-table td:not(.actions-cell) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Truncate school name and key ID columns to prevent row height shifts */
.keys-table td:first-child,
.keys-table td:nth-child(2) {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.keys-table tr:hover {
    background: #1a1a3e;
}

/* Status Badges */
.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.status-active { background: #0a4a0a; color: #5cff5c; }
.status-revoked { background: #4a0a0a; color: #ff5c5c; }
.status-expired { background: #4a3a0a; color: #ffcc5c; }

/* Buttons */
.btn-sm { padding: 4px 10px !important; font-size: 11px !important; display: inline-block; }

.btn-telegram { background: #0088cc !important; color: white !important; }
.btn-download { background: #28a745 !important; color: white !important; }
.btn-extend { background: #ffc107 !important; color: black !important; }
.btn-revoke { background: #dc3545 !important; color: white !important; }
.btn-restore { background: #17a2b8 !important; color: white !important; }

.actions-cell {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    white-space: normal;
}

/* Mobile */
@media (max-width: 768px) {
    /* Header */
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 12px 16px;
    }
    .section-header h1 {
        font-size: 18px;
    }
    .section-header .subtitle {
        font-size: 12px;
    }
    .section-header .actions {
        width: 100%;
    }
    .section-header .actions button {
        width: 100%;
    }
    
    /* School Name & Key */
    .school-name {
        font-size: 16px;
        font-weight: 700;
    }
    .school-key {
        font-size: 14px;
        font-family: monospace;
        background: #1a1a3e;
        padding: 4px 8px;
        border-radius: 4px;
        display: inline-block;
    }

    /* Actions Buttons — row layout on mobile, allow wrapping but no full-width stacking */
    .actions-cell {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 4px;
    }
    .actions-cell .btn {
        width: auto;
        flex: 1;
        min-width: 60px;
        justify-content: center;
        padding: 6px 8px;
        font-size: 10px;
    }

    /* Convert table rows to cards */
    .keys-table thead { display: none; }
    .keys-table tbody tr { 
        display: block;
        background: #16213e;
        margin-bottom: 12px;
        padding: 16px;
        border-radius: 8px;
    }
    .keys-table tbody tr td {
        display: flex;
        justify-content: space-between;
        padding: 6px 0;
        border: none;
        font-size: 13px;
        gap: 8px;
        overflow: hidden;
    }
    .keys-table tbody tr td:before {
        content: attr(data-label);
        font-weight: 600;
        color: #8892b0;
        font-size: 11px;
        text-transform: uppercase;
    }
    .keys-table tbody tr td > :not(.status-badge):not(.btn) {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 50%;
    }

    /* Status Badge */
    .status-badge {
        font-size: 10px;
        padding: 2px 10px;
    }
    
    /* Hide the domain display on mobile */
    .footer-domain {
        display: none;
    }
    
    #keys-section #system-stats-footer {
        display: flex !important;
    }
}

@media (max-width: 1200px) {
    .actions-cell .btn {
        padding: 4px 6px !important;
        font-size: 10px !important;
    }
    .btn-sm { padding: 3px 6px !important; font-size: 10px !important; }
}

@media (max-width: 1100px) {
    .nav-btn span { display: none; }
    .nav-btn { gap: 0; padding: 0.5rem; }
}
