/* ════════════════════════════════════════════════════════════════════════════
   MOBILE  (≤ 768 px)
   Everything below only applies to narrow viewports.
   Desktop layout is completely untouched.
   ════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    :root {
        --radius: 8px;
        --mobile-nav-h: 72px;
    }

    /* ── Header ── */
    #desktop-nav { display: none; }
    header { height: 48px; padding: 0 14px; }
    header h1 { font-size: 14px; letter-spacing: 4px; }

    /* ── Show mobile-only elements ── */
    .mobile-only { display: flex !important; }

    /* ── Bottom navigation bar ────────────────────────────────────────────────
       Horizontally scrollable strip of pill tabs.
       Tabs are fixed-width so 11 of them scroll naturally.
       Labels are injected from the existing aria-label attributes — no HTML
       changes needed for the labels themselves.
    ── */
    #mobile-nav {
        display: flex;
        align-items: center;
        height: var(--mobile-nav-h);
        background: var(--surface);
        border-top: 1px solid var(--border);
        flex-shrink: 0;

        /* Horizontal scroll */
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;

        gap: 5px;
        padding: 8px 10px;
        padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));

        /* Fade the edges to hint at scrollability */
        -webkit-mask-image: linear-gradient(
            to right,
            transparent 0px,
            black 12px,
            black calc(100% - 12px),
            transparent 100%
        );
        mask-image: linear-gradient(
            to right,
            transparent 0px,
            black 12px,
            black calc(100% - 12px),
            transparent 100%
        );
    }
    #mobile-nav::-webkit-scrollbar { display: none; }

    /* ── Individual tab pill ── */
    .mob-tab {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;

        flex: 0 0 auto;
        width: 58px;
        height: 100%;

        background: var(--surface2);
        border: 1px solid var(--border);
        border-radius: 10px;
        color: var(--text-dim);

        font-size: 19px;
        line-height: 1;

        cursor: pointer;
        position: relative;
        transition: background 0.15s, border-color 0.15s, color 0.15s;
        -webkit-tap-highlight-color: transparent;
        outline: none;

        gap: 4px;
        padding: 4px 2px 5px;
    }

    /* Label injected from aria-label via CSS — zero HTML changes required */
    .mob-tab::after {
        content: attr(aria-label);
        display: block;
        font-family: var(--font);
        font-size: 7.5px;
        font-weight: 600;
        color: inherit;
        letter-spacing: 0.4px;
        text-transform: uppercase;
        line-height: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: clip;
        max-width: 54px;
        text-align: center;
        opacity: 0.7;
    }

    /* Tap state */
    .mob-tab:active {
        background: var(--surface3);
        border-color: var(--text-faint);
        transform: scale(0.96);
        transition: transform 0.08s, background 0.08s;
    }

    /* Active state — accent glow pill */
    .mob-tab.active {
        background: var(--accent-dim);
        border-color: var(--accent);
        color: var(--accent);
        box-shadow: 0 0 8px -2px var(--accent-dim);
    }
    .mob-tab.active::after {
        opacity: 1;
    }

    /* Has-alert dot (top-right of pill) */
    .mob-tab.has-alert::before {
        content: '';
        position: absolute;
        top: 6px;
        right: 7px;
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: var(--warning);
        box-shadow: 0 0 4px var(--warning);
        z-index: 1;
    }

    /* Approval badge inside the button */
    .mob-approval-badge {
        position: absolute;
        top: 5px;
        right: 5px;
        min-width: 14px;
        height: 14px;
        background: var(--warning);
        color: #000;
        font-size: 8px;
        font-weight: 700;
        border-radius: 7px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 3px;
    }
    .mob-approval-badge.hidden { display: none; }

    /* ── Main area ── */
    main { flex: 1; min-height: 0; overflow: hidden; }

    /* ── Split-pane mobile behaviour ── */
    .split-container { position: relative; overflow: hidden; }
    .split-pane {
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        width: 100%;
        transition: transform 0.22s ease;
        background: var(--bg);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* List pane: visible by default */
    .split-list {
        transform: translateX(0);
        z-index: 1;
        width: 100% !important;
        border-right: none !important;
        flex-shrink: unset !important;
    }

    /* Detail pane: off-screen right */
    .split-detail {
        transform: translateX(100%);
        z-index: 2;
        width: 100% !important;
    }

    /* JS adds .mob-show-detail to .split-container */
    .split-container.mob-show-detail .split-list   { transform: translateX(-100%); }
    .split-container.mob-show-detail .split-detail { transform: translateX(0); }

    /* ── Back button bars ── */
    .detail-back-bar { display: flex !important; }

    /* ── Textareas ── */
    #identity-editor,
    #memory-editor,
    #scheduler-editor { font-size: 14px; padding: 12px; }

    /* ── Editor header ── */
    .editor-header { padding: 8px 10px; min-height: 44px; }
    .btn-save, .btn-delete { padding: 6px 12px; font-size: 12px; }
    .btn-back { font-size: 15px; padding: 2px 10px 2px 0; }

    /* ── Chat ── */
    #chat-messages { padding: 12px; }
    #chat-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
    }
    #chat-input  { font-size: 16px; padding: 10px; }
    #chat-send   { padding: 10px 16px; font-size: 14px; }
    .message     { max-width: 92%; }
    .message .content { font-size: 14px; }

    /* ── Chat sidebar → mobile slide-over ──────────────────────────────────── */
    .chat-layout { position: relative; overflow: hidden; }

    .chat-sidebar {
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        width: 100% !important;
        min-width: 0 !important;
        border-right: none !important;
        z-index: 1;
        transform: translateX(0);
        transition: transform 0.22s ease;
    }

    .chat-main {
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        z-index: 2;
        transform: translateX(100%);
        transition: transform 0.22s ease;
    }

    .chat-layout.mob-show-chat .chat-sidebar { transform: translateX(-100%); }
    .chat-layout.mob-show-chat .chat-main    { transform: translateX(0); }

    /* ── Status ── */
    #status-grid { grid-template-columns: 1fr 1fr; padding: 12px; gap: 8px; }
    .stat-value  { font-size: 20px; }

    /* ── Memories ── */
    #memories-toolbar { padding: 10px 8px; gap: 8px; }
    #memories-search  { font-size: 14px; padding: 8px 10px; }
    .memory-item      { padding: 10px 12px; }
    .memory-title     { font-size: 13px; }

    /* ── Scheduler ── */
    .cron-item     { padding: 12px; }
    .cron-schedule { font-size: 13px; }
    .cron-task     { white-space: normal; }

    /* ── Logs ── */
    #logs-container { flex-direction: column; }
    #logs-date-list, #logs-file-list { width: 100% !important; border-right: none !important; }
    #logs-content-pane { width: 100% !important; }
    #log-content { padding: 12px; font-size: 12px; }

    /* ── Tools ── */
    #tool-detail pre { font-size: 11px; }

    /* ── Modals ── */
    .modal-content { min-width: unset; width: calc(100vw - 32px); padding: 24px 20px; }

    /* ── Pipelines ── */
    #pipelines-sidebar { width: 100% !important; border-right: none !important; }
    .pipeline-modal-content { min-width: unset; width: calc(100vw - 32px); }
    #pipelines-list { max-height: 35%; }
    .pipeline-creator-content { min-width: unset; width: calc(100vw - 24px); max-height: 90vh; }
    .creator-row { flex-direction: column; }
    .creator-step-id-input { width: 100px; }

    /* ── Approvals ── */
    #approvals-sidebar { width: 100% !important; border-right: none !important; }
    #approvals-pending-list { max-height: 40%; }
}
