@media (max-width: 860px) {
  /* 입력창에서 전송·중지 버튼으로 포커스가 이동해도 클릭 중 레이아웃이 움직이지 않는다. */
  :root {
    --rail-h: calc(60px + env(safe-area-inset-bottom));
  }

  body:not(.sidebar-open):has(#chatForm:focus-within) {
    --rail-h: 0px;
  }

  body:not(.sidebar-open):has(#chatForm:focus-within) .app-rail {
    display: none;
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  /* dashboard.css가 뒤에 읽히므로 한 단계 더 구체적으로 고른다. */
  .app-shell .main-view-shell {
    height: calc(100vh - var(--rail-h));
    height: calc(100dvh - var(--rail-h));
  }

  .app-rail {
    position: fixed;
    inset: auto 0 0;
    z-index: 45;
    flex-direction: row;
    align-items: stretch;
    gap: 2px;
    height: var(--rail-h);
    padding: 4px 6px env(safe-area-inset-bottom);
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .rail-header {
    display: none;
  }

  .rail-items {
    flex: 1;
    flex-direction: row;
    gap: 2px;
    width: auto;
    min-width: 0;
  }

  .rail-item {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    padding: 4px 2px;
  }

  .rail-item .ui-icon {
    padding: 4px 14px;
  }

  .rail-account {
    flex-direction: row;
    width: auto;
    margin-top: 0;
  }

  .rail-theme-toggle { order: 0; }

  .account-menu {
    position: fixed;
    right: 8px;
    bottom: calc(var(--rail-h) + 8px);
    left: auto;
    width: min(300px, calc(100vw - 16px));
  }

  .toast-stack {
    bottom: calc(var(--rail-h) + 16px);
  }

  .control-group {
    padding: 12px 0;
  }

  .chat-panel {
    height: auto;
    min-height: 72vh;
    overflow: visible;
  }

  .chat-header {
    min-height: 60px;
    padding: 10px 20px;
    justify-content: flex-start;
  }

  .messages {
    padding: 20px;
  }

  .starter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .message {
    gap: 10px;
  }

  .user-message-content {
    max-width: 88%;
  }

  .issue-detail-header {
    display: grid;
  }

  .issue-detail-header em {
    justify-self: start;
  }

  .issue-detail-meta {
    grid-template-columns: 1fr;
  }

  /* 좁은 화면에서는 카드 바깥 여백을 줄이고, 원형 전송 버튼은 손가락 크기에 맞춰 키운다. */
  .composer {
    --composer-gutter: 12px;
    padding-bottom: 25px;
  }

  .composer::before {
    bottom: 14px;
  }

  .composer .send-button {
    width: 40px;
    height: 40px;
    border-radius: 999px;
  }

  .scroll-to-top-button {
    right: 20px;
  }

  .verification-checks {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .empty-state {
    padding: 24px 0;
  }

  .empty-state h3 {
    font-size: 22px;
    line-height: 31px;
  }

  .starter-grid {
    grid-template-columns: 1fr;
    margin-top: 22px;
  }

  .starter-card:nth-child(odd) {
    border-right: 0;
  }

  .data-status-line {
    max-width: calc(100vw - 90px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .modal-form {
    padding: 18px;
  }

  .template-fields,
  .feedback-reason-group {
    grid-template-columns: 1fr;
  }

  .modal-form-actions {
    grid-template-columns: 1fr;
  }

  .message-feedback-label,
  .message-action-divider {
    display: none;
  }

  /* 13px 글자에서도 답변 도구 버튼 네 개가 한 줄에 들어가도록 좌우 여백만 줄인다. */
  .message-actions {
    gap: 2px;
  }

  .message-actions button {
    padding: 4px 6px;
  }
}

@media (width > 860px) {
  .app-rail {
    overflow-y: auto;
  }

  /* 계정 메뉴가 스크롤되는 사이드바에 잘리지 않게 한다. */
  .account-menu {
    position: fixed;
    inset: auto auto var(--space-4) calc(var(--rail-w) + var(--space-2));
  }
}

/* 주 메뉴가 접혀 있거나 좁은 화면에서는 대화 기록을 드로어로 연다. */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 60;
  width: min(300px, 86vw);
  height: 100vh;
  height: 100dvh;
  padding: var(--space-4);
  border-right: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(-100%);
  visibility: hidden;
}

body.sidebar-open .sidebar {
  transform: translateX(0);
  visibility: visible;
}

body.sidebar-open .app-shell[data-view="chat"] .app-rail::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(10, 12, 16, 0.35);
}

@media (prefers-reduced-motion: no-preference) {
  /* 닫힐 때는 이동이 끝난 뒤 숨기고 열릴 때는 바로 포커스를 받을 수 있게 한다. */
  .sidebar {
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
  }

  body.sidebar-open .sidebar {
    transition: transform 0.22s ease, visibility 0s;
  }
}

@media (prefers-reduced-motion: reduce) {
  /* 자식도 표시 상태를 즉시 상속해야 열자마자 포커스를 받을 수 있다. */
  .sidebar,
  .sidebar * {
    transition-property: none;
  }
}
