@media screen and (max-width: 1024px) {
  .app {
    grid-template-columns: 220px 1fr;
  }

  .messages,
  .composer {
    max-width: 100%;
    padding-left: 18px;
    padding-right: 18px;
  }

  .subscription-plans {
    gap: 14px;
  }

  .plan-card {
    padding: 22px 18px;
  }

  .plan-price {
    font-size: 26px;
  }
}

@media screen and (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    position: relative;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 45;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .sidebar-overlay.active {
    display: block;
    opacity: 1;
  }

  .icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    transition: background 0.15s ease, color 0.15s ease;
  }

  .icon-btn:hover {
    background: var(--ink-800);
    color: var(--parchment);
  }

  .topbar {
    padding: 12px 16px;
    gap: 10px;
  }

  .topbar-title {
    font-size: 13.5px;
  }

  .topbar-actions {
    margin-right: 0;
    gap: 6px;
  }

  .topbar-btn {
    font-size: 11.5px;
    padding: 6px 10px;
  }

  .status-pill {
    font-size: 10px;
    padding: 3px 8px;
    gap: 4px;
  }

  .messages {
    padding: 20px 16px 8px;
    gap: 18px;
  }

  .msg.user .msg-bubble {
    max-width: 85%;
    font-size: 14px;
    padding: 10px 14px;
  }

  .msg.assistant .msg-bubble {
    font-size: 14px;
    padding-left: 12px;
  }

  .empty-state {
    padding: 32px 16px;
  }

  .empty-state h1 {
    font-size: 22px;
  }

  .empty-state p {
    font-size: 13px;
  }

  .suggestion-chip {
    font-size: 12.5px;
    padding: 8px 12px;
  }

  .composer {
    padding: 10px 16px 16px;
  }

  .composer-box {
    padding: 8px 8px 8px 14px;
    gap: 8px;
  }

  .composer-input {
    font-size: 14px;
  }

  .send-btn {
    width: 30px;
    height: 30px;
  }

  .composer-hint {
    font-size: 10.5px;
    margin-top: 8px;
  }

  .subscription-modal {
    padding: 0 8px;
  }

  .subscription-plans {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .subscription-head h2 {
    font-size: 22px;
  }

  .subscription-head p {
    font-size: 13px;
  }

  .plan-card {
    padding: 24px 20px;
  }

  .subscription-close {
    top: 0;
    right: 8px;
    width: 30px;
    height: 30px;
    font-size: 14px;
  }

  .contributor-drawer {
    width: 280px;
  }

  .msg.assistant .msg-bubble pre {
    padding: 12px 14px;
    margin: 0 0 10px;
  }

  .msg.assistant .msg-bubble pre code {
    font-size: 12.5px;
  }

  .code-copy-btn {
    opacity: 1;
    font-size: 10px;
    padding: 3px 7px;
    top: 6px;
    right: 6px;
  }

  .msg.assistant .msg-bubble table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .img-gen-card {
    max-width: 100%;
  }
}

@media screen and (max-width: 480px) {
  .sidebar {
    width: 260px;
  }

  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .topbar-title {
    font-size: 12.5px;
  }

  .topbar-actions {
    gap: 4px;
  }

  .topbar-btn {
    font-size: 11px;
    padding: 5px 8px;
    border-radius: var(--radius-sm);
  }

  .status-pill {
    font-size: 9.5px;
    padding: 2px 6px;
  }

  .brand-mark {
    font-size: 18px;
  }

  .btn-new-chat {
    font-size: 12.5px;
    padding: 9px 10px;
  }

  .messages {
    padding: 16px 12px 6px;
    gap: 16px;
  }

  .msg.user .msg-bubble {
    max-width: 88%;
    font-size: 13.5px;
    padding: 9px 12px;
    border-radius: var(--radius-md) var(--radius-md) 4px var(--radius-md);
  }

  .msg.assistant .msg-bubble {
    font-size: 13.5px;
    padding-left: 10px;
    border-left-width: 2px;
  }

  .msg.assistant .msg-bubble h1 { font-size: 17px; }
  .msg.assistant .msg-bubble h2 { font-size: 15px; }
  .msg.assistant .msg-bubble h3 { font-size: 14px; }

  .msg.assistant .msg-bubble blockquote {
    padding-left: 10px;
    margin: 0 0 10px;
  }

  .msg-role {
    font-size: 10px;
    letter-spacing: 0.06em;
  }

  .empty-state {
    padding: 24px 14px;
  }

  .hero-logo {
    width: 36px;
    height: 36px;
    margin-bottom: 10px;
  }

  .empty-state h1 {
    font-size: 20px;
  }

  .empty-state p {
    font-size: 12.5px;
    margin-bottom: 16px;
  }

  .suggestion-chip {
    font-size: 12px;
    padding: 8px 10px;
  }

  .composer {
    padding: 8px 12px 14px;
  }

  .composer-box {
    padding: 6px 6px 6px 12px;
    gap: 6px;
    border-radius: var(--radius-md);
  }

  .composer-input {
    font-size: 13.5px;
    padding: 4px 0;
  }

  .send-btn {
    width: 28px;
    height: 28px;
  }

  .composer-hint {
    font-size: 10px;
    margin-top: 6px;
  }

  /* Alert modal */
  .calert-box {
    padding: 18px;
    max-width: 280px;
  }

  .calert-message {
    font-size: 13px;
    margin-bottom: 14px;
  }

  .calert-btn {
    font-size: 12px;
    padding: 7px 12px;
  }

  .subscription-head h2 {
    font-size: 20px;
  }

  .plan-name {
    font-size: 14px;
  }

  .plan-price {
    font-size: 24px;
  }

  .plan-benefits li {
    font-size: 12.5px;
  }

  .plan-btn {
    font-size: 12.5px;
    padding: 10px;
  }

  .subscription-note {
    font-size: 10.5px;
  }

  .contributor-drawer {
    width: 260px;
    padding: 16px;
  }

  .contributor-drawer-head h2 {
    font-size: 15px;
  }

  .contributor-name {
    font-size: 13px;
  }

  .history-item {
    font-size: 12.5px;
    padding: 7px 8px;
  }

  .history-delete-btn {
    font-size: 12px;
    padding: 5px 7px;
    opacity: 0.6;
  }

  .model-label {
    font-size: 10px;
  }

  #modelSelect {
    font-size: 12.5px;
    padding: 7px 8px;
  }

  .model-note {
    font-size: 10px;
  }

  .img-gen-card {
    padding: 16px;
  }

  .img-gen-stage {
    width: 100px;
    height: 100px;
  }

  .img-gen-label {
    font-size: 10.5px;
  }
}

@media screen and (max-width: 360px) {
  .sidebar {
    width: 240px;
  }

  .topbar {
    padding: 8px 10px;
  }

  .topbar-title {
    font-size: 11.5px;
  }

  .status-pill {
    display: none;
  }

  .topbar-btn {
    font-size: 10.5px;
    padding: 4px 7px;
  }

  .messages {
    padding: 12px 10px 4px;
    gap: 12px;
  }

  .msg.user .msg-bubble {
    max-width: 92%;
    font-size: 13px;
    padding: 8px 10px;
  }

  .msg.assistant .msg-bubble {
    font-size: 13px;
  }

  .composer {
    padding: 6px 10px 12px;
  }

  .composer-input {
    font-size: 13px;
  }

  .subscription-plans {
    gap: 10px;
  }

  .plan-card {
    padding: 18px 14px;
  }
}

@media screen and (min-width: 1400px) {
  .app {
    grid-template-columns: 300px 1fr;
  }

  .messages,
  .composer {
    max-width: 860px;
  }

  .sidebar {
    padding: 22px 18px;
  }

  .empty-state {
    max-width: 560px;
  }
}

@media (hover: none) and (pointer: coarse) {
  .code-copy-btn {
    opacity: 0.6;
  }

  .history-delete-btn {
    opacity: 0.5;
  }

  .suggestion-chip:active {
    border-color: var(--signal);
    color: var(--parchment);
  }

  .btn-new-chat:active {
    border-color: var(--signal);
    background: var(--ink-700);
  }

  .send-btn:active {
    transform: scale(0.9);
  }
}

@media print {
  .sidebar,
  .topbar,
  .composer,
  .btn-new-chat,
  .send-btn,
  .icon-btn,
  .code-copy-btn,
  .subscription-overlay,
  .contributor-overlay,
  .calert-overlay,
  .sidebar-overlay {
    display: none !important;
  }

  .app {
    display: block;
  }

  .main {
    height: auto;
  }

  .chat {
    overflow: visible;
  }

  .msg.assistant .msg-bubble {
    border-left: 2px solid #000;
    color: #000;
  }

  .msg.user .msg-bubble {
    background: #f0f0f0;
    border: 1px solid #ccc;
    color: #000;
  }

  body {
    background: #fff;
    color: #000;
  }
}

@media screen and (max-height: 700px) {
  .empty-state {
    padding: 20px 16px;
  }

  .hero-logo {
    width: 32px;
    height: 32px;
    margin-bottom: 8px;
  }

  .empty-state h1 {
    font-size: 20px;
    margin-bottom: 4px;
  }

  .empty-state p {
    margin-bottom: 12px;
  }

  .suggestions {
    gap: 5px;
  }

  .suggestion-chip {
    padding: 7px 10px;
  }

  .composer {
    padding-bottom: 10px;
  }
}

@media screen and (max-height: 500px) and (orientation: landscape) {
  .topbar {
    padding: 8px 16px;
  }

  .empty-state {
    padding: 12px 16px;
  }

  .hero-logo {
    width: 28px;
    height: 28px;
  }

  .empty-state h1 {
    font-size: 18px;
  }

  .empty-state p {
    font-size: 12px;
    margin-bottom: 8px;
  }

  .messages {
    padding: 10px 16px 4px;
    gap: 12px;
  }

  .composer {
    padding: 6px 16px 10px;
  }
}