/* ============================================
   PROPELLERDECK MOBILE RESPONSIVE STYLES
   ============================================
   This file contains all mobile-specific styles
   and responsive overrides for PropellerDeck
   ============================================ */

/* ============================================
   1. CSS CUSTOM PROPERTIES & BREAKPOINTS
   ============================================ */
:root {
    /* Breakpoint Variables */
    --mobile-sm: 375px;
    /* iPhone SE, small phones */
    --mobile-md: 428px;
    /* Standard phones */
    --tablet: 768px;
    /* Tablets */
    --desktop: 1024px;
    /* Desktop */

    /* Mobile Spacing */
    --mobile-padding-sm: 8px;
    --mobile-padding-md: 12px;
    --mobile-padding-lg: 16px;
    --mobile-gap: 10px;

    /* Touch Targets */
    --touch-target-min: 44px;
    --touch-target-recommended: 48px;
}

/* ============================================
   2. MOBILE-FIRST BASE STYLES
   ============================================ */
@media (max-width: 768px) {

    /* Prevent horizontal scroll */
    html,
    body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* Smooth scrolling for touch */
    * {
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent zoom on input focus (iOS) */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important;
        /* Prevents iOS zoom */
    }
}

/* ============================================
   3. FLUID TYPOGRAPHY
   ============================================ */
/* Desktop to Mobile scaling */
@media (max-width: 1024px) {

    h1,
    .true-h1 {
        font-size: clamp(1.5rem, 5vw + 0.5rem, 2rem);
    }

    h2 {
        font-size: clamp(1.25rem, 4vw + 0.4rem, 1.5rem);
    }

    h3 {
        font-size: clamp(1.1rem, 3vw + 0.3rem, 1.25rem);
    }

    body,
    p {
        font-size: clamp(0.875rem, 2vw + 0.2rem, 1rem);
    }

    .chat-bubble,
    .llm {
        font-size: clamp(0.875rem, 2vw + 0.2rem, 0.95rem);
    }

    #topbar-logo {
        font-size: 16px;
    }
}

/* ============================================
   4. HAMBURGER MENU & OVERLAY
   ============================================ */
/* Hamburger Button - Hidden on Desktop */
.mobile-menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-around;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    z-index: 1001;
    transition: transform 0.3s ease;
}

.mobile-menu-toggle span {
    width: 100%;
    height: 3px;
    background-color: var(--color-text);
    border-radius: 2px;
    transition: all 0.3s ease;
}

/* Show hamburger on mobile */
@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
    }
}

/* Hamburger Animation when menu is open */
.mobile-menu-toggle.active span:nth-child(1) {
    transform: translateY(9px) rotate(45deg);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: translateY(-9px) rotate(-45deg);
}

/* Mobile Menu Overlay */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

/* ============================================
   5. TOPBAR MOBILE STYLES
   ============================================ */
@media (max-width: 768px) {
    .topbar {
        grid-template-columns: auto 1fr auto;
        grid-template-areas: "menu left nav";
        padding: 0.4rem 0.75rem;
        height: 44px;
    }

    .mobile-menu-toggle {
        grid-area: menu;
        margin-right: 0.5rem;
    }

    .topbar__left {
        grid-area: left;
    }

    #topbar-logo {
        font-size: 16px;
    }

    .topbar__nav {
        grid-area: nav;
        gap: 0.5rem;
    }

    .topbar__profile-pic {
        width: 28px;
        height: 28px;
    }

    .topbar__item {
        padding: 0 0.5rem;
    }

    /* Hide org name on mobile to save space */
    .product-selector__org-name {
        display: none;
    }

    /* Hide version badge text on very small screens */
    @media (max-width: 400px) {
        #version-badge {
            display: none;
        }
    }
}

/* ============================================
   6. SIDEBAR MOBILE BEHAVIOR
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 60px;
        /* Below topbar */
        left: 0;
        width: 280px;
        height: calc(100vh - 60px);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
        overflow-y: auto;
    }

    /* Sidebar visible when menu is open */
    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Always show text in mobile sidebar */
    .sidebar .sidebar__text {
        opacity: 1;
    }

    /* Disable hover expand on mobile */
    .sidebar:hover {
        width: 280px;
    }

    /* Make dropdown arrows always visible */
    .sidebar__dropdown-header .dropdown-icon {
        opacity: 1;
    }
}

/* Tablet: Collapsible but not slide-out */
@media (min-width: 769px) and (max-width: 1023px) {
    .sidebar {
        width: 60px;
    }

    .sidebar:hover {
        width: 240px;
    }
}

/* ============================================
   7. CONTENT AREA MOBILE LAYOUT
   ============================================ */
@media (max-width: 768px) {
    .content {
        padding: var(--mobile-padding-md);
        grid-area: content;
    }

    .content__section {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        grid-template-areas:
            "workflow-management"
            "llmchat";
        gap: 1rem;
        height: auto;
        max-height: none;
    }

    /* Hide divider on mobile */
    .divider {
        display: none;
    }

    /* Full width components */
    .workflow-management,
    .llmchat {
        width: 100%;
        max-height: 50vh;
        overflow-y: auto;
    }
}

/* ============================================
   8. CHAT INTERFACE MOBILE
   ============================================ */
@media (max-width: 768px) {
    .chat-window {
        padding-bottom: 1rem;
    }

    .chat-bubble {
        max-width: 90%;
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    .llm {
        font-size: 0.9rem;
        padding: 8px;
    }

    /* Input container */
    .input-container {
        flex-wrap: wrap;
        gap: 8px;
    }

    .input-wrapper {
        flex: 1 1 100%;
        min-width: 0;
    }

    .chat-input {
        font-size: 1rem;
        padding: 10px 14px;
        min-height: var(--touch-target-min);
    }

    .send-button {
        min-width: var(--touch-target-min);
        min-height: var(--touch-target-min);
        padding: 12px 18px;
        font-size: 1rem;
    }

    .upload_button {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    /* Cancel run button repositioning */
    .cancel-run-button-wrapper {
        bottom: 4rem;
        left: 0.5rem;
    }

    .cancel-run-button {
        width: 36px;
        height: 36px;
    }
}

/* ============================================
   9. TABLES RESPONSIVE
   ============================================ */
@media (max-width: 768px) {

    /* Add horizontal scroll wrapper */
    .user-dashboard__table-container,
    .workflows-table-container,
    .workspaces-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Minimum width to prevent squishing */
    .user-dashboard__table,
    .workflows-table,
    .workspaces-table {
        min-width: 600px;
    }

    /* Reduce padding in table cells */
    .user-dashboard__table th,
    .user-dashboard__table td,
    .workflows-table th,
    .workflows-table td,
    .workspaces-table th,
    .workspaces-table td {
        padding: 0.6rem 0.4rem;
        font-size: 0.85rem;
    }

    /* Stack action buttons */
    .workspace-actions,
    .credential-row {
        flex-direction: column;
        gap: 0.3rem;
    }
}

/* ============================================
   10. MODALS MOBILE OPTIMIZATION
   ============================================ */
@media (max-width: 768px) {

    .modal-content,
    #newChatModal .settings-modal-content,
    .changelog-modal-content {
        width: 95vw;
        max-width: 95vw;
        max-height: 90vh;
        padding: 15px;
        margin: 20px auto;
    }

    .modal-header h2,
    #newChatModal .modal-header h2 {
        font-size: 1.25rem;
    }

    /* Larger close button for touch */
    .close,
    .changelog-modal-close,
    #newChatModal .close {
        font-size: 32px;
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Full-width modal buttons */
    .modal-footer button,
    #newChatModal .modal-footer button {
        flex: 1;
        min-width: 0;
    }
}

/* ============================================
   11. FORMS MOBILE LAYOUT
   ============================================ */
@media (max-width: 768px) {

    /* Stack form grids vertically */
    #create-user-form,
    #edit-user-form {
        grid-template-columns: 1fr;
        gap: 0.8rem;
    }

    /* Full width inputs */
    .form-group input,
    .form-group select,
    .form-group textarea,
    .settings-select,
    .settings-input {
        width: 100%;
        min-height: var(--touch-target-min);
        font-size: 1rem;
        padding: 12px;
    }

    /* Larger submit buttons */
    .form-group input[type="submit"],
    .btn,
    .btn-primary,
    .btn-secondary {
        min-height: var(--touch-target-recommended);
        padding: 12px 20px;
        font-size: 1rem;
    }
}

/* ============================================
   12. SETTINGS PAGE MOBILE
   ============================================ */
@media (max-width: 768px) {
    .settings-container {
        flex-direction: column;
    }

    .settings-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        padding: 1rem 0;
    }

    .settings-nav {
        flex-direction: row;
        overflow-x: auto;
        padding: 0 0.5rem;
        gap: 0.3rem;
    }

    .settings-nav-item {
        flex-shrink: 0;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .settings-content {
        padding: 1rem;
    }

    .settings-card-content {
        padding: 1rem;
    }

    /* Profile picture section */
    .profile-picture-section {
        flex-direction: column;
        align-items: flex-start;
    }

    .profile-preview {
        width: 100px;
        height: 100px;
    }

    /* Credential inputs stack */
    .credential-input-group {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .credential-values {
        flex-direction: column;
        width: 100%;
    }
}

/* ============================================
   13. ADMIN DASHBOARD MOBILE
   ============================================ */
@media (max-width: 768px) {
    .stats-overview-container {
        flex-direction: column;
        gap: 0.75rem;
    }

    .stats-overview {
        padding: 1rem;
    }

    .widget-container {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .admin-content {
        flex-direction: column;
    }

    .admin-sidebar {
        width: 100%;
        transform: none;
        position: relative;
        box-shadow: none;
        border-bottom: 1px solid var(--color-border);
        height: auto;
        left: 0;
        top: 0;
    }

    .admin-main-content {
        margin-left: 0;
    }

    .admin-menu {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        padding: 0.5rem 0;
    }

    .admin-menu li {
        margin-bottom: 0;
        margin-right: 0.5rem;
        flex-shrink: 0;
    }
}

/* ============================================
   14. TOUCH OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {

    /* Minimum touch target sizes */
    a,
    button,
    .sidebar__link,
    .topbar__link {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Touch feedback */
    button:active,
    a:active,
    .sidebar__link:active {
        opacity: 0.7;
        transform: scale(0.98);
    }

    /* Prevent accidental text selection */
    .topbar,
    .sidebar,
    .footer {
        -webkit-user-select: none;
        user-select: none;
    }

    /* Better touch scrolling */
    .chat-window,
    .sidebar__nav,
    .settings-nav,
    .admin-menu {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* ============================================
   15. WORKFLOW CREATOR MOBILE
   ============================================ */
@media (max-width: 768px) {
    .reactflow-wrapper {
        height: 60vh;
    }

    .reactflow-controls .btn {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
        font-size: 1.1rem;
    }

    /* Touch-friendly node selection */
    .react-flow__node {
        min-width: 120px;
        min-height: 60px;
    }
}

/* ============================================
   16. FILE BROWSER MOBILE
   ============================================ */
@media (max-width: 768px) {
    .file-browser-content {
        flex-direction: column;
    }

    .file-browser-sidebar {
        width: 100%;
        max-height: 30vh;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }

    .folder-item {
        padding: 8px;
        min-height: var(--touch-target-min);
    }

    .breadcrumb {
        font-size: 0.85rem;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* ============================================
   17. FOOTER MOBILE
   ============================================ */
@media (max-width: 768px) {
    .footer {
        padding: 0.5rem;
        font-size: 0.75rem;
    }

    .footer__text {
        font-size: 0.75rem;
    }
}

/* ============================================
   18. UTILITY CLASSES
   ============================================ */
@media (max-width: 768px) {
    .mobile-hide {
        display: none !important;
    }

    .mobile-show {
        display: block !important;
    }

    .mobile-full-width {
        width: 100% !important;
    }

    .mobile-stack {
        flex-direction: column !important;
    }
}

/* ============================================
   19. LANDSCAPE ORIENTATION
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    .topbar {
        height: 50px;
    }

    .sidebar {
        top: 50px;
        height: calc(100vh - 50px);
    }

    /* Reduce vertical padding in landscape */
    .content {
        padding: 8px 12px;
    }
}

/* ============================================
   20. VERY SMALL SCREENS (< 375px)
   ============================================ */
@media (max-width: 374px) {
    #topbar-logo {
        font-size: 14px;
    }

    .topbar {
        padding: 0.5rem;
    }

    .content {
        padding: 8px;
    }

    .chat-bubble {
        max-width: 95%;
        font-size: 0.85rem;
    }
}

@media (max-width: 768px) {
    .cancel-run-button-wrapper {
        position: fixed !important;
        bottom: 70px !important;        /* Above input area */
        left: 15px !important;          /* Left side with padding */
        right: auto !important;
        z-index: 9999 !important;       /* Very high to stay on top */
    }
    
    .cancel-run-button-wrapper.active {
        display: block !important;
    }
    
    .cancel-run-button-wrapper .indicator-container {
        display: flex !important;
        padding: 5px 10px !important;
        gap: 8px !important;
        border-radius: 18px !important;
        background: var(--color-surface) !important;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4) !important;
        align-items: center !important;
    }
    
    .cancel-run-button-wrapper .crb-border {
        width: 26px !important;
        height: 26px !important;
    }
    
    .cancel-run-button-wrapper .cancel-run-button {
        width: 20px !important;
        height: 20px !important;
        font-size: 11px !important;
    }
    
    .cancel-run-button-wrapper .status-text {
        font-size: 11px !important;
        font-weight: 600 !important;
        white-space: nowrap !important;
    }

    .content__section.mobile-accordion-container {
        height: calc(100vh - 60px) !important;
        overflow: hidden;
    }

    .mobile-accordion-container {
        display: flex !important;
        flex-direction: column !important;
        gap: 0 !important;
        grid-template-columns: none !important;
        height: 100% !important;
        overflow: hidden !important;
    }

    .mobile-panel {
        width: 100%;
        position: relative;
        border-bottom: 1px solid var(--color-border);
        transition: all 0.3s ease;
        display: flex;
        flex-direction: column;
        flex: 1 1 0;
        min-height: 0;
    }

    .mobile-panel.collapsed {
        flex: 0 0 28px !important;
        min-height: 28px;
        max-height: 28px;
        overflow: hidden !important;
    }

    .mobile-panel-banner {
        background: var(--color-surface);
        border-bottom: 1px solid var(--color-border);
        padding: 8px 8px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        min-height: 28px;
        max-height: 28px;
        flex-shrink: 0;
    }

    .mobile-panel.collapsed .mobile-panel-banner {
        border-bottom: none;
    }

    .mobile-collapse-btn {
        background: transparent;
        border: none;
        color: var(--color-text-muted);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 20px;
        height: 20px;
        padding: 0;
        transition: all 0.2s ease;
    }

    .mobile-collapse-btn:hover {
        color: var(--color-accent);
        transform: scale(1.15);
    }

    .mobile-collapse-btn:active {
        transform: scale(0.9);
    }

    .mobile-collapse-btn i {
        font-size: 14px;
        transition: transform 0.3s ease;
    }

    .mobile-panel.collapsed .mobile-collapse-btn i {
        transform: rotate(180deg);
    }

    .mobile-panel-content {
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-x: hidden;
        transition: all 0.3s ease;
        display: flex;
        flex-direction: column;
        min-height: 0;
        height: 100%;
    }

    .mobile-panel.collapsed .mobile-panel-content {
        flex: 0 0 0;
        overflow: hidden;
        opacity: 0;
        min-height: 0 !important;
        max-height: 0 !important;
    }

    .mobile-accordion-container .divider {
        display: none !important;
    }

    #llmchat.llmchat,
    .mobile-panel-content>#llmchat,
    .mobile-panel-content>.llmchat,
    .mobile-panel-content .llmchat {
        height: 100% !important;
        max-height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        padding: 10px 6% !important;
    }

    #llmchat .chat-window,
    .mobile-panel-content .chat-window,
    .llmchat .chat-window {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        min-height: 0 !important;
        height: auto !important;
        max-height: none !important;
        margin-bottom: 1rem !important;
    }

    #llmchat .input-container,
    .mobile-panel-content .input-container,
    .llmchat .input-container {
        flex-shrink: 0 !important;
        margin-top: auto !important;
    }

    #llmchat .llmchat_header,
    .mobile-panel-content .llmchat_header,
    .llmchat .llmchat_header {
        flex-shrink: 0 !important;
    }

}

@media (min-width: 769px) {
    .mobile-panel-banner {
        display: none !important;
    }

    .mobile-collapse-btn {
        display: none !important;
    }

    .mobile-panel {
        display: contents;
    }

    .mobile-panel-content {
        display: contents;
    }

    .content__section.mobile-accordion-container {
        height: calc(100vh - 120px);
    }
}