/**
 * Art on Tour / SmartHomeConsulting - WebApp Specific Styles (CENTRAL)
 * Name: Arthur Peter Lorenzen
 * Adresse: Bachtelstrasse 68, 8342 Wernetshausen, Schweiz
 * Telefon: +41 44 938 07 15
 * E-Mail: info@art-on-tour.ch
 * web: www.art-on-tour.ch
 *
 * Description: Verbesserte Styles für Browser- und WebApp-Modus
 */

/* ======================================= */
/*   1. GEMEINSAME BASIS-EINSTELLUNGEN     */
/* ======================================= */

/* 1.1 HTML und Body Grundeinstellungen */
html {
    height: 100%; /* Standardhöhe für nicht-WebApp */
}

/* 1.2 WebApp-spezifische Body-Anpassungen */
body.webapp-mode {
    /* Grundlegende Einstellungen */
    position: relative; /* Wichtig: In BEIDEN Modi relative, nicht fixed! */
    min-height: 100%;
    width: 100%;
    overflow-x: hidden;
    
    /* Verhindert Pull-to-Refresh */
    overscroll-behavior-y: none;
    
    /* Touch-Optimierungen */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    
    /* Keine Standard-Abstände */
    margin: 0;
    padding: 0 !important;
    
    /* Hintergrund */
    background-color: var(--background-color);
}

/* ======================================= */
/*   2. HEADER - GEMEINSAME STILE          */
/* ======================================= */

/* 2.1 Gemeinsamer Header für beide Modi */
.header {
    position: fixed; /* Bleibt auch im Browser-Modus fixed */
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: var(--header-height);
    z-index: var(--z-index-header);
    background-color: var(--primary-color);
    box-shadow: var(--shadow);
}

/* WebApp-spezifische Anpassungen für Header */
.webapp-mode .header {
    /* In WebApp Safe Area zusätzlich berücksichtigen */
    padding-top: env(safe-area-inset-top);
    height: calc(var(--header-height) + env(safe-area-inset-top));
    display: flex;
    align-items: center;
}

/* ======================================= */
/*   3. FOOTER - MODUS-SPEZIFISCHE STILE   */
/* ======================================= */

/* 3.1 Footer im normalen Browser-Modus (nicht WebApp) */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: var(--footer-height);
    z-index: var(--z-index-footer);
    background-color: var(--container-bg-color);
    border-top: 3px solid var(--primary-color);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

/* 3.2 Footer im WebApp-Modus */
.webapp-mode .footer {
    /* Baseline bleibt, aber + Safe Area */
    height: calc(var(--footer-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    
    /* Kritisch für iOS - vermeidet Verschwinden */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* 3.3 Gemeinsame Footer-Inhalte */
.footer .footer-menu {
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    width: 100%;
    height: var(--footer-height);
    box-sizing: border-box;
}

/* WebApp-spezifische Anpassungen für Footer-Menü */
.webapp-mode .footer .footer-menu {
    /* Horizontale Safe Areas berücksichtigen */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ======================================= */
/*   4. HAUPTINHALT - ANPASSUNGEN FÜR MODI */
/* ======================================= */

/* 4.1 Hauptinhalt im normalen Browser-Modus */
.main-content {
    /* Position relativ zu Header/Footer */
    position: relative;
    padding-top: var(--header-height);
    padding-bottom: var(--footer-height);
    min-height: calc(100vh - var(--header-height) - var(--footer-height));
    overflow-y: auto;
    overflow-x: hidden;
    z-index: var(--z-index-content);
}

/* 4.2 Hauptinhalt im WebApp-Modus */
.webapp-mode .main-content {
    /* Angepasst für WebApp mit Safe Areas */
    padding-top: calc(var(--header-height) + env(safe-area-inset-top));
    padding-bottom: calc(var(--footer-height) + env(safe-area-inset-bottom));
    min-height: calc(100vh - (var(--header-height) + env(safe-area-inset-top)) - (var(--footer-height) + env(safe-area-inset-bottom)));
    
    /* Wichtig für Scrolling in iOS */
    -webkit-overflow-scrolling: touch;
}

/* 4.3 Container im Hauptinhalt */
.main-content > .container,
.main-content > div:first-child {
    padding: var(--container-padding);
    box-sizing: border-box;
    margin: 0 auto;
    max-width: var(--container-width-max);
}

/* WebApp-spezifische Safe Areas für Container */
.webapp-mode .main-content > .container,
.webapp-mode .main-content > div:first-child {
    padding-left: calc(var(--container-padding) + env(safe-area-inset-left));
    padding-right: calc(var(--container-padding) + env(safe-area-inset-right));
}

/* 4.4 Panorama-Viewer-Spezialfall */
.main-content > #panorama,
.main-content > #panorama-container {
    max-width: none;
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
}

/* ======================================= */
/*   5. SIDE-MENU - ANPASSUNGEN FÜR MODI   */
/* ======================================= */

/* 5.1 Gemeinsame Side-Menu-Stile */
.side-menu {
    position: fixed;
    top: var(--header-height);
    bottom: var(--footer-height);
    right: 0;
    width: 280px;
    max-width: 85%;
    z-index: var(--z-index-side-menu);
    background-color: var(--container-bg-color);
    transform: translateX(100%);
    transition: transform 0.3s ease-out;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid var(--border-color-light);
}

/* 5.2 Side-Menu im WebApp-Modus */
.webapp-mode .side-menu {
    /* Safe Areas hinzufügen */
    top: calc(var(--header-height) + env(safe-area-inset-top));
    bottom: calc(var(--footer-height) + env(safe-area-inset-bottom));
    padding-right: env(safe-area-inset-right);
    
    /* Safari fixes */
    transform: translate3d(100%, 0, 0);
    -webkit-transform: translate3d(100%, 0, 0);
    transition: transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
    -webkit-transition: -webkit-transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* 5.3 Aktiver Zustand */
.side-menu.active {
    transform: translateX(0);
}

.webapp-mode .side-menu.active {
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
}

/* 5.4 Side-Menu Innenelemente */
.side-menu .side-menu-header {
    flex-shrink: 0;
    min-height: 50px;
}

.side-menu .room-list {
    flex-grow: 1;
    overflow-y: auto;
}

.webapp-mode .side-menu .room-list {
    -webkit-overflow-scrolling: touch;
}

/* 5.5 Overlay für Side-Menu */
.rooms-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: var(--z-index-side-menu-overlay);
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease-out, visibility 0s 0.3s linear;
}

.rooms-overlay.active {
    visibility: visible;
    opacity: 1;
    transition: opacity 0.3s ease-out, visibility 0s 0s linear;
}

/* ======================================= */
/*   6. VIEWER CONTROLS - ANPASSUNGEN      */
/* ======================================= */

/* 6.1 Grundlegende Controls-Position */
.controls {
    position: fixed;
    bottom: var(--footer-height);
    left: 0;
    right: 0;
    width: 100%;
    z-index: calc(var(--z-index-content) + 10);
}

/* 6.2 WebApp-spezifische Anpassung */
.webapp-mode .controls {
    bottom: calc(var(--footer-height) + env(safe-area-inset-bottom));
}

/* ======================================= */
/*   7. RESPONSIVE & LANDSCAPE ANPASSUNGEN */
/* ======================================= */

/* 7.1 Landscape-Modus */
@media screen and (orientation: landscape) and (max-height: 500px) {
    /* Header anpassen */
    .webapp-mode .header {
        height: calc(var(--header-height-landscape) + env(safe-area-inset-top));
    }
    
    /* Footer anpassen */
    .webapp-mode .footer {
        height: calc(var(--footer-height-landscape) + env(safe-area-inset-bottom));
    }
    
    /* Footer-Menü-Höhe anpassen */
    .webapp-mode .footer .footer-menu {
        height: var(--footer-height-landscape);
    }
    
    /* Footer-Items kompakter */
    .webapp-mode .footer .footer-item {
        padding-top: 5px;
        padding-bottom: 2px;
    }
    
    .webapp-mode .footer .footer-icon {
        width: 20px;
        height: 20px;
        margin-bottom: 2px;
    }
    
    .webapp-mode .footer .footer-label {
        font-size: 8px;
        margin-top: 1px;
    }
    
    /* Hauptinhalt-Abstände anpassen */
    .webapp-mode .main-content {
        padding-top: calc(var(--header-height-landscape) + env(safe-area-inset-top));
        padding-bottom: calc(var(--footer-height-landscape) + env(safe-area-inset-bottom));
    }
    
    /* Side-Menu anpassen */
    .webapp-mode .side-menu {
        top: calc(var(--header-height-landscape) + env(safe-area-inset-top));
        bottom: calc(var(--footer-height-landscape) + env(safe-area-inset-bottom));
    }
    
    /* Controls für Panorama anpassen */
    .webapp-mode .controls {
        bottom: calc(var(--footer-height-landscape) + env(safe-area-inset-bottom));
    }
}

/* ======================================= */
/*   8. iOS-SPEZIFISCHE ANPASSUNGEN        */
/* ======================================= */

/* 8.1 iOS-spezifische Fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS spezifische Höhenanpassung */
    html {
        height: -webkit-fill-available;
    }
    
    body.webapp-mode {
        min-height: -webkit-fill-available;
    }
    
    /* iOS-spezifische Fixes für Footer */
    .webapp-mode .footer {
        /* Explizite Stile für iOS */
        transform: translate3d(0, 0, 0) !important;
        -webkit-transform: translate3d(0, 0, 0) !important;
    }
    
    /* iOS-spezifische Fixes für Controls */
    .webapp-mode .controls {
        transform: translate3d(0, 0, 0) !important;
        -webkit-transform: translate3d(0, 0, 0) !important;
    }
    
    /* iOS-spezifisches Scroll-Verhalten */
    .webapp-mode .main-content {
        -webkit-overflow-scrolling: touch;
    }
    
    /* iPhone X+ Safe Area zusätzlicher Fix für Footer */
    @media only screen and (min-device-width: 375px) and (max-device-width: 812px) and (-webkit-min-device-pixel-ratio: 3) {
        .webapp-mode .footer {
            height: calc(var(--footer-height) + 20px + env(safe-area-inset-bottom)) !important;
            padding-bottom: calc(20px + env(safe-area-inset-bottom)) !important;
        }
        
        .webapp-mode .main-content {
            padding-bottom: calc(var(--footer-height) + 20px + env(safe-area-inset-bottom));
        }
        
        .webapp-mode .controls {
            bottom: calc(var(--footer-height) + 20px + env(safe-area-inset-bottom));
        }
    }
}

/* ======================================= */
/*   9. FULLSCREEN-MODUS ANPASSUNGEN       */
/* ======================================= */

body.webapp-mode.fullscreen-active {
    background-color: #000 !important;
}

.webapp-mode.fullscreen-active .header,
.webapp-mode.fullscreen-active .footer,
.webapp-mode.fullscreen-active .side-menu,
.webapp-mode.fullscreen-active .rooms-overlay {
    display: none !important;
}

.webapp-mode.fullscreen-active .main-content {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* ======================================= */
/*   10. INSTALLATIONSHINWEISE             */
/* ======================================= */

.install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--container-bg-color);
    padding: 10px 15px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 9998;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
    visibility: hidden;
}

.webapp-mode .install-banner {
    padding-left: calc(15px + env(safe-area-inset-left));
    padding-right: calc(15px + env(safe-area-inset-right));
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

.install-banner.active {
    transform: translateY(0);
    visibility: visible;
}
/* ======================================= */
/*   9. WEBAPP-SPEZIFISCHE ANPASSUNGEN     */
/* ======================================= */

/* 9.1 Detail Container im WebApp-Modus */
.webapp-mode .detail-container {
    /* Safe Area Insets berücksichtigen */
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
}

/* 9.2 Fullscreen-Controls im WebApp-Modus */
.webapp-mode .fullscreen-controls {
    bottom: calc(10px + var(--safe-area-inset-bottom));
    padding-bottom: calc(10px + var(--safe-area-inset-bottom));
}

/* 9.3 Landscape-Modus-Optimierungen */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .webapp-mode .fullscreen-caption {
        bottom: 60px;
        font-size: 14px;
    }
    
    .webapp-mode .fullscreen-controls {
        bottom: calc(5px + var(--safe-area-inset-bottom));
        padding: 5px;
    }
    
    .webapp-mode .fullscreen-btn,
    .webapp-mode .fullscreen-nav {
        width: 36px;
        height: 36px;
    }
}
/* ======================================= */
/*   7. WEBAPP-SPEZIFISCHE ANPASSUNGEN     */
/* ======================================= */

/* 7.1 Anpassungen für WebApp-Modus */
.webapp-mode .contact-container {
    padding-top: calc(var(--spacing-lg) + var(--safe-area-inset-top));
    padding-bottom: calc(var(--spacing-lg) + var(--safe-area-inset-bottom));
    padding-left: calc(var(--spacing-xl) + var(--safe-area-inset-left));
    padding-right: calc(var(--spacing-xl) + var(--safe-area-inset-right));
}

@media (max-width: 768px) {
    .webapp-mode .contact-container {
        padding-top: calc(var(--spacing-lg) + var(--safe-area-inset-top));
        padding-bottom: calc(var(--spacing-lg) + var(--safe-area-inset-bottom));
        padding-left: calc(var(--spacing-md) + var(--safe-area-inset-left));
        padding-right: calc(var(--spacing-md) + var(--safe-area-inset-right));
    }
}

@media (max-width: 480px) {
    .webapp-mode .contact-container {
        padding-top: calc(var(--spacing-md) + var(--safe-area-inset-top));
        padding-bottom: calc(var(--spacing-md) + var(--safe-area-inset-bottom));
        padding-left: calc(var(--spacing-sm) + var(--safe-area-inset-left));
        padding-right: calc(var(--spacing-sm) + var(--safe-area-inset-right));
    }
}

/* 7.2 Touch-Optimierungen für WebApp */
@media (pointer: coarse) {
    .webapp-mode .share-button,
    .webapp-mode .form-actions .btn,
    .webapp-mode .checkbox-container {
        min-height: 44px;
    }
    
    .webapp-mode .contact-form input[type="text"],
    .webapp-mode .contact-form input[type="email"],
    .webapp-mode .contact-form input[type="tel"] {
        height: 44px;
    }
    
    .webapp-mode .checkmark {
        width: 26px;
        height: 26px;
    }
    
    .webapp-mode .checkbox-container .checkmark:after {
        left: 9px;
        top: 5px;
        width: 6px;
        height: 12px;
    }
    
    .webapp-mode .checkbox-container {
        padding-left: 36px;
    }
}

/* 7.3 Landscape-Modus Optimierungen */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .webapp-mode .contact-container {
        padding-top: calc(var(--spacing-sm) + var(--safe-area-inset-top));
        padding-bottom: calc(var(--spacing-sm) + var(--safe-area-inset-bottom));
    }
    
    .webapp-mode .contact-container section {
        padding: var(--spacing-sm);
    }
    
    .webapp-mode .contact-container h2 {
        font-size: 1.3rem;
        margin-bottom: var(--spacing-sm);
    }
    
    .webapp-mode .contact-image {
        width: 80px;
        height: 80px;
    }
    
    .webapp-mode .sharing-content {
        gap: var(--spacing-sm);
    }
    
    .webapp-mode .qr-code {
        width: 150px;
        height: 150px;
    }
}
/* ======================================= */
/*   8. WEBAPP-SPEZIFISCHE ANPASSUNGEN     */
/* ======================================= */

/* 8.1 Direkte Anpassungen für WebApp */
@media all and (display-mode: standalone), (display-mode: fullscreen) {
    /* Container positionieren */
    body {
        /* iOS-Safari Fix für Viewport */
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    /* WebApp-Startseite sauber darstellen */
    .welcome-screen {
        /* Mit Safe Area umgehen */
        padding-top: env(safe-area-inset-top, 0);
        padding-bottom: env(safe-area-inset-bottom, 0);
        padding-left: env(safe-area-inset-left, 0);
        padding-right: env(safe-area-inset-right, 0);
    }
}

/* 8.2 WebApp-Buttons und UI-Steuerelemente optimiert */
.webapp-mode .start-button,
.webapp-mode .webapp-launch-btn {
    /* Größere Klickfläche für Touch-Geräte */
    min-height: 28px;
    padding: 12px 25px;
    
    /* Visuelles Feedback auf Berührung */
    touch-action: manipulation;
}

/* 8.3 WebApp-Buttons nebeneinander anordnen */
.webapp-mode .welcome-screen .button-container {
    display: flex;
    flex-direction: row;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 20px;
}

/* 8.4 Optimierte Darstellung auf iOS-Geräten (notch) */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .webapp-mode .welcome-screen,
    html[data-ios-webapp="true"] .welcome-screen {
        padding-top: env(safe-area-inset-top, 0);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    
    .webapp-mode .welcome-content {
        /* Abstand unten für Home-Indikator */
        margin-bottom: env(safe-area-inset-bottom, 0);
    }
}

/* 8.5 Anpassungen für WebApp-Buttons */
.webapp-mode .welcome-screen .start-button,
.webapp-mode .welcome-screen .webapp-launch-btn {
    margin: 0 10px 20px 10px;
    display: inline-block;
}

/* Verbesserte WebApp-Buttons-Reihe */
.webapp-mode .button-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin-bottom: 30px;
}

@media (max-width: 480px) {
    .webapp-mode .button-row {
        flex-direction: column;
        gap: 10px;
    }
    
    .webapp-mode .welcome-screen .start-button,
    .webapp-mode .welcome-screen .webapp-launch-btn {
        width: 100%;
        margin: 0 0 10px 0;
    }
}
/* ======================================= */
/*   8. WEBAPP-SPEZIFISCHE ANPASSUNGEN     */
/* ======================================= */

/* 8.1 Container-Anpassungen im WebApp-Modus */
.webapp-mode .floorplan-container {
    margin-top: 0;
    margin-bottom: 0;
    padding-top: var(--spacing-md);
    padding-bottom: var(--spacing-md);
    padding-left: calc(var(--spacing-lg) + var(--safe-area-inset-left));
    padding-right: calc(var(--spacing-lg) + var(--safe-area-inset-right));
}

/* 8.2 Touch-Optimierungen */
@media (pointer: coarse) {
    .webapp-mode .floor-tab {
        min-height: 44px;
        padding: 10px var(--spacing-md);
    }
    
    .webapp-mode .interactive-point {
        width: 30px;
        height: 30px;
    }
    
    .webapp-mode .point-tooltip {
        font-size: 14px;
        padding: 8px var(--spacing-sm);
    }
}

/* 8.3 Landscape-Modus-Optimierungen */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .webapp-mode .floorplan-container {
        padding-top: var(--spacing-sm);
        padding-bottom: var(--spacing-sm);
    }
    
    .webapp-mode .floor-tabs {
        margin-bottom: var(--spacing-xs);
    }
    
    .webapp-mode .floorplan-instructions {
        margin-bottom: var(--spacing-sm);
        font-size: 11px;
    }
    
    .webapp-mode .floorplan-image {
        max-height: calc(100vh - 140px);
    }
}