/* ═══════════════════════════════════════════════════
   mobile.css — Phone & tablet overrides
   Must be the LAST stylesheet linked in index.html
═══════════════════════════════════════════════════ */

/* ── iOS / Android base fixes ── */
html, body {
  height: 100%;
  height: -webkit-fill-available;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

input, select, textarea {
  font-size: max(0.9rem, 16px) !important;
}

#app {
  height: 100dvh;
  min-height: -webkit-fill-available;
}

/* ════════════════════════════════════════════════
   TABLET ≤ 900px
════════════════════════════════════════════════ */
@media (max-width: 900px) {
  #app {
    grid-template-columns: 1fr 4px clamp(300px, 42vw, 460px);
  }
  .topbar-right .stat-pill:not(:last-child) { display: none; }
}

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

  #app {
    grid-template-columns: 1fr !important;
    grid-template-rows: 48px 1fr 56px !important;
    height: 100dvh;
  }

  #drag-resizer { display: none !important; }

  #graph-panel {
    grid-row: 2 !important;
    grid-column: 1 !important;
    height: 100%;
    border: none !important;
    display: none;
  }
  #graph-panel.mobile-active { display: block; }

  #right-panel {
    grid-row: 2 !important;
    grid-column: 1 !important;
    border: none !important;
    width: 100%;
    height: 100%;
  }

  /* ── Bottom nav bar ── */
  #mobile-nav {
    display: flex !important;
    grid-row: 3;
    grid-column: 1;
    background: var(--deep);
    border-top: 1px solid var(--rim);
    align-items: stretch;
    z-index: 100;
  }
  .mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    border: none;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.5rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    padding: 6px 0;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-nav-btn .nav-icon { font-size: 1.1rem; line-height: 1; }
  .mobile-nav-btn.active { color: var(--phosphor); }
  .mobile-nav-btn.active .nav-icon { filter: drop-shadow(0 0 4px var(--phosphor)); }

  /* Hide desktop nav */
  .topbar-nav { display: none !important; }

  /* Topbar slim */
  #topbar { padding: 0 12px; grid-column: 1; }
  .topbar-logo { font-size: 0.75rem; letter-spacing: 0.22em; margin-right: auto; }
  .topbar-right { gap: 6px; }
  .topbar-right .stat-pill { display: none !important; }
  .topbar-right .stat-pill:last-child { display: flex !important; padding: 3px 6px; gap: 4px; }
  #conn-label { display: none; }

  /* View */
  .view-header  { padding: 8px 14px 7px; }
  .view-title   { font-size: 0.6rem; }
  .view-subtitle{ font-size: 0.82rem; }
  .view-body    { padding: 10px 14px; }

  /* Chat */
  .chat-messages     { padding: 10px 12px; gap: 12px; }
  .chat-filter       { padding: 5px 12px; }
  .chat-filter-label { display: none; }
  .filter-select     { font-size: 0.7rem; }
  .msg-bubble        { padding: 9px 12px; font-size: 0.78rem; }
  .chat-input-area   { padding: 8px 10px; gap: 6px; }
  .chat-input        { font-size: 0.78rem; padding: 8px 12px; min-height: 38px; }
  .chat-send         { width: 38px; height: 38px; font-size: 15px; }
  .sources-toggle    { font-size: 0.58rem; padding: 4px 8px; }
  .source-chip-name  { font-size: 0.58rem; }
  .source-chip-text  { font-size: 0.68rem; }
  .chat-image        { max-height: 200px; }

  /* Corpus */
  .upload-zone    { padding: 16px; }
  .upload-icon    { font-size: 1.4rem; }
  .upload-text    { font-size: 0.72rem; }
  .doc-item       { padding: 9px 10px; }
  .doc-name       { font-size: 0.74rem; }
  .doc-meta       { font-size: 0.58rem; }
  .doc-actions    { opacity: 1 !important; }
  .doc-action-btn { width: 30px; height: 30px; font-size: 12px; }

  /* Inspect */
  .inspect-stats { padding: 10px 12px; gap: 6px; }
  .stat-box-val  { font-size: 0.8rem; }
  .inspect-hero  { padding: 12px 14px; }
  .inspect-title { font-size: 0.88rem; }

  /* Toast above bottom nav */
  #toast {
    bottom: 68px;
    max-width: 88vw;
    white-space: normal;
    text-align: center;
    font-size: 0.68rem;
  }

  * { scrollbar-width: none; }
  *::-webkit-scrollbar { display: none; }

  #login-screen > div,
  .login-card {
    width: 100% !important;
    max-width: 340px !important;
    padding: 20px 16px !important;
  }
}

/* ════════════════════════════════════════════════
   SMALL PHONES ≤ 390px
════════════════════════════════════════════════ */
@media (max-width: 390px) {
  .topbar-logo { font-size: 0.68rem; }
  .msg-bubble  { font-size: 0.74rem; padding: 8px 10px; }
  .chat-input  { font-size: 0.74rem; }
  .chat-image  { max-height: 170px; }
  .mobile-nav-btn { font-size: 0.45rem; }
  .mobile-nav-btn .nav-icon { font-size: 1rem; }
}

/* ════════════════════════════════════════════════
   LIGHTBOX close button
════════════════════════════════════════════════ */
#img-lightbox-close { display: none; }

@media (max-width: 768px) {
  #img-lightbox-close {
    display: flex;
    position: fixed;
    top: 16px; right: 16px;
    z-index: 9999;
    width: 40px; height: 40px;
    background: rgba(0,0,0,0.7);
    border: 1px solid var(--rim2);
    border-radius: 50%;
    color: var(--text);
    font-size: 18px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(4px);
  }
}

/* Desktop — hide mobile nav */
#mobile-nav { display: none; }