/* =============================================================================
   RWD Teamplanung – mobile.css   (App-artige Mobil-Ansicht, Vorbild Mitarbeiter-App)

   Wird IMMER geladen, die eigentlichen Regeln stehen aber in @media (max-width:1023px).
   Auf Desktop bleibt nur das Ausblenden der mobilen Chrome-Elemente aktiv → 0 Einfluss
   auf die bestehende Desktop-Ansicht.

   App-Shell: feste dunkelblaue Top-Bar (Hamburger + Titel), feste Bottom-Tab-Leiste,
   Sidebar als hochschiebbares Bottom-Sheet. Safe-Area (Notch) + 100dvh + Touch-Polish.
   ============================================================================= */

/* Mobile-Chrome auf dem Desktop ausblenden (Regeln greifen nur in der Media-Query). */
.tp-topbar, .tp-tabbar, .tp-drawer-overlay, .tp-mobile-assign, .tp-assign-backdrop, .kw-current-mobile { display: none; }

@media (max-width: 1023px) {

    /* ── Grundlagen / App-Feel ─────────────────────────────────────────────── */
    html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
    body { -webkit-tap-highlight-color: transparent; }
    .app-shell { min-height: 100dvh; background: var(--bg); }
    /* iOS: 16px verhindert Auto-Zoom beim Fokussieren von Eingaben */
    input, select, textarea { font-size: 16px !important; }

    /* ── Inhaltsspalte: Platz für fixe Top-Bar (oben) + Tab-Leiste (unten) ──── */
    .main {
        margin-left: 0 !important;
        min-width: 0;
        max-width: 100vw;
        overflow-x: clip;
        padding: 14px 12px;
        padding-top: calc(60px + env(safe-area-inset-top));
        padding-bottom: calc(68px + env(safe-area-inset-bottom));
    }

    /* ── Top-Bar (dunkelblau, Titel mittig, Hamburger links) ────────────────── */
    .tp-topbar {
        display: flex;
        align-items: center;
        gap: 4px;
        position: fixed;
        top: 0; left: 0; right: 0;
        height: calc(52px + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) 6px 0;
        background: var(--rwd-blue-900);
        z-index: 120;
        box-shadow: 0 1px 6px rgba(0,0,0,0.18);
    }
    .tp-topbar-btn {
        flex: 0 0 44px;
        height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        color: #fff;
        cursor: pointer;
        border-radius: 10px;
        padding: 0;
    }
    .tp-topbar-btn:active { background: rgba(255,255,255,0.14); }
    .tp-topbar-ghost { pointer-events: none; }
    .tp-topbar-title {
        flex: 1;
        text-align: center;
        color: #fff;
        font-size: 17px;
        font-weight: 700;
        letter-spacing: -0.2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    /* Animierter Hamburger → X */
    .tp-burger { position: relative; width: 22px; height: 16px; display: inline-block; }
    .tp-burger span {
        position: absolute; left: 0; width: 22px; height: 2px;
        background: #fff; border-radius: 2px; transition: transform .25s, opacity .25s;
    }
    .tp-burger span:nth-child(1) { top: 0; }
    .tp-burger span:nth-child(2) { top: 7px; }
    .tp-burger span:nth-child(3) { top: 14px; }
    .tp-burger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    .tp-burger.open span:nth-child(2) { opacity: 0; }
    .tp-burger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

    /* ── Bottom-Tab-Leiste ──────────────────────────────────────────────────── */
    .tp-tabbar {
        display: flex;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        background: #fff;
        border-top: 1px solid var(--border);
        padding: 4px 4px env(safe-area-inset-bottom);
        z-index: 120;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
    }
    .tp-tab {
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 6px 2px;
        min-height: 52px;
        background: none;
        border: none;
        cursor: pointer;
        color: #9aa0a6 !important;
        font-size: 11px;
        font-weight: 600;
        text-decoration: none !important;
        -webkit-tap-highlight-color: transparent;
        transition: color .15s;
    }
    .tp-tab .tp-tab-ico { font-size: 21px; line-height: 1; }
    .tp-tab .tp-tab-lbl {
        line-height: 1.2;
        max-width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .tp-tab.active { color: var(--rwd-blue-700) !important; }
    .tp-tab.active .tp-tab-ico { transform: scale(1.06); }
    .tp-tab:active .tp-tab-ico { transform: scale(0.88); transition: transform .08s ease; }

    /* ── Sidebar als Bottom-Sheet (Drawer) ──────────────────────────────────── */
    .tp-drawer-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        opacity: 0;
        pointer-events: none;
        transition: opacity .25s ease;
        z-index: 240;
    }
    .tp-drawer-overlay.open { opacity: 1; pointer-events: auto; }

    .sidebar {
        width: 100% !important;
        left: 0 !important; right: 0 !important;
        top: auto !important; bottom: 0 !important;
        height: auto !important;
        max-height: 84vh;
        flex-direction: column;
        border-radius: 18px 18px 0 0;
        padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
        transform: translateY(110%);
        transition: transform .28s cubic-bezier(.2,.8,.2,1);
        z-index: 250;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar.open { transform: translateY(0); box-shadow: 0 -8px 28px rgba(0,0,0,0.28); }
    /* Greifer oben am Sheet */
    .sidebar-header { position: relative; }
    .sidebar-header::before {
        content: '';
        display: block;
        width: 40px; height: 4px;
        background: rgba(255,255,255,0.32);
        border-radius: 3px;
        margin: 0 auto 12px;
    }
    /* Nav-Links im Sheet großzügiger antippbar */
    .sidebar .nav-link { padding: 13px 14px; font-size: 15px; }
    .sidebar .nav-link:active { background: rgba(255,255,255,0.18); }

    /* „Zum Dashboard"-FAB über die Tab-Leiste heben */
    .back-to-dashboard {
        bottom: calc(72px + env(safe-area-inset-bottom)) !important;
        right: 14px !important;
    }

    /* ═══════════════ Wochenplanung mobil ═══════════════════════════════════ */

    /* Toolbar: nicht mehr sticky (würde unter der Top-Bar verschwinden), umbrechend */
    .plan-toolbar {
        position: static !important;
        margin: 0 0 12px !important;
        padding: 0 0 12px !important;
        gap: 10px;
        background: transparent;
    }
    .toolbar-filters { width: 100%; }
    .toolbar-search { flex: 1; min-width: 150px; }
    .toolbar-search input { width: 100% !important; }
    /* Bug-Fix: .kw-stats-bar hat auf Desktop negative Margins + sticky top:0 (Bleed ins
       .main-Padding). Mobil zieht das die Leiste UND die direkt darunter liegenden
       klickbaren KW-Tabs UNTER die fixe Top-Bar → Kopf abgeschnitten + Taps landen auf
       der Top-Bar statt den KW-Tabs. Daher: kein negativer Margin, nicht sticky. */
    .kw-stats-bar {
        flex-wrap: wrap;
        position: static !important;
        margin: 0 0 10px 0 !important;
        padding: 0 !important;
        border-bottom: none !important;
        z-index: auto !important;
    }
    .kw-stats-bar + .plan-toolbar { top: auto !important; margin-top: 0 !important; }

    /* ── KW-Auswahl kompakt (mobil) ───────────────────────────────────────────
       6-Wochen-Tabs + „Springen zu KW" + „heute"-● raus — nur die aktuelle KW
       mit Vor/Zurück. Spart viel vertikalen Platz. */
    .kw-tabs { display: none !important; }
    .kw-heute, .kw-sep, .kw-jump-label, .kw-jump-input, .kw-jump-slash, .btn-nav-go { display: none !important; }
    .kw-current-mobile {
        display: inline-flex; align-items: baseline; gap: 5px;
        font-size: 16px; font-weight: 800; color: var(--rwd-blue-900); padding: 0 6px;
        white-space: nowrap;
    }
    .kw-cur-jahr { font-size: 12px; font-weight: 600; color: var(--text-muted); }
    .kw-nav { gap: 10px; align-items: center; justify-content: flex-start; }
    .btn-nav { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; }

    /* Filter / Suche / Sortierung: volle Breite, untereinander — kein abgeschnittenes Suchfeld. */
    .toolbar-filters { flex-direction: column; align-items: stretch; gap: 8px; }
    .gewerk-pill { width: 100%; display: flex; }
    .gewerk-pill button { flex: 1; }
    .toolbar-search { width: 100%; }
    .toolbar-sort { width: 100%; justify-content: space-between; }
    .toolbar-sort select { flex: 1; min-height: 42px; }

    /* Aktions-Buttons (Vorwoche kopieren / + Team / Teams verwalten): volle Breite,
       gleich groß, sauber gestapelt statt krumm umgebrochen. */
    .plan-toolbar .flex-spacer { display: none; }
    .plan-toolbar .btn-icon { width: 100%; justify-content: center; min-height: 44px; font-size: 14px; }

    /* MA-Pool: aus „fixed am Viewport" → normaler, kompakter Block oben.
       (Zuordnen läuft auf Touch über „➕" am Team, nicht per Ziehen.) */
    .plan-grid { display: block; }
    .ma-pool {
        position: static !important;
        left: auto !important; top: auto !important;
        width: auto !important;
        max-height: 46vh;
        margin: 0 0 14px 0;
    }
    .ma-pool-list { max-height: 30vh; }
    /* Pool-Aktionen (🌴 / 🚪) auf Touch immer sichtbar (kein Hover) */
    .ma-card-action, .ma-card-hide { opacity: 0.85 !important; font-size: 16px; padding: 4px 6px; }
    .ma-card { cursor: default; }

    /* Team-Grid: eine Spalte, volle Breite */
    .team-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        margin-left: 0 !important;
        gap: 12px;
    }
    .team-block-grip { display: none; }   /* Reorder per Drag entfällt auf Touch */

    /* Team-Aktionen + Zeilen-Buttons fingerfreundlich */
    .team-block-actions { gap: 2px; flex-wrap: wrap; }
    .team-block-action { font-size: 16px; padding: 6px 8px; min-width: 36px; min-height: 36px; }
    .tp-mobile-assign { display: inline-flex !important; align-items: center; justify-content: center; }

    .team-row { padding-top: 4px; padding-bottom: 4px; }
    /* ✕ (Entfernen) und 🌴 (Abwesenheit) auf Touch dauerhaft sichtbar + größer */
    .team-row-remove, .team-row-abw {
        opacity: 1 !important;
        font-size: 15px;
        padding: 4px 7px;
        min-width: 30px; min-height: 30px;
    }
    .team-row-rolle { min-height: 26px; }

    /* ── Tap-Zuordnen-Sheet ─────────────────────────────────────────────────── */
    /* Bug-Fix: Sheet von OBEN einblenden (nicht unten), damit die Trefferliste im oberen
       Bildschirmbereich erscheint und NICHT von der eingeblendeten Tastatur (unten) verdeckt
       wird. Suchfeld oben, Treffer direkt darunter — alles über der Tastatur sichtbar. */
    .tp-assign-backdrop {
        display: flex;
        align-items: flex-start;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 300;
        animation: tpFadeBg .2s ease;
    }
    @keyframes tpFadeBg { from { opacity: 0; } to { opacity: 1; } }
    .tp-assign-sheet {
        width: 100%;
        max-height: 72vh;
        display: flex;
        flex-direction: column;
        gap: 10px;
        background: #fff;
        border-radius: 0 0 18px 18px;
        padding: calc(8px + env(safe-area-inset-top)) 16px 14px;
        box-shadow: 0 8px 28px rgba(0,0,0,0.28);
        animation: tpSheetDrop .26s cubic-bezier(.2,.8,.2,1);
    }
    @keyframes tpSheetDrop { from { transform: translateY(-100%); } to { transform: translateY(0); } }
    .tp-assign-grip { width: 40px; height: 4px; background: #d1d5db; border-radius: 3px; margin: 0 auto 2px; }
    .tp-assign-head { display: flex; align-items: baseline; gap: 8px; }
    .tp-assign-head strong { font-size: 16px; }
    .tp-assign-search {
        width: 100%; padding: 10px 12px;
        border: 1px solid var(--border); border-radius: 8px;
    }
    .tp-assign-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 6px; }
    .tp-assign-item {
        display: flex; align-items: center; gap: 10px;
        width: 100%; text-align: left;
        background: #f9fafb; border: 1px solid var(--border); border-radius: 10px;
        padding: 10px 12px; cursor: pointer;
    }
    .tp-assign-item:active { background: #eef2f6; }
    .tp-assign-item-body { display: flex; flex-direction: column; min-width: 0; }
    .tp-assign-item-name { font-size: 14px; font-weight: 600; line-height: 1.2; }
    .tp-assign-item-meta { font-size: 11.5px; color: var(--text-muted); }

    /* ── Modals near-fullwidth (Gekündigt / Neues-Team etc.) ────────────────── */
    .modal { width: calc(100vw - 20px) !important; max-width: 100% !important; max-height: 88vh; overflow-y: auto; }
}

/* ── Sehr kleine Phones ─────────────────────────────────────────────────────*/
@media (max-width: 480px) {
    .main { padding-left: 10px; padding-right: 10px; }
    .tp-tab .tp-tab-lbl { font-size: 10px; }
    .tp-topbar-title { font-size: 16px; }
    h1 { font-size: 19px; }
}
