/* ============================================================
   Mobile — Responsive styles for tablet and mobile viewports
   ============================================================ */

/* ── Tablet Sidebar Toggle ────────────────────────────────── */

.tablet-sidebar-toggle {
    display: none !important;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    align-items: center;
    margin-right: 4px;
    transition: color 0.15s, background 0.15s;
}

.tablet-sidebar-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* ── Mobile Bottom Tab Bar ────────────────────────────────── */

.mobile-tab-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    z-index: 100;
    padding: 0;
    justify-content: space-around;
    align-items: center;
}

.mobile-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    flex: 1;
    font-size: 10px;
    font-family: inherit;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.mobile-tab svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.5;
}

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

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

/* Badge on mobile tab */
.mobile-tab-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 16px);
    background: var(--accent);
    color: var(--bg-primary);
    border-radius: 8px;
    font-size: 9px;
    font-weight: 700;
    min-width: 14px;
    height: 14px;
    line-height: 14px;
    text-align: center;
    padding: 0 3px;
}

/* ── Mobile-only overflow menu items (hidden on desktop) ── */

.mobile-overflow-only {
    display: none !important;
}

/* ── Mobile Send Button (hidden on desktop) ──────────────── */

.mobile-send-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.mobile-send-btn:active {
    opacity: 0.8;
    transform: scale(0.95);
}

/* ── Mobile Agent List (full screen) ──────────────────────── */

.mobile-agent-list {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-agent-list .session-list {
    padding-bottom: 60px; /* space for bottom tab bar */
}

/* ── Mobile Back Button ───────────────────────────────────── */

.mobile-back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    font-size: 18px;
    line-height: 1;
    margin-right: 4px;
}

/* ── Tablet: ≤ 1023px ─────────────────────────────────────── */

@media (max-width: 1023px) {
    /* Hide agentic state panel on tablet */
    .agentic-state-panel,
    .task-bar-resize-handle {
        display: none !important;
    }

    /* Sidebar collapsible overlay on tablet */
    .sidebar {
        width: 280px;
        min-width: 280px;
        position: fixed;
        top: 49px;
        left: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: none;
    }

    .sidebar.tablet-open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    /* Hide resize handle on tablet */
    .sidebar-resize-handle {
        display: none !important;
    }

    /* Show hamburger toggle on tablet */
    .tablet-sidebar-toggle {
        display: flex !important;
    }

    /* Overlay backdrop when sidebar is open */
    .tablet-sidebar-backdrop {
        display: none;
        position: fixed;
        top: 49px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 49;
    }

    .tablet-sidebar-backdrop.active {
        display: block;
    }

    /* Command pane more compact */
    .command-pane {
        height: 200px !important;
    }
}

/* ── Mobile: ≤ 767px ──────────────────────────────────────── */

@media (max-width: 767px) {
    /* Thinner scrollbar on mobile */
    ::-webkit-scrollbar {
        width: 3px;
    }

    /* Show bottom tab bar */
    .mobile-tab-bar {
        display: flex;
    }

    /* Hide desktop/tablet elements */
    .sidebar,
    .sidebar-resize-handle,
    .tablet-sidebar-toggle,
    .tablet-sidebar-backdrop {
        display: none !important;
    }

    .top-bar {
        padding: 8px 12px;
    }

    .top-bar h1 {
        font-size: 14px;
    }

    /* Adjust layout for bottom bar */
    .layout {
        height: calc(100vh - 49px - 56px); /* subtract top bar + bottom tab bar */
    }

    .main-content {
        width: 100%;
    }

    /* Show mobile agent list view */
    .mobile-agent-list {
        display: flex;
    }

    /* Show mobile back button in session header */
    .mobile-back-btn {
        display: inline-flex;
    }

    /* Live session view adjustments */
    .live-body {
        flex-direction: column !important;
    }

    .agentic-state-panel,
    .task-bar-resize-handle {
        display: none !important;
    }

    /* Command pane: compact sticky input bar at bottom on mobile */
    .command-pane {
        max-height: none !important;
        height: auto !important;
        min-height: 0 !important;
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        z-index: 10;
        border-top: 1px solid var(--border);
    }

    /* Hide toolbar (macros, nav keys, mode buttons) on mobile */
    .command-pane-toolbar {
        display: none !important;
    }

    /* Compact input body: single row with send button inline */
    .command-pane-body {
        padding: 6px 8px !important;
        gap: 6px;
        align-items: flex-end;
    }

    .command-pane textarea {
        min-height: 36px !important;
        max-height: 80px;
        font-size: 16px !important; /* prevent iOS zoom on focus */
        padding: 7px 12px;
        border-radius: 18px;
    }

    .command-hint {
        display: none !important;
    }

    /* Send button group is always visible; ensure it shows on mobile too */
    .command-pane .send-btn-group {
        display: flex;
    }

    .command-pane-resize-handle {
        display: none !important;
    }

    /* Capture pane scroll speed fix — enable momentum scrolling */
    .output-scroll,
    .xterm-container {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* Hide tab bar when virtual keyboard is open */
    body.keyboard-open .mobile-tab-bar {
        display: none !important;
    }

    body.keyboard-open .layout {
        height: calc(100vh - 49px); /* full height minus top bar only */
    }

    /* Session header: single compact row on mobile */
    .session-header {
        padding: 6px 10px !important;
        flex-wrap: nowrap;
        gap: 0;
    }

    .session-header h2 {
        font-size: 14px !important;
    }

    /* Hide branch, badge, status — keep Goal as single truncated line */
    .session-title #session-branch,
    .session-title #session-type-badge,
    .session-meta {
        display: none !important;
    }

    /* Goal: show text but hide action buttons, compact font */
    .session-title #session-summary .goal-action-btn {
        display: none !important;
    }

    .session-title #session-summary .goal-label {
        font-size: 12px;
    }

    .session-title #session-summary .summary-text {
        font-size: 12px;
    }

    /* Compact title: everything on one line, goal truncates */
    .session-title {
        margin-bottom: 0 !important;
        gap: 6px !important;
        flex-wrap: nowrap;
        min-width: 0;
    }

    /* Goal fills remaining space and truncates */
    .session-title #session-summary {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        white-space: nowrap;
    }

    /* Hide the separate Attach and Restart buttons, keep only the overflow menu */
    .session-title-actions .btn-icon-label {
        display: none !important;
    }

    .session-title-actions {
        flex-shrink: 0;
    }

    /* Show Attach/Restart inside the overflow menu on mobile */
    .mobile-overflow-only {
        display: flex !important;
    }

    /* Message board adjustments */
    #mb-subscribers-panel {
        display: none !important;
    }

    #mb-board {
        padding-bottom: 0 !important;
    }

    /* Message board full-screen on mobile */
    #messageboard-view {
        flex-direction: column;
    }

    #messageboard-view .session-header {
        flex-wrap: wrap;
    }

    #messageboard-view .view-body {
        flex: 1;
        min-height: 0;
    }

    /* Board message bubbles: compact on mobile */
    .mb-message {
        margin-bottom: 8px !important;
        padding: 8px 10px !important;
    }

    /* Board input area — lift above bottom tab bar */
    #mb-board {
        padding-bottom: 60px !important;
    }

    #mb-post-input {
        font-size: 16px !important; /* prevent iOS zoom on focus */
    }

    /* Goal/summary: single truncated line on mobile */
    .summary-line .summary-text {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: inline-block;
        max-width: calc(100% - 40px);
        vertical-align: middle;
    }

    /* Scheduler view mobile */
    .scheduler-view {
        padding: 12px !important;
    }

    .sched-header h2 {
        font-size: 15px !important;
    }

    /* Job cards stack full width */
    .sched-card {
        padding: 10px !important;
    }

    /* History session view mobile */
    #history-session-view .session-header {
        flex-wrap: wrap;
        gap: 6px;
    }

    /* Hide session ID on mobile (too long) */
    .session-header .session-id {
        display: none;
    }

    /* Hide resize handles */
    .sidebar-resize-handle,
    .command-pane-resize-handle,
    .task-bar-resize-handle,
    .agentic-block-resize-handle {
        display: none !important;
    }

    /* Welcome screen compact */
    .welcome h2 {
        font-size: 16px;
    }

    .welcome p {
        font-size: 12px;
    }

    .welcome-actions {
        gap: 8px;
    }

    .welcome-action-card {
        width: 90px;
        height: 80px;
        padding: 12px;
        font-size: 11px;
    }

    .welcome-action-card .material-icons {
        font-size: 22px;
    }

    /* History tabs scrollable */
    .history-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
    }

    /* Modal adjustments */
    .modal-content,
    .modal-content-wide,
    .modal-content-extra-wide {
        width: 95vw !important;
        max-width: 95vw !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Team columns stack vertically on mobile */
    .team-columns {
        flex-direction: column !important;
    }

    .team-col-left,
    .team-col-right {
        width: 100% !important;
        min-width: 0 !important;
    }

    /* Toolbar wrapping */
    .command-toolbar {
        flex-wrap: wrap;
    }

    .command-toolbar .btn-label {
        display: none;
    }

    /* Output container full width */
    .output-container {
        min-height: 200px;
    }

    /* Waiting banner compact */
    .waiting-banner {
        font-size: 12px !important;
        padding: 8px 12px !important;
    }

    /* View body for message board */
    .view-body {
        flex-direction: column !important;
    }
}

/* ── Pull-to-Refresh Indicator ────────────────────────────── */

.pull-refresh-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 0;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 12px;
    transition: height 0.1s ease-out;
}

/* ── Touch-friendly adjustments ───────────────────────────── */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .session-list li {
        min-height: 52px;
    }

    /* Always show kebab buttons (no hover on touch) */
    .sidebar-kebab-btn {
        opacity: 0.5 !important;
    }

    .mb-delete-msg-btn {
        opacity: 0.4 !important;
    }

    /* Larger buttons */
    .btn-small {
        min-height: 36px;
        padding: 6px 14px;
    }
}
