/* =========================================================
   PRINTNERD BACKEND – MOBILE ERWEITERUNG
   ========================================================= */

/* =========================================================
   MOBILE NAVIGATION – DESKTOP GRUNDZUSTAND
   ========================================================= */

.backend-menu-toggle,
.backend-sidebar__mobile-header {
  display: none;
}

.backend-sidebar-overlay {
  display: none;
}

/* =========================================================
   TABLETS / MOBILE
   ========================================================= */

@media (max-width: 900px) {
  html {
    -webkit-text-size-adjust: 100%;
  }

  body {
    min-width: 0;
    overflow-x: hidden;
  }

  body.backend-nav-open {
    overflow: hidden;
  }

  /* =======================================================
     HEADER
     ======================================================= */

  .backend-header {
    position: sticky;
    top: 0;
    z-index: 900;

    width: 100%;
    height: 64px;

    display: grid;

    /*
     * Drei feste Bereiche:
     *
     * links   = Burger
     * mitte   = Logo
     * rechts  = Benutzer
     *
     * Durch die zwei identischen 1fr-Spalten
     * bleibt das Logo exakt in der Bildschirmmitte.
     */
    grid-template-columns: 1fr auto 1fr;
    align-items: center;

    gap: 0;

    padding: env(safe-area-inset-top, 0) 16px 0;

    background: #ffffff;

    border-bottom: 1px solid #e5e7eb;
  }

  /* =======================================================
     LOGO
     ======================================================= */

  .backend-header__brand {
    grid-column: 2;

    position: static;

    width: auto;
    min-width: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    margin: 0;
    padding: 0;

    justify-self: center;

    transform: none;

    z-index: 1;
  }

  .backend-header__logo-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: auto;

    margin: 0;
    padding: 0;

    text-decoration: none;

    transform: none;
  }

  /*
   * Auch bei Hover / Focus / Active keine
   * Positionsänderung des Logos.
   */
  .backend-header__logo-link:hover,
  .backend-header__logo-link:focus,
  .backend-header__logo-link:active {
    transform: none;
  }

  .backend-header__logo {
    display: block;

    width: auto;
    height: 30px;

    max-width: 130px;

    margin: 0;

    object-fit: contain;

    transform: none;
  }

  /* =======================================================
     BENUTZER RECHTS
     ======================================================= */

  .backend-header__user {
    grid-column: 3;

    position: relative;

    justify-self: end;

    min-width: 0;
    max-width: 110px;

    margin: 0;
    padding: 0;

    overflow: hidden;

    text-overflow: ellipsis;
    white-space: nowrap;

    font-size: 13px;

    z-index: 2;
  }

  /* =======================================================
     HAMBURGER
     ======================================================= */

  .backend-menu-toggle {
    grid-column: 1;

    position: relative;

    justify-self: start;

    width: 44px;
    height: 44px;

    min-width: 44px;
    min-height: 44px;

    display: inline-flex;
    flex-direction: column;

    align-items: center;
    justify-content: center;

    gap: 5px;

    padding: 0;
    margin: 0;

    background: #ffffff;

    border: 1px solid #e5e7eb;
    border-radius: 9px;

    cursor: pointer;

    z-index: 2;

    -webkit-tap-highlight-color: transparent;
  }

  .backend-menu-toggle:hover {
    background: #f9fafb;
  }

  .backend-menu-toggle:focus-visible {
    outline: 2px solid #da3389;
    outline-offset: 2px;
  }

  .backend-menu-toggle span {
    display: block;

    width: 19px;
    height: 2px;

    margin: 0;
    padding: 0;

    background: #374151;

    border-radius: 999px;
  }

  /* =======================================================
     LAYOUT
     ======================================================= */

  .backend-content {
    display: block;

    width: 100%;

    min-height: calc(100dvh - 64px);
  }

  .backend-main {
    width: 100%;
    min-width: 0;

    padding: 24px 20px 40px;

    overflow: visible;
  }

  /* =======================================================
     SIDEBAR DRAWER
     ======================================================= */

  .backend-sidebar {
    position: fixed;

    top: 0;
    bottom: 0;
    left: 0;

    z-index: 1100;

    width: min(82vw, 320px);
    height: 100dvh;

    padding: calc(18px + env(safe-area-inset-top, 0)) 16px
      calc(18px + env(safe-area-inset-bottom, 0));

    overflow-y: auto;

    overscroll-behavior: contain;

    background: #ffffff;

    border-right: 1px solid #e5e7eb;

    box-shadow: 18px 0 50px rgba(17, 24, 39, 0.16);

    transform: translateX(-105%);

    visibility: hidden;

    transition:
      transform 0.22s ease,
      visibility 0.22s ease;
  }

  body.backend-nav-open .backend-sidebar {
    transform: translateX(0);

    visibility: visible;
  }

  /* =======================================================
     SIDEBAR – MOBILE HEADER
     ======================================================= */

  .backend-sidebar__mobile-header {
    display: flex;

    align-items: center;
    justify-content: space-between;

    gap: 16px;

    margin-bottom: 18px;

    padding: 0 4px 14px;

    border-bottom: 1px solid #e5e7eb;
  }

  .backend-sidebar__mobile-header strong {
    color: #111827;

    font-size: 15px;
  }

  /* =======================================================
     SIDEBAR – SCHLIESSEN BUTTON
     ======================================================= */

  .backend-sidebar__close {
    width: 42px;
    height: 42px;

    display: inline-grid;

    place-items: center;

    padding: 0;

    background: #f9fafb;
    color: #374151;

    border: 1px solid #e5e7eb;
    border-radius: 9px;

    font: inherit;
    font-size: 26px;
    line-height: 1;

    cursor: pointer;

    -webkit-tap-highlight-color: transparent;
  }

  .backend-sidebar__close:hover {
    background: #f3f4f6;
  }

  .backend-sidebar__close:focus-visible {
    outline: 2px solid #da3389;
    outline-offset: 2px;
  }

  /* =======================================================
     MOBILE NAVIGATION
     ======================================================= */

  .backend-nav__link {
    min-height: 46px;

    display: flex;
    align-items: center;

    padding: 12px 14px;

    font-size: 15px;
  }

  /* =======================================================
     SIDEBAR OVERLAY
     ======================================================= */

  .backend-sidebar-overlay {
    position: fixed;

    inset: 0;

    z-index: 1000;

    display: block;

    background: rgba(17, 24, 39, 0.48);

    opacity: 0;
    visibility: hidden;

    transition:
      opacity 0.2s ease,
      visibility 0.2s ease;
  }

  body.backend-nav-open .backend-sidebar-overlay {
    opacity: 1;
    visibility: visible;
  }

  body.backend-nav-open .backend-sidebar-overlay[hidden] {
    display: block;
  }

  /* =======================================================
     ALLGEMEINE INHALTE
     ======================================================= */

  .page-header,
  .section-header,
  .project-page-header {
    align-items: stretch;

    flex-direction: column;

    gap: 16px;
  }

  .page-header {
    margin-bottom: 22px;
  }

  .backend-main h1 {
    font-size: 25px;
  }

  .card {
    padding: 20px;
  }

  .detail-section {
    margin-top: 20px;
  }

  /* =======================================================
     FILTER
     ======================================================= */

  .filter-card {
    margin-bottom: 22px;
  }

  .filter-card__summary,
  .filter-card__content {
    padding-left: 18px;
    padding-right: 18px;
  }

  /* =======================================================
     DASHBOARD
     ======================================================= */

  .dashboard-stats,
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));

    gap: 14px;
  }

  .dashboard-stat-card,
  .stat-card {
    padding: 18px;
  }

  .dashboard-stat-card__value,
  .stat-card__value {
    font-size: 29px;
  }

  /* =======================================================
     FORMULARE / DETAILANSICHT
     ======================================================= */

  .form-grid,
  .detail-grid,
  .detail-list--grid {
    grid-template-columns: 1fr;
  }

  .status-control {
    width: 100%;
    min-width: 0;
  }

  .status-select {
    width: 100%;
  }

  .project-page-header__actions,
  .table-actions {
    width: 100%;

    flex-wrap: wrap;

    justify-content: flex-start;
  }

  /* =======================================================
     TABELLEN
     ======================================================= */

  .card--table {
    overflow: hidden;
  }

  .table-wrapper {
    width: 100%;

    overflow-x: auto;

    -webkit-overflow-scrolling: touch;
  }

  .backend-table {
    min-width: 720px;
  }
}

/* =========================================================
   KLEINE SMARTPHONES
   ========================================================= */

@media (max-width: 600px) {
  /* =======================================================
     HEADER
     ======================================================= */

  .backend-header {
    padding-left: 12px;
    padding-right: 12px;
  }

  .backend-header__logo {
    height: 30px;

    max-width: 125px;
  }

  .backend-header__user {
    max-width: 88px;

    font-size: 12px;
  }

  /* =======================================================
     MAIN
     ======================================================= */

  .backend-main {
    padding: 18px 14px calc(32px + env(safe-area-inset-bottom, 0));
  }

  .backend-main h1 {
    font-size: 23px;
  }

  /* =======================================================
     CARDS
     ======================================================= */

  .card {
    padding: 17px;

    border-radius: 10px;
  }

  /* =======================================================
     DASHBOARD
     ======================================================= */

  .dashboard-stats,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-card-header {
    align-items: flex-start;

    flex-direction: column;

    padding: 17px;
  }

  /* =======================================================
     FORM ACTIONS
     ======================================================= */

  .form-actions {
    flex-direction: column-reverse;

    align-items: stretch;

    padding-bottom: 20px;
  }

  .form-actions .button,
  .project-page-header__actions .button,
  .table-actions .button {
    width: 100%;
  }

  /* =======================================================
     DETAILANSICHT
     ======================================================= */

  .detail-row {
    grid-template-columns: 1fr;

    gap: 5px;
  }

  /* =======================================================
     DATEIEN
     ======================================================= */

  .file-upload,
  .file-item {
    align-items: stretch;

    flex-direction: column;
  }

  .file-upload .button,
  .file-item__action .button {
    width: 100%;
  }

  /* =======================================================
     PAGINATION
     ======================================================= */

  .pagination {
    align-items: stretch;
  }

  .pagination__buttons {
    width: 100%;
  }

  /* =======================================================
     LOGIN
     ======================================================= */

  .login-page {
    min-height: 100dvh;
  }

  .login-wrapper {
    min-height: 100dvh;

    display: flex;

    align-items: center;
    justify-content: center;

    padding: calc(20px + env(safe-area-inset-top, 0)) 16px
      calc(20px + env(safe-area-inset-bottom, 0));
  }

  .login-card {
    width: 100%;
    max-width: 440px;

    padding: 28px 20px;
  }

  .login-logo img {
    width: auto;
    height: auto;

    max-width: 180px;
  }

  .login-header h1 {
    font-size: 24px;
  }

  .login-header p {
    font-size: 14px;

    line-height: 1.55;
  }

  .login-field input {
    min-height: 48px;

    font-size: 16px;
  }

  .login-button {
    width: 100%;
    min-height: 48px;
  }
}

/* =========================================================
   SEHR SCHMALE GERÄTE
   ========================================================= */

@media (max-width: 390px) {
  .backend-header {
    padding-left: 10px;
    padding-right: 10px;
  }

  .backend-menu-toggle {
    width: 42px;
    height: 42px;

    min-width: 42px;
    min-height: 42px;
  }

  .backend-header__logo {
    height: 27px;

    max-width: 110px;
  }

  .backend-header__user {
    max-width: 68px;

    font-size: 11px;
  }

  .backend-sidebar {
    width: 88vw;
  }
}

/* =========================================================
   REDUZIERTE BEWEGUNG
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
  .backend-sidebar,
  .backend-sidebar-overlay {
    transition: none;
  }
}
