/* ═══════════════════════════════════════════════════════════
   mobile.css — TaskiChat Mobile Responsive Layout
   Breakpoint: ≤ 768px
   Pattern: WhatsApp-style panel slide (list ↔ chat)
   ═══════════════════════════════════════════════════════════ */

/* ── Desktop: hide mobile-only elements ── */
@media (min-width: 769px) {
  .mobile-nav        { display: none !important; }
  .mobile-back-btn   { display: none !important; }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE LAYOUT
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Fix viewport height — dvh prevents iOS toolbar collapse issues */
  body {
    height: 100dvh;
    height: 100vh; /* fallback for older browsers */
    overflow: hidden;
  }

  /* Hide the desktop left nav rail */
  .nav { display: none; }

  /* App shell: relative container for absolutely-positioned panels */
  #appShell {
    position: relative;
    width: 100vw;
    overflow: hidden;
    /* flex:1 stays — just overriding child layout below */
  }

  /* ── PANEL SLIDE SYSTEM ─────────────────────────────────── */
  /* Both panels are full-screen, layered. mid is default view.
     .right slides in from the right when a chat is opened.    */

  .mid {
    position: absolute;
    inset: 0;
    bottom: calc(56px + env(safe-area-inset-bottom, 0px)); /* above mobile bottom nav */
    width: 100%;
    transform: translateX(0);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
    border-right: none;
  }

  .right {
    position: absolute;
    inset: 0;
    bottom: calc(56px + env(safe-area-inset-bottom, 0px)); /* above mobile bottom nav */
    width: 100%;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2;
  }

  /* Chat open state: mid recedes, right slides in */
  #appShell.mobile-chat-open .mid {
    transform: translateX(-30%);
  }

  #appShell.mobile-chat-open .right {
    transform: translateX(0);
    bottom: 0;
  }

  #appShell.mobile-chat-open .mobile-nav {
    display: none !important;
  }

  /* ── MOBILE BOTTOM NAV ──────────────────────────────────── */
  .mobile-nav {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--text);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 100;
    /* Safe area for notched phones */
    padding-bottom: env(safe-area-inset-bottom, 0);
    overflow-x: auto;          /* ← ADD */
    scrollbar-width: none;     /* ← ADD — hides scrollbar on Firefox */
  }
  .mobile-nav::-webkit-scrollbar {
  display: none;
}
  .mobile-nav-btn {
    min-width: 64px;   /* ← ADD — consistent tap target width */
    flex-shrink: 0;    /* ← ADD — prevents buttons from squishing */
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    font-family: var(--font);
    font-size: 9px;
    font-weight: 500;
    padding: 0;
    position: relative;
    transition: color 0.12s;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-nav-btn.on { color: var(--accent); }

  .mobile-more-menu {
    display: none;
    position: fixed;
    right: 10px;
    bottom: calc(62px + env(safe-area-inset-bottom, 0px));
    min-width: 158px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    z-index: 120;
  }

  .mobile-more-menu.open {
    display: block;
  }

  .mobile-more-menu button {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
    font: 500 13px var(--font);
    text-align: left;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
  }

  .mobile-more-menu button:active {
    background: var(--surface2);
  }

  .mobile-more-menu button svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    color: var(--text2);
  }

  /* Unread badge on the Chat nav button */
  .mobile-nav-btn .m-badge {
    position: absolute;
    top: 5px;
    right: calc(50% - 20px);
    background: var(--danger);
    color: #fff;
    font-size: 8px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 8px;
    min-width: 14px;
    text-align: center;
    display: none;
  }

  .mobile-nav-btn .m-badge.show { display: block; }

  /* ── BACK BUTTON ────────────────────────────────────────── */
  .mobile-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    margin-right: 2px;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-back-btn:active { background: var(--surface2); }

  /* ── COMPOSE AREA ───────────────────────────────────────── */
  /* font-size ≥ 16px prevents iOS Safari from zooming on focus */
  .compose textarea {
    font-size: 16px;
  }

  /* ── TOUCH TARGETS ──────────────────────────────────────── */
  /* Minimum 44px tap targets per iOS HIG */
  .conv-item {
    padding: 13px 14px;
    min-height: 60px;
  }

  .conv-list {
    padding-bottom: 12px;
  }

  .mid-action {
    display: block;
    padding: 0;
    border-top: none;
  }

  .mid-new-btn {
    display: none;
  }

  .new-chat-btn {
    position: fixed;
    right: 16px;
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 8px 18px rgba(13, 138, 99, .28), 0 2px 6px rgba(0, 0, 0, .12);
    z-index: 90;
    font-size: 0;
  }

  .new-chat-btn svg {
    width: 20px;
    height: 20px;
  }

  #appShell.mobile-chat-open .mid-action {
    display: none;
  }

  .ib, .c-btn, .c-icon-btn {
    min-width: 38px;
    min-height: 38px;
  }

  /* ── CHAT HEADER ────────────────────────────────────────── */
  .r-hdr {
    padding: 10px 12px;
  }

  /* ── MESSAGE BUBBLES ────────────────────────────────────── */
  /* Wider on small screens — more reading space */
  .m-block { max-width: 87%; }

  /* ── MODAL ──────────────────────────────────────────────── */
  .modal {
    width: 96%;
    max-width: 96%;
    max-height: 88vh;
    overflow-y: auto;
    border-radius: var(--radius);
  }

  /* ── SETTINGS ───────────────────────────────────────────── */
  .settings-wrap {
    padding: 14px;
    max-width: 100%;
  }

  /* ── PAGE HEADERS (Files, Links, etc.) ──────────────────── */
  .page-hdr {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
  }

  .filter-pills { flex-wrap: wrap; }

  /* ── FILE GRID ───────────────────────────────────────────── */
  .file-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  /* ── NOTES PANEL ─────────────────────────────────────────── */
  /* Stack list above editor on mobile */
  .notes-wrap {
    flex-direction: column;
  }

  .note-list-panel {
    width: 100%;
    height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  /* ── CONTEXT MENU ────────────────────────────────────────── */
  .ctx-menu { min-width: 230px; }

  /* ── AUTH SCREEN ─────────────────────────────────────────── */
  #authScreen > div {
    margin: 16px;
    padding: 24px 20px;
    max-width: calc(100vw - 32px);
  }

  /* ── CHAT TABS: allow wrapping ───────────────────────────── */
  .chat-tabs { flex-wrap: wrap; }

  /* ── MID HEADER: tighter ─────────────────────────────────── */
  .mid-hdr { padding: 12px 12px 8px; }

  /* ── LINK ADD BAR: stack on mobile ──────────────────────── */
  .l-add-bar {
    flex-wrap: wrap;
  }
}

/* Non-chat panels (Notes, Files, Links, etc.) need right panel visible */
@media (max-width: 768px) {
  #appShell.mobile-panel-open .right {
    transform: translateX(0);
  }
}
