/* =====================================================================
   Telegram Mini App - Modern Cyber/Telegram Design System
   ===================================================================== */

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #121824;
    --bg-card: rgba(22, 30, 46, 0.7);
    --bg-card-hover: rgba(28, 38, 58, 0.85);
    --bg-glass: rgba(18, 24, 36, 0.75);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(88, 166, 255, 0.3);
    
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --text-muted: #545d68;
    
    --accent: #2481cc;
    --accent-hover: #1c6ba8;
    --accent-gradient: linear-gradient(135deg, #2481cc 0%, #6c5ce7 100%);
    --accent-glow: rgba(36, 129, 204, 0.35);
    
    --emerald: #00b894;
    --emerald-bg: rgba(0, 184, 148, 0.15);
    --warning: #fdcb6e;
    --danger: #ff7675;
    --danger-bg: rgba(255, 118, 117, 0.15);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-glow: 0 0 20px rgba(36, 129, 204, 0.25);
    
    --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --safe-bottom: env(safe-area-inset-bottom, 16px);
}

/* Telegram Native Theme Overrides if present */
body.tg-app {
    background-color: var(--tg-theme-bg-color, var(--bg-primary));
    color: var(--tg-theme-text-color, var(--text-primary));
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    min-height: 100vh;
    padding-bottom: calc(75px + var(--safe-bottom));
    user-select: none;
    -webkit-user-select: none;
}

/* Base Container */
.app-container {
    max-width: 540px;
    margin: 0 auto;
    padding: 16px;
    position: relative;
}

/* =====================================================================
   Header
   ===================================================================== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0 16px;
    margin-bottom: 8px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-badge {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: var(--accent-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    box-shadow: var(--shadow-glow);
    text-transform: uppercase;
}

.user-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

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

.user-plan-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    background: rgba(36, 129, 204, 0.2);
    color: #58a6ff;
    width: fit-content;
    border: 1px solid rgba(88, 166, 255, 0.3);
}

.btn-fast-action {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    padding: 9px 16px;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 4px 14px var(--accent-glow);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-fast-action:active {
    transform: scale(0.96);
}

/* =====================================================================
   Banner CTA
   ===================================================================== */
.banner-cta {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-glow);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    backdrop-filter: blur(16px);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.banner-glow {
    position: absolute;
    top: -40px;
    right: -40px;
    width: 140px;
    height: 140px;
    background: var(--accent);
    filter: blur(60px);
    opacity: 0.25;
    pointer-events: none;
}

.banner-content {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 16px;
}

.banner-icon {
    font-size: 32px;
    width: 52px;
    height: 52px;
    background: rgba(36, 129, 204, 0.15);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.banner-text h3 {
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 4px;
}

.banner-text p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.banner-btn {
    width: 100%;
    background: var(--accent-gradient);
    border: none;
    color: #fff;
    padding: 13px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 4px 16px var(--accent-glow);
    transition: transform 0.15s ease;
}

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

/* =====================================================================
   Stats Grid
   ===================================================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 22px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 10px;
    text-align: center;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.stat-icon {
    font-size: 20px;
}

.stat-value {
    display: block;
    font-size: 20px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.1;
}

.stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* =====================================================================
   Sections & Cards
   ===================================================================== */
.section-block {
    margin-bottom: 24px;
}

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

.section-header h4 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-accent {
    font-size: 11px;
    font-weight: 700;
    color: var(--emerald);
    background: var(--emerald-bg);
    padding: 3px 8px;
    border-radius: var(--radius-full);
}

.link-more {
    font-size: 13px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

/* =====================================================================
   Account Compact Card with 1/3s Toggle
   ===================================================================== */
.account-card-compact {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    backdrop-filter: blur(12px);
    transition: border-color 0.2s ease;
}

.account-card-compact:hover {
    border-color: var(--border-glow);
}

.acc-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.acc-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.acc-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: rgba(88, 166, 255, 0.15);
    color: #58a6ff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

.acc-details h5 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.acc-details span {
    font-size: 12px;
    color: var(--text-secondary);
}

.acc-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--emerald);
    box-shadow: 0 0 8px var(--emerald);
}

/* Toggle Switch */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-top: 1px solid var(--border-color);
}

.toggle-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 80%;
}

.toggle-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.toggle-sub {
    font-size: 11px;
    color: var(--text-secondary);
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 26px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255, 255, 255, 0.15);
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

input:checked + .slider {
    background-color: var(--emerald);
}

input:checked + .slider:before {
    transform: translateX(18px);
}

/* =====================================================================
   Broadcast Card
   ===================================================================== */
.broadcast-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.bcast-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.bcast-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: var(--radius-full);
}

.badge-active {
    background: var(--emerald-bg);
    color: var(--emerald);
}

.badge-paused {
    background: rgba(253, 203, 110, 0.15);
    color: var(--warning);
}

.bcast-body {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.2);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
}

.bcast-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
}

.bcast-actions {
    display: flex;
    gap: 8px;
}

.btn-icon-action {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-icon-action.danger {
    color: var(--danger);
    background: var(--danger-bg);
}

/* =====================================================================
   Views Navigation
   ===================================================================== */
.app-view {
    display: none;
    animation: fadeIn 0.2s ease;
}

.app-view.active {
    display: block;
}

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

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

.view-header h2 {
    font-size: 20px;
    font-weight: 800;
}

.btn-create-broadcast-small, .btn-sync-folders {
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* =====================================================================
   Bottom Navigation
   ===================================================================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(18, 24, 36, 0.9);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding: 8px 12px calc(8px + var(--safe-bottom));
    z-index: 100;
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s, transform 0.1s;
    width: 60px;
}

.nav-item.active {
    color: #58a6ff;
}

.nav-item:active {
    transform: scale(0.92);
}

/* =====================================================================
   Modal (Fast Create Broadcast)
   ===================================================================== */
.modal-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

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

.modal-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 540px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border-glow);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

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

.modal-header h3 {
    font-size: 17px;
    font-weight: 800;
}

.btn-close-modal {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-primary);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.label-with-action {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-use-template {
    background: none;
    border: none;
    color: #58a6ff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.chips-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 14px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.chip.active {
    background: rgba(36, 129, 204, 0.25);
    border-color: #58a6ff;
    color: #58a6ff;
    box-shadow: 0 0 12px rgba(88, 166, 255, 0.25);
}

.form-select, .form-textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.form-select:focus, .form-textarea:focus {
    border-color: #58a6ff;
}

.textarea-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
}

.char-counter {
    font-size: 11px;
    color: var(--text-muted);
}

.modal-footer {
    padding: 16px 20px calc(16px + var(--safe-bottom));
    border-top: 1px solid var(--border-color);
}

.btn-submit-broadcast {
    width: 100%;
    background: var(--accent-gradient);
    border: none;
    color: #fff;
    padding: 14px;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--accent-glow);
    transition: transform 0.15s;
}

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

/* =====================================================================
   Toast Notification
   ===================================================================== */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: rgba(22, 30, 46, 0.95);
    border: 1px solid var(--border-glow);
    color: #fff;
    padding: 12px 20px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    z-index: 999;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    white-space: nowrap;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: #58a6ff;
    animation: spin 0.8s linear infinite;
    margin: 30px auto;
}

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