/*
 * GastroOS Mitarbeiter-App — mobile Oberfläche
 * Separater Dateiname ist beabsichtigt: Mobilgeräte dürfen kein altes
 * Desktop-Stylesheet aus einem langlebigen Browser-/Proxy-Cache verwenden.
 */

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    color: var(--on-accent);
    background: var(--accent);
    box-shadow: 0 5px 16px color-mix(in srgb, var(--accent) 35%, transparent);
}

.brand-copy {
    display: flex;
    flex-direction: column;
    line-height: 1.08;
}

.brand-copy strong { font-size: .96rem; }
.brand-copy small {
    margin-top: 4px;
    color: var(--nav-muted);
    font-size: .66rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.skip-link {
    min-height: 44px;
    position: fixed;
    top: 8px;
    left: 12px;
    z-index: 1000;
    padding: 10px 14px;
    border-radius: 10px;
    color: #fff;
    background: #0f172a;
    box-shadow: 0 8px 24px rgba(15,23,42,.25);
    display: inline-flex;
    align-items: center;
    transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

:where(a, button, input, select, textarea):focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

@media (max-width: 900px) {
    :root {
        --mobile-topbar: 64px;
        --mobile-bottom-nav: 72px;
    }

    html {
        width: 100%;
        min-height: 100%;
        overflow: hidden;
        background: var(--bg);
        -webkit-text-size-adjust: 100%;
    }

    body.staff-body {
        width: 100%;
        min-width: 0;
        height: 100dvh;
        overflow: hidden;
        background: var(--bg);
    }

    body.mobile-nav-open { overflow: hidden; }

    .app-shell {
        display: grid !important;
        width: 100%;
        min-width: 0;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-rows: calc(var(--mobile-topbar) + env(safe-area-inset-top)) minmax(0, 1fr) !important;
        grid-template-areas: "topbar" "main" !important;
    }

    .topbar {
        grid-area: topbar;
        width: 100%;
        min-width: 0;
        min-height: 0;
        height: calc(var(--mobile-topbar) + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) 14px 0;
        gap: 11px;
        border-bottom: 1px solid rgba(15, 23, 42, .07);
        background: var(--card);
        box-shadow: none;
        z-index: 220;
    }

    .mobile-menu-button,
    .sidebar-close {
        display: inline-flex !important;
        width: 44px;
        height: 44px;
        min-width: 44px;
        padding: 0;
        align-items: center;
        justify-content: center;
        border: 0;
        border-radius: 13px;
        background: #f1f5f9;
        color: #1e293b;
        font: inherit;
        font-size: 1.05rem;
        cursor: pointer;
    }

    .topbar .page-title {
        min-width: 0;
        max-width: 48vw;
        overflow: hidden;
        color: #172033;
        font-size: 1.02rem;
        font-weight: 750;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar-tenant-logo { display: inline-grid; }

    .topbar .spacer { min-width: 0; }

    .topbar .user-chip {
        width: 44px;
        height: 44px;
        min-width: 44px;
        padding: 0;
        justify-content: center;
        border: 0;
        border-radius: 50%;
        background: transparent;
    }

    .topbar .user-chip > span,
    .topbar .user-chip > .fa-chevron-down { display: none !important; }

    .topbar .user-chip .avatar {
        width: 38px;
        height: 38px;
        border: 3px solid color-mix(in srgb, var(--accent) 18%, white);
        background: var(--primary);
        font-size: .82rem;
    }

    .user-dropdown {
        position: fixed;
        top: calc(var(--mobile-topbar) + env(safe-area-inset-top) + 6px);
        right: 12px;
        left: 12px;
        width: auto;
        max-height: calc(100dvh - var(--mobile-topbar) - 28px - env(safe-area-inset-top));
        overflow-y: auto;
        border-radius: 18px;
        box-shadow: 0 22px 55px rgba(15,23,42,.22);
    }

    .user-dropdown .dropdown-item {
        min-height: 48px;
        padding: 11px 16px;
        font-size: .91rem;
    }

    .sidebar {
        display: flex !important;
        position: fixed !important;
        inset: 0 auto 0 0 !important;
        grid-area: auto !important;
        width: min(88vw, 348px) !important;
        height: 100dvh !important;
        min-height: 100dvh;
        overflow: hidden;
        padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
        background: var(--primary);
        box-shadow: none;
        transform: translate3d(-105%, 0, 0) !important;
        transition: transform .24s cubic-bezier(.2,.8,.2,1);
        z-index: 410;
    }

    .app-shell.nav-open .sidebar { transform: translate3d(0, 0, 0) !important; box-shadow: 20px 0 55px rgba(2,6,23,.28); }

    .sidebar .brand {
        min-height: 74px;
        padding: 14px 16px;
        gap: 11px;
    }

    .sidebar .brand > span { display: flex !important; }

    .sidebar .brand .sidebar-close {
        margin-left: auto;
        background: var(--nav-hover);
        color: var(--on-primary);
    }

    .sidebar nav {
        padding: 8px 10px 26px;
        overscroll-behavior: contain;
    }

    .sidebar nav .nav-section {
        padding: 18px 12px 7px;
        color: var(--nav-muted);
        font-size: .67rem;
    }

    .sidebar nav a,
    .sidebar nav a.nav-subitem {
        min-height: 48px;
        margin-bottom: 3px;
        padding: 11px 13px;
        border-radius: var(--radius-md);
        font-size: .91rem;
    }

    .sidebar nav a span.label { display: inline !important; }

    .sidebar nav a.active {
        background: var(--accent);
        color: var(--on-accent);
        box-shadow: none;
    }

    .sidebar-backdrop {
        display: block !important;
        position: fixed;
        inset: 0;
        visibility: hidden;
        opacity: 0;
        background: rgba(2,6,23,.55);
        backdrop-filter: blur(3px);
        -webkit-backdrop-filter: blur(3px);
        transition: opacity .2s ease, visibility .2s ease;
        z-index: 400;
    }

    .app-shell.nav-open .sidebar-backdrop {
        visibility: visible;
        opacity: 1;
    }

    .main {
        grid-area: main;
        width: 100%;
        min-width: 0;
        height: auto;
        overflow-x: hidden;
        overflow-y: auto;
        padding: 18px 14px calc(var(--mobile-bottom-nav) + 24px + env(safe-area-inset-bottom));
        background: var(--bg);
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
    }

    .main > *,
    .main section,
    .main article,
    .main form,
    .main form > * { min-width: 0; }

    .mobile-bottom-nav {
        display: grid !important;
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        min-height: var(--mobile-bottom-nav);
        grid-auto-flow: column;
        grid-auto-columns: 1fr;
        align-items: stretch;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
        border: 0;
        border-top: 1px solid var(--nav-border);
        border-radius: 0;
        background: var(--primary);
        box-shadow: none;
        z-index: 300;
    }

    .mobile-bottom-nav a,
    .mobile-bottom-nav button {
        min-width: 0;
        min-height: 58px;
        padding: 5px 2px;
        border: 0;
        border-radius: 15px;
        background: transparent;
        color: var(--nav-text);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        font: inherit;
        font-size: .64rem;
        font-weight: 700;
        line-height: 1;
        cursor: pointer;
    }

    .mobile-bottom-nav i { font-size: 1.08rem; }
    .mobile-bottom-nav a.active,
    .mobile-bottom-nav button.active {
        color: var(--on-accent);
        background: var(--accent);
    }

    .mobile-bottom-nav a span,
    .mobile-bottom-nav button span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Allgemeine mobile Komponenten */
    .main h1 { font-size: clamp(1.35rem, 6vw, 1.65rem); line-height: 1.18; }
    .main .lead { margin-bottom: 18px; font-size: .88rem; }
    .card,
    .kpi,
    .todo-list,
    .channel-list,
    .chat-window,
    .wiki-list,
    .wiki-detail {
        max-width: 100%;
        border-radius: var(--radius-lg);
        box-shadow: none;
    }

    .card, .kpi { padding: 16px; }
    .card-header { gap: 10px; flex-wrap: wrap; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 20px; }
    .kpi .value { font-size: 1.48rem; }
    .btn { min-height: 44px; padding: 9px 14px; justify-content: center; line-height: 1.25; }
    .btn.sm { min-height: 44px; }
    .modal-close { min-width: 44px; min-height: 44px; }

    input[type=text], input[type=date], input[type=time], input[type=password],
    input[type=number], input[type=email], input[type=search], textarea, select {
        min-height: 46px;
        max-width: 100%;
        font-size: 16px;
    }

    input[type=checkbox], input[type=radio] {
        width: 22px;
        height: 22px;
        accent-color: var(--accent);
    }

    table.tbl {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    table.tbl th,
    table.tbl td { padding: 11px 12px; }

    .page-heading {
        display: flex;
        align-items: flex-end;
        justify-content: space-between;
        gap: 12px;
        margin: 0 0 16px;
    }

    .page-heading h1 { margin: 0; }
    .page-heading p {
        max-width: 680px;
        margin: 5px 0 0;
        color: var(--text-secondary);
        font-size: .82rem;
        line-height: 1.45;
    }

    .page-eyebrow {
        display: block;
        margin-bottom: 4px;
        color: var(--accent);
        font-size: .68rem;
        font-weight: 800;
        letter-spacing: .09em;
        text-transform: uppercase;
    }

    .mobile-scroll-hint {
        display: flex;
        align-items: center;
        gap: 6px;
        margin: 8px 2px 0;
        color: var(--text-muted);
        font-size: .72rem;
    }

    .empty-state {
        padding: 32px 18px;
        border: 1px dashed var(--border);
        border-radius: 17px;
        color: var(--text-muted);
        background: #fff;
        text-align: center;
    }

    .chat-shell,
    .wiki-shell {
        height: auto;
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
    }

    .chat-shell { min-height: calc(100dvh - 174px); }
    .channel-list, .wiki-list { max-height: 210px; }
    .wiki-detail { max-height: none; padding: 18px; }
    .msg { max-width: 88%; }
    .chat-input input { min-width: 0; }
    .todo-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .tpl-editor-grid { grid-template-columns: minmax(0, 1fr); }
    .tpl-field-full { grid-column: auto; }
    .dept-chooser-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .dept-card { padding: 19px 12px 16px; }

    .modal-overlay,
    .dp-modal-overlay,
    .fd-overlay,
    .wiki-modal-overlay {
        z-index: 500 !important;
    }

    .modal-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .modal-card {
        width: 100%;
        max-width: none;
        max-height: 92dvh;
        border-radius: 22px 22px 0 0;
    }

    .modal-body { padding: 18px 16px; }
    .modal-header { padding: 17px 16px; }
    .modal-footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }

    .login-shell {
        width: 100%;
        min-height: 100dvh;
        height: auto;
        padding: max(20px, env(safe-area-inset-top)) 14px max(20px, env(safe-area-inset-bottom));
    }

    .login-card { width: 100%; max-width: 390px; padding: 28px 20px; }
}

@media (max-width: 520px) {
    .main { padding-right: 12px; padding-left: 12px; }
    .kpi-grid { grid-template-columns: minmax(0, 1fr); }
    .page-heading { align-items: stretch; flex-direction: column; }
    .page-heading > .btn { width: 100%; }
}

@media (max-width: 370px) {
    .mobile-bottom-nav { right: 6px; left: 6px; }
    .mobile-bottom-nav a,
    .mobile-bottom-nav button { font-size: .59rem; }
    .topbar .page-title { font-size: .94rem; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .sidebar-backdrop { transition: none !important; }
}
