:root {
    --bg-dark: #0f172a;
    --card-dark: #1e293b;
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.4);
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --accent: #10b981;
    --danger: #ef4444;
    --sidebar-width: 260px;
    --radius-lg: 16px;
    --radius-md: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body.dark-theme {
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

.hidden {
    display: none !important;
}

/* Overlay & Loader */
.overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

/* Login Page Styling */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top right, #1e293b, #0f172a);
}

.login-card {
    background: var(--card-dark);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-icon.large {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: block;
}

.login-header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-dim);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-dim);
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    color: white;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--primary);
}

.error-msg {
    color: var(--danger);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    text-align: center;
}

.btn-primary {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-primary:active {
    transform: scale(0.98);
}

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

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

/* Hub Container & Sidebar */
#hub-container {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: #0b1120;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2.5rem;
}

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

.logo-text {
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.025em;
}

.nav-links {
    list-style: none;
    flex-grow: 1;
}

.nav-links li {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    color: var(--text-dim);
}

.nav-links li:hover:not(.disabled) {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.nav-links li.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.nav-links li.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.user-profile {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

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

.user-info .username {
    font-weight: 600;
    font-size: 0.95rem;
}

.user-info .role {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
}

/* Content Area */
.content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
}

.content-header {
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.content-header h1 {
    font-size: 1.1rem;
    font-weight: 600;
}

.iframe-container {
    flex-grow: 1;
    position: relative;
}

#module-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.status-indicator {
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}

/* Telegram Login Widget */
.auth-divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0 1.25rem;
    color: var(--text-dim);
    font-size: 0.85rem;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
}

.auth-divider::before {
    margin-right: 0.75rem;
}

.auth-divider::after {
    margin-left: 0.75rem;
}

#telegram-widget-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 48px;
}

.tg-loading {
    color: var(--text-dim);
    font-size: 0.85rem;
}

@media (max-width: 768px) {
    .sidebar {
        width: 80px;
        padding: 1rem 0.5rem;
    }

    .logo-text,
    .nav-links .label,
    .user-info {
        display: none;
    }

    .nav-links li {
        justify-content: center;
    }

    .user-profile {
        justify-content: center;
    }
}

/* ── Login system hardening additions ── */

/* Error message: tinted background + fade-in */
.error-msg {
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-md);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.error-msg:not(.hidden) {
    animation: fadeIn 0.2s ease;
}

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

/* Telegram loading: mini spinner via pseudo-element */
.tg-loading {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.tg-loading::before {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--text-dim);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

/* Telegram auth-in-progress spinner */
.tg-spinner {
    width: 24px;
    height: 24px;
    margin: 12px auto;
}

/* Success overlay — absolute inset on .login-card */
.login-card {
    position: relative;
    overflow: hidden;
}

.login-success-overlay {
    position: absolute;
    inset: 0;
    background: rgba(30, 41, 59, 0.95);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    z-index: 10;
    color: var(--text-main);
    font-weight: 600;
    font-size: 1.1rem;
}

.success-check {
    font-size: 2.5rem;
    color: var(--accent);
    line-height: 1;
}

/* Disabled button: stronger opacity, explicit not-allowed */
.btn-primary:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Telegram widget container: smooth height transitions */
#telegram-widget-container {
    transition: min-height 0.2s;
}

/* Telegram OAuth button */
.tg-auth-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.72rem 1rem;
    background: #2AABEE;
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.2s, transform 0.1s;
    box-sizing: border-box;
}

.tg-auth-btn:hover {
    opacity: 0.88;
}

.tg-auth-btn:active {
    transform: scale(0.98);
}

.tg-auth-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

/* Telegram paper-plane icon via inline SVG background */
.tg-auth-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0zm5.562 8.248-1.97 9.289c-.145.658-.537.818-1.084.508l-3-2.21-1.447 1.394c-.16.16-.295.295-.605.295l.213-3.053 5.56-5.023c.242-.213-.054-.333-.373-.12L8.32 14.617l-2.96-.924c-.643-.204-.657-.643.136-.953l11.57-4.461c.537-.194 1.006.131.496.969z'/%3E%3C/svg%3E") no-repeat center / contain;
}
