/* ═══════════════════════════════════════════════════════════════════════
   Xipher — Universal Mobile & Tablet Responsive Adaptation
   Supports: iPhone SE (320px) → iPhone 16 Pro Max (430px) → tablets (768px+)
   Includes: safe areas, touch targets, font scaling, orientation handling
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── BASE: Touch & Viewport Fixes ─── */
*,
*::before,
*::after {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
    overscroll-behavior-y: contain;
}

/* Prevent iOS zoom on input focus */
@supports (-webkit-touch-callout: none) {
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px !important;
    }
}

/* Minimum touch target size (WCAG 2.5.5) */
@media (pointer: coarse) {
    button,
    a,
    [role="button"],
    input[type="submit"],
    input[type="button"],
    .chat-item,
    .context-menu-item,
    .app-menu-item,
    .folder-rail-item {
        min-height: 44px;
        min-width: 44px;
    }

    /* Scrollbar hide on touch devices */
    ::-webkit-scrollbar {
        width: 0;
        height: 0;
    }
}

/* Safe area padding support */
@supports (padding: env(safe-area-inset-top)) {
    .site-header,
    .chat-header {
        padding-top: env(safe-area-inset-top);
    }

    .chat-input-area,
    .footer {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   LANDING PAGE (index.html) — Mobile Navigation & Layout
   ═══════════════════════════════════════════════════════════════════════ */

/* Hamburger menu button — hidden by default, shown on mobile */
.mobile-hamburger {
    display: none;
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    color: var(--text-primary, #f0f0f5);
    font-size: 1.4rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
    z-index: 200;
    position: relative;
}

.mobile-hamburger:hover,
.mobile-hamburger:active {
    background: rgba(255, 255, 255, 0.12);
}

/* Mobile slide-in nav */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-nav-overlay.active {
    display: block;
    opacity: 1;
}

.mobile-nav-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(320px, 85vw);
    height: 100%;
    background: var(--bg-primary, #0a0a0f);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 9999;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    padding: calc(24px + env(safe-area-inset-top, 0px)) 24px calc(24px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
}

.mobile-nav-drawer.active {
    transform: translateX(0);
}

.mobile-nav-close {
    align-self: flex-end;
    width: 40px;
    height: 40px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary, #999);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    transition: all 0.2s;
}

.mobile-nav-close:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary, #fff);
}

.mobile-nav-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mobile-nav-links a {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-radius: 12px;
    color: var(--text-secondary, #aaa);
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
}

.mobile-nav-links a:hover,
.mobile-nav-links a:active {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary, #fff);
}

.mobile-nav-actions {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mobile-nav-actions .btn,
.mobile-nav-actions .btn-primary {
    width: 100%;
    text-align: center;
    justify-content: center;
}

/* ─── Max width 900px: Show hamburger, hide desktop nav ─── */
@media (max-width: 900px) {
    .mobile-hamburger {
        display: flex;
    }

    /* Landing page nav */
    .site-nav {
        display: none !important;
    }

    .lang-toggle {
        display: none;
    }

    .header-inner {
        padding: 10px 0;
    }

    /* Hero adjustments */
    .hero h1 {
        font-size: clamp(1.8rem, 6vw, 2.8rem);
        line-height: 1.15;
    }

    .hero-subtitle {
        font-size: clamp(0.95rem, 2.5vw, 1.1rem);
    }

    .hero-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .hero-actions .btn {
        width: 100%;
        text-align: center;
        justify-content: center;
    }

    /* Section titles */
    .section-title {
        font-size: clamp(1.6rem, 4vw, 2.5rem);
    }

    .section-subtitle {
        font-size: clamp(0.9rem, 2.5vw, 1.05rem);
    }

    /* Stats grid */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    /* Card grid */
    .card-grid {
        grid-template-columns: 1fr;
    }

    /* FAQ */
    .faq-grid {
        grid-template-columns: 1fr;
    }

    /* Footer */
    .footer-links {
        flex-direction: column;
        text-align: center;
    }
}

/* ─── Max width 600px: Small phones ─── */
@media (max-width: 600px) {
    .container {
        width: calc(100vw - 32px);
        padding: 0;
    }

    .section {
        padding: 48px 0;
    }

    /* Hero */
    .hero {
        min-height: auto;
        padding: 40px 0;
    }

    .hero h1 {
        font-size: clamp(1.5rem, 7vw, 2rem);
    }

    .hero-stats-row {
        flex-direction: column;
        gap: 12px;
        align-items: center;
    }

    /* Phone mockup */
    .phone-mockup {
        width: 200px;
        height: 400px;
    }

    .hero-visual {
        transform: scale(0.85);
    }

    /* Cards */
    .feature-card,
    .card {
        padding: 20px;
    }

    /* Stats */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 16px 12px;
    }

    /* Compare table scroll */
    .compare-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }

    /* Install section */
    .install-grid {
        grid-template-columns: 1fr;
    }
}

/* ─── Max width 380px: Very small phones (iPhone SE, Galaxy S series compact) ─── */
@media (max-width: 380px) {
    .container {
        width: calc(100vw - 24px);
    }

    .hero h1 {
        font-size: 1.4rem;
    }

    .hero-subtitle {
        font-size: 0.9rem;
    }

    .btn,
    .btn-primary,
    .btn-secondary {
        padding: 0.75rem 1.25rem;
        font-size: 0.9rem;
    }

    .section-title {
        font-size: 1.4rem;
    }

    .section-subtitle {
        font-size: 0.85rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   CHAT PAGE — Enhanced Mobile Adaptation
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── 900px: Sidebar overlay mode ─── */
@media (max-width: 900px) {
    /* Better sidebar behavior */
    .chats-sidebar {
        width: min(380px, 100vw) !important;
        max-width: 100vw;
    }

    /* Info panel always hidden */
    .info-panel {
        display: none !important;
    }

    /* Chat header back button space */
    .chat-header {
        min-height: 56px;
    }

    /* Folder rail compact */
    .folders-rail {
        width: 64px;
    }

    .folder-rail-item,
    .folder-rail-edit {
        width: 54px;
    }

    /* Settings panel full screen */
    .settings-panel {
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        border-radius: 0 !important;
    }

    /* Modal full width */
    .modal-content {
        width: 96vw !important;
        max-width: 100% !important;
        border-radius: 14px !important;
    }

    /* Context menu touch-friendly */
    .message-context-menu {
        min-width: 220px;
    }

    .context-menu-item {
        padding: 12px 16px;
        font-size: 0.95rem;
    }
}

/* ─── 768px: Tablet portrait ─── */
@media (max-width: 768px) {
    /* Chat messages slightly tighter */
    .chat-messages {
        padding: 1rem 0.75rem;
    }

    .message-bubble {
        max-width: min(82%, calc(100% - 44px));
    }

    /* Header adjustments */
    .chat-header-details h3 {
        font-size: 0.95rem;
    }

    .chat-header-details p {
        font-size: 0.78rem;
    }

    /* Reaction grid smaller */
    .reaction-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 0.75rem;
    }

    .reaction-item {
        width: 44px;
        height: 44px;
        font-size: 1.6rem;
    }
}

/* ─── 640px: Large phones ─── */
@media (max-width: 640px) {
    /* Chat container */
    .chat-container {
        height: 100dvh;
        height: -webkit-fill-available;
    }

    /* Chats sidebar full screen on show */
    .chats-sidebar.show {
        width: 100vw !important;
        max-width: 100vw !important;
    }

    /* Sidebar header compact */
    .chats-header {
        padding: 0.65rem 0.85rem;
    }

    .chats-search {
        padding: 0.5rem 0.85rem;
    }

    /* Chat items touch targets */
    .chat-item {
        padding: 0.75rem 0.85rem;
        gap: 0.65rem;
    }

    .chat-avatar {
        width: 44px;
        height: 44px;
        font-size: 1rem;
    }

    .chat-name {
        font-size: 0.92rem;
    }

    .chat-preview {
        font-size: 0.82rem;
    }

    /* Stories bar compact */
    .stories-bar {
        min-height: 76px;
        padding: 8px;
        gap: 4px;
    }

    .story-bar-item {
        min-width: 60px;
        max-width: 60px;
    }

    .story-ring {
        width: 48px;
        height: 48px;
    }

    .story-avatar {
        width: 42px;
        height: 42px;
    }

    .story-bar-name {
        font-size: 10px;
    }

    /* Chat header compact */
    .chat-header {
        padding: 0.55rem 0.75rem;
        padding-left: 3.2rem;
        gap: 0.5rem;
    }

    .chat-header-avatar {
        width: 34px;
        height: 34px;
    }

    .chat-header-details h3 {
        font-size: 0.9rem;
    }

    .chat-header-details p {
        font-size: 0.75rem;
    }

    .chat-action-btn {
        width: 34px;
        height: 34px;
    }

    .chat-actions {
        gap: 0.3rem;
    }

    /* Messages area */
    .chat-messages {
        padding: 0.75rem 0.65rem;
        gap: 0.85rem;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        flex: 0 0 32px;
        font-size: 0.8rem;
    }

    .message-bubble {
        max-width: min(85%, calc(100% - 42px));
        padding: 0.7rem 0.95rem;
        border-radius: 14px;
    }

    .message-text {
        font-size: 0.92rem;
    }

    .message-time {
        font-size: 0.7rem;
    }

    /* Input area */
    .chat-input-area {
        padding: 0.55rem 0.65rem;
        padding-bottom: calc(0.55rem + env(safe-area-inset-bottom, 0px));
    }

    .chat-input-wrapper {
        gap: 0.4rem;
    }

    .chat-action-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .chat-send-btn {
        padding: 0.55rem 0.85rem;
        font-size: 0.85rem;
        border-radius: 10px;
    }

    /* Modals full screen on phones */
    .modal-content {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
    }

    /* Wallet / Settings panels full screen */
    .wallet-panel,
    .premium-panel,
    .settings-panel {
        width: 100vw !important;
        height: 100dvh !important;
        border-radius: 0 !important;
        max-width: 100vw !important;
    }

    /* App menu */
    .app-menu {
        width: min(320px, 90vw);
    }

    /* Channel admin panel */
    #channelAdminPanel .modal-content.channel-admin {
        max-width: 100vw;
        border-radius: 0;
        max-height: 100dvh;
    }

    /* Typing indicator */
    .typing-dots span {
        width: 3px;
        height: 3px;
    }
}

/* ─── 480px: Standard phones ─── */
@media (max-width: 480px) {
    /* Sidebar */
    .chats-header {
        padding: 0.55rem 0.75rem;
    }

    .header-action-btn {
        width: 36px;
        height: 36px;
    }

    /* Chat type tabs scroll */
    .chat-type-tabs {
        padding: 0.4rem 0.75rem;
        gap: 0.3rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .chat-type-tabs::-webkit-scrollbar {
        display: none;
    }

    .chat-type-tab {
        padding: 0.4rem 0.75rem;
        font-size: 0.82rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Search input */
    .search-input {
        padding: 0.65rem 0.85rem;
        font-size: 0.88rem;
        border-radius: 10px;
    }

    /* Messages */
    .message-bubble {
        max-width: min(88%, calc(100% - 38px));
        padding: 0.65rem 0.85rem;
    }

    .message-text {
        font-size: 0.9rem;
        line-height: 1.45;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        flex: 0 0 28px;
        font-size: 0.75rem;
    }

    .message {
        gap: 0.5rem;
    }

    /* Voice messages compact */
    .message-voice {
        min-width: 140px;
        max-width: 260px;
    }

    /* Video notes smaller */
    .message-video-note {
        width: min(180px, 60vw);
    }

    /* Input area compact */
    .chat-input-wrapper {
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .chat-input-actions {
        width: 100%;
        justify-content: flex-start;
        order: 1;
        gap: 0.25rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .chat-input {
        order: 2;
        flex: 1 1 0;
        min-width: 0;
    }

    .chat-send-btn {
        order: 3;
        padding: 0.5rem 0.75rem;
        font-size: 0.82rem;
    }

    /* Pending attachments compact */
    .pending-attachment {
        max-width: 200px;
    }

    .pending-attachment-thumb {
        width: 36px;
        height: 36px;
    }

    /* Reply preview compact */
    .reply-preview {
        padding: 0.6rem 0.75rem;
    }

    .reply-preview-text {
        font-size: 0.8rem;
        max-width: 200px;
    }

    /* Reaction grid */
    .reaction-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 0.5rem;
    }

    .reaction-item {
        width: 42px;
        height: 42px;
        font-size: 1.5rem;
        border-radius: 10px;
    }

    /* Quick reaction bar */
    .quick-reaction-btn {
        font-size: 1.25rem;
        padding: 0.15rem 0.25rem;
    }

    /* Checklist compact */
    .message-checklist {
        min-width: 160px;
    }

    .checklist-title {
        font-size: 0.88rem;
    }

    .checklist-item {
        font-size: 0.82rem;
    }

    /* Gift messages compact */
    .message-gift {
        width: min(220px, 85%);
        padding: 2.8rem 0.9rem 0.85rem;
    }

    /* Keyboard buttons */
    .keyboard-button {
        min-width: 60px;
        padding: 0.45rem 0.7rem;
        font-size: 0.82rem;
    }

    .reply-keyboard-button {
        min-width: 70px;
        padding: 0.5rem 0.7rem;
        font-size: 0.82rem;
    }

    /* Directory modal */
    .directory-modal .directory-content {
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }

    /* Folder management */
    .folder-hero {
        flex-direction: column;
        align-items: flex-start;
    }

    .folder-list-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .folder-list-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ─── 380px: Very small phones (iPhone SE 1st/2nd gen) ─── */
@media (max-width: 380px) {
    /* Mobile nav button smaller */
    .mobile-nav-btn {
        width: 38px;
        height: 38px;
        font-size: 18px;
        border-radius: 10px;
    }

    /* Chat items tighter */
    .chat-item {
        padding: 0.6rem 0.65rem;
        gap: 0.5rem;
    }

    .chat-avatar {
        width: 38px;
        height: 38px;
        font-size: 0.9rem;
    }

    .chat-name {
        font-size: 0.88rem;
    }

    .chat-preview {
        font-size: 0.78rem;
    }

    /* Messages tighter */
    .chat-messages {
        padding: 0.5rem 0.45rem;
        gap: 0.7rem;
    }

    .message-bubble {
        max-width: 90%;
        padding: 0.55rem 0.75rem;
        border-radius: 12px;
    }

    .message-text {
        font-size: 0.87rem;
        line-height: 1.4;
    }

    .message-avatar {
        width: 26px;
        height: 26px;
        flex: 0 0 26px;
        font-size: 0.7rem;
    }

    .message {
        gap: 0.35rem;
    }

    /* Smaller buttons */
    .chat-action-btn {
        width: 30px;
        height: 30px;
    }

    .chat-header-avatar {
        width: 30px;
        height: 30px;
    }

    .header-action-btn {
        width: 34px;
        height: 34px;
    }

    /* Input area very compact */
    .chat-input-area {
        padding: 0.4rem 0.5rem;
        padding-bottom: calc(0.4rem + env(safe-area-inset-bottom, 0px));
    }

    .chat-action-icon {
        width: 32px;
        height: 32px;
        font-size: 0.95rem;
    }

    /* Stories bar very compact */
    .stories-bar {
        min-height: 68px;
        padding: 6px;
        gap: 3px;
    }

    .story-bar-item {
        min-width: 54px;
        max-width: 54px;
    }

    .story-ring {
        width: 42px;
        height: 42px;
    }

    .story-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .story-bar-name {
        font-size: 9px;
        max-width: 52px;
    }

    .story-add-badge {
        width: 16px;
        height: 16px;
        font-size: 11px;
    }

    /* Folder rail hide on very small screens */
    .folders-rail {
        width: 56px;
    }

    .folder-rail-item {
        width: 48px;
    }

    .folder-rail-icon {
        width: 30px;
        height: 30px;
        font-size: 0.85rem;
    }

    .folder-rail-label {
        font-size: 0.58rem;
    }

    /* Modals compact padding */
    .modal-header {
        padding: 0.75rem;
    }

    .modal-header h2 {
        font-size: 1.15rem;
    }

    .modal-body {
        padding: 0.75rem;
    }

    /* Settings compact */
    .settings-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .settings-tabs::-webkit-scrollbar {
        display: none;
    }

    .settings-tab {
        white-space: nowrap;
        flex-shrink: 0;
        padding: 0.35rem 0.75rem;
        font-size: 0.78rem;
    }
}

/* ─── 320px: Absolute minimum (old small phones) ─── */
@media (max-width: 320px) {
    .chat-messages {
        padding: 0.4rem 0.35rem;
    }

    .message-bubble {
        max-width: 92%;
        padding: 0.5rem 0.65rem;
    }

    .message-text {
        font-size: 0.85rem;
    }

    .message-avatar {
        width: 24px;
        height: 24px;
        flex: 0 0 24px;
        font-size: 0.65rem;
    }

    /* Hide folders rail on tiny screens */
    .folders-rail {
        display: none;
    }

    /* Chats header minimal */
    .chats-header {
        padding: 0.45rem 0.55rem;
    }

    .user-avatar {
        width: 32px;
        height: 32px;
    }

    .user-info h3 {
        font-size: 0.88rem;
    }

    /* Stories extremely compact */
    .stories-bar {
        min-height: 60px;
        padding: 4px;
    }

    .story-bar-item {
        min-width: 48px;
        max-width: 48px;
    }

    .story-ring {
        width: 38px;
        height: 38px;
    }

    .story-avatar {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   LOGIN / REGISTER PAGES — Mobile Adaptation
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    body.login-page {
        padding: 16px 12px;
        align-items: flex-start;
        padding-top: calc(24px + env(safe-area-inset-top, 0px));
    }

    .login-card {
        padding: 1.75rem 1.5rem;
        border-radius: 18px;
    }

    .login-heading {
        font-size: 1.5rem;
        letter-spacing: -0.2px;
    }

    .login-subheading {
        font-size: 0.88rem;
        margin-bottom: 1.5rem;
    }

    .login-brand-icon {
        width: 40px;
        height: 40px;
        border-radius: 10px;
    }

    .login-brand-name {
        font-size: 1.1rem;
    }

    .login-input {
        height: 50px;
        padding: 0 14px;
        border-radius: 12px;
    }

    .login-submit {
        height: 50px;
        border-radius: 12px;
        font-size: 0.95rem;
    }

    .form-label {
        font-size: 0.88rem;
    }

    .login-terms {
        font-size: 0.82rem;
    }
}

@media (max-width: 380px) {
    body.login-page {
        padding: 12px 8px;
    }

    .login-card {
        padding: 1.5rem 1.25rem;
        border-radius: 16px;
    }

    .login-heading {
        font-size: 1.35rem;
    }

    .login-subheading {
        font-size: 0.82rem;
        margin-bottom: 1.25rem;
    }

    .login-input {
        height: 46px;
        font-size: 0.95rem;
    }

    .login-submit {
        height: 46px;
        font-size: 0.9rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   BOT IDE — Mobile Adaptation
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .ide-main {
        flex-direction: column;
    }

    .ide-activitybar {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--ide-border, #333);
        padding: 6px 8px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .ide-activitybar::-webkit-scrollbar {
        display: none;
    }

    .ide-sidebar {
        width: 100% !important;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--ide-border, #333);
    }

    .ide-sidebar.collapsed {
        max-height: 0;
        display: none;
    }

    .ide-editor-area {
        flex: 1;
        min-height: 0;
    }

    /* Toolbar wrap */
    .ide-toolbar {
        flex-wrap: wrap;
        gap: 8px;
    }

    .ide-toolbar-group {
        flex-wrap: wrap;
    }

    /* Bottom panel */
    .ide-bottom-panel {
        max-height: 35vh;
    }
}

@media (max-width: 480px) {
    .ide-titlebar {
        padding: 0 8px;
        font-size: 0.8rem;
    }

    .ide-sidebar {
        max-height: 35vh;
    }

    .activity-btn {
        width: 36px;
        height: 36px;
    }

    /* AI panel */
    .ai-composer textarea {
        font-size: 0.85rem;
        min-height: 32px;
    }

    .ai-message {
        font-size: 0.8rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   ADMIN PAGES — Mobile Adaptation
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    .admin-container,
    .admin-panel {
        padding: 0.75rem;
    }

    .admin-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    .admin-sidebar.show {
        transform: translateX(0);
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   LANDSCAPE ORIENTATION — Adjustments
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-height: 500px) and (orientation: landscape) {
    /* Chat input area stays visible */
    .chat-input-area {
        padding: 0.35rem 0.65rem;
        padding-bottom: calc(0.35rem + env(safe-area-inset-bottom, 0px));
    }

    /* Compact messages in landscape */
    .chat-messages {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .message-bubble {
        padding: 0.5rem 0.75rem;
    }

    /* Compact header */
    .chat-header {
        padding: 0.35rem 0.75rem;
        min-height: 44px;
    }

    .chat-header-avatar {
        width: 28px;
        height: 28px;
    }

    /* Hide stories in landscape */
    .stories-bar {
        display: none;
    }

    /* Sidebar compact */
    .chats-header {
        padding: 0.35rem 0.75rem;
    }

    .chat-item {
        padding: 0.5rem 0.75rem;
    }

    /* Story viewer landscape */
    .story-viewer {
        max-width: 60vh;
        flex-direction: row;
    }

    /* Login page landscape */
    .login-card {
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   DARK/LIGHT THEME MOBILE ADJUSTMENTS
   ═══════════════════════════════════════════════════════════════════════ */

/* Better contrast on small screens in light mode */
@media (max-width: 640px) {
    body[data-theme="light"] .message.received .message-bubble {
        border-color: rgba(0, 0, 0, 0.08);
    }

    body[data-theme="light"] .chat-item:hover {
        background: rgba(0, 0, 0, 0.04);
    }

    body[data-theme="light"] .mobile-nav-btn {
        background: rgba(0, 0, 0, 0.06);
        color: var(--text-primary);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    body[data-theme="light"] .mobile-hamburger {
        background: rgba(0, 0, 0, 0.05);
        color: var(--text-primary);
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   PRINT — Hide non-essential elements
   ═══════════════════════════════════════════════════════════════════════ */

@media print {
    .mobile-nav-btn,
    .mobile-hamburger,
    .mobile-nav-overlay,
    .mobile-nav-drawer,
    .sidebar-overlay,
    .app-menu,
    .app-menu-overlay,
    .chat-input-area,
    .stories-bar,
    .chats-sidebar {
        display: none !important;
    }

    .chat-main {
        width: 100% !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   ANIMATIONS — Reduced motion preference
   ═══════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .mobile-nav-drawer,
    .chats-sidebar,
    .app-menu {
        transition: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   HIGH RESOLUTION DISPLAYS — Thin borders
   ═══════════════════════════════════════════════════════════════════════ */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {
    .chat-item,
    .message-bubble,
    .modal-content {
        border-width: 0.5px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   PWA STANDALONE MODE — Extra full-screen handling
   ═══════════════════════════════════════════════════════════════════════ */

@media (display-mode: standalone) {
    body {
        overscroll-behavior: none;
    }

    .site-header {
        padding-top: env(safe-area-inset-top, 0px);
    }

    .chat-container {
        height: 100dvh;
    }

    .chat-input-area {
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   NOTCHED PHONES (iPhone X+, Android with cutouts) — Safe areas
   ═══════════════════════════════════════════════════════════════════════ */

@supports (padding: max(0px)) {
    .chat-header {
        padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
    }

    .chat-input-area {
        padding-left: max(0.65rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.65rem, env(safe-area-inset-right, 0px));
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
    }

    .chats-sidebar {
        padding-left: env(safe-area-inset-left, 0px);
    }

    .mobile-nav-btn {
        top: max(12px, env(safe-area-inset-top, 12px));
        left: max(12px, env(safe-area-inset-left, 12px));
    }
}
