@media (max-width: 768px) {

  /* ── Tab bar: compact for mobile ── */
  .tab-bar {
    padding: 0 8px;
    gap: 0;
    flex-wrap: wrap;
  }

  .tab-brand {
    display: none;
  }

  .tab-buttons {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-width: 0;
    scrollbar-width: none;
  }

  .tab-buttons::-webkit-scrollbar {
    display: none;
  }

  .tab-bar button {
    padding: 10px 12px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .tab-bar .spacer {
    display: none;
  }

  .tab-bar .status {
    margin: 6px 0 6px 4px;
    padding: 4px 8px;
    font-size: 11px;
  }

  .tab-bar .status span {
    display: none;
  }

  /* ── App: no padding on mobile ── */
  #app {
    padding: 0 !important;
  }

  /* ── Chat tab: stack vertically, hide sidebar ── */
  #tab-chat {
    flex-direction: column !important;
    border-radius: 0 !important;
  }

  .thread-sidebar {
    display: none !important;
  }

  .chat-header {
    display: none;
  }

  .chat-container {
    flex: 1;
    min-height: 0;
  }

  .chat-messages {
    padding: 12px 12px 8px;
    gap: 12px;
  }

  .message {
    max-width: 95%;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.6;
  }

  .message.user {
    max-width: 85%;
  }

  .message.assistant {
    padding: 10px 14px;
  }

  .message pre {
    padding: 10px 12px;
    font-size: 12px;
    margin: 6px -4px;
  }

  .message code {
    font-size: 12px;
  }

  /* ── Chat input: touch-friendly ── */
  .chat-input {
    padding: 8px 10px 14px;
    gap: 8px;
  }

  .chat-input textarea {
    padding: 12px 16px;
    font-size: 15px;
    min-height: 46px;
    border-radius: 22px;
  }

  .chat-input button {
    width: 44px;
    height: 44px;
    font-size: 13px;
  }

  .chat-status {
    padding: 4px 12px;
    font-size: 11px;
    min-height: 24px;
  }

  /* Thread sidebar: fully hidden on mobile (display:none above) */

  /* ── Approval / auth cards ── */
  .approval-card,
  .auth-card {
    max-width: 100%;
  }

  .approval-actions {
    flex-wrap: wrap;
  }

  /* ── Memory: vertical stack ── */
  .memory-container {
    flex-direction: column;
  }

  .memory-sidebar {
    width: 100%;
    max-height: 180px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .memory-viewer {
    padding: 12px;
    font-size: 13px;
  }

  /* ── Jobs ── */
  .jobs-container {
    padding: 10px;
  }

  .jobs-table th,
  .jobs-table td {
    padding: 8px 6px;
    font-size: 12px;
  }

  /* Hide less important columns */
  .jobs-table th:nth-child(3),
  .jobs-table td:nth-child(3),
  .jobs-table th:nth-child(5),
  .jobs-table td:nth-child(5) {
    display: none;
  }

  .job-detail-header {
    flex-wrap: wrap;
  }

  .job-detail-header h2 {
    min-width: 100%;
    order: -1;
    font-size: 16px;
  }

  .job-detail-tabs {
    flex-wrap: wrap;
  }

  .job-files {
    flex-direction: column;
    height: auto;
  }

  .job-files-sidebar {
    width: 100%;
    max-height: 160px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .job-meta-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* ── Logs ── */
  .logs-toolbar {
    flex-wrap: wrap;
    padding: 8px 10px;
    gap: 6px;
  }

  .logs-toolbar select {
    min-width: 80px;
  }

  .logs-toolbar input {
    max-width: none;
    flex: 1 1 100%;
    order: -1;
  }

  .log-entry {
    padding: 2px 8px;
    font-size: 11px;
  }

  .log-ts {
    width: 50px;
    font-size: 10px;
  }

  .log-target {
    display: none;
  }

  /* ── Routines ── */
  .routines-container {
    padding: 10px;
  }

  .routines-table th,
  .routines-table td {
    padding: 8px 6px;
    font-size: 12px;
  }

  /* Hide less important columns */
  .routines-table th:nth-child(3),
  .routines-table td:nth-child(3),
  .routines-table th:nth-child(4),
  .routines-table td:nth-child(4),
  .routines-table th:nth-child(5),
  .routines-table td:nth-child(5) {
    display: none;
  }

  /* ── Extensions ── */
  .extensions-container {
    padding: 10px;
  }

  .extensions-list {
    grid-template-columns: 1fr;
  }

  .ext-install-form {
    flex-direction: column;
    align-items: stretch;
  }

  .ext-install-form input,
  .ext-install-form select {
    width: 100%;
  }

  .ext-url {
    font-size: 11px;
  }

  .tools-table th,
  .tools-table td {
    padding: 6px 8px;
    font-size: 12px;
  }

  /* ── Job card in chat ── */
  .job-card {
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 8px;
  }

  .job-card-view,
  .job-card-browse {
    padding: 6px 14px;
  }
}

/* Extra small screens (< 400px) */
@media (max-width: 400px) {
  .tab-bar button {
    padding: 10px 8px;
    font-size: 11px;
  }

  .chat-messages {
    padding: 8px 8px 6px;
    gap: 10px;
  }

  .message {
    padding: 10px 12px;
    font-size: 13.5px;
  }

  .chat-input {
    padding: 6px 8px 10px;
  }

  .chat-input textarea {
    padding: 10px 14px;
    font-size: 15px;
  }
}
