/* Vision — Responsive / Mobile Support
   ────────────────────────────────────────
   Breakpoints:
     - ≤1024px  : tablet — reduce padding, 2-col grids
     - ≤768px   : mobile — sidebar overlay, 1-col grids, full-width modals
     - ≤480px   : small mobile — tighter spacing
*/

/* ── Hamburger Button (hidden on desktop) ── */
.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--surface-3);
    border: 1px solid var(--border-default);
    border-radius: var(--r-md);
    cursor: pointer;
    flex-shrink: 0;
    z-index: 200;
    color: var(--text-primary);
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-toggle:hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
}

.sidebar-toggle svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

/* ── Sidebar overlay backdrop (mobile only) ── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.visible {
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════════
   TABLET  (≤1024px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    .content-area {
        padding: var(--s6) var(--s6) !important;
    }

    .topbar {
        padding: var(--s3) var(--s6);
    }

    .grid-3 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .metric-value {
        font-size: 22px;
    }

    .section-title {
        font-size: 18px;
    }

    /* Compact infra pill */
    #vision-infra-pill {
        height: 28px !important;
    }

    #vision-infra-pill > div {
        font-size: 9px !important;
        padding: 0 8px !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE  (≤768px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Show hamburger */
    .sidebar-toggle {
        display: flex;
    }

    /* Show backdrop element */
    .sidebar-backdrop {
        display: block;
        pointer-events: none;
    }

    .sidebar-backdrop.visible {
        pointer-events: auto;
    }

    /* Sidebar becomes off-canvas overlay */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 200;
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 8px 0 30px rgba(0, 0, 0, 0.5);
    }

    /* Main viewport takes full width */
    .main-viewport {
        width: 100vw;
    }

    /* Topbar adjustments */
    .topbar {
        padding: var(--s3) var(--s4);
        min-height: 48px;
        gap: 8px;
    }

    .breadcrumb {
        font-size: 12px;
        min-width: 0;
        overflow: hidden;
    }

    .breadcrumb-item {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 120px;
    }

    /* Hide version/branch segments on mobile — just show env dot */
    #vision-version,
    #vision-branch,
    #env-drift-badge {
        display: none !important;
    }

    #vision-infra-pill {
        height: 26px !important;
    }

    /* Content area */
    .content-area {
        padding: var(--s4) var(--s4) !important;
    }

    /* All grids become 1 column */
    .grid-3,
    .grid-2 {
        grid-template-columns: 1fr !important;
    }

    .grid-auto {
        grid-template-columns: 1fr !important;
    }

    /* Metric cards — 2-col on mobile landscape, 1-col portrait */
    .metric-card {
        padding: var(--s4) var(--s4);
    }

    .metric-value {
        font-size: 20px;
    }

    .metric-label {
        font-size: 10px;
    }

    .section-title {
        font-size: 16px;
    }

    .section-subtitle {
        font-size: 12px;
    }

    /* Tables: horizontal scroll wrapper */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Modals go near full-screen */
    .modal {
        width: 100% !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: var(--s5) !important;
    }

    .modal-overlay {
        align-items: stretch !important;
        padding: 0 !important;
    }

    #disc-modal-inner {
        max-width: 100vw !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        height: 100vh !important;
    }

    #simple-modal-box {
        max-width: 100vw !important;
        border-radius: 12px !important;
        margin: 8px !important;
    }

    /* Buttons: slightly larger touch targets */
    .btn {
        padding: 10px 16px;
        font-size: 12px;
        min-height: 40px;
    }

    .btn-sm {
        padding: 8px 12px !important;
        min-height: 36px !important;
    }

    /* Entity cards: no translateX on hover (jarring on mobile) */
    .entity-card:hover {
        transform: none;
    }

    .metric-card:hover {
        transform: none;
    }

    /* Flex-between wraps on mobile */
    .flex-between {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* Section header stacks vertically */
    .section-header {
        flex-direction: column;
        gap: 12px;
    }

    /* Inputs: larger touch targets */
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="tel"],
    select,
    textarea {
        padding: 12px 14px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    /* Nav links: larger tap targets */
    .nav-link {
        padding: 10px var(--s3);
        font-size: 14px;
    }

    /* ── View-specific: LLM Control Center ── */
    .llm-usage-view {
        max-width: 100% !important;
    }

    /* LLM summary grid: 2x2 on mobile */
    .llm-usage-view > div:first-child {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .llm-provider-card {
        padding: 12px !important;
    }

    .llm-provider-card > div {
        grid-template-columns: 30px 1fr auto !important;
    }

    /* ── View-specific: Dashboard metric grids ── */
    [style*="grid-template-columns: repeat(4"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    [style*="grid-template-columns: repeat(3"] {
        grid-template-columns: 1fr !important;
    }

    /* ── View-specific: Cockpit tab bar ── */
    .cockpit-tabs,
    [style*="display:flex"][style*="border-bottom"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

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

    /* ── View-specific: Execute tab 3-panel layout ── */
    #execute-tab-content {
        flex-direction: column !important;
        height: auto !important;
    }

    /* Session sidebar → horizontal strip at top */
    #exec-session-sidebar {
        width: 100% !important;
        max-height: 200px !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-subtle) !important;
        flex-shrink: 0 !important;
    }

    /* Mind panel → strip at bottom (hidden by default on mobile) */
    #exec-mind-panel {
        width: 100% !important;
        max-height: 250px !important;
        border-left: none !important;
        border-top: 1px solid var(--border-subtle) !important;
    }

    /* Prompt bar adjustments */
    #exec-prompt-input {
        font-size: 16px !important; /* Prevent iOS zoom */
        padding: 12px 100px 12px 14px !important;
        border-radius: 12px !important;
    }

    /* Chat messages: reduce max-width */
    #exec-messages {
        padding: 16px !important;
    }

    #exec-messages > div > div {
        max-width: 90% !important;
    }

    /* ── View-specific: Work items board ── */
    .board-columns {
        flex-direction: column !important;
    }

    .board-column {
        width: 100% !important;
        min-width: 100% !important;
    }

    /* ── Toast notification: bottom center ── */
    #toast {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        max-width: calc(100vw - 32px) !important;
        font-size: 12px !important;
    }

    /* Pipeline canvas: scrollable */
    #drawflow {
        min-width: 800px;
    }

    .drawflow-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* ── Inline grid overrides for dynamically generated HTML ── */
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   SMALL MOBILE  (≤480px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .content-area {
        padding: var(--s3) var(--s3) !important;
    }

    .topbar {
        padding: var(--s2) var(--s3);
    }

    .breadcrumb-item {
        max-width: 80px;
    }

    /* Even the env badge can hide on very small screens */
    #env-badge {
        display: none !important;
    }

    .metric-value {
        font-size: 18px;
    }

    .section-title {
        font-size: 15px;
    }

    /* LLM summary grid: stacked */
    .llm-usage-view > div:first-child {
        grid-template-columns: 1fr !important;
    }

    [style*="grid-template-columns: repeat(4"] {
        grid-template-columns: 1fr !important;
    }

    /* Tighter sidebar */
    .sidebar.open {
        width: 260px;
    }
}

/* ═══════════════════════════════════════════════════════════
   TOUCH DEVICE OPTIMIZATIONS
   ═══════════════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
    /* Disable hover transforms on touch devices */
    .entity-card:hover,
    .metric-card:hover,
    .pipeline-card:hover,
    .btn:hover {
        transform: none !important;
    }

    /* Bigger scrollbars for touch */
    ::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }

    /* Active state instead of hover */
    .nav-link:active {
        background: var(--surface-active);
        color: var(--accent-light);
    }

    .btn:active {
        filter: brightness(0.9);
    }

    .entity-card:active {
        background: var(--surface-active);
        border-color: var(--accent-glow);
    }
}
