/* SchichtFunk mobile layout guardrails */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 100vw;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  overflow-x: hidden;
}

.sidebar,
.topbar,
.main,
.content,
.view {
  min-width: 0;
  max-width: 100%;
}

.topbar {
  overflow: hidden;
}

.search,
.search input,
.page-head > div,
.table-head,
.employee-pool-head,
.library-head {
  min-width: 0;
}

.page-head h1,
.page-head p,
.table-head h3,
.employee-pool-head small {
  overflow-wrap: anywhere;
}

@media (max-width: 820px) {
  /* Einheitliche, fingerfreundliche Touch-Ziele. */
  :where(
    button,
    [role="button"],
    summary,
    [tabindex]:not([tabindex="-1"]),
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select,
    textarea
  ) {
    min-height: 44px !important;
    touch-action: manipulation;
  }

  :where(button, [role="button"], summary, [tabindex]:not([tabindex="-1"])) {
    min-width: 44px !important;
  }

  a[href] {
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex;
    align-items: center;
    touch-action: manipulation;
  }

  label:has(input[type="checkbox"]),
  label:has(input[type="radio"]) {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    touch-action: manipulation;
  }

  .main {
    overflow-x: hidden;
  }

  .calendar,
  .shift-row,
  .table-card > div[style*="overflow"] {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .form,
  .profile-metrics {
    grid-template-columns: 1fr;
  }

  .form .full,
  .form-actions {
    grid-column: 1;
  }
}

@media (max-width: 560px) {
  :root {
    --sidebar: 56px;
  }

  .app {
    grid-template-rows: 56px minmax(0, 1fr);
  }

  .sidebar {
    padding: 10px 6px;
  }

  .brand {
    padding: 0 1px 10px;
  }

  .app-brand-img {
    width: 44px;
    height: 44px;
  }

  .nav {
    gap: 4px;
  }

  .nav button {
    min-height: 44px;
    padding: 9px 6px;
  }

  .topbar {
    gap: 6px;
    padding: 0 8px;
  }

  .search {
    width: auto;
    flex: 1 1 auto;
  }

  .search input {
    min-width: 0;
    padding-right: 10px;
    text-overflow: ellipsis;
  }

  .top-actions {
    flex: 0 0 auto;
    gap: 4px;
    margin-left: 0;
  }

  #sfCloudState,
  #newTemplateBtn,
  .top-actions .iconbtn,
  .top-actions .sp-legacy-action {
    display: none !important;
  }

  .sf-notify-btn,
  .sp-topbar-logout,
  #sfAdminLogout {
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    padding: 0 !important;
    justify-content: center;
  }

  #sfAdminLogout {
    overflow: hidden;
    color: transparent !important;
    font-size: 0 !important;
  }

  #sfAdminLogout::before {
    content: "↪";
    color: #ff9aaa;
    font-size: 18px;
    line-height: 1;
  }

  .sp-topbar-logout span {
    display: none;
  }

  .sp-topbar-logout i {
    margin: 0 !important;
  }

  .main {
    padding: 12px 10px 26px;
  }

  .page-head {
    gap: 12px;
  }

  .page-head > button,
  .page-head > select {
    width: 100%;
    align-self: stretch;
  }

  .stats,
  #view-employees .sp-employee-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat {
    min-width: 0;
  }

  #view-schedule .stats {
    gap: 8px;
    margin: 8px 0 12px;
  }

  #view-schedule .stat {
    min-height: 96px !important;
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 8px;
    padding: 10px !important;
  }

  #view-schedule .stat-icon {
    width: 36px;
    height: 36px;
    border-radius: 9px;
  }

  #view-schedule .stat small,
  #view-schedule .stat em {
    font-size: 10px !important;
    line-height: 1.3;
    overflow-wrap: anywhere;
  }

  #view-schedule .stat strong {
    font-size: 21px !important;
    line-height: 1.05;
  }

  #view-schedule .page-head {
    margin-bottom: 8px;
  }

  #view-schedule .page-head h1 {
    font-size: 27px;
  }

  #view-schedule .page-head p {
    font-size: 13px;
    line-height: 1.45;
  }

  .library,
  .employee-pool,
  .table-card,
  .form-card {
    padding-left: 12px;
    padding-right: 12px;
  }

  .library-head,
  .employee-pool-head,
  .table-head {
    align-items: stretch;
    flex-direction: column;
  }

  .library-head button,
  .employee-pool-head input,
  .table-head input,
  .table-head select {
    width: 100%;
    min-width: 0 !important;
    margin-left: 0;
  }

  #view-schedule .employee-drag {
    min-width: 0 !important;
  }

  .emp {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }

  .emp > :nth-child(2) {
    flex: 1 1 calc(100% - 52px);
    min-width: 0;
  }

  .absence-row-final {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .absence-toolbar select,
  .absence-main-action {
    width: 100%;
  }

  .absence-calendar-days {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .profile-summary {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .profile-summary > :last-child {
    grid-column: 1 / -1;
  }

  .save-toast,
  .sp-assign-notice {
    left: 10px;
    right: 10px;
    bottom: 10px;
    min-width: 0;
    max-width: none;
  }

  .tpl-back,
  .sp-assign-backdrop,
  .abs-modal-backdrop {
    padding: 6px !important;
  }

  .tpl-modal,
  .sp-assign-modal,
  .absence-modal {
    width: 100%;
    max-width: 100%;
    max-height: 96dvh;
  }
}

@media (max-width: 340px) {
  #view-schedule .stats,
  #view-employees .sp-employee-stats {
    grid-template-columns: 1fr;
  }
}
