/* ===== LLM Council — Mobile Adaptation (iPhone 14 Pro Max & similar) ===== */

/* Safe area insets for notch & home indicator */
:root {
  --sat: env(safe-area-inset-top);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);
  --sar: env(safe-area-inset-right);
}

/* Prevent iOS overscroll bounce */
html {
  overflow: hidden;
  height: 100%;
}
body {
  overflow: hidden;
  height: 100%;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {

  /* ── App shell ── */
  .app {
    padding-top: var(--sat);
    padding-bottom: var(--sab);
    padding-left: var(--sal);
    padding-right: var(--sar);
  }

  /* ── Sidebar refinements ── */
  .sidebar {
    width: 85vw;
    max-width: 320px;
    padding-top: var(--sat);
  }

  .sidebar-overlay {
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }

  .conversation-item {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 14px;
  }

  .sidebar-footer {
    padding-bottom: calc(8px + var(--sab));
  }

  /* ── Top bar ── */
  .chat-topbar {
    padding: 8px 8px 8px 12px;
    min-height: 44px;
    gap: 6px;
    flex-wrap: nowrap;
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .hamburger-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 20px;
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  .chat-topbar-title {
    font-size: 14px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  /* Export buttons — compact row */
  .topbar-actions {
    display: flex !important;
    gap: 4px;
    flex-shrink: 0;
  }

  .export-btn {
    padding: 4px 8px;
    font-size: 11px;
    min-height: 32px;
    border-radius: 4px;
  }

  /* ── Messages area ── */
  .messages-container {
    padding: 8px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }

  .message-content {
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  .message-content pre {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: calc(100vw - 32px);
    font-size: 13px;
  }

  .message-content code {
    font-size: 13px;
  }

  .message-content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: calc(100vw - 32px);
  }

  .message-content img {
    max-width: 100%;
    height: auto;
  }

  /* User message */
  .user-message {
    padding: 10px 12px;
    border-radius: 16px;
    font-size: 15px;
  }

  /* ── Stage section (Individual Responses / Council) ── */
  .stage {
    padding: 8px;
    margin: 8px 0;
    border-radius: 8px;
  }

  .stage-header {
    font-size: 14px;
    padding: 6px 8px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .stage-controls {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
  }

  .stage-controls button {
    padding: 4px 8px;
    font-size: 12px;
    min-height: 32px;
  }

  /* ── Model tabs — horizontal scroll ── */
  .model-tabs {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    gap: 0;
    flex-wrap: nowrap !important;
    padding-bottom: 2px;
  }

  .model-tabs::-webkit-scrollbar {
    display: none;
  }

  .model-tab {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 13px;
    min-height: 36px;
    white-space: nowrap;
  }

  /* ── Compare panels ── */
  .compare-panels {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }

  .compare-panel {
    max-height: 50vh;
    overflow-y: auto;
  }

  /* ── Input form ── */
  .input-form {
    padding: 8px;
    padding-bottom: calc(8px + var(--sab));
    gap: 8px;
    position: sticky;
    bottom: 0;
    z-index: 40;
    border-top: 1px solid var(--border-color, #2a2a40);
  }

  .message-input {
    font-size: 16px !important; /* Prevents iOS zoom on focus */
    min-height: 44px;
    max-height: 120px;
    padding: 10px 12px;
    border-radius: 12px;
    -webkit-appearance: none;
  }

  .send-button {
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 12px;
    font-size: 14px;
    flex-shrink: 0;
  }

  .attach-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Loading states ── */
  .stage-loading-header {
    font-size: 12px;
    padding: 6px 8px;
  }

  /* ── Empty state ── */
  .empty-state {
    padding: 20px;
  }

  .empty-state h2 {
    font-size: 20px;
  }

  .empty-state p {
    font-size: 14px;
  }

  /* ── Attachment chips ── */
  .attachment-chip {
    max-width: calc(100vw - 100px);
    font-size: 12px;
  }

  /* ── Search in sidebar ── */
  .search-input,
  .sidebar input[type="text"] {
    font-size: 16px !important; /* Prevents iOS zoom */
    min-height: 40px;
  }

  /* ── Smooth scrolling for momentum ── */
  * {
    -webkit-tap-highlight-color: transparent;
  }

  /* ── Standalone PWA mode — extra bottom padding ── */
  @media (display-mode: standalone) {
    .input-form {
      padding-bottom: calc(16px + var(--sab));
    }

    .sidebar-footer {
      padding-bottom: calc(16px + var(--sab));
    }
  }
}

/* ── Small phones (iPhone SE, etc) ── */
@media (max-width: 375px) {
  .chat-topbar-title {
    font-size: 13px;
  }

  .export-btn {
    padding: 3px 6px;
    font-size: 10px;
  }

  .model-tab {
    padding: 6px 10px;
    font-size: 12px;
  }

  .message-content {
    font-size: 14px;
  }
}


/* ===== Mobile Enhancements Styles ===== */

/* ── Scroll navigation buttons ── */
.scroll-nav-btn {
  position: fixed;
  right: 16px;
  z-index: 100;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(59,130,246,0.25);
  color: #60a5fa;
  border: 1px solid rgba(59,130,246,0.3);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  cursor: pointer;
}
.scroll-nav-btn.visible {
  opacity: 0.7;
  pointer-events: auto;
}
.scroll-nav-btn:active {
  opacity: 1;
  transform: scale(0.9);
}
.scroll-nav-up { top: 70px; }
.scroll-nav-down { bottom: 80px; }
@media (display-mode: standalone) {
  .scroll-nav-down { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* ── Export toggle button (mobile) ── */
.export-toggle-btn {
  min-width: 36px;
  min-height: 36px;
  border-radius: 6px;
  background: var(--bg-stage, #1e1e38);
  border: 1px solid var(--border-color, #2a2a40);
  color: var(--text-secondary, #8888aa);
  font-size: 18px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
@media (max-width: 768px) {
  .export-toggle-btn { display: flex; }
  .topbar-actions {
    display: none !important;
    position: absolute;
    right: 8px;
    top: 48px;
    flex-direction: column;
    background: var(--bg-stage, #1e1e38);
    border: 1px solid var(--border-color, #2a2a40);
    border-radius: 8px;
    padding: 6px;
    gap: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    z-index: 60;
  }
  .topbar-actions.export-expanded {
    display: flex !important;
  }
  .topbar-actions .export-btn {
    width: 100%;
    text-align: center;
    padding: 8px 16px;
    font-size: 13px;
  }
}

/* ── Info tab button ── */
.info-tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  margin-top: 4px;
  background: transparent;
  border: none;
  color: var(--text-secondary, #8888aa);
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: background .15s;
}
.info-tab-btn:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary, #e0e0e0);
}

/* ── Info modal ── */
.info-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.info-modal-content {
  background: var(--bg-primary, #1a1a2e);
  border: 1px solid var(--border-color, #2a2a40);
  border-radius: 16px;
  max-width: 360px;
  width: 100%;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.info-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color, #2a2a40);
}
.info-modal-header h3 {
  margin: 0;
  font-size: 18px;
  color: var(--text-primary, #e0e0e0);
}
.info-close-btn {
  background: none;
  border: none;
  color: var(--text-secondary, #8888aa);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.info-modal-body {
  padding: 20px;
}
.info-version {
  font-size: 13px;
  color: var(--text-secondary, #8888aa);
  margin: 0 0 12px;
}
.info-desc {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary, #e0e0e0);
  margin: 0 0 16px;
}
.info-divider {
  height: 1px;
  background: var(--border-color, #2a2a40);
  margin: 16px 0;
}
.info-feedback-label {
  font-size: 13px;
  color: var(--text-secondary, #8888aa);
  margin: 0 0 12px;
}
.info-telegram-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(42,171,238,0.1);
  border: 1px solid rgba(42,171,238,0.2);
  border-radius: 12px;
  text-decoration: none;
  color: #2AABEE;
  font-size: 16px;
  font-weight: 500;
  transition: background .15s;
}
.info-telegram-link:hover {
  background: rgba(42,171,238,0.2);
}
