/* ============================================
   Vanaheim Farm — Mobile Optimierung
   Desktop bleibt Prioritaet — nur ab <=768px aktiv
   ============================================ */

/* === Sidebar Overlay (versteckt auf Desktop) === */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 99;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.open {
    display: block;
    opacity: 1;
}

/* === Mobile-Profil-Bar (versteckt auf Desktop) === */
.mobile-profile-bar {
    display: none;
}

/* ==========================================
   TABLET (max 768px)
   ========================================== */
@media (max-width: 768px) {

    /* --- Mobile-Profil-Bar sichtbar --- */
    .mobile-profile-bar {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        padding: 0.55rem 1rem;
        border-bottom: 1px solid var(--clr-border);
        background: var(--clr-bg-sidebar);
    }

    .mobile-profile-bar a {
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--clr-text-bright);
        text-decoration: none;
    }

    .mobile-profile-bar .mobile-logout-link {
        font-size: 0.68rem;
        color: var(--clr-danger);
        font-weight: 600;
    }

    /* --- Sidebar: Footer verstecken (Profil/Logout jetzt im Menue) --- */
    .sidebar-footer {
        display: none !important;
    }

    /* --- Sidebar-Header kompakter auf Mobile --- */
    .sidebar-header {
        padding: 1rem 1rem 0.8rem !important;
    }

    .sidebar-search-trigger {
        margin: 0.35rem 0.5rem !important;
    }

    .sidebar-search-kbd {
        display: none !important;
    }

    .logo-icon {
        font-size: 1.4rem !important;
        margin-bottom: 0.2rem !important;
    }

    .logo-text {
        font-size: 0.9rem !important;
    }

    .logo-sub {
        font-size: 0.52rem !important;
        margin-top: 0.2rem !important;
    }

    /* --- Hamburger-Button: X-State --- */
    .menu-toggle.open {
        background: var(--clr-surface-alt);
    }

    /* --- Globale Inline-Grid Overrides ---
       Faengt ALLE inline style="display:grid;grid-template-columns:..."
       und macht sie single-column auf Mobile */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    [style*="grid-template-columns: repeat(3"],
    [style*="grid-template-columns:repeat(3"] {
        grid-template-columns: 1fr 1fr !important;
    }

    [style*="grid-template-columns:1fr 1fr auto 1fr"] {
        grid-template-columns: 1fr 1fr !important;
    }

    [style*="grid-template-columns:1fr 110px 80px 30px"],
    [style*="grid-template-columns:1fr 60px 90px 30px"] {
        grid-template-columns: 1fr 60px 80px 30px !important;
    }

    /* --- Globale Inline min-width Overrides --- */
    [style*="min-width:280px"],
    [style*="min-width: 280px"],
    [style*="min-width:300px"],
    [style*="min-width: 300px"] {
        min-width: 0 !important;
    }

    [style*="min-width:130px"],
    [style*="min-width: 130px"],
    [style*="min-width:150px"],
    [style*="min-width: 150px"] {
        min-width: 100px !important;
    }

    /* --- Globale Inline max-width fuer Suchfelder --- */
    [style*="max-width:400px"],
    [style*="max-width: 400px"],
    [style*="max-width:300px"],
    [style*="max-width: 300px"],
    [style*="max-width:420px"],
    [style*="max-width: 420px"] {
        max-width: 100% !important;
    }

    /* --- Globale Inline gap Override fuer enge Screens --- */
    [style*="gap:2rem"],
    [style*="gap: 2rem"] {
        gap: 0.75rem !important;
    }

    /* ==========================================
       LAYOUT — Sidebar & Content
       ========================================== */
    .content {
        padding: 1rem 0.75rem !important;
        padding-top: 3.5rem !important;
    }

    /* ==========================================
       STAT CARDS
       ========================================== */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
    }

    .stat-card {
        padding: 0.8rem 0.75rem !important;
    }

    .stat-value {
        font-size: 1.3rem !important;
    }

    .stat-icon {
        font-size: 1.2rem !important;
        top: 0.6rem !important;
        right: 0.6rem !important;
    }

    .stat-label {
        font-size: 0.62rem !important;
    }

    /* ==========================================
       GRIDS
       ========================================== */
    .grid-2 {
        grid-template-columns: 1fr !important;
    }

    .form-row {
        grid-template-columns: 1fr !important;
    }

    /* ==========================================
       PAGE HEADER
       ========================================== */
    .page-header {
        flex-direction: column;
        gap: 0.5rem;
    }

    .page-header h2 {
        font-size: 1.25rem !important;
    }

    .page-header-actions {
        width: 100%;
    }

    /* content-header (Stempelkarten etc) */
    .content-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }

    /* ==========================================
       TABLES — horizontaler Scroll
       ========================================== */
    .card-body:has(table),
    .card-body:has(.data-table) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 500px;
    }

    thead th {
        padding: 0.5rem 0.7rem !important;
        font-size: 0.62rem !important;
        white-space: nowrap !important;
    }

    tbody td {
        padding: 0.5rem 0.7rem !important;
        font-size: 0.8rem !important;
    }

    /* ==========================================
       CARDS
       ========================================== */
    .card-header {
        padding: 0.65rem 0.85rem !important;
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .card-header h3 {
        font-size: 0.85rem !important;
    }

    .card-body {
        padding: 0.85rem !important;
    }

    .card-body.no-padding {
        padding: 0 !important;
    }

    /* ==========================================
       BUTTONS & FORMS
       ========================================== */
    .btn {
        padding: 0.45rem 0.75rem !important;
        font-size: 0.76rem !important;
    }

    .btn-sm, .btn.btn-sm {
        padding: 0.3rem 0.55rem !important;
        font-size: 0.68rem !important;
    }

    .form-control {
        font-size: 0.85rem !important;
        padding: 0.5rem 0.7rem !important;
    }

    /* Touch-friendly: Mindesthoehe fuer Inputs/Buttons */
    .form-control,
    .btn,
    select.form-control {
        min-height: 40px;
    }

    /* ==========================================
       MODAL
       ========================================== */
    .modal {
        margin: 0.5rem !important;
        max-width: calc(100vw - 1rem) !important;
        max-height: 90vh !important;
        border-radius: var(--radius-lg) !important;
    }

    .modal-body {
        padding: 1rem !important;
    }

    .modal-header {
        padding: 0.85rem 1rem !important;
    }

    .modal-footer {
        padding: 0.65rem 1rem !important;
        flex-wrap: wrap;
    }

    /* ==========================================
       SCHNELLVERKAUF
       ========================================== */

    /* Checkout Grid: Kassiert von / Kunde / Rabatt / Button */
    #checkout-form > div[style*="grid-template-columns:1fr 1fr auto 1fr"] {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.5rem !important;
    }

    /* Rabatt-Feld Breite freigeben */
    #cart-manueller-rabatt {
        width: 100% !important;
    }

    /* Produkt-Grid */
    .produkt-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
    }

    .produkt-card {
        padding: 0.65rem !important;
    }

    .produkt-card-name {
        font-size: 0.75rem !important;
    }

    .produkt-card-preis {
        font-size: 1rem !important;
    }

    .produkt-card-bestand {
        font-size: 0.62rem !important;
    }

    /* Stempel-Option responsive */
    #stempel-option > div {
        flex-wrap: wrap !important;
        gap: 0.4rem !important;
    }

    /* Produkt-Suche volle Breite */
    #produkt-suche {
        max-width: 100% !important;
    }

    /* Warenkorb sticky weniger Abstand */
    #warenkorb-card {
        top: 3.5rem !important;
    }

    /* ==========================================
       KASSENBUCH
       ========================================== */

    /* Filter-Formular */
    form[style*="display:flex"][style*="flex-wrap:wrap"][style*="align-items:flex-end"] {
        gap: 0.5rem !important;
    }

    form[style*="flex-wrap:wrap"] .form-group[style*="min-width"] {
        min-width: 0 !important;
        flex: 1 1 calc(50% - 0.5rem) !important;
    }

    /* ==========================================
       LAGER
       ========================================== */

    /* Such- und Filterleisten volle Breite */
    #material-suche,
    #fw-suche {
        max-width: 100% !important;
    }

    /* ==========================================
       KUNDEN — Detail-Ansicht
       ========================================== */
    .stat-card[style*="grid-column"] {
        grid-column: auto !important;
    }

    /* ==========================================
       KALKULATOR
       ========================================== */

    /* Preisrechner-Grid */
    #pr-tabelle[style*="grid-template-columns:repeat(3"] {
        grid-template-columns: 1fr 1fr !important;
    }

    /* ==========================================
       MITTEILUNGEN
       ========================================== */
    .mitteilung-card {
        padding: 0.75rem 0.85rem !important;
    }

    .mitteilung-header {
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    /* ==========================================
       ACTION BANNER
       ========================================== */
    .action-banner {
        padding: 0.75rem 0.85rem !important;
    }

    .action-banner-links {
        gap: 0.3rem !important;
    }

    .action-banner-links .btn {
        flex: 1 1 auto;
        text-align: center;
        min-width: 0;
    }

    /* ==========================================
       FILTER BARS — allgemein
       ========================================== */
    .filter-bar {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.5rem !important;
    }

    .filter-bar .form-group {
        min-width: 0 !important;
        width: 100% !important;
    }

    /* Tab-Navigation scrollbar */
    .tab-nav {
        gap: 0.15rem !important;
        -webkit-overflow-scrolling: touch;
    }

    .tab-nav .btn {
        padding: 0.45rem 0.65rem !important;
        font-size: 0.7rem !important;
        white-space: nowrap;
    }

    /* ==========================================
       PROFIL / BENUTZERVERWALTUNG
       ========================================== */
    [style*="grid-template-columns:repeat(auto-fill,minmax(200px"] {
        grid-template-columns: 1fr 1fr !important;
    }

    [style*="grid-template-columns:repeat(auto-fill,minmax(240px"] {
        grid-template-columns: 1fr !important;
    }

    [style*="grid-template-columns:repeat(auto-fill,minmax(300px"] {
        grid-template-columns: 1fr !important;
    }

    /* ==========================================
       SCHICHTPROTOKOLL
       ========================================== */
    /* Schichtkarten-Grid */
    [style*="grid-template-columns:repeat(auto-fill,minmax(300px,1fr))"] {
        grid-template-columns: 1fr !important;
    }

    /* ==========================================
       STATISTIKEN
       ========================================== */
    canvas {
        max-width: 100% !important;
        height: auto !important;
    }

    /* ==========================================
       GEHALTSRECHNER
       ========================================== */
    /* Filter row wrapping */
    .card-header form[style*="display:flex"] {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    /* ==========================================
       STEMPELKARTEN (ergaenzt bestehende Klassen)
       ========================================== */
    .sk-settings-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .sk-karten-row {
        flex-direction: column !important;
        gap: 0.6rem !important;
    }

    .sk-karte {
        min-width: 0 !important;
    }

    .sk-stempel-dot {
        width: 30px !important;
        height: 30px !important;
        font-size: 0.85rem !important;
    }

    .sk-kunde-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.4rem !important;
    }

    .sk-actions {
        flex-direction: column !important;
    }

    .sk-actions form {
        width: 100% !important;
    }

    .sk-actions .btn {
        width: 100% !important;
    }

    .sk-filter-bar .btn {
        flex: 1 !important;
        text-align: center !important;
        min-width: 0 !important;
    }

    .sk-history-table th:nth-child(5),
    .sk-history-table td:nth-child(5) {
        display: none !important;
    }

    .sk-setting-box {
        padding: 0.75rem !important;
    }

    .sk-checkbox-row {
        padding: 0.6rem !important;
    }

    .sk-checkbox-row label {
        font-size: 0.8rem !important;
    }

    /* ==========================================
       LOGIN
       ========================================== */
    .login-wrapper {
        padding: 1rem !important;
    }

    .login-box {
        padding: 1.75rem 1.25rem !important;
    }

    /* ==========================================
       UTILITY: Scrollbare Container
       ========================================== */
    .table-wrap,
    [style*="overflow-x:auto"],
    [style*="overflow-x: auto"] {
        -webkit-overflow-scrolling: touch;
    }

    /* Flex-Rows die wrappen sollen */
    [style*="display:flex"][style*="justify-content:space-between"] {
        flex-wrap: wrap !important;
        gap: 0.4rem !important;
    }

    /* ==========================================
       DETAIL-LABELS (Info-Rows)
       ========================================== */
    .info-row {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .detail-value {
        font-size: 0.82rem !important;
    }

    /* ==========================================
       DESCRIPTION BLOCK
       ========================================== */
    .desc-block {
        font-size: 0.82rem !important;
        padding: 0.55rem 0.7rem !important;
    }

    /* ==========================================
       TOP BAR — Mobile
       ========================================== */
    .topbar {
        margin: -1.25rem -1rem 0.75rem -1rem !important;
        padding: 0.4rem 0.5rem !important;
        gap: 0.4rem !important;
        font-size: 0.65rem !important;
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
    }
    .topbar-item { white-space: nowrap; flex-shrink: 0; }
    .topbar-spacer { display: none !important; }
    .topbar-btn { padding: 0.15rem 0.35rem !important; font-size: 0.75rem !important; }

    /* ==========================================
       NOTES PANEL — Mobile
       ========================================== */
    .notes-panel {
        width: 100% !important;
        right: -100% !important;
    }
    .notes-panel.open { right: 0 !important; }

    /* ==========================================
       SIDEBAR FAVORITEN — Mobile
       ========================================== */
    .sidebar-favs {
        padding: 0.2rem 0.5rem 0.3rem !important;
    }

    /* ==========================================
       COMMAND PALETTE — Mobile
       ========================================== */
    #cmd-palette {
        padding-top: 5vh !important;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .cmd-box {
        max-width: 100% !important;
    }

    .cmd-footer {
        display: none !important;
    }

    /* Scroll-to-top auf Mobile kleiner */
    .scroll-to-top {
        bottom: 1rem !important;
        right: 1rem !important;
        width: 36px !important;
        height: 36px !important;
    }

    /* ==========================================
       FLASH MESSAGES
       ========================================== */
    .flash {
        font-size: 0.78rem !important;
        padding: 0.65rem 0.85rem !important;
        border-radius: var(--radius) !important;
    }
}


/* ==========================================
   SMALL PHONE (max 480px)
   ========================================== */
@media (max-width: 480px) {

    .content {
        padding: 0.75rem 0.5rem !important;
        padding-top: 3.25rem !important;
    }

    /* Stats: 2 Spalten beibehalten, aber kompakter */
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.4rem !important;
    }

    .stat-card {
        padding: 0.65rem 0.6rem !important;
    }

    .stat-value {
        font-size: 1.15rem !important;
    }

    .stat-detail {
        font-size: 0.62rem !important;
    }

    /* Schnellverkauf checkout: komplett gestapelt */
    #checkout-form > div[style*="grid-template-columns:1fr 1fr auto 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Produkt-Grid: 2 Spalten, enger */
    .produkt-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.4rem !important;
    }

    .produkt-card {
        padding: 0.55rem !important;
    }

    .produkt-card-name {
        font-size: 0.7rem !important;
    }

    .produkt-card-preis {
        font-size: 0.9rem !important;
    }

    /* Page header */
    .page-header h2 {
        font-size: 1.1rem !important;
    }

    /* Card headers */
    .card-header h3 {
        font-size: 0.8rem !important;
    }

    /* Kalkulator 3er-Grid */
    #pr-tabelle[style*="grid-template-columns:repeat(3"] {
        grid-template-columns: 1fr !important;
    }

    /* Profil Stats-Grid */
    [style*="grid-template-columns:repeat(auto-fill,minmax(200px"] {
        grid-template-columns: 1fr !important;
    }

    /* Stempel-Dots kleiner */
    .sk-stempel-dot {
        width: 26px !important;
        height: 26px !important;
        font-size: 0.75rem !important;
    }

    /* Alle Inline-Grids: 1fr erzwingen */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Tabellen kleiner */
    thead th {
        padding: 0.4rem 0.5rem !important;
        font-size: 0.64rem !important;
    }

    tbody td {
        padding: 0.4rem 0.5rem !important;
        font-size: 0.72rem !important;
    }

    /* Badges */
    .badge {
        font-size: 0.64rem !important;
        padding: 0.15rem 0.4rem !important;
    }
}


/* ==========================================
   VERY SMALL PHONE (max 360px)
   ========================================== */
@media (max-width: 360px) {

    .content {
        padding: 0.5rem 0.35rem !important;
        padding-top: 3rem !important;
    }

    .stat-value {
        font-size: 1rem !important;
    }

    .stat-label {
        font-size: 0.64rem !important;
    }

    .stat-card {
        padding: 0.55rem 0.5rem !important;
    }

    .btn {
        padding: 0.4rem 0.5rem !important;
        font-size: 0.7rem !important;
    }

    .form-control {
        font-size: 0.8rem !important;
    }

    .card-header {
        padding: 0.55rem 0.65rem !important;
    }

    .card-body {
        padding: 0.65rem !important;
    }

    /* Sidebar Logo */
    .sidebar.open .logo-text {
        font-size: 0.9rem;
    }
}


/* ==========================================
   TOUCH-OPTIMIERUNG (Hover-Geraete erkennen)
   ========================================== */
@media (hover: none) and (pointer: coarse) {

    /* Kein Hover-Effekt auf Touch-Geraeten */
    .stat-card:hover {
        transform: none !important;
        box-shadow: var(--shadow-sm) !important;
    }

    .produkt-card:not(.ausverkauft):hover {
        transform: none !important;
    }

    .mitteilung-card:hover {
        transform: none !important;
    }

    /* Groessere Tap-Targets */
    .nav-menu li a {
        padding: 0.6rem 1rem !important;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .table-actions .btn {
        min-width: 36px;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .logout-btn {
        padding: 0.55rem !important;
        min-height: 44px;
    }

    /* Scrollbar ausblenden auf Touch */
    .nav-menu::-webkit-scrollbar,
    .tab-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-menu,
    .tab-nav {
        scrollbar-width: none;
    }
}
