/* ================================================================
   Responsive — Mobile & tablet adaptations (≤768px).
   ================================================================ */

@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
  }

  /* Sidebar: overlay drawer */
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform 250ms ease;
  }

  #sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

  #sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 49;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 250ms ease;
  }

  #sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* 移动端为抽屉式侧栏，不显示宽度调节手柄 */
  #sidebar-resizer {
    display: none;
  }

  /* Header */
  #chat-header {
    padding: var(--space-sm) var(--space-md);
    min-height: 48px;
  }

  /* Header: keep the context capacity indicator reachable on mobile */
  #header-left .capacity-label {
    display: none;
  }

  /* Messages */
  .message-wrapper {
    padding: var(--space-xs) var(--space-md);
  }

  .message {
    max-width: 88%;
  }

  .message--user {
    padding: 8px 12px;
    font-size: 14px;
  }

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

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

  /* Hide floating bar on mobile */
  #floating-bar {
    display: none;
  }

  /* Input */
  #input-area {
    padding: var(--space-sm) var(--space-md) var(--space-md);
  }

  #input-card {
    max-width: 100%;
  }

  #message-input {
    font-size: 14px;
  }

  /* Hide time on user messages on mobile */
  .message-time {
    display: none;
  }

  /* Settings modal */
  .modal-panel {
    width: 95%;
    max-height: 90vh;
  }

  .modal-with-sidebar {
    flex-direction: column;
    width: 90vw;
    max-width: 500px;
    height: auto;
    max-height: 85vh;
  }

  .modal-sidebar {
    width: 100%;
    flex-direction: row;
    padding: var(--space-sm);
    border-right: none;
    border-bottom: 1px solid var(--rule);
  }

  .modal-sidebar-title {
    display: none;
  }

  .sidebar-tabs {
    flex-direction: row;
    flex: 1;
  }

  .settings-tab {
    padding: 6px 12px;
    font-size: 12px;
    gap: 6px;
    flex: 1;
    justify-content: center;
  }

  .modal-close-float {
    top: -24px;
    right: 2px;
    padding: 4px 10px;
    font-size: 11px;
  }

  .modal-close-float::after {
    content: '\2715';
  }

  /* Thinking block */
  .ai-think-body {
    max-height: 200px;
  }

  /* Conv item actions: always visible on mobile (no reliable hover) */
  .conv-item-actions {
    opacity: 1;
  }
}

/* Touch devices: always show conv item action buttons */
@media (hover: none) {
  .conv-item-actions {
    opacity: 1;
  }
}

@media (max-width: 480px) {
  :root {
    --sidebar-width: 280px;
  }

  .btn-kbd {
    display: none;
  }

  .message-wrapper {
    padding: 2px var(--space-sm);
  }

  .message {
    max-width: 92%;
    font-size: 14px;
  }

  #input-area {
    padding: var(--space-xs) var(--space-sm) var(--space-sm);
  }

  .code-block-header {
    padding: var(--space-xs) var(--space-sm);
  }

  .markdown-content pre code {
    padding: var(--space-md);
    font-size: 12px;
  }
}
