/* =============================================================================
   MOBILE RESPONSIVENESS OVERHAUL — OPT Digital Dashboard
   =============================================================================
   Comprehensive mobile fixes across all pages. Loaded after style.css to
   override where needed. Breakpoints:
     - 992px: Tablet landscape → stack layouts
     - 768px: Tablet portrait → sidebar hidden, hamburger visible
     - 576px: Phone → single column, compact UI
     - 400px: Small phone → minimal padding
   ============================================================================= */

/* ── Topbar: Condense on mobile ── */
@media (max-width: 767.98px) {
    .topbar {
        padding: 0 12px;
        height: 44px;
        gap: 6px;
    }

    /* Hide search label text, keep icon */
    .topbar-search .search-label { display: none; }

    /* Compact action buttons */
    .topbar-actions {
        gap: 4px;
    }
    .topbar-actions .btn,
    .topbar-actions button {
        padding: 4px 6px;
        font-size: 0.7rem;
    }

    /* Notification bell — tighter */
    .notification-bell-btn {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
    }
}

/* ── Sidebar: Smoother mobile experience ── */
@media (max-width: 767.98px) {
    .sidebar {
        width: 280px;
        box-shadow: 4px 0 24px rgba(0,0,0,0.2);
    }

    /* Sidebar section headers — more compact */
    .sidebar .nav-section-title {
        padding: 8px 16px 4px;
        font-size: 0.6rem;
    }

    /* Sidebar links — bigger touch targets */
    .sidebar .nav-link {
        padding: 10px 16px;
        min-height: 40px;
    }

    /* Sidebar badge counts */
    .sidebar .badge {
        font-size: 0.6rem;
        padding: 2px 6px;
    }
}

/* ── Content Brain: Tighter layout ── */
@media (max-width: 992px) {
    /* Move cards/spreadsheet toggle into detail panel header */
    .cb-view-toggle {
        position: static;
        margin-bottom: 8px;
    }
}

@media (max-width: 767.98px) {
    /* Client list sidebar — collapsible on mobile */
    .cb-sidebar {
        max-height: 200px;
        min-height: 0;
        border-bottom: 2px solid var(--border-200);
        border-right: none;
    }

    /* Client list items — more compact */
    .cb-client-item {
        padding: 8px 12px;
    }

    /* Detail panel — full width */
    .cb-main {
        min-height: auto;
    }

    /* Detail header — stack */
    .cb-detail-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    /* Detail grid cards — 2 columns min */
    .cb-detail-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
    }

    /* Detail card — compact */
    .cb-detail-card {
        padding: 10px;
    }
    .cb-detail-card .card-label {
        font-size: 0.6rem;
    }
    .cb-detail-card .card-value {
        font-size: 0.75rem;
    }

    /* View toggle bar — horizontal scroll instead of wrap */
    .view-toggle-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        padding-bottom: 4px;
    }
    .view-toggle-bar .view-toggle {
        flex-shrink: 0;
        padding: 6px 12px;
        font-size: 0.72rem;
    }
    .view-toggle-bar .btn {
        flex-shrink: 0;
    }

    /* Page title row */
    .cb-page-title-row {
        flex-direction: column;
        gap: 6px;
    }

    /* Stats bar — horizontal scroll */
    .cb-stats-bar {
        overflow-x: auto;
        flex-wrap: nowrap;
        gap: 6px;
        padding-bottom: 4px;
    }
    .cb-stats-bar .cb-stat {
        flex-shrink: 0;
        min-width: 60px;
    }
}

@media (max-width: 576px) {
    /* Sidebar becomes a thin strip showing selected client */
    .cb-sidebar {
        max-height: 150px;
    }

    /* Detail grid — single column */
    .cb-detail-grid {
        grid-template-columns: 1fr !important;
    }

    /* Tabs — scroll horizontally */
    .cb-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .cb-tabs .cb-tab {
        flex-shrink: 0;
        white-space: nowrap;
    }
}

/* ── Bot Registry: Mobile Kanban ── */
@media (max-width: 992px) {
    .br-container {
        flex-direction: column;
    }

    .br-sidebar {
        width: 100%;
        min-width: 0;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
}

@media (max-width: 767.98px) {
    /* Kanban board — single column stack */
    .br-board {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    /* Task cards — full width */
    .br-column {
        min-width: 0;
    }

    /* Usage panel — stack */
    .br-usage-panel {
        flex-direction: column;
    }

    /* Agent sidebar — collapse */
    .br-sidebar {
        max-height: 150px;
        overflow-y: auto;
    }

    /* Status tabs — scroll */
    .br-status-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .br-status-tab {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 6px 10px;
        font-size: 0.7rem;
    }

    /* Filter bar */
    .br-board-filters {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    .br-board-filters .view-toggle {
        flex-shrink: 0;
        font-size: 0.72rem;
    }

    /* Task detail panel — full screen overlay on mobile */
    .br-detail-panel,
    .br-task-detail {
        width: 100vw !important;
        max-width: 100vw !important;
        right: 0;
    }
}

@media (max-width: 576px) {
    .br-board {
        gap: 8px;
    }

    .br-task {
        padding: 10px;
    }

    .br-task-title {
        font-size: 0.75rem;
    }

    .br-task-meta {
        font-size: 0.65rem;
    }
}

/* ── Client Detail Page ── */
@media (max-width: 767.98px) {
    /* Client header — stack name and actions */
    .client-header {
        flex-direction: column;
        gap: 8px;
    }
    .client-header-actions {
        flex-wrap: wrap;
        gap: 6px;
    }

    /* Tab navigation — horizontal scroll */
    .client-tabs,
    .nav-tabs,
    .opt-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .client-tabs::-webkit-scrollbar,
    .nav-tabs::-webkit-scrollbar,
    .opt-tabs::-webkit-scrollbar {
        display: none;
    }
    .client-tabs .nav-link,
    .nav-tabs .nav-link,
    .opt-tabs .opt-tab {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 8px 12px;
    }

    /* Info grid cards */
    .client-info-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    /* Overview cards */
    .overview-card {
        padding: 12px;
    }

    /* Activity timeline */
    .activity-timeline {
        font-size: 0.75rem;
    }

    /* Action items */
    .action-item {
        padding: 10px;
    }
}

@media (max-width: 576px) {
    .client-info-grid {
        grid-template-columns: 1fr;
    }

    /* Client name — smaller */
    .client-name {
        font-size: 1.25rem;
    }
}

/* ── Overview / Dashboard Page ── */
@media (max-width: 767.98px) {
    /* KPI grids already handled in style.css */

    /* Chart containers */
    .chart-container {
        height: 200px;
        min-height: 200px;
    }

    /* Two-column layouts — stack */
    .dashboard-two-col,
    .two-col-layout {
        grid-template-columns: 1fr !important;
    }
}

/* ── GMB Management ── */
@media (max-width: 767.98px) {
    .gmb-split-panel {
        flex-direction: column;
    }

    .gmb-sidebar {
        width: 100%;
        max-height: 250px;
        border-right: none;
        border-bottom: 1px solid var(--border-200);
    }

    .gmb-detail {
        min-height: auto;
    }

    .gmb-profile-card {
        padding: 10px;
    }

    .gmb-status-sections {
        grid-template-columns: 1fr;
    }
}

/* ── Finance / Weekly Ledger ── */
@media (max-width: 767.98px) {
    .finance-grid,
    .ledger-grid {
        grid-template-columns: 1fr !important;
    }

    .finance-card,
    .ledger-card {
        padding: 12px;
    }
}

/* ── Account Managers ── */
@media (max-width: 767.98px) {
    .am-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

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

    .am-card {
        padding: 12px;
    }
}

/* ── Lifecycle ── */
@media (max-width: 767.98px) {
    .lifecycle-pipeline {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .lifecycle-stages {
        flex-wrap: nowrap;
        min-width: 600px;
    }
}

/* ── Tables: Universal mobile treatment ── */
@media (max-width: 767.98px) {
    /* All data tables get horizontal scroll */
    .table-responsive,
    .data-table-wrapper,
    [class*="table-wrap"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -12px;
        padding: 0 12px;
    }

    /* Tighter cells */
    table th,
    table td {
        padding: 6px 8px;
        font-size: 0.72rem;
    }
}

/* ── Modals: Full screen on mobile ── */
@media (max-width: 576px) {
    .modal-dialog {
        margin: 0;
        max-width: 100vw;
        min-height: 100vh;
    }

    .modal-content {
        border-radius: 0;
        min-height: 100vh;
    }

    /* OPT custom modals */
    .opt-modal {
        width: 100vw !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }
}

/* ── Forms: Mobile friendly ── */
@media (max-width: 576px) {
    .form-row,
    .form-grid {
        grid-template-columns: 1fr !important;
    }

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

/* ── Bot Activity Panel: Mobile ── */
@media (max-width: 576px) {
    .bot-panel {
        width: 100vw;
        max-width: 100vw;
    }

    .bot-panel-filters {
        padding: 8px 12px;
    }

    .bot-panel-agents {
        padding: 6px 12px;
    }

    .bot-agent-chip {
        font-size: 0.6rem;
        padding: 2px 8px;
    }

    .bot-task-item {
        padding: 10px 12px;
    }
}

/* ── Live Activity Ticker: Mobile ── */
@media (max-width: 767.98px) {
    .opt-ticker {
        font-size: 0.7rem;
    }

    .opt-ticker-item {
        padding: 4px 12px;
    }
}

/* ── Page Headers: Consistent mobile sizing ── */
@media (max-width: 767.98px) {
    h1 {
        font-size: 1.4rem;
    }

    h2 {
        font-size: 1.1rem;
    }

    /* Page header rows with actions */
    .page-header,
    [class*="page-header"],
    .header-row {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
}

@media (max-width: 576px) {
    h1 {
        font-size: 1.2rem;
    }

    h2 {
        font-size: 1rem;
    }
}

/* ── Floating Help Widget: Mobile position ── */
@media (max-width: 576px) {
    .help-widget,
    .chat-widget {
        bottom: 12px;
        right: 12px;
    }

    .help-widget-panel,
    .chat-panel {
        width: calc(100vw - 24px);
        max-width: 100vw;
        height: 60vh;
        bottom: 60px;
        right: 12px;
    }
}

/* ── Engine Dashboard ── */
@media (max-width: 767.98px) {
    .engine-container {
        flex-direction: column;
    }

    .engine-sidebar {
        width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-200);
    }

    .engine-main {
        min-height: auto;
    }
}

/* ── Documentation / KB ── */
@media (max-width: 767.98px) {
    .kb-container {
        flex-direction: column;
    }

    .kb-sidebar {
        width: 100%;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border-200);
    }
}

/* ── Print: Hide non-essential ── */
@media print {
    .sidebar,
    .topbar,
    .sidebar-toggle,
    .sidebar-overlay,
    .bot-panel,
    .help-widget,
    .opt-ticker {
        display: none !important;
    }

    .app-main {
        margin-left: 0 !important;
    }

    .app-content {
        padding: 0 !important;
    }
}
