/**
 * VertrauensPost – durchgängig mobil (Tablet ≤960px, Phone ≤768px)
 * Lädt zuletzt und überschreibt Desktop-Kompaktstyles.
 */

html {
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body.is-mobile {
  overflow-x: hidden;
}

body.is-mobile.nav-open {
  overflow: hidden;
  touch-action: none;
}

/* ========== App-Shell ========== */
@media (max-width: 960px) {
  .nav-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  #app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    min-height: 100svh;
    max-height: 100dvh;
    max-height: 100svh;
    overflow: hidden;
  }

  #app-shell > .header {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    flex-shrink: 0;
    padding: max(0.4rem, env(safe-area-inset-top, 0px)) 0.5rem 0.4rem;
    gap: 0.35rem;
  }

  #app-shell > .header .header-start {
    flex: 1;
    min-width: 0;
    width: auto;
    justify-content: flex-start;
    gap: 0.4rem;
  }

  #app-shell > .header .user-limit-info {
    display: none;
  }

  #app-shell > .header .nav:not(.is-open) {
    display: none !important;
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    padding: 0;
    margin: 0;
    border: 0;
  }

  #app-shell > .header .nav.is-open {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(18rem, 90vw);
    z-index: 1100;
    flex-direction: column;
    align-items: stretch;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #151d2b;
    padding: max(0.5rem, env(safe-area-inset-top, 0px)) 0 0.75rem;
    margin: 0;
    border: none;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
    clip: auto;
  }

  #app-shell > .header .nav-group {
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0.35rem 0 0.5rem;
    margin: 0 0 0.35rem;
    flex-direction: column;
    align-items: stretch;
  }

  #app-shell > .header .nav-group--collapsed .nav-link {
    display: flex !important;
  }

  #app-shell > .header .nav-group-label::after {
    display: none;
  }

  #app-shell > .header .nav-group-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.15rem 0.5rem 0.35rem;
    width: 100%;
    flex-basis: auto;
  }

  #app-shell > .header .nav-link,
  #app-shell > .header .nav-footer .btn-text {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0.45rem 0.65rem !important;
    font-size: 0.92rem !important;
    border-radius: 8px;
    width: 100%;
    box-sizing: border-box;
  }

  #app-shell > .header .nav-footer {
    flex-direction: column;
    align-items: stretch;
    margin: 0.5rem 0 0;
    gap: 0.25rem;
  }

  #app-shell > .header:has(.nav.is-open) {
    z-index: 1101;
  }

  #app-shell > .dsgvo-footer-fixed {
    flex-shrink: 0;
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    z-index: 5;
    font-size: 0.65rem;
    line-height: 1.35;
    padding: 0.3rem 0.55rem;
    padding-bottom: max(0.3rem, env(safe-area-inset-bottom, 0px));
  }

  #app-shell > #content.content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0.85rem 0.75rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  }

  #app-shell.mail-view-active > #content.content--mail {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #app-shell.mail-pane-read > .dsgvo-footer-fixed {
    display: none;
  }

  .logo-text {
    font-size: 0.92rem;
  }
}

@media (max-width: 520px) {
  .logo-text {
    display: none;
  }
  .logo-mark {
    font-size: 1.15rem;
  }
}

/* ========== Formulare, Karten, Aktionen ========== */
@media (max-width: 960px) {
  .card {
    padding: 0.85rem;
    margin-left: 0;
    margin-right: 0;
    overflow-x: auto;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
  }

  .page-header h2 {
    font-size: 1.15rem;
  }

  .page-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .page-actions .btn-primary,
  .page-actions .btn-secondary,
  .page-actions .btn-ghost,
  .page-actions .btn-warning,
  .page-actions .btn-danger {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .form-row,
  .form-inline,
  .smtp-row,
  .filter-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.5rem !important;
  }

  .form-row > *,
  .form-inline > *,
  .smtp-row > * {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }

  .btn-group,
  .action-row,
  .toolbar-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
  }

  .btn-group .btn-primary,
  .btn-group .btn-ghost,
  .btn-group .btn-secondary,
  .action-row button {
    flex: 1 1 calc(50% - 0.2rem);
    min-height: 44px;
    min-width: calc(50% - 0.2rem);
  }

  .table-wrap {
    margin: 0 -0.35rem;
    width: calc(100% + 0.7rem);
    max-width: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 520px;
    font-size: 0.82rem;
  }

  th, td {
    padding: 0.5rem 0.4rem;
    word-break: break-word;
  }

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

  .template-preview-pane {
    position: static;
  }

  .tracking-kpi-grid,
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

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

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

  .modal-content {
    width: 100%;
    max-width: none;
    max-height: 92dvh;
    border-radius: 14px 14px 0 0;
    margin: 0;
  }

  .modal-content .btn-primary,
  .modal-content .btn-ghost {
    min-height: 44px;
    width: 100%;
    margin-top: 0.35rem;
  }

  #toast-root {
    left: 0.5rem;
    right: 0.5rem;
    bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
  }

  .toast {
    max-width: none;
    font-size: 0.9rem;
  }

  .login-card {
    padding: 1.25rem;
    max-width: none;
  }

  .scheduled-countdown {
    font-size: 0.95rem;
    padding: 0.75rem;
  }

  /* SMTP / Admin: lange Listen */
  .smtp-config-card,
  .admin-user-row,
  .campaign-row {
    flex-direction: column;
    align-items: stretch;
  }

  pre, code, .log-preview {
    max-width: 100%;
    overflow-x: auto;
    font-size: 0.75rem;
  }

  input, select, textarea, .mail-input {
    font-size: 16px;
    max-width: 100%;
  }

  img {
    max-width: 100%;
    height: auto;
  }
}

@media (max-width: 480px) {
  .tracking-kpi-grid,
  .kpi-grid {
    grid-template-columns: 1fr !important;
  }

  .btn-group .btn-primary,
  .btn-group .btn-ghost,
  .btn-group .btn-secondary {
    flex: 1 1 100%;
    min-width: 100%;
  }
}
