/*
 * Responsive Schicht des SMARTB4-Portals. Wird nach style.css.php geladen.
 * Die Farben des gewählten Skins kommen als CSS-Variablen aus meine/index.php.
 *
 * bis 1400px  schmalere Innenabstände, Layout wie am Desktop
 * bis 1024px  eine Spalte, Seitenleisten als Panels, Reiterleiste unten
 * bis 720px   Listen als Karten, Dialoge im Vollbild
 */

/* App-Elemente gibt es am Desktop nicht */
.app-tabbar,
.app-backdrop,
.app-sheet {
  display: none;
}

@media (max-width: 1400px) {
  .containerfull {
    grid-template-columns: 220px 10px minmax(0, 1fr) 10px 220px;
  }
  .listtable {
    padding: 0 16px;
    overflow-x: auto;
  }
  .listtable table {
    margin-left: 0;
  }
  .cardslist {
    padding: 10px 16px;
  }
  .overview {
    margin-left: 16px;
    margin-right: 16px;
  }
  .zelleaction nobr {
    white-space: normal;
  }
}

@media (max-width: 1024px) {
  :root {
    --app-tabbar-height: 60px;
    --app-safe-top: env(safe-area-inset-top, 0px);
    --app-safe-bottom: env(safe-area-inset-bottom, 0px);
  }

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

  body {
    overflow-x: clip;
    padding-bottom: calc(var(--app-tabbar-height) + var(--app-safe-bottom));
  }

  body.app-open-menu,
  body.app-open-profile,
  body.app-open-more {
    overflow: hidden;
  }

  /* Kopfleiste */
  .title-bar {
    position: sticky;
    top: 0;
    z-index: 80;
    padding: calc(8px + var(--app-safe-top)) 12px 8px;
    gap: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  }
  .title-bar a > img {
    display: block;
    width: 120px;
  }
  .title-bar .navigation,
  .title-bar .colorswitch {
    display: none;
  }
  .register-button,
  #helpbutton {
    margin: 0;
    padding: 6px 12px;
    font-size: 14px;
    min-height: 40px;
    white-space: nowrap;
  }
  #reglogin {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }
  #reglogin > a {
    display: none; /* Versionshinweis */
  }

  /* Superchat über der Reiterleiste, und nicht über Panels */
  #superchat-widget-content-root {
    bottom: calc(var(--app-tabbar-height) + var(--app-safe-bottom)) !important;
  }
  .app-open-menu #superchat-widget-root,
  .app-open-profile #superchat-widget-root,
  .app-open-more #superchat-widget-root,
  body:has(#formbox:not([hidden])) #superchat-widget-root {
    display: none;
  }

  /* Grundlayout: eine Spalte */
  .container,
  .containerfull,
  .containeronlymain {
    display: block;
    height: auto;
    transition: none;
  }
  .container .pfeil {
    display: none;
  }
  .main-content {
    min-height: calc(100vh - 120px);
    min-height: calc(100dvh - 120px);
    min-width: 0;
  }
  .header h1 {
    padding: 12px;
    font-size: 18px;
    overflow-wrap: anywhere;
  }

  /* Seitenleisten als Panels */
  .sidebar,
  .user-info {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 90;
    width: min(86vw, 340px);
    padding: calc(16px + var(--app-safe-top)) 16px calc(16px + var(--app-safe-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0.22s;
  }
  .sidebar {
    left: 0;
    transform: translateX(-100%);
  }
  .user-info {
    right: 0;
    transform: translateX(100%);
  }
  .app-open-menu .sidebar,
  .app-open-profile .user-info {
    transform: none;
    visibility: visible;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.4);
  }
  .sidebar ul li {
    height: auto;
    min-height: 48px;
    margin: 6px 0 6px 40px;
    padding: 4px 0;
  }
  #context-menu {
    left: 16px;
    right: 16px;
    line-height: 2.4;
  }

  /* Abdunklung und Reiterleiste */
  .app-backdrop {
    position: fixed;
    inset: 0;
    z-index: 88;
    display: block;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }
  .app-open-menu .app-backdrop,
  .app-open-profile .app-backdrop,
  .app-open-more .app-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .app-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 85;
    display: flex;
    height: calc(var(--app-tabbar-height) + var(--app-safe-bottom));
    padding-bottom: var(--app-safe-bottom);
    background: var(--app-bar-bg);
    box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.2);
  }
  .app-tab {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 44px;
    margin: 0;
    padding: 4px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--app-bar-text);
    font-size: 12px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .app-tab svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .app-tab[aria-expanded="true"] {
    color: var(--app-accent);
  }
  html:not(.app-session) .app-tab[data-session] {
    display: none;
  }

  /* Panel "Mehr" */
  .app-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    display: block;
    max-height: 80vh;
    max-height: 80dvh;
    overflow-y: auto;
    padding: 20px 20px calc(var(--app-tabbar-height) + var(--app-safe-bottom) + 16px);
    border-radius: 16px 16px 0 0;
    background: var(--app-bar-bg);
    color: var(--app-bar-text);
    visibility: hidden;
    transform: translateY(100%);
    transition: transform 0.22s ease, visibility 0.22s;
  }
  .app-open-more .app-sheet {
    transform: none;
    visibility: visible;
  }
  .app-open-more .app-tabbar {
    z-index: 91;
  }
  .app-sheet h2 {
    margin: 16px 0 6px;
    font-size: 14px;
    font-weight: normal;
    opacity: 0.8;
  }
  .app-sheet h2:first-child {
    margin-top: 0;
  }
  .app-sheet a {
    display: block;
    padding: 12px 0;
    color: inherit;
    text-decoration: none;
    font-size: 16px;
  }
  .app-sheet-skins {
    display: flex;
    gap: 16px;
  }
  .app-sheet-skins a {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 48px;
    padding: 0;
  }
  .app-sheet-skins img {
    width: 28px;
  }
  .app-sheet button {
    width: 100%;
    min-height: 48px;
    background: var(--app-button-bg);
    color: var(--app-button-text);
  }
  #app-install-area,
  .app-standalone #app-install-area {
    display: none;
  }
  #app-install-area.app-can-install {
    display: block;
  }
  #app-ios-hint {
    margin-top: 8px;
    font-size: 14px;
    line-height: 1.5;
  }

  /* Dialoge */
  .alertgrey {
    inset: 0;
    width: auto;
    height: auto;
  }
  .alertbox {
    width: min(470px, calc(100vw - 24px));
    height: auto;
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    padding: 24px;
  }
  .alertbox h1 {
    font-size: 28px;
  }
  .alertbox img {
    position: static;
    display: block;
    width: 64px;
    height: 64px;
    margin: 12px 0 0 auto;
  }
  .formbox {
    width: calc(100vw - 24px);
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    padding: 64px 16px 24px;
  }
  .formbox h1 {
    font-size: 24px;
    padding: 12px 16px;
  }
  .formbox div {
    padding: 8px 0;
  }
  .formbox img {
    position: static;
    width: 64px;
    height: 64px;
  }
  .infobox {
    top: calc(8px + var(--app-safe-top));
    right: 8px;
    left: 8px;
    z-index: 150;
  }

  /* Formulare und Inhalte */
  input,
  select,
  textarea {
    max-width: 100%;
    font-size: 16px;
  }
  select[style] {
    max-width: 100% !important;
  }
  button {
    min-height: 44px;
  }
  #main-body img,
  #main-body iframe,
  #app img,
  #app iframe,
  .formbox iframe {
    max-width: 100%;
  }
  .cardslist {
    padding: 10px 12px;
    gap: 10px;
  }
  .carddoppel {
    min-width: 100%;
  }
  .overview {
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 12px 0;
  }
  .teaser-box,
  .info-box {
    width: auto;
    margin: 12px;
  }
  .overview .teaser-box {
    flex: 1 1 100%;
    margin: 0;
  }
  .teaser-box img {
    width: 110px;
    margin-right: 12px;
  }
  .teaser-box h1 {
    margin: 12px;
    font-size: 20px;
  }
  .teaser-box p {
    font-size: 16px;
  }
  .info-box {
    padding: 16px;
  }
  .info-box h2 {
    width: 60px;
    height: 60px;
    font-size: 48px;
  }
  .info-box p {
    margin-left: 72px;
    padding: 8px 12px;
    font-size: 16px;
  }
  .zweispaltig,
  .cardzweispaltig {
    columns: 1;
  }
  p.trenner {
    margin: 14px 12px;
    font-size: 18px;
  }
  p.trenner::before,
  p.trenner::after {
    display: none;
  }
}

@media (max-width: 380px) {
  .title-bar a > img {
    width: 92px;
  }
  .register-button,
  #helpbutton {
    padding: 6px 8px;
    font-size: 13px;
  }
}

@media (max-width: 720px) {
  /* Listen als Karten */
  .listtable {
    padding: 0 12px;
    overflow: visible;
  }
  .listtable table,
  .listtable tbody {
    display: block;
    width: 100%;
  }
  .listtable thead,
  .listtable tr.ueberschriften,
  .listtable tr.app-headrow {
    display: none;
  }
  .listtable h1 {
    font-size: 20px;
  }
  .listtable tr {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    column-gap: 10px;
    height: auto;
    margin-bottom: 10px;
    padding: 10px;
    border-radius: 12px;
    background-color: var(--app-card-bg);
  }
  .listtable td {
    display: block;
    grid-column: 2;
    width: auto;
    padding: 3px 0;
    border: none;
    background-color: transparent;
    overflow-wrap: anywhere;
  }
  .listtable td:empty:not(.zelleicon):not(.zelleiconbig),
  .listtable td.app-emptycell {
    display: none;
  }
  .listtable td[data-label]::before {
    content: attr(data-label) ": ";
    font-size: 13px;
    opacity: 0.75;
  }
  .listtable td[data-label="Name"]::before,
  .listtable td[data-label="Dokument"]::before,
  .listtable td[data-label="Aktionen"]::before,
  .listtable td[data-label="Status"]::before {
    content: none;
  }
  .listtable .zelleicon,
  .listtable .zelleiconbig {
    display: block;
    grid-column: 1;
    grid-row: 1 / span 8;
    width: 48px;
    height: 48px;
    background-size: 48px 48px !important; /* die Zelle setzt inline das background-Kürzel */
    border-radius: 8px;
  }
  .listtable .zelleaction nobr {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    white-space: normal;
  }
  .listtable .zelleaction {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    grid-column: 1 / -1;
    padding-top: 8px;
    text-align: left;
    border-radius: 0;
  }
  .listtable .zelleaction img,
  .listtable .zelleaction input[type="image"] {
    width: 36px;
    height: 36px;
    margin: 0;
  }
  .listtable tr.zeileneu {
    display: block;
    padding: 0;
    background-color: transparent;
  }
  .listtable tr.zeileneu td {
    padding: 12px;
    border: 2px dashed var(--app-card-bg);
    border-radius: 12px;
    color: var(--app-card-bg);
  }

  /* Formular-Tabellen außerhalb der Listen untereinander */
  #main-body table:not(.listtable table),
  #main-body table:not(.listtable table) tbody,
  #main-body table:not(.listtable table) tr,
  #main-body table:not(.listtable table) td,
  #main-body table:not(.listtable table) th,
  .formbox table,
  .formbox tbody,
  .formbox tr,
  .formbox td,
  .formbox th {
    display: block;
    width: 100%;
    height: auto;
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="image"]):not([type="hidden"]),
  .inputdocumentname,
  select,
  textarea {
    width: 100%;
  }
  .shortinput input {
    width: 96px !important;
  }
  .inputdocumentname {
    font-size: 18px;
  }

  /* Dialog im Vollbild */
  .formbox {
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    transform: none;
    padding-top: calc(64px + var(--app-safe-top));
  }
  .formbox h1 {
    border-radius: 0;
    padding-top: calc(12px + var(--app-safe-top));
    font-size: 20px;
  }

  /* Karten auf der Übersicht */
  .card {
    flex-basis: calc(50% - 5px);
    min-width: 0;
  }
  .card h1 {
    font-size: 16px;
  }
  .card h2 {
    font-size: 22px;
  }
  .card h3 {
    font-size: 34px;
  }
  .cardfull {
    flex-basis: 100%;
  }
}

/* Dateimanager am Desktop: die urspruenglichen Abstaende aus style.css.php */
.browse-desktop .listtable {
  padding: 0 140px 0 0;
  overflow: visible;
}
.browse-desktop .listtable table {
  margin-left: 70px;
}

/* Pflegemodus (/meine/?feldpflege=1): Felder ohne field_label rot markieren, auch am Desktop */
.app-feldpflege #filebody input[placeholder=""],
.app-feldpflege #filebody textarea[placeholder=""] {
  outline: 3px dashed #c00000 !important;
  outline-offset: 1px;
}
.app-feldpflege .docform-list .docform-crop {
  outline: 3px dashed #c00000;
}

.docform-end {
  display: none;
}
@media (max-width: 1024px) {
  .docform-end:not([hidden]) {
    display: block;
    margin: 16px 12px 24px;
    padding: 14px;
    border-radius: 12px;
    background: var(--app-card-bg);
    text-align: left;
  }
  .docform-end p {
    margin: 0 0 10px;
    font-size: 14px;
  }
  .docform-end button {
    width: 100%;
    min-height: 48px;
    background: var(--app-button-bg);
    color: var(--app-button-text);
    font-weight: bold;
  }
}

/* Hilfselemente der Ausfüllansicht gibt es nur in der Formular-Ansicht auf Handy und Tablet */
#docform-bar,
.docform-label,
.docform-crop,
.docform-description {
  display: none;
}

/* Dateimanager im iFrame */
@media (max-width: 1024px) {
  body.browse-page {
    padding-bottom: 0;
  }
  .browse-page .main-content {
    min-height: 0;
  }
  .browse-move {
    display: block;
    width: 100%;
    margin-top: 8px;
    font-size: 13px;
  }
  .browse-move select {
    display: block;
    width: 100%;
    min-height: 44px;
    margin-top: 2px;
    font-size: 16px;
  }
  .listtable td[data-label="Aktionen"] {
    text-align: left;
  }
  .listtable td[data-label="Aktionen"] img {
    width: 36px;
    height: 36px;
    margin: 0 6px 4px 0;
  }
  .listtable input[type="file"] {
    max-width: 100%;
  }
}

/* Dokumente ausfüllen */
@media (max-width: 1024px) {
  #filebody {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    text-align: left;
  }
  .inputdocumentname {
    width: 100% !important;
  }
  .docform-zoom-hidden {
    display: none;
  }
  #docform-bar {
    display: block;
    margin: 8px 12px;
    text-align: left;
  }
  .docform-switch {
    display: flex;
    gap: 2px;
    overflow: hidden;
    border-radius: 12px;
  }
  .docform-switch button {
    flex: 1 1 0;
    margin: 0;
    border: none;
    border-radius: 0;
    min-height: 44px;
    background: var(--app-card-bg);
    color: var(--app-bar-text);
  }
  .docform-switch button[aria-pressed="true"] {
    background: var(--app-accent);
    color: #ffffff;
    font-weight: bold;
  }
  .docform-hint {
    margin: 8px 2px 0;
    font-size: 14px;
    line-height: 1.4;
  }

  #filebody.docform-list {
    padding: 0 12px 16px;
    overflow-x: visible;
  }
  .docform-list .docform-pagetitle {
    margin: 16px 0 8px;
    font-weight: bold;
  }
  .docform-list .docform-nofields:not(img) {
    display: none;
  }
  .docform-list div.baseimg {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: auto !important;
    height: auto !important;
    padding: 12px;
    border: none;
    border-radius: 12px;
    background: var(--app-card-bg) !important;
  }
  .docform-list img.baseimg {
    width: 100%;
    height: auto;
    max-width: 100%;
  }
  .docform-list nobr {
    white-space: normal;
  }
  .docform-list .docform-label {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
    line-height: 1.3;
    overflow-wrap: anywhere;
  }
  .docform-list .docform-crop {
    display: block;
    width: 100%;
    margin-bottom: 4px;
    border-radius: 6px;
    background-color: #ffffff;
    background-repeat: no-repeat;
  }
  .docform-list .docform-description {
    display: block;
    margin: -2px 0 6px;
    font-size: 13px;
    line-height: 1.35;
    opacity: 0.85;
  }
  .docform-readstate {
    margin: 8px 0 0;
    padding: 8px 10px;
    border-left: 4px solid #c00000;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    line-height: 1.4;
  }
  .docform-readstate-done {
    border-left-color: #2e7d32;
  }
  .docform-list .docform-required .docform-crop {
    border-left: 4px solid #c00000;
  }
  .docform-list .docform-required .docform-label::after {
    content: " *";
    color: #c00000;
    font-weight: bold;
  }
  .docform-list .docform-field input,
  .docform-list .docform-field textarea {
    position: static !important;
    display: block;
    width: 100% !important;
    height: auto !important;
    min-height: 44px;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 16px !important;
  }
  .docform-list .docform-field textarea {
    min-height: 110px;
  }
  /* Kontrollkästchen: Feld links, Beschriftung rechts */
  .docform-list .docform-checkbox {
    display: flex;
    flex-direction: row-reverse;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    min-height: 44px;
  }
  .docform-list .docform-checkbox .docform-label {
    margin: 0;
    flex: 1 1 auto;
  }
  .docform-list .docform-field input[type="checkbox" i] {
    flex: 0 0 auto;
    width: 28px !important;
    height: 28px !important;
    min-height: 0;
    padding: 0;
  }
  /* Unterschrift: gut sichtbare Fläche zum Antippen */
  .docform-list .docform-field input[type="image" i] {
    height: 96px !important;
    object-fit: contain;
    background: #ffffff;
    border: 2px dashed var(--app-accent);
  }
  .docform-list .docform-field input[type="button" i] {
    background: var(--app-button-bg);
    color: var(--app-button-text);
  }
}

/* Unterschrift: der Finger zeichnet, statt die Seite zu scrollen */
#newSignature {
  max-width: 100%;
  touch-action: none;
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .user-info,
  .app-sheet,
  .app-backdrop {
    transition: none !important;
  }
}

@media print {
  .app-tabbar,
  .app-backdrop,
  .app-sheet {
    display: none !important;
  }
}
