/*
 * BMS Mobil: Darstellung auf Handy und Tablet.
 * Ergänzt bms-design und die Ansichten der anderen BMS-Erweiterungen; am PC (ab 1024 px, Maus) ändert sich nichts.
 * html.bms-touch = Touchscreen, html.bms-standalone = als App vom Startbildschirm gestartet (setzt lib/mobil.js).
 */

/* ------------------------------------------------------------ Hinweis "Als App installieren" */
#bms-mobil-hinweis {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 2100;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 520px;
    margin: 0 auto;
    padding: 12px 12px 12px 14px;
    background: #fff;
    color: #0a3d7a;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(10, 61, 122, .25);
    font-size: 14px;
    line-height: 1.4;
    animation: bms-mobil-rein .3s ease-out;
}
#bms-mobil-hinweis img { width: 44px; height: 44px; border-radius: 10px; flex: none; box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
#bms-mobil-hinweis .bms-mobil-text { flex: 1; min-width: 0; color: #4d6378; }
#bms-mobil-hinweis .bms-mobil-text strong { display: block; color: #0a3d7a; font-size: 15px; }
#bms-mobil-hinweis .bms-mobil-text b { color: #0a3d7a; }
#bms-mobil-hinweis .bms-mobil-teilen {
    display: inline-block;
    width: 14px;
    height: 16px;
    vertical-align: -2px;
    background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 18' fill='none' stroke='%230d58b2' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 1v10M3.5 4.5 7 1l3.5 3.5M4 7H2v10h10V7h-2'/%3E%3C/svg%3E");
}
#bms-mobil-hinweis .bms-mobil-installieren {
    flex: none;
    border: 0;
    border-radius: 999px;
    padding: 10px 16px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #0d58b2, #2489be);
}
#bms-mobil-hinweis .bms-mobil-zu {
    flex: none;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: #eef3f9;
    color: #4d6378;
    font-size: 22px;
    line-height: 1;
}
@keyframes bms-mobil-rein { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ------------------------------------------------------------ Touch: größere Tippflächen */
html.bms-touch #navbar .navbar-right > li > a,
html.bms-touch #navbar .navbar-right > li > button { min-height: 44px; min-width: 44px; }
html.bms-touch .bms-tel .t-btn,
html.bms-touch .bms-tel button { min-height: 40px; }
html.bms-touch .dropdown-menu > li > a { padding-top: 10px; padding-bottom: 10px; }
html.bms-touch input[type="checkbox"],
html.bms-touch input[type="radio"] { transform: scale(1.2); }
html.bms-touch * { -webkit-tap-highlight-color: rgba(13, 88, 178, .12); }

/* Als App: kein Gummiband-Effekt am oberen Rand, Espo-Fußzeile weg */
html.bms-standalone body { overscroll-behavior-y: none; }
html.bms-standalone footer { display: none; }

/* ------------------------------------------------------------ Breite Tabellen: seitlich wischen statt abschneiden */
#main .bms-zeit-tabelle,
#main .bms-stat-tabelle {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
@media (max-width: 1023px) {
    #main .bms-zeit-tabelle > table,
    #main .bms-stat-tabelle > table { min-width: 100%; width: max-content; }
    #main .bms-zeit-tabelle th:first-child,
    #main .bms-zeit-tabelle td:first-child,
    #main .bms-stat-tabelle th:first-child,
    #main .bms-stat-tabelle td:first-child {
        position: sticky;
        left: 0;
        z-index: 1;
        background: #fff;
        box-shadow: 1px 0 0 #e6ecf3;
    }
    /* Espo-Listen im Panel ebenfalls wischbar */
    #main .list-container .list { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ------------------------------------------------------------ Kalender: ganze Wörter statt "He", "Mo", "Wo" */
@media (max-width: 1199px) {
    #main .btn[data-action="today"] .visible-xs,
    #main .btn[data-action="today"] .visible-sm,
    #main .btn[data-action="mode"] .visible-xs,
    #main .btn[data-action="mode"] .visible-sm,
    #main .btn[data-action="mode"] .visible-md { display: none !important; }
    #main .btn[data-action="today"] .hidden-xs,
    #main .btn[data-action="mode"] .hidden-xs { display: inline !important; }
}

/* ------------------------------------------------------------ Handy (bis 767 px) */
@media (max-width: 767px) {
    /* Seitenränder etwas schmaler, mehr Platz für Inhalt */
    #main > .page-header,
    #main .page-header { margin-bottom: 12px; }
    #main .page-header h3 { font-size: 20px; line-height: 1.3; word-break: break-word; }

    /* Knöpfe dürfen umbrechen statt über den Rand zu laufen */
    #main .btn-lg { white-space: normal; max-width: 100%; height: auto; line-height: 1.3; padding-top: 12px; padding-bottom: 12px; }
    #main .btn-group { flex-wrap: wrap; }

    /* Kopfleiste ausgeklappt: Tour, Stempeluhr und Anruf-Lampe nebeneinander */
    #navbar .navbar-collapse .navbar-right > li.bms-tour-container,
    #navbar .navbar-collapse .navbar-right > li.bms-stempeluhr-container,
    #navbar .navbar-collapse .navbar-right > li.bms-anruf-lampe-container { display: inline-block; vertical-align: middle; }

    /* Telefonieren: Gesprächskopf mit Knöpfen in eigener Zeile */
    .bms-tel .t-mitte-kopf { flex-wrap: wrap; padding: 14px 16px; }
    .bms-tel .t-mitte-kopf > div:last-child {
        width: 100%;
        margin-left: 0 !important;
        flex-wrap: wrap;
    }
    .bms-tel .t-mitte-kopf > div:last-child > button { flex: 1 1 auto; justify-content: center; }
    .bms-tel .t-mitte-kopf > div:last-child > [data-action="anrufenHaupt"] { flex-basis: 100%; min-height: 48px; font-size: 16px; }
    .bms-tel .t-abschnitt { padding: 14px 16px; }

    /* Zeitnachweis: Unterschreiben-Knopf über die ganze Breite */
    #main [data-action="einreichen"].btn-lg,
    #main [data-action="freigeben"].btn-lg { width: 100%; margin-bottom: 8px; }
}

/* ------------------------------------------------------------ Browser-Telefon (Erweiterung Telefonie) auf dem Handy */
@media (max-width: 767px) {
    html #bms-telefon { left: 12px; bottom: 12px; }
    html #bms-telefon .bt-knopf { width: 58px; height: 58px; font-size: 22px; }
    html #bms-telefon .bt-fenster {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: 82px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 140px);
        overflow-y: auto;
        border-radius: 18px;
        padding: 16px;
    }
    html #bms-telefon input.bt-eingabe { font-size: 22px; padding: 12px; text-align: center; }
    html #bms-telefon .bt-zeile button { padding: 14px 6px; font-size: 16px; border-radius: 12px; }
    html #bms-telefon .bt-tasten { gap: 10px; }
    html #bms-telefon .bt-tasten button { padding: 14px 0; font-size: 22px; border-radius: 12px; }
    html #bms-telefon .bt-nummer { font-size: 22px; }
    /* Hinweis "Als App" nicht über dem Telefonknopf */
    body:has(#bms-telefon) #bms-mobil-hinweis { left: 80px; }
}

/* ------------------------------------------------------------ work4all-Bausteine: Plantafel, Deckungsbeitrag, Belege, Verträge */
@media (max-width: 1023px) {
    /* Plantafel (bms-einsatzplanung): wischbar, Technikerspalte bleibt stehen */
    #main .bms-plan-raster { -webkit-overflow-scrolling: touch; }
    #main .bms-plan-raster td.name {
        position: sticky;
        left: 0;
        z-index: 2;
        box-shadow: 1px 0 0 #e6ecf3;
    }
    #main .bms-plan-raster table { min-width: 760px; }
    #main .bms-plan-block { font-size: 13px; padding: 6px 8px; }
    #main .bms-plan-leiste .bms-plan-zeitraum { min-width: 0; font-size: 16px; flex-basis: 100%; order: -1; }

    /* Deckungsbeitrag (bms-controlling): Tabelle wischbar, erste Spalte bleibt stehen */
    #main .bms-db-tabelle table { min-width: 100%; width: max-content; }
    #main .bms-db-tabelle th:first-child,
    #main .bms-db-tabelle td:first-child {
        position: sticky;
        left: 0;
        z-index: 1;
        background: #fff;
        box-shadow: 1px 0 0 #e6ecf3;
    }
}

@media (max-width: 767px) {
    #main .bms-plan-legende span:last-child { display: none; }
    #main .bms-plan-raster th:first-child, #main .bms-plan-raster td.name { width: 112px !important; font-size: 13px; }
    #main .bms-db-kacheln { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    #main .bms-db-kachel { padding: 10px 12px; }
    #main .bms-db-kachel .w { font-size: 18px; }
    #main .bms-db-leiste > span { display: flex; gap: 6px; align-items: center; width: 100%; }
    #main .bms-db-leiste input[type=date] { flex: 1; width: auto; min-width: 0; }
    /* Sammelabrechnung und Vorlagen-Fenster */
    .modal .bms-sa .zeile { flex-direction: column; }
    .modal .bms-sa table { display: block; overflow-x: auto; }
    .modal .bms-ph-liste code { white-space: normal; word-break: break-all; }
}
