/*
   TelegramBlast Pro — Obsidian Premium UI System (v3.0)
   Mobile-first native app experience
*/

/* ─── DESIGN TOKENS ────────────────────────────────────────────────────────── */
:root {
    /* Core palette */
    --tg-bg:              #030712;
    --tg-sidebar:         #0f172a;
    --tg-card:            rgba(15, 23, 42, 0.6);
    --tg-accent:          #3b82f6;
    --tg-accent-glow:     rgba(59, 130, 246, 0.45);
    --tg-bubble:          #1e293b;
    --tg-bubble-text:     #f8fafc;
    --tg-input:           rgba(15, 17, 21, 0.6);
    --tg-border:          rgba(255, 255, 255, 0.08);
    --tg-text:            #f1f5f9;
    --tg-text-secondary:  #94a3b8;
    --tg-success:         #10b981;
    --tg-error:           #ef4444;
    --tg-warning:         #f59e0b;
    --tg-header:          rgba(3, 7, 18, 0.9);

    /* Glassmorphism */
    --glass-blur:   24px;
    --glass-border: rgba(255, 255, 255, 0.05);
    --glass-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --anim-speed:   0.4s;

    /* Native app layout */
    --header-h:      64px;
    --header-h-mob:  54px;
    --bottom-nav-h:  68px;
    --sidebar-w:     300px;

    /* Safe areas (iOS notch / home indicator) */
    --safe-top:    env(safe-area-inset-top,    0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left:   env(safe-area-inset-left,   0px);
    --safe-right:  env(safe-area-inset-right,  0px);
}

/* Light theme overrides */
.light-theme {
    --tg-bg:             #f1f5f9;
    --tg-sidebar:        #ffffff;
    --tg-card:           rgba(255, 255, 255, 0.85);
    --tg-accent:         #2563eb;
    --tg-accent-glow:    rgba(37, 99, 235, 0.3);
    --tg-success:        #059669;
    --tg-error:          #dc2626;
    --tg-text:           #0f172a;
    --tg-text-secondary: #475569;
    --tg-border:         rgba(0, 0, 0, 0.06);
    --tg-input:          rgba(255, 255, 255, 0.9);
    --tg-bubble:         #e2e8f0;
    --tg-bubble-text:    #0f172a;
    --tg-header:         rgba(255, 255, 255, 0.9);

    --glass-blur:   16px;
    --glass-border: rgba(0, 0, 0, 0.05);
    --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

/* ─── BASE ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    /* Prevent double-tap zoom */
    touch-action: manipulation;
}

body {
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: var(--tg-text);
    background-color: var(--tg-bg);
    /* Dynamic viewport height — handles mobile address bar correctly */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    transition: background-color var(--anim-speed) ease, color var(--anim-speed) ease;
    /* Prevent overscroll on body */
    overscroll-behavior: none;
}

/* iOS fill-available fallback */
@supports not (height: 100dvh) {
    body { height: -webkit-fill-available; }
}

/* ─── SCROLLBAR ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--tg-border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--tg-text-secondary); }

/* ─── GLASS COMPONENTS ──────────────────────────────────────────────────────── */
.glass-card {
    background: var(--tg-card);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.glass-panel {
    background: var(--tg-card);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
}

/* Only apply hover lifts on pointer devices */
@media (hover: hover) and (pointer: fine) {
    .glass-card:hover {
        border-color: rgba(255, 255, 255, 0.1);
        box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.6);
        transform: translateY(-4px);
    }
}

.premium-shadow {
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.3),
                0 0 20px -5px var(--tg-accent-glow);
}

.premium-glow { position: relative; }
.premium-glow::after {
    content: '';
    position: absolute;
    inset: -1px;
    background: linear-gradient(45deg, transparent, var(--tg-accent), transparent);
    background-size: 200% 200%;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.5s ease;
    border-radius: inherit;
    filter: blur(8px);
}
@media (hover: hover) and (pointer: fine) {
    .premium-glow:hover::after { opacity: 0.3; }
}

/* ─── ANIMATIONS ────────────────────────────────────────────────────────────── */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 10px var(--tg-accent-glow); }
    50%       { box-shadow: 0 0 25px var(--tg-accent-glow); }
}
@keyframes tabEntrance {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes loading {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
@keyframes sheetUp {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
@keyframes backdropIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.animate-slide-up { animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.animate-fade-in  { animation: fadeIn 0.4s ease forwards; }

/* ─── TAB CONTENT ───────────────────────────────────────────────────────────── */
.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 5rem;
    position: relative;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}
.tab-content.active {
    display: block;
    animation: tabEntrance 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* ─── TELEGRAM BUBBLE ───────────────────────────────────────────────────────── */
.telegram-preview-container {
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-size: cover;
    background-position: center;
    border-radius: 2rem;
    position: relative;
    overflow: hidden;
}
.telegram-bubble {
    background: var(--tg-bubble);
    border-radius: 1.5rem 1.5rem 0.5rem 1.5rem;
    padding: 1rem 1.25rem;
    max-width: 85%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* ─── INPUTS ────────────────────────────────────────────────────────────────── */
.premium-input {
    background: var(--tg-input);
    border: 1px solid var(--tg-border);
    border-radius: 1.25rem;
    padding: 0.875rem 1.25rem;
    color: var(--tg-text);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    width: 100%;
    font-size: 16px; /* Prevent iOS auto-zoom */
}
.premium-input:focus {
    border-color: var(--tg-accent);
    box-shadow: 0 0 0 3px var(--tg-accent-glow);
    outline: none;
}

/* Prevent iOS input zoom */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="search"],
select,
textarea {
    font-size: 16px;
}

/* ─── NAVIGATION PILLS (SIDEBAR) ────────────────────────────────────────────── */
.nav-pill {
    padding: 0.625rem 1.25rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    font-weight: 700;
    transition: all 0.25s ease;
    color: var(--tg-text-secondary);
    cursor: pointer;
    border: none;
    background: transparent;
}
.nav-pill.active {
    background: var(--tg-accent);
    color: white;
    box-shadow: 0 6px 18px var(--tg-accent-glow);
}

.sidebar-pill {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1.25rem;
    border-radius: 1rem;
    transition: all 0.25s ease;
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--tg-text-secondary);
    position: relative;
    overflow: hidden;
    text-align: left;
    margin-bottom: 0.25rem;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
}
@media (hover: hover) and (pointer: fine) {
    .sidebar-pill:hover {
        background: rgba(255, 255, 255, 0.05);
        color: var(--tg-text);
        border-color: var(--tg-border);
        transform: translateX(3px);
    }
}
.sidebar-pill.active {
    background: #2563eb;
    color: white;
    box-shadow: 0 8px 24px -4px var(--tg-accent-glow);
    border-color: rgba(255, 255, 255, 0.1);
}
.sidebar-pill.active::after {
    content: '';
    position: absolute;
    right: 0;
    top: 25%;
    height: 50%;
    width: 3px;
    background: white;
    border-radius: 3px 0 0 3px;
}

.sidebar-header {
    font-size: 0.625rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.35em;
    color: var(--tg-text);
    opacity: 0.3;
    margin-left: 0.5rem;
    margin-bottom: 0.75rem;
}

/* ─── SKELETON LOADER ───────────────────────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, var(--tg-sidebar) 25%, var(--tg-bubble) 50%, var(--tg-sidebar) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

/* ─── SIDEBAR (MOBILE DRAWER) ───────────────────────────────────────────────── */
@media (max-width: 1023px) {
    #mainSidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                    box-shadow 0.35s ease;
        z-index: 200;
        padding-top: var(--safe-top);
    }
    #mainSidebar.open {
        transform: translateX(0);
        box-shadow: 24px 0 64px rgba(0, 0, 0, 0.6);
    }
}

/* ─── SIDEBAR BACKDROP ──────────────────────────────────────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 199;
    animation: backdropIn 0.3s ease;
}
.sidebar-backdrop.visible { display: block; }

/* ─── BOTTOM NAVIGATION (NATIVE APP) ───────────────────────────────────────── */
.bottom-nav {
    display: none; /* hidden on desktop */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 150;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--tg-header);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid var(--tg-border);
    align-items: stretch;
    overscroll-behavior: none;
}

@media (max-width: 1023px) {
    .bottom-nav { display: flex; }

    /* More room for content above bottom nav */
    .tab-content {
        padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 1rem);
    }

    /* Toast sits above bottom nav */
    #toast {
        bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 1rem) !important;
    }

    /* Thinner top header on mobile */
    header.top-header {
        height: var(--header-h-mob) !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 2px 6px;
    border: none;
    background: transparent;
    color: var(--tg-text-secondary);
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    position: relative;
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.bottom-nav-item .nav-icon {
    font-size: 21px;
    line-height: 1;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: block;
}

.bottom-nav-item.active {
    color: var(--tg-accent);
}

.bottom-nav-item.active .nav-icon {
    transform: translateY(-2px) scale(1.12);
}

.bottom-nav-item:active .nav-icon {
    transform: scale(0.88);
    transition-duration: 0.1s;
}

/* Active indicator pill */
.bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 4px;
    width: 28px;
    height: 3px;
    border-radius: 2px;
    background: var(--tg-accent);
    box-shadow: 0 0 10px var(--tg-accent-glow);
}

/* ─── MOBILE MODAL BOTTOM SHEETS ────────────────────────────────────────────── */
@media (max-width: 767px) {
    /* Transform center modals into bottom sheets */
    .modal-overlay {
        align-items: flex-end !important;
        padding: 0 !important;
    }
    .modal-sheet {
        border-radius: 1.75rem 1.75rem 0 0 !important;
        max-height: 88vh !important;
        width: 100% !important;
        max-width: 100% !important;
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
        animation: sheetUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
    }
    /* Drag handle */
    .modal-sheet::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 2px;
        margin: 0.75rem auto 0;
        flex-shrink: 0;
    }
    .light-theme .modal-sheet::before {
        background: rgba(0, 0, 0, 0.15);
    }

    /* Media gallery is full-screen on mobile */
    #mediaModal .modal-sheet {
        max-height: 92vh;
    }
}

/* ─── TOP HEADER ────────────────────────────────────────────────────────────── */
.top-header {
    height: var(--header-h);
    padding-top: var(--safe-top);
    display: flex;
    align-items: center;
}

/* ─── SCROLL AREAS ──────────────────────────────────────────────────────────── */
.custom-scrollbar {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--tg-border) transparent;
}

/* ─── BADGES / STATUS ───────────────────────────────────────────────────────── */
.badge-success { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.badge-error   { background: rgba(239, 68, 68, 0.15);  color: #ef4444; }
.badge-partial { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.badge-pending { background: rgba(148, 163, 184, 0.1); color: #94a3b8; }

/* ─── LIGHT THEME BOTTOM NAV ────────────────────────────────────────────────── */
.light-theme .bottom-nav {
    background: rgba(255, 255, 255, 0.95);
    border-top-color: rgba(0, 0, 0, 0.07);
}
.light-theme .sidebar-backdrop {
    background: rgba(0, 0, 0, 0.35);
}

/* ─── COMPOSER MOBILE TWEAKS ────────────────────────────────────────────────── */
@media (max-width: 1023px) {
    #tabContent-composer .telegram-preview-container {
        min-height: 200px !important;
    }
}

/* ─── REDUCED MOTION ────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ─── LIGHT THEME: WHITE-ALPHA OVERRIDES ────────────────────────────────────── */
/*
   Tailwind's bg-white/X and border-white/X compile to literal rgba(255,255,255,X)
   which are invisible on the light #f1f5f9 background.
   Override them with equivalent black-alpha values.
*/

/* Solid backgrounds */
.light-theme .bg-white\/5  { background-color: rgba(0,0,0,0.04) !important; }
.light-theme .bg-white\/8  { background-color: rgba(0,0,0,0.05) !important; }
.light-theme .bg-white\/10 { background-color: rgba(0,0,0,0.06) !important; }
.light-theme .bg-white\/20 { background-color: rgba(0,0,0,0.09) !important; }

/* Borders */
.light-theme .border-white\/5  { border-color: rgba(0,0,0,0.07) !important; }
.light-theme .border-white\/10 { border-color: rgba(0,0,0,0.10) !important; }
.light-theme .border-white\/20 { border-color: rgba(0,0,0,0.14) !important; }

/* Divider spans (w-px bg-white/10) */
.light-theme .bg-white\/10.w-px,
.light-theme .w-px.bg-white\/10 { background-color: rgba(0,0,0,0.12) !important; }

/* Hover backgrounds */
.light-theme .hover\:bg-white\/5:hover  { background-color: rgba(0,0,0,0.04) !important; }
.light-theme .hover\:bg-white\/8:hover  { background-color: rgba(0,0,0,0.05) !important; }
.light-theme .hover\:bg-white\/10:hover { background-color: rgba(0,0,0,0.06) !important; }
.light-theme .hover\:bg-white\/20:hover { background-color: rgba(0,0,0,0.09) !important; }

/* glass-card hover — remove the dark border and shadow */
@media (hover: hover) and (pointer: fine) {
    .light-theme .glass-card:hover {
        border-color: rgba(0,0,0,0.14) !important;
        box-shadow: 0 20px 50px -10px rgba(0,0,0,0.10) !important;
    }
}

/* sidebar-pill hover — was rgba(255,255,255,0.05) which is invisible on white */
@media (hover: hover) and (pointer: fine) {
    .light-theme .sidebar-pill:hover {
        background: rgba(0,0,0,0.05) !important;
        border-color: rgba(0,0,0,0.08) !important;
    }
}

/*
   hover:text-white is invisible on the light transparent hover backgrounds.
   Make it dark. Then re-override to white for elements with a real colored hover bg.
   Order matters — the colored-bg rules MUST come last to win the cascade.
*/
.light-theme .hover\:text-white:hover   { color: #1e293b !important; }
.light-theme .hover\:bg-tg-accent:hover { background-color: var(--tg-accent) !important; color: white !important; }
.light-theme .hover\:bg-red-500:hover   { color: white !important; }

/* Hardcoded light text colors that are unreadable on white */
.light-theme .text-slate-400 { color: #64748b !important; }
.light-theme .text-slate-500 { color: #475569 !important; }

/* Modal drag handle */
.light-theme .modal-sheet::before { background: rgba(0,0,0,0.15) !important; }

/* Sidebar drawer open shadow */
.light-theme #mainSidebar.open {
    box-shadow: 24px 0 64px rgba(0,0,0,0.15) !important;
}
