/**
 * mobile.css — Small-screen shell (max-width: 768px).
 *
 * This file is a no-op above 768px: every rule that changes the desktop
 * three-column layout lives inside the media query. The new state classes
 * (`app--left-open`, `app--editing`) are likewise inert on desktop.
 *
 * Behaviour that CSS cannot express lives in js/mobile.js.
 */

/* Height reserved for the bottom navigation bar. Only consumed on mobile. */
:root {
  --bottom-bar-h: 56px;
}

/* Desktop: the mobile-only pieces simply do not render. */
.bottom-bar,
.drawer-backdrop,
.layer-search,
.comments-view,
.mobile-overlay-header,
.mobile-only {
  display: none;
}

/* Desktop: the App-menu Search reuses the search overlay full-screen. The
   bottom bar is hidden above 768px, so the overlay spans the whole viewport. */
@media (min-width: 769px) {
  .layer-search:not([hidden]) {
    display: flex;
    bottom: 0;
  }
}

/* ====================================================================== *
 * Mobile shell
 * ====================================================================== */

@media (max-width: 768px) {

  /* ---- Single-column grid, dynamic viewport height ---- */
  .app {
    grid-template-columns: 1fr;
    height: 100vh;
    height: 100dvh;
  }

  /* Grid items default to min-width:auto, so a wide child (a table, a fixed
     width header) can force the single 1fr track past the viewport where
     `.app { overflow: hidden }` clips it. Let every layer shrink and scroll. */
  .app > * {
    min-width: 0;
  }

  .layer,
  .sidepanel {
    height: 100vh;
    height: 100dvh;
  }

  /* Reserve room for the always-visible bottom bar. */
  .layer {
    padding-bottom: calc(var(--bottom-bar-h) + env(safe-area-inset-bottom));
  }

  /* Panel resizing is a pointer gesture; disable it on touch. */
  .resize-handle,
  #right-panel-tab {
    display: none !important;
  }

  .mobile-only {
    display: inline-flex;
  }

  /* ==================================================================== *
   * Bottom navigation bar
   * ==================================================================== */

  .bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: calc(var(--bottom-bar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -1px 3px rgba(60, 50, 40, 0.06);
  }

  .bottom-tab {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 44px;
    padding: 4px 2px;
    background: none;
    border: 0;
    color: var(--color-text-muted);
    font-family: var(--font-sans);
    font-size: 0.62rem;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-tab-icon {
    width: 20px;
    height: 20px;
    display: block;
    object-fit: contain;
  }

  .bottom-tab-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .bottom-tab.is-active {
    color: var(--color-primary);
  }

  .bottom-tab.is-active .bottom-tab-label {
    font-weight: 600;
  }

  .bottom-tab-create .bottom-tab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    margin-bottom: 1px;
    padding: 6px;
    background: var(--color-primary);
    border-radius: 50%;
    filter: brightness(1) invert(1);
    box-sizing: border-box;
  }

  /* ==================================================================== *
   * Binder overview (cards)
   * ==================================================================== */

  .cards-grid {
    min-width: 0;
    padding: 16px 12px;
  }

  /* The desktop header is a single fixed-width row; let it wrap instead so its
     320px search box cannot push the single grid track past the viewport. */
  .cards-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .cards-header h1 {
    flex: 1 1 auto;
    min-width: 0;
  }

  .cards-search {
    order: 3;
    flex: 1 1 100%;
    width: auto;
    max-width: none;
  }

  .card {
    min-width: 0;
  }

  /* ==================================================================== *
   * Settings / user panel
   * ==================================================================== */

  .up-header,
  .up-tabs {
    padding-left: 12px;
    padding-right: 12px;
  }

  .up-tab-content {
    padding: 16px 12px;
  }

  /* ==================================================================== *
   * Left drawer (binder tree)
   * ==================================================================== */

  .sidepanel-left {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(320px, 88vw);
    height: auto;
    z-index: 60;
    border-right: 1px solid var(--color-border);
    transform: translateX(-100%);
    visibility: hidden;
    transition:
      transform var(--transition),
      visibility 0s linear var(--transition);
  }

  .app--left-open .sidepanel-left {
    transform: translateX(0);
    visibility: visible;
    box-shadow: var(--shadow-lg);
    transition:
      transform var(--transition),
      visibility 0s;
  }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(40, 32, 24, 0.42);
  }

  /* ==================================================================== *
   * Right panel → full-screen Pastes sheet
   * ==================================================================== */

  .sidepanel-right {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: calc(var(--bottom-bar-h) + env(safe-area-inset-bottom));
    width: 100%;
    height: auto;
    z-index: 50;
    border-left: 0;
  }

  /* The grid-collapse rule from sidepanel.css is meaningless in one column. */
  .app--right-collapsed {
    grid-template-columns: 1fr;
  }

  .sidepanel-right .panel-top {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
  }

  .panel-top-row {
    padding: 12px 14px;
  }

  .panel-top-title {
    font-size: 1.1rem;
  }

  /* The collapse control becomes a large back/close target. */
  .panel-collapse {
    width: 44px;
    height: 44px;
    margin-left: 6px;
    font-size: 1.5rem;
    border-radius: var(--radius);
  }

  /* ---- Paste cards as tiles ---- */
  .paste-list-controls {
    padding: 10px 12px;
  }

  .paste-scope {
    min-height: 44px;
    font-size: var(--fontsize-mainlevel);
  }

  .paste-search {
    min-height: 44px;
  }

  .paste-card-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-items: stretch;
    gap: 10px;
    padding: 10px;
  }

  .paste-card {
    max-width: none;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .paste-card-media {
    min-height: 84px;
    max-height: 84px;
  }

  .paste-card-media > img {
    max-height: 84px;
  }

  .paste-card-content {
    flex: 1;
    padding: 8px 10px;
  }

  .paste-card-snippet {
    -webkit-line-clamp: 3;
  }

  /* Touch has no hover: reveal the footer permanently and drop the tag bar. */
  .paste-card-footer {
    position: static;
    opacity: 1;
    pointer-events: auto;
    padding: 6px 10px;
    border-top: 1px solid var(--color-border);
  }

  .paste-card-tagbar {
    display: none;
  }

  /* ==================================================================== *
   * Editor: toolbar chrome
   * ==================================================================== */

  .tabs-header {
    gap: 6px;
    padding: 6px 10px;
  }

  .editor-toolbar {
    display: flex;
  }

  .editor-toolbar.is-hidden {
    display: none !important;
  }

  /* Bigger, finger-sized toolbar buttons. */
  .editor-toolbar-btn {
    min-width: 44px;
    min-height: 40px;
    padding: 6px 10px;
    font-size: 0.95rem;
  }

  .editor-toolbar-mode-btn {
    min-width: 44px;
    padding: 6px 8px;
  }

 /*  .cm-comment-gutter {
    width: 26px !important;
  } */

  /* While typing, the status bar is the only chrome we can afford to drop. */
  .app--editing .editor-status {
    display: none;
  }

  /* ==================================================================== *
   * Full-screen comments view
   * ==================================================================== */

  .comments-view:not([hidden]) {
    display: flex;
  }

  /* ==================================================================== *
   * Search overlay
   * ==================================================================== */

  .layer-search:not([hidden]) {
    display: flex;
  }
}

/* ====================================================================== *
 * Shared mobile overlay (search + comments)
 * ====================================================================== */

.comments-view,
.layer-search {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--bottom-bar-h) + env(safe-area-inset-bottom));
  z-index: 70;
  flex-direction: column;
  background: var(--color-surface);
  overflow: hidden;
}

  .mobile-overlay-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top));
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-1);
    position: sticky;
    top: 0;
    z-index: 2;
  }

  .mobile-overlay-back-icon {
    width: 18px;
    height: 18px;
    display: block;
  }

.mobile-overlay-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mobile-overlay-back:hover {
  background: var(--color-border);
}

.mobile-overlay-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
}

.mobile-overlay-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Search overlay: give the component room and a large touch field. */
.layer-search .nt-search {
  padding: 12px;
}

.layer-search .nt-search-input {
  min-height: 46px;
  font-size: 1rem;
}

/* ====================================================================== *
 * Comments view contents
 * ====================================================================== */

.comments-view-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.comments-view-actions .select {
  min-height: 40px;
}

.comments-view-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  padding: 0 8px;
  background: none;
  border: none;
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 1.1rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.comments-view-action:hover {
  background: var(--color-border);
}

.comments-view-action.is-off {
  opacity: 0.5;
}

.comments-view-count {
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--color-primary);
  color: var(--color-surface-2);
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.comments-view-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.comments-view-thread {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.comments-view-thread.is-active {
  border-color: var(--color-primary);
}

/* The popover is reused verbatim inside the list, without positioning. */
.comments-view-thread .cm-comment-popover {
  position: static;
  width: auto;
  max-width: none;
  max-height: none;
  padding: 12px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.comments-view-empty {
  margin: 24px 12px;
  color: var(--color-text-muted);
  font-size: var(--fontsize-ui);
  text-align: center;
}

/* ====================================================================== *
 * Touch-friendly targets (mobile only)
 * ====================================================================== */

@media (max-width: 768px) {

.editor-close,
.up-close,
.binder-top-close,
.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
  font-size: 1.3rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.drawer-close {
  width: 35px;
  position: fixed;
  top: -2px;
  left: 90%;
  text-indent: 5px;
  border: 0px;
  padding-left: 3px;
  font-size: var(--fontsize-above-8);
  background-color: var(--color-border);
}

.tree-node {
  min-height: 30px;
}

.tree-node-actions .btn {
  min-width: 40px;
  min-height: 40px;
  font-size: 1rem;
}

/* The tree action buttons are hover-revealed on desktop; always show them. */
.tree-node-actions {
  opacity: 1;
}

/* Keep the paste-window dock above the bottom bar. */
.paste-window-dock {
  bottom: calc(var(--bottom-bar-h) + env(safe-area-inset-bottom) + 8px);
}

/* Keep the notification popover above the bottom bar. */
.notification-panel {
  bottom: calc(var(--bottom-bar-h) + env(safe-area-inset-bottom) + 8px) !important;
}

}

/* ====================================================================== *
 * Print
 * ====================================================================== */

@media print {
  .bottom-bar,
  .drawer-backdrop {
    display: none !important;
  }
}

  .tabs-header {
    gap: 4px;
    padding: 4px 6px;
  }

  .tabs-list {
    gap: 1px;
  }

  .editor-tab {
    max-width: 140px;
    padding: 4px 6px;
  }
