/* Dashboard mobile layout — drawer nav, touch targets, safe areas. Loaded after styles.css. */

.mobile-nav-toggle,
.mobile-nav-backdrop {
  display: none;
}

.topbar-leading {
  display: contents;
}

.topbar-copy {
  min-width: 0;
}

@media (max-width: 860px) {
  .content {
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  .topbar {
    gap: 14px;
  }

  .topbar-leading {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
    flex: 1 1 auto;
  }

  .topbar-copy {
    flex: 1 1 auto;
    min-width: 0;
  }

  .mobile-nav-toggle {
    display: none;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    min-width: 44px;
    padding-inline: 12px;
    margin-top: 2px;
  }

  body.server-selected .mobile-nav-toggle {
    display: inline-flex;
  }

  .mobile-nav-toggle-bars {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 16px;
    height: 14px;
    flex-shrink: 0;
  }

  .mobile-nav-toggle-bars span {
    display: block;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    transition:
      transform 180ms ease,
      opacity 160ms ease;
  }

  body.mobile-nav-open .mobile-nav-toggle-bars span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }

  body.mobile-nav-open .mobile-nav-toggle-bars span:nth-child(2) {
    opacity: 0;
  }

  body.mobile-nav-open .mobile-nav-toggle-bars span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  .mobile-nav-toggle-label {
    font-weight: 800;
    font-size: 12px;
  }

  .mobile-nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1290;
    background: rgba(4, 8, 14, 0.82);
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
  }

  .mobile-nav-backdrop:not([hidden]) {
    opacity: 1;
    pointer-events: auto;
  }

  body:not(.server-selected) .sidebar {
    display: none;
  }

  body.server-selected .sidebar {
    position: fixed;
    z-index: 1300;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 88vw);
    max-width: 100%;
    margin: 0;
    height: auto;
    isolation: isolate;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: linear-gradient(180deg, #0c141f 0%, #060a10 100%);
    transform: translate3d(-105%, 0, 0);
    transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
    border-bottom: none;
    border-right: 1px solid var(--line);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    box-shadow: 24px 0 64px rgba(0, 0, 0, 0.42);
    pointer-events: none;
  }

  body.server-selected .sidebar .brand-lockup strong {
    color: #f2fbff;
    background: none;
    -webkit-background-clip: border-box;
    background-clip: border-box;
  }

  body.server-selected.mobile-nav-open .sidebar {
    transform: translate3d(0, 0, 0);
    pointer-events: auto;
  }

  body.server-selected.mobile-nav-open #configNav,
  body.server-selected.mobile-nav-open #configNav .nav {
    filter: none;
    -webkit-filter: none;
  }

  body.server-selected .sidebar::after {
    display: none;
  }

  body.server-selected .brand {
    margin-bottom: 20px;
  }

  body.server-selected #configNav {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    overflow: visible;
    padding: 0;
    margin-inline: 0;
    scroll-snap-type: none;
  }

  body.server-selected #configNav .nav,
  body.server-selected #configNav .nav.active {
    flex: none;
    min-width: 0;
    width: 100%;
    min-height: 44px;
    justify-content: flex-start;
    scroll-snap-align: none;
    padding-left: 14px;
    padding-right: 14px;
  }

  body.server-selected #configNav .nav::before {
    inset: 8px auto 8px 7px;
    width: 3px;
    height: auto;
    transform: scaleY(0.45);
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  body.mobile-nav-open .content {
    touch-action: none;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .guild-search-input {
    max-width: none;
    width: 100%;
    flex: 1 1 100%;
    min-height: 44px;
  }

  .guild-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .nav,
  .button,
  .mini,
  .server-action,
  .lang-chip,
  .account-button,
  .dropdown-item {
    min-height: 44px;
  }

  .server {
    min-height: 152px;
  }

  .details {
    padding: 14px;
    min-height: 280px;
  }

  .details .panel,
  .details .settings-block,
  .details .module-card-pro {
    max-width: 100%;
  }

  .details .matrix-chart-wrap,
  .details .analytics-chart-wrap,
  .details .starboard-highlights-table,
  .details table,
  .details .audit-table-wrap,
  .details .invoice-table-wrap {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .command-layer,
  .confirm-layer {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    align-items: flex-end;
  }

  .command-dialog,
  .confirm-dialog,
  .backup-preview-dialog {
    width: min(100%, calc(100vw - 24px));
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow: auto;
  }

  .confirm-dialog {
    grid-template-columns: 1fr;
  }

  .confirm-actions,
  .backup-preview-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .confirm-actions .button,
  .confirm-actions .mini,
  .backup-preview-actions .button,
  .backup-preview-actions .mini {
    width: 100%;
  }

  .toast-stack {
    top: max(12px, env(safe-area-inset-top));
    bottom: auto;
  }

  /* --- Phase 2: Tickets, Support, Live, Settings --- */

  .live-command,
  .ops-radar {
    grid-template-columns: 1fr;
    align-items: stretch;
    padding: 14px;
  }

  .pulse-bars,
  .health-command-strip,
  .metrics,
  .ops-grid,
  .system-grid,
  .reward-board,
  .radar-grid,
  .score-grid {
    grid-template-columns: 1fr;
  }

  .live-section-head {
    flex-direction: column;
    align-items: stretch;
  }

  .action-row {
    padding: 12px;
  }

  .action-row span,
  .action-row strong,
  .action-row small {
    display: block;
    margin-bottom: 4px;
  }

  .inline-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-top: 12px;
  }

  .inline-actions .mini,
  .inline-actions .mini-input,
  .inline-actions .button {
    width: 100%;
    min-height: 44px;
    margin-top: 0;
  }

  .mini-input,
  .mini-input.tiny {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .live-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .live-footer .mini {
    width: 100%;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .category-row:not(.category-row--form),
  .blacklist-row,
  .macro-row {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 10px;
  }

  .category-row:not(.category-row--form) .mini,
  .blacklist-row .mini,
  .macro-row .mini,
  .category-row:not(.category-row--form) .category-remove {
    width: 100%;
  }

  .category-row.category-row--form {
    grid-template-columns: 1fr;
  }

  .category-field--emoji {
    max-width: none;
  }

  .category-field--stretch {
    grid-column: 1;
  }

  .macro-row textarea {
    min-height: 88px;
  }

  .section-tabs {
    top: max(8px, env(safe-area-inset-top));
    margin-bottom: 4px;
    padding: 8px;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scroll-padding-inline: 8px;
  }

  .section-tab {
    min-height: 44px;
    padding-inline: 14px 16px;
    font-size: 13px;
  }

  .settings-form > .button[type="submit"],
  .settings-form > .button.save-settings,
  .settings-form .economy-form-submit,
  .settings-form > .mini[type="submit"] {
    width: 100%;
    min-height: 48px;
    margin-top: 4px;
  }

  .whitelist-form {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .whitelist-form input {
    min-height: 44px;
    font-size: 16px;
  }

  .whitelist-form .mini[type="submit"] {
    width: 100%;
  }

  .whitelist-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .whitelist-row .mini {
    width: 100%;
  }

  .access-guard {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .access-guard-grid {
    justify-content: flex-start;
  }

  .panel-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .panel-head .mini,
  .panel-head .button {
    width: 100%;
  }

  .details-head-row {
    gap: 12px;
  }

  .details-actions {
    width: 100%;
  }

  .details-actions .mini {
    flex: 1 1 auto;
    min-width: min(100%, 160px);
  }

  .activity-feed-list article {
    padding: 12px;
  }

  .audit-tools {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .audit-tools input,
  .audit-tools select {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .check-field,
  .check-field.compact,
  .switch-with-hints {
    min-height: 44px;
  }

  .field input,
  .field select,
  .field textarea {
    min-height: 44px;
    font-size: 16px;
  }

  .field textarea {
    min-height: 96px;
  }

  .panel[data-panel^="module-"] .settings-group:hover,
  .panel[data-panel="premium"] .premium-panel:hover,
  .settings-block:hover,
  .metric:hover,
  .system-card:hover,
  .score-row:hover,
  .inventory-card:hover,
  .invoice-row:hover,
  .playbooks-card__item:hover {
    transform: none;
  }

  /* --- Phase 3: Owner, Backups, Audit, Premium, Wizard, Modules --- */

  .observability-hero,
  .overview-hero,
  .wizard-hero {
    grid-template-columns: 1fr;
    align-items: stretch;
    padding: 16px;
    gap: 14px;
  }

  .observability-ring,
  .overview-score,
  .wizard-score {
    justify-self: start;
    margin-top: 4px;
  }

  .observability-grid,
  .observability-grid.ops-grid {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .button-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: 100%;
  }

  .form-actions .button,
  .form-actions .mini,
  .button-row .button,
  .button-row .mini {
    width: 100%;
    min-height: 44px;
    margin-top: 0;
  }

  .action-row .mini.ghost,
  .action-row .mini.danger-lite,
  .danger-row .mini {
    width: 100%;
    min-height: 44px;
    margin-top: 8px;
  }

  .ops-card.backup-row {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(13, 17, 23, 0.42);
  }

  .ops-card.backup-row > div:first-child strong,
  .ops-card.backup-row > div:first-child span {
    display: block;
    overflow-wrap: anywhere;
  }

  .ops-list {
    display: grid;
    gap: 12px;
  }

  .mini-metrics {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .mini-metrics span {
    width: 100%;
    border-radius: 8px;
    text-align: left;
  }

  .backup-scheduler-strip .mini-metrics {
    gap: 10px;
  }

  .panel-jump-nav {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(13, 17, 23, 0.35);
  }

  .panel-jump-nav a {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(84, 215, 197, 0.18);
    background: rgba(8, 12, 18, 0.55);
    text-align: center;
    min-height: 44px;
    line-height: 1.35;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .audit-list,
  .error-list {
    gap: 10px;
  }

  .audit-row,
  .error-row {
    padding: 12px;
  }

  .error-row pre {
    max-width: 100%;
    font-size: 11px;
    max-height: 220px;
  }

  .inventory-summary,
  .audit-summary {
    grid-template-columns: 1fr;
  }

  .inventory-grid {
    grid-template-columns: 1fr;
  }

  .inventory-top {
    flex-direction: column;
    align-items: stretch;
  }

  .inventory-badges {
    justify-content: flex-start;
  }

  .inventory-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .inventory-meta small {
    text-align: left;
  }

  .inventory-columns {
    grid-template-columns: 1fr;
  }

  .premium-panel {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 16px;
  }

  .premium-status-card {
    width: 100%;
    min-height: 120px;
  }

  .premium-status-card strong {
    font-size: 24px;
  }

  .premium-flow {
    grid-template-columns: 1fr;
  }

  .premium-tiers {
    grid-template-columns: 1fr;
  }

  .premium-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .premium-actions .button,
  .premium-actions .mini,
  .premium-actions .manual-premium-days {
    width: 100%;
  }

  .manual-premium-days {
    display: grid;
    gap: 6px;
  }

  .manual-premium-days input {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .owner-remote-premium-row {
    flex-direction: column;
    align-items: stretch;
  }

  .owner-remote-premium-field {
    width: 100%;
  }

  .owner-remote-premium-field input[type="text"],
  .owner-remote-premium-field input[type="number"] {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    font-size: 16px;
  }

  .owner-remote-premium-row .mini {
    width: 100%;
  }

  .premium-contact {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .billing-status,
  .billing-history {
    padding: 14px;
  }

  .invoice-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .invoice-row .mini {
    width: 100%;
  }

  .module-list.module-grid-pro,
  .module-grid-pro {
    grid-template-columns: 1fr;
  }

  .module-card-pro {
    min-height: 44px;
  }

  .wizard-hero-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .wizard-hero-actions .wizard-start,
  .wizard-hero-actions .mini {
    width: 100%;
  }

  .wizard-intro {
    padding: 16px 14px 8px;
  }

  .wizard-step-board {
    margin: 12px 14px 18px;
    padding: 14px;
  }

  .wizard-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding-bottom: 6px;
  }

  .wizard-pill {
    scroll-snap-align: start;
    flex: 0 0 auto;
    min-height: 44px;
  }

  .playbooks-card__head {
    flex-direction: column;
    align-items: stretch;
  }

  .playbooks-card__grid {
    grid-template-columns: 1fr;
  }

  .playbooks-card__item .button,
  .playbooks-card__item .mini {
    width: 100%;
  }

  .matrix-advisor-page__cols,
  .matrix-charts-stack {
    grid-template-columns: 1fr;
  }

  .matrix-charts-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .matrix-chart-days {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .matrix-chart-days-btn {
    min-height: 44px;
    min-width: 44px;
  }

  .matrix-ops-card {
    padding: 12px;
  }

  .plan-snapshot-head {
    flex-direction: column;
    align-items: stretch;
  }

  .intro-send-card {
    flex-direction: column;
    align-items: stretch;
  }

  .intro-send-btn {
    width: 100%;
    min-height: 44px;
  }

  .copy-portable-grid {
    grid-template-columns: 1fr;
  }

  .copy-portable-grid .mini {
    width: 100%;
  }

  .reward-row,
  .announcement-button-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .announcement-button-row > * {
    width: 100%;
  }

  .leaderboard-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .mod-commands-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .backup-preview-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .details-head {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (min-width: 861px) {
  .mobile-nav-toggle,
  .mobile-nav-backdrop {
    display: none !important;
  }

  body.mobile-nav-open {
    overflow: auto;
  }
}

@media (max-width: 860px) and (prefers-reduced-motion: reduce) {
  body.server-selected .sidebar,
  .mobile-nav-backdrop,
  .mobile-nav-toggle-bars span {
    transition: none;
  }

  body.server-selected.mobile-nav-open .sidebar {
    transform: translate3d(0, 0, 0);
  }
}
