/* mobile.css — ≤780px overrides. Top bar, tab bar, drawer. */
/* Loaded after components.css so selectors here cleanly win on width queries. */

/* Mobile chrome hidden by default; revealed inside the media query. */
.mobile-topbar,
.mobile-tabbar,
.drawer-scrim {
  display: none;
}

@media (max-width: 780px) {
  /* ----- Top bar ----- */
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    height: 54px;
    background: var(--ink-0);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 30;
  }

  .mobile-menu-btn,
  .mobile-search-btn {
    width: 34px;
    height: 34px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--fg-2);
    display: grid;
    place-items: center;
    padding: 0;
    flex-shrink: 0;
  }

  .mobile-menu-btn:hover,
  .mobile-search-btn:hover {
    background: var(--ink-2);
    color: var(--fg);
  }

  .mobile-title {
    flex: 1;
    font-family: var(--display);
    font-weight: 400;
    font-size: 24px;
    line-height: 1;
    letter-spacing: -0.01em;
    margin: 0;
    color: var(--fg);
  }

  /* ----- App layout collapses to a single column ----- */
  #app-layout {
    grid-template-columns: 1fr;
  }

  /* ----- Sidebar becomes a drawer, off-screen by default ----- */
  #sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 86%;
    max-width: 340px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform var(--dur-med) var(--ease-out);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    min-height: 100vh;
    overflow-y: auto;
  }

  body.drawer-open #sidebar {
    transform: translateX(0);
  }

  /* Legacy style.css has aggressive mobile overrides (display: none / horizontal
     chip rows / hidden section headers). We're building a proper slide-in drawer
     instead, so undo the legacy rules with higher-specificity selectors. */
  #sidebar #sidebar-nav {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    flex: 1;
    overflow-y: auto;
    gap: 0;
    padding: 24px 0 16px;
  }

  #sidebar .sidebar-section {
    display: block;
    margin-bottom: 14px;
    gap: 0;
  }

  #sidebar .sidebar-section-header {
    display: block;
    padding: 10px 22px 6px;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--fg-3);
  }

  #sidebar .sidebar-bottom {
    margin-top: auto;
    border-top: 1px solid var(--line);
    padding-top: 10px;
  }

  #sidebar .sidebar-nav-item {
    width: calc(100% - 12px);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
  }

  #sidebar .sidebar-nav-item.active {
    background: var(--ink-2);
    color: var(--fg);
  }

  #sidebar .sidebar-toggle {
    display: none;
  }

  /* ----- Drawer scrim ----- */
  .drawer-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-med) var(--ease-out);
    z-index: 50;
  }

  body.drawer-open .drawer-scrim {
    opacity: 1;
    pointer-events: auto;
  }

  /* ----- Bottom tab bar ----- */
  .mobile-tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    background: var(--ink-0);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .mobile-tabbar .tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 4px 12px;
    background: transparent;
    border: 0;
    color: var(--fg-3);
    cursor: pointer;
    font-family: var(--mono);
    font-size: 9.5px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-decoration: none;
    position: relative;
    min-height: 64px;
  }

  .mobile-tabbar .tab:hover {
    color: var(--fg);
    background: transparent;
  }

  /* Main content gets breathing room / full width. */
  #main-content {
    min-width: 0;
  }

  /* Kill the giant horizontal padding on content rows and headers. */
  #view-reading-list::before {
    padding: 22px 18px 6px;
  }

  #content-list-section::before {
    padding: 0 18px 20px;
    font-size: 38px;
    line-height: 1.05;
  }

  .reading-list-controls {
    padding: 12px 18px;
    flex-wrap: wrap;
  }

  #content-list .content-item {
    grid-template-columns: 1fr;
    padding: 18px 18px;
  }

  #content-list .content-item::before {
    /* Hide the № rail on mobile — taps open the reader. */
    display: none;
  }

  #content-list .content-item-actions {
    /* Most actions never surface on touch; tapping the row navigates.
       The TTS button remains visible so audio can be triggered directly. */
    display: flex;
    flex-direction: row;
    justify-self: end;
    margin-top: 6px;
  }

  #content-list .content-item-actions > button:not(.tts-btn) {
    display: none;
  }

  #content-list .content-description {
    max-width: 100%;
  }

  .toolbar-panel {
    padding: 14px 18px;
  }

  #auth-section:not(:empty) {
    padding: 10px 18px;
  }

  /* Reader: metadata inline above body, no max-width games. */
  .reader-content {
    padding: 20px 18px 100px;
    max-width: none;
  }

  .reader-nav {
    gap: 4px;
    flex-wrap: wrap;
  }

  .reader-nav button {
    padding: 5px 9px;
    font-size: 10px;
  }

  .reader-nav .btn-text {
    display: none;
  }

  #article-title {
    font-size: 34px;
    line-height: 1.06;
  }

  #article-content {
    font-size: 16px;
    line-height: 1.7;
    max-width: none;
  }

  #article-content blockquote {
    font-size: 19px;
    margin: 22px 0;
    padding: 4px 16px;
  }

  #view-manage-feeds {
    padding: 22px 18px 80px;
  }

  #view-manage-feeds > h2 {
    font-size: 32px;
  }

  /* Feed items view — mirror the reading-list mobile layout. */
  #feed-items-header {
    display: block;
    padding: 22px 18px 20px;
    gap: 10px;
  }

  #feed-items-header::before {
    margin-bottom: 4px;
  }

  #feed-items-title {
    font-size: 38px;
    line-height: 1.05;
    margin: 0 0 14px;
  }

  #feed-items-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
  }

  #feed-items-toolbar button {
    padding: 5px 9px;
    font-size: 10px;
  }

  #feed-items-list .feed-item {
    grid-template-columns: 1fr;
    padding: 18px 18px;
  }

  /* Hide the № rail on mobile — taps open the article. */
  #feed-items-list .feed-item::before {
    display: none;
  }

  /* Actions hide on touch (same as reading list); tap the row to open. */
  #feed-items-list .feed-item-actions {
    display: none;
  }

  #feed-items-list .feed-item-description {
    max-width: 100%;
  }

  #feed-items-list .feed-item-title {
    flex-wrap: wrap;
  }

  /* Tapping the title opens the reader — the external-link arrow is redundant on touch. */
  #feed-items-list .feed-item-external-link {
    display: none;
  }

  #feed-items-list > p {
    padding: 24px 18px;
  }

  /* Hide the sidebar hamburger (its own toggle) on mobile — the top bar owns it. */
  #sidebar .sidebar-toggle {
    display: none;
  }

  /* Push content above the fixed bottom tab bar so rows aren't hidden behind it. */
  #main-content {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  /* Sidebar action modals: keep them inside the viewport between the top bar
     and bottom tab bar, with internal scrolling for the tall Upload form.
     Letting `margin: auto` (the UA default) handle centering keeps small
     modals like Add URL vertically centered while tall ones cap at max-height. */
  dialog.sidebar-modal {
    width: calc(100vw - 24px);
    max-width: none;
    max-height: calc(100vh - 54px - 64px - env(safe-area-inset-bottom) - 24px);
    padding: 16px 18px;
    overflow-y: auto;
  }

  dialog.sidebar-modal form {
    gap: 8px;
  }

  /* Note modal gets the same treatment so it doesn't overflow on mobile. */
  dialog#note-modal {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 54px - 64px - env(safe-area-inset-bottom) - 24px);
    padding: 16px 18px;
    overflow-y: auto;
  }
}
