/* ── PWA mobile-specific overrides ── */

/* Safe area insets for notch phones */
.page-shell {
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  padding-bottom: max(32px, env(safe-area-inset-bottom));
}

/* Touch targets: minimum 44px */
.tabs a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button,
input[type="checkbox"] {
  min-height: 44px;
  min-width: 44px;
}

.scrap-star {
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

/* ── Feed header: compact toolbar ── */
.feed-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.feed-info {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.feed-sep-dot {
  margin: 0 3px;
  color: var(--line);
}

.filter-toggle-btn {
  margin-left: auto;
  font-size: 0.75rem;
  padding: 4px 10px;
  min-height: 32px;
  min-width: auto;
}

/* ── Collapsible filter panel ── */
.feed-filter-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease;
}

.feed-filter-panel.open {
  max-height: 200px;
  padding: 8px 0;
}

.feed-filter-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.feed-filter-form label {
  display: flex !important;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.feed-filter-form input {
  min-width: 50px !important;
  width: 65px;
  padding: 3px 6px;
  font-size: 0.8rem;
}

/* ── Auto-sync spinner ── */
.auto-sync-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Compact post cards ── */
.post-list {
  display: flex;
  flex-direction: column;
}

.post-card {
  padding: 6px 4px;
  border-bottom: 1px solid #f0f3f8;
}

.post-card:active {
  background: #f6f9ff;
}

.post-title-row {
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

.post-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink);
  text-decoration: none;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-title:visited {
  color: #94a3b8;
}

.post-title:hover {
  color: var(--brand);
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}

.post-sep {
  margin: 0 3px;
  color: #d1d5db;
}

.post-tag {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-rec {
  color: #dc2626;
  font-weight: 700;
  white-space: nowrap;
}

.post-comments {
  white-space: nowrap;
}

.post-time {
  white-space: nowrap;
  color: #94a3b8;
}

/* ── Mobile: bottom tab bar + compact layout ── */
@media (max-width: 768px) {
  /* Bottom-fixed tab bar for thumb reachability */
  .tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--panel);
    border-top: 1px solid var(--line);
    margin: 0;
    padding: 4px;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-around;
    gap: 2px;
  }

  .tabs a {
    flex: 1;
    text-align: center;
    font-size: 0.72rem;
    padding: 8px 2px;
    border-radius: 8px;
  }

  /* Reserve space for the fixed bottom tab bar */
  .page-shell {
    padding-bottom: max(72px, calc(56px + env(safe-area-inset-bottom)));
  }

  /* Compact content area */
  .content {
    padding: 6px;
  }

  /* Post card: tighter on mobile */
  .post-card {
    padding: 5px 2px;
  }

  .post-title {
    font-size: 14px;
  }

  .post-meta {
    font-size: 11px;
  }

  .scrap-star {
    min-width: 36px;
    min-height: 36px;
    font-size: 1rem;
  }

  /* Feed filter / gallery form: vertical layout */
  .feed-filter-form {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .feed-filter-form label {
    flex-direction: row;
    justify-content: space-between;
  }

  .feed-filter-form input {
    width: 80px !important;
    min-width: 80px !important;
  }

  .form-grid {
    flex-direction: column;
  }

  .form-grid label {
    width: 100%;
  }

  .form-grid input,
  .form-grid select {
    min-width: 100%;
  }

  .form-grid button[type="submit"] {
    width: 100%;
  }

  /* Gallery card: stack vertically */
  .card.row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .inline-controls {
    justify-content: flex-end;
  }

  /* Hide subtitle on mobile */
  .subtitle {
    display: none;
  }

  .topbar {
    padding: 6px 12px;
  }

  .topbar h1 {
    font-size: 0.95rem;
  }
}

/* ── Desktop: multi-column posts ── */
@media (min-width: 1000px) {
  .post-list {
    column-count: 2;
    column-gap: 16px;
  }
  .post-card {
    break-inside: avoid;
  }
}

@media (min-width: 1400px) {
  .post-list {
    column-count: 3;
  }
}

/* ── Pull-to-refresh prevention ── */
html {
  overscroll-behavior-y: contain;
}

/* ── Smooth scrolling ── */
html {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* ── Disable text selection on UI chrome (not on content) ── */
.tabs,
button,
.topbar {
  -webkit-user-select: none;
  user-select: none;
}
