/* Mobile Oberfläche und PWA. Diese Datei lädt nach style.css und ändert die Desktopansicht kaum. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html:has(dialog[open]) {
  overflow: hidden;
}
button,
a,
input,
select,
textarea,
label {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.breadcrumb-root {
  font-style: normal;
}
.login {
  min-height: 100dvh;
}
main {
  min-height: calc(100dvh - 133px);
}
dialog {
  overscroll-behavior: contain;
}
#bottom-nav,
#refresh-state,
#nav-backdrop {
  display: none;
}
.journal-filter-toggle {
  display: none;
}
#pwa-install {
  width: 100%;
  margin-bottom: 12px;
}
#offline-banner {
  margin: 0;
  padding: 10px 16px;
  background: #fff4dc;
  border-bottom: 1px solid #ecdcae;
  color: #704b13;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}
#toast {
  inset: auto 25px 25px auto;
  margin: 0;
  border: 0;
  overflow: visible;
}
.chart-month[title] {
  cursor: pointer;
}
.file-share-dialog {
  width: min(440px, 92vw);
}
.file-share-body {
  display: grid;
  gap: 10px;
  padding: 20px 24px 24px;
}
.file-share-body p {
  margin: 0 0 8px;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.file-share-body .wide {
  justify-content: center;
  margin: 0;
}

/* Touchbedienung: ab 16 px zoomt iOS beim Fokussieren nicht mehr in das Formular. */
@media (pointer: coarse) {
  input:not([type='checkbox'], [type='radio'], [type='file']),
  select,
  textarea,
  .filterbar select,
  .filterbar input {
    font-size: 16px;
  }
  .primary,
  .secondary {
    min-height: 44px;
    font-size: 14px;
  }
  .subtle-button {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 13px;
  }
  .text-button {
    min-height: 40px;
    font-size: 13px;
  }
  label input,
  label select,
  .filterbar select,
  .filterbar input {
    min-height: 44px;
  }
  input[type='checkbox'],
  input[type='radio'],
  label.check input,
  .filterbar input[type='checkbox'],
  .export-option input[type='checkbox'] {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
  }
  label.check,
  .export-option {
    min-height: 44px;
  }
  .modal-header button {
    min-width: 44px;
    min-height: 44px;
  }
  .sort-heading {
    min-height: 36px;
  }
  .pdf-toolbar button {
    min-height: 44px;
    min-width: 44px;
  }
}

@media (max-width: 900px) {
  /* Grundgerüst */
  body {
    overflow-x: hidden;
  }
  .workspace {
    margin-left: 0;
    padding-bottom: calc(66px + env(safe-area-inset-bottom));
  }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 9;
    height: auto;
    min-height: calc(56px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0
      max(16px, env(safe-area-inset-left));
  }
  #mobile-menu,
  .today,
  .separator,
  .breadcrumb-root {
    display: none;
  }
  .breadcrumb b {
    font-size: 16px;
    font-weight: 600;
  }
  .topbar-right {
    gap: 8px;
  }
  #refresh-state {
    display: block;
    width: 44px;
    height: 44px;
    background: none;
    color: var(--green);
    font-size: 22px;
  }
  main {
    min-height: calc(100dvh - 180px);
    padding: 20px max(16px, env(safe-area-inset-right)) 18px max(16px, env(safe-area-inset-left));
  }
  footer {
    display: none;
  }
  #toast {
    inset: auto 16px calc(78px + env(safe-area-inset-bottom));
    width: auto;
    max-width: none;
  }

  /* Vollständige Navigation als Schublade */
  .sidebar {
    z-index: 40;
    width: min(300px, 86vw);
    padding: calc(14px + env(safe-area-inset-top)) 16px calc(14px + env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
    transform: translateX(-100%);
    visibility: hidden;
    transition:
      transform 0.2s,
      visibility 0.2s;
    overscroll-behavior: contain;
  }
  .sidebar.open {
    transform: translateX(0);
    visibility: visible;
    box-shadow: 10px 0 30px #0002;
  }
  .sidebar .brand {
    width: 130px;
    margin-bottom: 6px;
  }
  .sidebar nav {
    flex: 1;
    overscroll-behavior: contain;
  }
  .sidebar nav a {
    min-height: 44px;
    margin: 2px 0;
    padding: 10px 14px;
  }
  .sidebar-bottom {
    margin-top: 8px;
  }
  .local-status {
    margin: 8px 12px;
  }
  .user-card {
    min-height: 56px;
    padding: 10px 0;
  }
  .user-card b {
    max-width: 180px;
  }
  .logout {
    width: 100%;
    min-height: 44px;
    padding: 8px;
    font-size: 13px;
  }
  #nav-backdrop:not([hidden]) {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    background: #3b2e2266;
  }

  /* Untere Schnellnavigation */
  #bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    padding: 4px max(4px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom))
      max(4px, env(safe-area-inset-left));
    background: #fff;
    border-top: 1px solid var(--line);
  }
  #bottom-nav a,
  #bottom-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 54px;
    margin: 0;
    padding: 4px 2px;
    border-radius: 8px;
    background: none;
    color: #746b60;
    font-size: 11px;
    font-weight: 500;
  }
  #bottom-nav span {
    font-size: 20px;
    line-height: 1.1;
  }
  #bottom-nav a.active,
  #bottom-nav button.active {
    background: var(--sage);
    color: var(--green);
    font-weight: 650;
  }
  #bottom-nav a.active::after {
    content: none;
  }

  /* Seitenkopf, Filter und Kennzahlen */
  h1 {
    font-size: 24px;
    letter-spacing: -0.5px;
  }
  .page-heading {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 20px;
  }
  .actions > * {
    flex: 1 1 auto;
  }
  .filterbar {
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 18px;
  }
  .filterbar .filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    flex: none;
  }
  .filterbar .filters select,
  .filterbar .search,
  .filterbar input[type='search'] {
    width: 100%;
    max-width: none;
    min-width: 0;
  }
  .filterbar .filters label {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    white-space: normal;
  }
  .filterbar .filters label:has(input[type='checkbox']) {
    flex-direction: row;
    align-items: center;
  }
  .filter-caption {
    align-self: center;
  }
  .export-option {
    flex-direction: row;
    align-items: flex-start;
    line-height: 1.45;
  }
  .journal-filter-toggle {
    display: block;
    width: 100%;
    margin-bottom: 14px;
  }
  .journal-filters {
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 14px;
  }
  .journal-filters.open {
    display: grid;
  }
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
  }
  .stat {
    min-width: 0;
    padding: 14px;
  }
  .stat strong {
    font-size: 20px;
    letter-spacing: -0.3px;
    overflow-wrap: anywhere;
  }
  .panel-header,
  .section-title {
    flex-wrap: wrap;
  }
  .panel-body {
    padding: 16px;
  }
  .building-top {
    flex-wrap: wrap;
  }
  .building-top .tag {
    margin-left: 0;
  }
  .building-meta {
    flex-wrap: wrap;
  }
  .building-meta button {
    margin-left: 0;
    width: 100%;
  }
  .settlement-guide,
  .settlement-totals {
    margin-right: 16px;
    margin-left: 16px;
  }
  .upload-zone {
    margin: 0 16px 16px;
    padding: 28px 16px;
  }
  .import-batch-summary {
    padding-right: 16px;
    padding-left: 16px;
  }
  .import-batch details > summary {
    min-height: 44px;
    padding: 14px 16px;
  }
  .inline-import-proposal {
    min-width: 0;
    max-width: none;
  }
  .row-actions {
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .passkey-list li {
    flex-wrap: wrap;
  }
  .address-card small {
    display: block;
    margin-top: 4px;
  }
  .audit-changes dl {
    grid-template-columns: minmax(0, 1fr);
  }
  input[type='date'],
  input[type='month'],
  input[type='time'] {
    width: 100%;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
  }
  input[type='file'] {
    width: 100%;
  }
  input[type='file']::file-selector-button {
    min-height: 44px;
    margin-right: 10px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
  }

  /* Dialoge als Vollbild; Kopf und Aktionen bleiben beim Scrollen erreichbar. */
  dialog:not(.file-share-dialog),
  #dialog.datev-modal,
  #dialog.utility-modal {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  #dialog[open] {
    display: flex;
    flex-direction: column;
  }
  #dialog .modal-header,
  .pdf-dialog .modal-header {
    position: sticky;
    top: 0;
    z-index: 3;
    flex-shrink: 0;
    padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px
      max(16px, env(safe-area-inset-left));
    background: #fff;
  }
  #modal-form {
    display: flex;
    flex: 1 0 auto;
    flex-direction: column;
    min-width: 0;
  }
  #modal-fields {
    flex: 1 0 auto;
    align-content: start;
    min-width: 0;
    padding-right: max(16px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
  }
  #modal-fields > * {
    min-width: 0;
  }
  #dialog .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 3;
    flex-wrap: wrap;
    padding: 10px max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }
  #dialog .modal-footer button {
    flex: 1 1 130px;
  }
  .error {
    margin-right: 16px;
    margin-left: 16px;
  }
  .register-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .bank-split-row {
    padding: 12px;
  }
  .datev-mapping {
    max-height: none;
  }

  /* PDF-Ansicht */
  .pdf-dialog {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
  }
  .pdf-toolbar {
    gap: 8px;
    padding: 8px 16px;
  }
  .pdf-toolbar .secondary {
    flex: 1 1 100%;
  }
  .pdf-status {
    margin: 6px 16px;
  }
  .pdf-pages {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  }

  /* Tabellen werden Karten. Sortierung bleibt als wischbare Leiste über den Karten bedienbar. */
  table.table-cards,
  table.table-cards tbody {
    display: block;
    width: 100%;
    min-width: 0 !important;
    table-layout: auto;
  }
  table.table-cards thead {
    display: block;
    background: #faf8f5;
  }
  table.table-cards thead tr {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  table.table-cards thead th {
    flex: none;
    width: auto !important;
    padding: 0 !important;
    background: none;
    text-align: left !important;
  }
  table.table-cards thead th:empty {
    display: none;
  }
  table.table-cards .sort-heading {
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
    font-size: 11px;
    white-space: nowrap;
  }
  table.table-cards th[aria-sort] .sort-heading {
    border-color: var(--green);
    background: var(--sage);
    text-decoration: none;
  }
  table.table-cards tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 14px;
    padding: 16px;
    border-top: 1px solid #f0eae2;
  }
  table.table-cards tbody td {
    display: block;
    min-width: 0 !important;
    max-width: none;
    padding: 0 !important;
    border: 0;
    background: transparent !important;
    font-size: 13px;
    text-align: left;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
  }
  table.table-cards tbody td:first-child {
    border-left: 0;
  }
  table.table-cards tbody td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.25px;
  }
  table.table-cards tbody td[data-label='']::before,
  table.table-cards tbody td[data-card-kind='actions']::before {
    content: none;
  }
  table.table-cards tbody td.numeric {
    font-size: 14px;
    font-weight: 600;
  }
  table.table-cards tbody td[data-card-kind='empty'] {
    display: none;
  }
  table.table-cards tbody td[data-card-kind='wide'] {
    grid-column: 1 / -1;
  }
  table.table-cards tbody td[data-card-kind='actions'] {
    display: flex;
    grid-column: 1 / -1;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }
  table.table-cards tbody td input,
  table.table-cards tbody td select {
    width: 100%;
    min-width: 0;
  }

  /* Zeilenzustände aus der Desktoptabelle bleiben als Farbkante der Karte erkennbar. */
  table.table-cards .booking-reversed {
    box-shadow: inset 4px 0 0 #b74d40;
  }
  table.table-cards .booking-reversal {
    box-shadow: inset 4px 0 0 #b38a45;
  }
  table.table-cards .import-row-open {
    box-shadow: inset 4px 0 0 var(--batch-color);
  }
  #report-data .report-row-section,
  #report-data .report-row-supplement {
    background: #e8f0ec;
  }
  #report-data .report-row-subtotal {
    font-weight: 600;
  }
  #report-data .report-row-result,
  #report-data .report-row-balance,
  #report-data .report-row-private-total {
    background: #f0f5f2;
    font-weight: 700;
  }

  /* Tabellen mit zwei Spalten bleiben Tabellen, dürfen aber nicht über den Rand laufen. */
  table:not(.table-cards) th,
  table:not(.table-cards) td {
    padding: 11px 12px;
  }
}

@media (min-width: 600px) and (max-width: 900px) {
  table.table-cards tbody tr {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  table.table-cards tbody td[data-card-kind='wide'] {
    grid-column: span 2;
  }
  table.table-cards tbody td[data-card-kind='actions'] {
    grid-column: 1 / -1;
  }
}

@media (max-width: 420px) {
  .stat-top {
    align-items: flex-start;
  }
  .stat-icon {
    display: none;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  #bottom-nav a,
  #bottom-nav button {
    flex-direction: row;
    gap: 6px;
    min-height: 44px;
  }
  .workspace {
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }
}

@media (display-mode: standalone) {
  #refresh-state {
    display: block;
    width: 44px;
    height: 44px;
    background: none;
    color: var(--green);
    font-size: 22px;
  }
  body {
    overscroll-behavior-y: none;
  }
}
