/* Mobile adaptation — phones & small tablets */

@media (max-width: 860px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 0.65rem;
    padding: 0.75rem 0.85rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
  }

  .brand h1 {
    font-size: 1rem;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .topbar-actions .btn {
    flex: 1 1 auto;
    min-height: 42px;
    padding: 0.55rem 0.7rem;
    font-size: 0.88rem;
  }

  .btn-label-full {
    display: none;
  }

  .btn-label-short {
    display: inline;
  }

  .switch-label {
    font-size: 0.8rem;
  }

  .status-pill {
    padding: 0.35rem 0.55rem;
    font-size: 0.75rem;
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    flex: 0 0 auto;
    padding: 0.55rem 0.85rem 0;
  }

  .mobile-nav-btn {
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-elevated);
    color: var(--muted);
    font-weight: 500;
    cursor: pointer;
  }

  .mobile-nav-btn.active {
    color: #d7fff7;
    border-color: rgba(45, 212, 191, 0.5);
    background: var(--accent-dim);
  }

  .layout {
    display: block;
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    padding: 0.65rem 0.85rem;
    padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
    overflow: hidden;
  }

  .sidebar,
  .logs-area {
    position: absolute;
    inset: 0.65rem 0.85rem;
    bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
    height: auto;
    max-height: none;
    display: none;
    overflow: hidden;
  }

  .app[data-mobile-tab="subs"] .sidebar,
  .app[data-mobile-tab="logs"] .logs-area {
    display: flex;
    flex-direction: column;
  }

  .panel.subs-panel,
  .logs-panel {
    height: 100%;
    max-height: 100%;
    flex: 1 1 0;
    min-height: 0;
  }

  .panel.subs-panel {
    padding: 0.85rem;
  }

  .form.compact {
    gap: 0.55rem;
  }

  .form input[type="text"],
  .form input[type="number"],
  .form input[type="password"],
  .btn {
    min-height: 42px;
    font-size: 16px; /* avoid iOS zoom on focus */
  }

  .logs-head {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .logs-actions {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .logs-table-wrap {
    display: none !important;
  }

  .logs-cards {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    flex: 1 1 0;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-right: 0.1rem;
  }

  .logs-cards.hidden {
    display: none !important;
  }

  .log-card {
    flex: 0 0 auto;
    background: #0c1015;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.7rem 0.75rem;
  }

  .log-card-top {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-family: var(--mono);
  }

  .log-card-topic {
    color: var(--accent);
    font-family: var(--mono);
    font-size: 0.78rem;
    word-break: break-all;
    margin-bottom: 0.45rem;
  }

  .log-card-payload {
    font-family: var(--mono);
    font-size: 0.8rem;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.35;
  }

  .empty-state {
    padding: 1.25rem;
    font-size: 0.9rem;
  }

  .modal {
    padding: 0;
    align-items: stretch;
  }

  .modal-dialog {
    width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
    border: 0;
    padding:
      calc(1rem + env(safe-area-inset-top, 0px))
      1rem
      calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  .modal-actions {
    position: sticky;
    bottom: 0;
    padding-top: 0.75rem;
    background: linear-gradient(transparent, var(--bg-elevated) 30%);
  }

  .modal-actions .btn {
    flex: 1;
  }
}

@media (min-width: 861px) {
  .mobile-nav {
    display: none !important;
  }

  .btn-label-short {
    display: none;
  }

  .logs-cards {
    display: none !important;
  }
}
