/* ========================= */
/* MOBILE */
/* ========================= */
@media (max-width: 768px) {
    
    /* ========================= */
    /* BASE */
    /* ========================= */
    html, body {
        height: 100%;
        overflow: hidden;
    }

    body {
        font-size: 16px;
        touch-action: manipulation;
    }

    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* ========================= */
    /* MAIN MENU - Left side, tap to reveal */
    /* ========================= */
    .main-menu-trigger {
        display: block !important;
        position: fixed;
        top: 0;
        left: 0;
        width: 30px;
        height: 60%;
        z-index: 99;
    }

    /* Mobile: Katze ausblenden */
    #cat-nav-btn {
        display: none !important;
    }

    #top-left #home-btn {
        display: flex !important;
    }

    #top-bar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: 60px;
        height: 100% !important;
        flex-direction: column !important;
        padding: 20px 10px !important;
        gap: 12px !important;
        background: rgba(18, 18, 26, 0.95) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        border-right: 1px solid var(--border) !important;
        border-bottom: none !important;
        transform: translateX(-100%);
        opacity: 0;
        transition: transform 0.25s, opacity 0.25s;
        justify-content: flex-start !important;
        align-items: center !important;
        z-index: 100;
        pointer-events: none;
    }

    .main-menu-trigger:hover ~ #top-bar,
    #top-bar:hover {
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
    }

    /* Tap-toggle statt Hover: verhindert Ghost-Klicks auf die Icons darunter */
    #top-bar.mobile-open {
        transform: translateX(0) !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    #top-left {
        display: flex !important;
        margin-bottom: 6px;
    }

    #top-left #logo,
    #top-left #home-btn {
        width: 42px !important;
        height: 42px !important;
        border-radius: 10px !important;
    }

    .companion-dock {
        display: none !important;
    }

    #page-title {
        display: none !important; /* Kein störender Text neben dem Icon */
    }

    #top-right {
        flex-direction: column !important;
        gap: 10px !important;
    }

    #top-bar .icon-btn {
        width: 42px !important;
        height: 42px !important;
        border-radius: 10px !important;
    }

    /* ========================= */
    /* CHAT HEADER - Tap to reveal */
    /* ========================= */
    .chat-header-trigger {
        display: block !important;
        position: fixed;
        top: 0;
        left: 30px;
        right: 0;
        height: 40px;
        z-index: 19;
    }

    #chat-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        margin: 0;
        max-width: 100%;
        width: 100%;
        border-radius: 0;
        opacity: 0;
        transform: translateY(-100%);
        transition: opacity 0.25s, transform 0.25s;
        pointer-events: none;
        z-index: 20;
        padding: 10px 12px;
        gap: 8px;
    }

    .chat-header-trigger:hover ~ #chat-header,
    #chat-header:hover,
    #chat-header.show {
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }

    /* Chat Header kompakter */
    #chat-char-avatar {
        display: none !important;
    }

    #chat-header-info {
        flex-direction: row !important;
        align-items: center !important;
        gap: 8px !important;
    }

    #chat-char-name {
        font-size: 14px !important;
    }

    #chat-header-meta {
        font-size: 10px !important;
        flex-direction: row !important;
    }

    #chat-actions {
        gap: 4px !important;
    }

    #chat-actions .icon-btn {
        width: 32px !important;
        height: 32px !important;
    }

    #chat-actions .icon-btn svg {
        width: 14px !important;
        height: 14px !important;
    }

    .bulk-delete-toolbar {
        padding: 8px 10px;
        gap: 8px;
        flex-wrap: wrap;
    }

    #bulk-delete-count {
        width: 100%;
        font-size: 12px;
    }

    .bulk-delete-actions {
        width: 100%;
        gap: 6px;
    }

    .bulk-delete-actions .btn-secondary,
    .bulk-delete-actions .btn-danger {
        flex: 1;
    }

    /* ========================= */
    /* CHAT AREA - Full width */
    /* ========================= */
    #chat-area {
        padding: 0 !important;
    }

    /* ========================= */
    /* CHAT FULLSCREEN & INPUT DOCKING */
    /* ========================= */
    #chat-page {
        position: fixed !important;
        inset: 0 !important;
        width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        margin: 0 !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        overflow: hidden !important;
        z-index: 10 !important;
    }

    #chat-container {
        flex: 1 !important;
        height: auto !important;
        overflow-y: auto !important;
        padding: 10px 12px !important;
        margin: 0 !important;
    }

    #input-area {
        position: relative !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        margin: 0 !important;
        border-radius: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)) 12px !important;
        gap: 8px !important;
        border-left: none !important;
        border-right: none !important;
        border-bottom: none !important;
        flex-shrink: 0 !important;
    }

    #input-area-wrap {
        margin: 0 !important;
        max-width: 100% !important;
    }

    #user-input {
        font-size: 16px;
        padding-right: 40px;
    }

    /* Emoji Button weg */
    #emoji-btn {
        display: none !important;
    }

    /* Macro Button neben Input */
    #macro-toggle-btn {
        width: 42px;
        height: 42px;
        border-radius: 10px;
    }

    #chat-image-btn {
        right: 10px;
        bottom: 9px;
        width: 22px;
        height: 22px;
        min-width: 22px;
        margin-left: 0;
    }

    .macro-bar {
        position: relative;
        order: unset;
        max-height: 35vh;
        z-index: 10;
    }
	
	    .macro-bar.open {
        margin-top: 0;
    }

    /* ===================================================== */
    /* MOBILE MACRO BAR - Tools oben, User-Makros drunter    */
    /* ===================================================== */
    #macro-toolbar {
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }

    /* Tool-Zeile (Expand, Spell, Retry, Director) = eigene volle Zeile oben */
    #macro-toolbar > div:first-child {
        width: 100% !important;
        margin-right: 0 !important;
        padding-right: 0 !important;
        padding-bottom: 8px !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border) !important;
        justify-content: flex-start;
    }

    /* User-Makros + Add-Button teilen sich die zweite Zeile */
    #macro-list {
        flex: 1;
        min-width: 0;
    }

    /* ========================= */
    /* PANELS */
    /* ========================= */
    .side-panel {
        position: fixed;
        top: 0 !important;
        bottom: 0 !important;
        width: 85% !important;
        max-width: 320px;
        z-index: 90;
        border-radius: 0 !important;
    }

    #left-panel {
        left: 0;
        transform: translateX(-100%);
        background: rgba(18, 18, 26, 0.95) !important;
        border-right: 1px solid var(--border) !important;
    }

    #left-panel.open {
        transform: translateX(0);
    }

    #right-panel {
        right: 0;
        transform: translateX(100%);
    }

    #right-panel.open {
        transform: translateX(0);
    }

    #right-panel .panel-content,
    #settings-panel {
        height: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        border: none !important;
    }

    /* Overlay */
    #left-panel.open::before,
    #right-panel.open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }

    /* ========================= */
    /* STORY DIRECTOR */
    /* ========================= */
    .director-card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .director-card-header input[type="text"],
    .director-card-header select {
        font-size: 16px;
        padding: 12px 14px;
        min-height: 44px;
    }

    .director-card textarea {
        font-size: 15px;
        padding: 12px 14px;
        min-height: 120px;
    }

    /* ========================= */
    /* CHARACTER MODAL */
    /* ========================= */
    #char-tab-visuals > div {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }

    /* ===================================================== */
    /* MOBILE DROPDOWNS & DIRECTOR POPOVER FIX               */
    /* ===================================================== */

    /* 1. Hauptmenü 3-Punkte Dropdown klappt nach RECHTS auf (statt links aus dem Screen) */
    #top-bar .nav-dropdown-menu {
        left: calc(100% + 10px) !important;
        right: auto !important;
        top: 0 !important;
    }

    /* 2. Director Note Popover: Dockt sauber über der Input-Bar an (statt rechts rauszulaufen) */
    .director-note-popover {
        position: fixed !important;
        bottom: 75px !important;
        left: 12px !important;
        right: 12px !important;
        width: auto !important;
        max-width: none !important;
        z-index: 200 !important;
    }
}