/* OSINT.science Mobile Responsive Styles */

/* Mobile Variables */
:root {
    --mobile-nav-height: 56px;
    --mobile-bottom-nav-height: 60px;
}

/* ============================================
   Mobile Navigation
   ============================================ */

/* Mobile Top Bar */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    padding: 0 var(--space-md);
    align-items: center;
    justify-content: space-between;
}

.mobile-header .logo {
    font-size: var(--font-size-lg);
}

.mobile-menu-btn {
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    position: relative;
    z-index: 101;
}

.mobile-menu-btn:hover {
    background: var(--bg-hover);
}

.mobile-menu-btn:active {
    background: var(--bg-tertiary);
    transform: scale(0.95);
}

/* Mobile Bottom Navigation */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-bottom-nav-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    z-index: 100;
    padding: 0;
}

.mobile-nav-items {
    display: flex;
    height: 100%;
}

.mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 10px;
    cursor: pointer;
    text-decoration: none;
    padding: 8px 4px;
}

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

.mobile-nav-item:active {
    background: var(--bg-hover);
}

.mobile-nav-icon {
    font-size: 20px;
    font-weight: bold;
}

/* Mobile Search Bar */
.mobile-search-bar {
    display: none;
    position: fixed;
    top: var(--mobile-nav-height);
    left: 0;
    right: 0;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 99;
}

.mobile-search-bar .search-input-wrapper {
    margin: 0;
}

.mobile-search-bar input {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 12px 16px;
}

.mobile-search-bar .search-btn {
    padding: 12px 16px;
}

/* ============================================
   Mobile Overlay Panels
   ============================================ */

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    opacity: 1;
}

/* Mobile Panel Close Button - hidden on desktop */
.mobile-panel-close {
    display: none;
}

/* ============================================
   Responsive Breakpoints
   ============================================ */

/* Tablet - 1024px and below */
@media (max-width: 1024px) {
    :root {
        --sidebar-left-width: 240px;
        --sidebar-right-width: 220px;
    }

    .toolbar-btn .btn-text {
        display: none;
    }
}

/* Mobile - 768px and below */
@media (max-width: 768px) {
    /* Show mobile elements */
    .mobile-header,
    .mobile-bottom-nav,
    .mobile-search-bar {
        display: flex;
    }

    .mobile-more-menu,
    .mobile-account-panel,
    .mobile-notifications-panel {
        display: block;
    }

    .mobile-panel-close {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
        background: var(--bg-tertiary);
        border: 1px solid var(--border);
        border-radius: 50%;
        color: var(--text-primary);
        font-size: 20px;
        line-height: 1;
        z-index: 10;
        cursor: pointer;
    }

    /* Left Sidebar Mobile Panel */
    .sidebar-left.mobile-panel {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        z-index: 201;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        padding-top: 60px;
        background: var(--bg-secondary);
    }

    .sidebar-left.mobile-panel.active {
        transform: translateX(0);
    }

    /* Right Sidebar Mobile Panel */
    .sidebar-right.mobile-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        z-index: 201;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        padding-top: 60px;
        background: var(--bg-secondary);
    }

    .sidebar-right.mobile-panel.active {
        transform: translateX(0);
    }

    /* Hide desktop elements */
    .toolbar {
        display: none;
    }

    .status-bar {
        display: none;
    }

    /* Adjust main layout */
    #app {
        padding-top: calc(var(--mobile-nav-height) + 60px); /* header + search bar */
        padding-bottom: var(--mobile-bottom-nav-height);
    }

    .three-panel-layout {
        height: calc(100vh - var(--mobile-nav-height) - 60px - var(--mobile-bottom-nav-height));
        flex-direction: column;
    }

    /* Hide sidebars on mobile by default */
    .sidebar-left,
    .sidebar-right {
        display: none;
    }

    .sidebar-left.mobile-panel,
    .sidebar-right.mobile-panel {
        display: block;
    }

    /* Results panel full width */
    .results-panel {
        width: 100%;
        height: 100%;
    }

    /* Results header adjustments */
    .results-header {
        flex-direction: column;
        gap: var(--space-sm);
        padding: var(--space-sm) var(--space-md);
    }

    .results-controls {
        width: 100%;
        flex-wrap: wrap;
        gap: var(--space-sm);
    }

    .control-group {
        flex: 1;
        min-width: 120px;
    }

    .control-group select {
        width: 100%;
    }

    /* Results list adjustments */
    .results-list {
        padding: var(--space-sm);
    }

    /* Result card mobile styles */
    .result-card {
        padding: var(--space-md);
    }

    .result-title {
        font-size: var(--font-size-base);
    }

    .result-snippet {
        font-size: var(--font-size-sm);
        -webkit-line-clamp: 3;
    }

    .result-actions {
        flex-wrap: wrap;
        gap: var(--space-xs);
    }

    /* Modal adjustments */
    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: var(--space-md);
    }

    .modal-small {
        width: 95%;
    }

    /* Analysis modes wrap */
    .analysis-modes {
        flex-wrap: wrap;
    }

    .mode-btn {
        flex: 1;
        min-width: 80px;
        text-align: center;
    }

    /* Export options */
    .export-options {
        grid-template-columns: 1fr;
    }

    /* Category tree mobile */
    .category-panel {
        padding: var(--space-md);
    }

    .tree-node {
        margin-bottom: var(--space-xs);
    }

    .tree-header {
        padding: var(--space-sm);
        min-height: 44px; /* Touch target */
    }

    .tree-child {
        padding: var(--space-sm);
        min-height: 44px;
    }

    /* Quick search panel mobile */
    .quick-search {
        display: none; /* Hidden on mobile, using mobile search bar instead */
    }

    /* Panel titles */
    .panel-title {
        font-size: var(--font-size-base);
    }

    /* Task buttons larger touch targets */
    .task-btn {
        padding: var(--space-md);
        min-height: 44px;
    }

    /* Folder items */
    .folder-item {
        padding: var(--space-md);
        min-height: 44px;
    }

    /* History items */
    .history-item {
        padding: var(--space-md);
        min-height: 44px;
    }

    /* Hide certain desktop elements on mobile */
    .toolbar-center {
        display: none;
    }

    /* Placeholder adjustments */
    .results-placeholder {
        padding: var(--space-xl);
    }

    .placeholder-icon {
        width: 60px;
        height: 60px;
        font-size: 24px;
    }

    .results-placeholder h2 {
        font-size: var(--font-size-lg);
    }
}

/* Small phones - 480px and below */
@media (max-width: 480px) {
    .mobile-header {
        padding: 0 var(--space-sm);
    }

    .logo-text {
        font-size: var(--font-size-base);
    }

    .mobile-search-bar {
        padding: var(--space-xs) var(--space-sm);
    }

    .mobile-nav-item {
        font-size: 9px;
    }

    .mobile-nav-icon {
        font-size: 18px;
    }

    .results-header {
        padding: var(--space-xs) var(--space-sm);
    }

    .control-group {
        min-width: 100px;
    }

    .result-card {
        padding: var(--space-sm);
    }

    .modal-content {
        margin: var(--space-sm);
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: var(--space-md);
    }

    /* Advanced form on small screens */
    .advanced-form {
        gap: var(--space-sm);
    }

    .form-group input,
    .form-group select {
        padding: var(--space-sm);
        font-size: 16px; /* Prevent zoom */
    }
}

/* ============================================
   Touch Optimizations
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .toolbar-btn,
    .task-btn,
    .link-btn,
    .icon-btn,
    .checkbox-label {
        min-height: 44px;
        min-width: 44px;
    }

    /* Remove hover effects on touch devices */
    .toolbar-btn:hover,
    .task-btn:hover,
    .folder-item:hover,
    .history-item:hover,
    .result-card:hover {
        background: transparent;
    }

    /* Add active states instead */
    .toolbar-btn:active,
    .task-btn:active,
    .folder-item:active,
    .history-item:active {
        background: var(--bg-hover);
    }

    /* Prevent text selection on interactive elements */
    button, .task-btn, .folder-item, .history-item, .mobile-nav-item {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ============================================
   Landscape Mode Adjustments
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {
    .mobile-bottom-nav {
        height: 50px;
    }

    .mobile-nav-item {
        flex-direction: row;
        gap: 8px;
    }

    .mobile-nav-icon {
        font-size: 16px;
    }

    #app {
        padding-bottom: 50px;
    }

    .three-panel-layout {
        height: calc(100vh - var(--mobile-nav-height) - 60px - 50px);
    }

    .sidebar-left.mobile-panel,
    .sidebar-right.mobile-panel {
        width: 50%;
        max-width: 400px;
    }
}

/* ============================================
   Dark Mode Mobile Adjustments
   ============================================ */

@media (max-width: 768px) {
    body.dark-mode .mobile-header,
    body.dark-mode .mobile-bottom-nav,
    body.dark-mode .mobile-search-bar {
        background: var(--bg-secondary);
    }

    body.light-mode .mobile-header,
    body.light-mode .mobile-bottom-nav,
    body.light-mode .mobile-search-bar {
        background: var(--bg-primary);
        border-color: var(--border);
    }
}

/* ============================================
   PWA / Standalone Mode
   ============================================ */

@media (display-mode: standalone) {
    .mobile-header {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--mobile-nav-height) + env(safe-area-inset-top));
    }

    .mobile-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
    }

    #app {
        padding-top: calc(var(--mobile-nav-height) + env(safe-area-inset-top) + 60px);
        padding-bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
    }
}

/* ============================================
   Mobile Header Right Section
   ============================================ */

.mobile-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mobile-user-btn {
    position: relative;
}

.mobile-user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    pointer-events: none;
}

.mobile-user-icon {
    font-size: 16px;
    font-weight: 600;
    pointer-events: none;
}

.mobile-notif-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: var(--error);
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
    pointer-events: none;
}

.mobile-login-btn {
    padding: 8px 16px;
    background: var(--accent);
    color: white;
    border-radius: 6px;
    font-size: var(--font-size-sm);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}

/* ============================================
   Mobile More Menu
   ============================================ */

.mobile-more-menu {
    display: none;
    position: fixed;
    bottom: var(--mobile-bottom-nav-height);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    z-index: 150;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    max-height: 60vh;
    overflow-y: auto;
}

.mobile-more-menu.active {
    transform: translateY(0);
}

.mobile-more-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.mobile-more-close {
    width: 32px;
    height: 32px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
}

.mobile-more-items {
    padding: var(--space-sm);
}

.mobile-more-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    width: 100%;
    padding: var(--space-md);
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: var(--font-size-base);
    text-decoration: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
}

.mobile-more-item:active {
    background: var(--bg-hover);
}

.mobile-more-item .more-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
}

/* ============================================
   Mobile Account Panel
   ============================================ */

.mobile-account-panel,
.mobile-notifications-panel {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    background: var(--bg-secondary);
    z-index: 201;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.mobile-account-panel.active,
.mobile-notifications-panel.active {
    display: block;
    transform: translateX(0);
}

.mobile-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: var(--font-size-lg);
}

.mobile-account-content {
    padding: var(--space-md);
}

.mobile-account-user {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-tertiary);
    border-radius: 12px;
    margin-bottom: var(--space-md);
}

.account-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.account-avatar-placeholder {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
}

.account-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.account-name {
    font-weight: 600;
    color: var(--text-primary);
}

.account-email {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.account-plan {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    width: fit-content;
    margin-top: 4px;
}

.account-plan.plan-free {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.account-plan.plan-pro {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
}

.mobile-account-items {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.mobile-account-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    width: 100%;
    padding: var(--space-md);
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: var(--font-size-base);
    text-decoration: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    position: relative;
}

.mobile-account-item:active {
    background: var(--bg-hover);
}

.mobile-account-item .account-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
}

.mobile-account-item.upgrade {
    background: rgba(245, 158, 11, 0.1);
}

.mobile-account-item.upgrade .account-icon {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
}

.mobile-account-item.admin .account-icon {
    background: rgba(139, 92, 246, 0.2);
    color: #a78bfa;
}

.mobile-account-item.logout {
    color: var(--error);
}

.mobile-account-item.logout .account-icon {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.mobile-notif-badge {
    position: absolute;
    right: var(--space-md);
    background: var(--error);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* Guest content */
.mobile-guest-content {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
}

.mobile-guest-content p {
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

.mobile-signin-btn {
    display: block;
    width: 100%;
    padding: var(--space-md);
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: var(--font-size-base);
    font-weight: 500;
    text-decoration: none;
    text-align: center;
    margin-bottom: var(--space-md);
}

.mobile-register-link {
    display: block;
    color: var(--accent);
    font-size: var(--font-size-sm);
    text-decoration: none;
}

/* ============================================
   Mobile Notifications Panel
   ============================================ */

.mobile-notif-content {
    padding: var(--space-sm);
    min-height: 200px;
}

.mobile-notif-item {
    display: block;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
}

.mobile-notif-item:active {
    background: var(--bg-hover);
}

.mobile-notif-item.unread {
    background: rgba(59, 130, 246, 0.05);
    border-left: 3px solid var(--accent);
}

.mobile-notif-item .notif-title {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.mobile-notif-item .notif-preview {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.mobile-notif-item .notif-time {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: 4px;
}

.mobile-notif-footer {
    padding: var(--space-md);
    border-top: 1px solid var(--border);
}

.mark-all-read-btn {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    cursor: pointer;
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .mobile-header,
    .mobile-bottom-nav,
    .mobile-search-bar,
    .sidebar-left,
    .sidebar-right,
    .toolbar,
    .status-bar {
        display: none !important;
    }

    #app {
        padding: 0;
    }

    .results-panel {
        width: 100%;
    }

    .result-card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
