/* ── Mobile & small tablet layout ─────────────────────────────── */

@media (max-width: 768px) {
  :root {
    --layout-gutter: 1rem;
  }

  .container {
    padding: 1rem var(--layout-gutter);
  }

  /* Navigation */
  .navbar {
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    padding: 0.65rem var(--layout-gutter);
    min-height: auto;
  }

  .nav-brand {
    flex: 1 1 auto;
    min-width: 0;
  }

  .nav-subtitle {
    display: none;
  }

  .nav-meta {
    order: 3;
    width: 100%;
    font-size: 0.75rem;
  }

  .nav-links {
    order: 4;
    width: 100%;
    margin-left: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.25rem;
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
  }

  .nav-links > a {
    padding: 0.55rem 0.4rem;
    font-size: 0.78rem;
    text-align: center;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-bottom: none;
    border-radius: var(--radius);
  }

  .nav-links > a.active {
    background: var(--primary-light);
    border-bottom: none;
  }

  .nav-reset-form {
    margin: 0;
    grid-column: 1 / -1;
  }

  .nav-reset-form .btn {
    width: 100%;
    min-height: 44px;
  }

  /* Touch-friendly controls */
  .btn {
    min-height: 44px;
  }

  .btn-sm {
    min-height: 40px;
  }

  .btn-lg {
    width: 100%;
    justify-content: center;
  }

  /* Forms & actions */
  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }

  .survey-action-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .survey-action-bar .btn {
    width: 100%;
    justify-content: center;
  }

  .upload-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .upload-actions .btn {
    width: 100%;
  }

  /* Tables — horizontal scroll */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 calc(-1 * var(--layout-gutter));
    padding: 0 var(--layout-gutter);
  }

  .milestone-table--pro {
    min-width: 720px;
  }

  /* Page headers */
  .page-header h1 {
    font-size: 1.25rem;
    line-height: 1.3;
  }

  .page-header p {
    font-size: 0.875rem;
  }

  /* Risk upload / picker */
  .risk-doc-picker-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .risk-doc-picker-actions {
    width: 100%;
    display: flex;
    gap: 0.5rem;
  }

  .risk-doc-picker-actions .btn {
    flex: 1;
  }

  .risk-doc-picker-item {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .risk-doc-picker-label {
    width: 100%;
  }

  .risk-doc-filename {
    white-space: normal;
    word-break: break-word;
  }

  .risk-doc-delete {
    align-self: stretch;
    width: 100%;
  }

  /* Modals */
  .modal {
    align-items: flex-end;
    padding: 0;
  }

  .modal-content,
  .modal-wide {
    width: 100%;
    min-width: 0;
    max-width: none;
    max-height: 92vh;
    overflow-y: auto;
    border-radius: var(--radius) var(--radius) 0 0;
    margin: 0;
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions .btn {
    width: 100%;
  }

  /* Agent chat */
  .agent-chat {
    bottom: 0.75rem;
    right: 0.75rem;
    left: 0.75rem;
  }

  .agent-chat-panel {
    width: 100%;
    max-width: none;
    max-height: min(72vh, 520px);
  }

  .agent-chat-toggle {
    width: 100%;
    justify-content: center;
    min-height: 48px;
  }

  /* Footer */
  .footer {
    flex-direction: column;
    gap: 0.35rem;
    text-align: center;
    padding: 0.85rem var(--layout-gutter);
  }

  /* Legacy risk overview */
  .risk-overview {
    grid-template-columns: 1fr;
  }

  .features-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .persona-grid {
    grid-template-columns: 1fr;
  }

  .pathway-grid {
    grid-template-columns: 1fr;
  }

  .step-indicator .step {
    font-size: 0.65rem;
    padding: 0.2rem 0.4rem;
  }

  .nav-links {
    grid-template-columns: 1fr;
  }

  .extracted-preview-grid {
    grid-template-columns: 1fr !important;
  }
}
