/* ===== FVN Portal - Custom Styles ===== */
/* Design System comes from VgBlazor (Tailwind CSS) */
/* This file only contains app-specific overrides */

/* --- Date-Input auf Mobile normalisieren (iOS Safari rendert groesser) --- */
input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
    min-height: 38px;
}

/* --- Scrollbar auf Mobile ausblenden (inkl. iOS Safari) --- */
@media (max-width: 767px) {
    html, body, * { -webkit-overflow-scrolling: touch; -ms-overflow-style: none; scrollbar-width: none; }
    html::-webkit-scrollbar, body::-webkit-scrollbar, *::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; background: transparent !important; }
}

/* --- Safe Area (iOS PWA Standalone) --- */
@supports (padding-top: env(safe-area-inset-top)) {
    @media (max-width: 767px) {
        header.gradient-primary {
            padding-top: env(safe-area-inset-top, 0px);
            height: calc(4rem + env(safe-area-inset-top, 0px)) !important;
        }
        main {
            margin-top: calc(4rem + env(safe-area-inset-top, 0px)) !important;
        }
    }
}

/* --- Gradient Header (AppBar) --- */
.gradient-primary {
    background: linear-gradient(135deg, var(--primary), color-mix(in oklch, var(--primary) 80%, black)) !important;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
.dark .gradient-primary {
    background: linear-gradient(135deg, var(--card), var(--background)) !important;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
}

/* --- Animations --- */
@keyframes fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Markdown Prose --- */
.prose img { max-width: 320px; height: auto; border-radius: 8px; margin: 8px 0; cursor: pointer; border: 1px solid var(--border); transition: opacity 0.2s; }
.prose img:hover { opacity: 0.85; }
.prose p { margin: 0.5em 0; }
.prose code { background: var(--muted); padding: 2px 6px; border-radius: 4px; font-size: 0.85em; }
.prose pre { background: var(--muted); padding: 12px; border-radius: 8px; overflow-x: auto; }
.prose a { color: var(--primary); text-decoration: underline; }
.prose ul, .prose ol { padding-left: 1.5em; margin: 0.5em 0; }

/* --- Lightbox --- */
.lightbox-overlay { position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; cursor: zoom-out; backdrop-filter: blur(4px); }
.lightbox-overlay img { max-width: 90vw; max-height: 90vh; border-radius: 8px; box-shadow: 0 25px 50px rgba(0,0,0,0.5); }

.animate-fade-in {
    animation: fade-in 0.3s ease-out;
}

/* --- Hover Utilities --- */
.hover-scale {
    transition: transform 200ms ease;
}
.hover-scale:hover {
    transform: scale(1.02);
}

.hover-lift {
    transition: all 200ms ease;
}
.hover-lift:hover {
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

/* --- Glass Effects --- */
.glass-card {
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.2);
}
.dark .glass-card {
    background: rgba(255,255,255,0.05);
    border-color: rgba(255,255,255,0.1);
}

/* --- Status Badges --- */
.status-erfasst { background: #3b82f6; color: white; }
.status-inbearbeitung { background: #eab308; color: #1a1a1a; }
.status-freigabe, .status-freigegeben { background: #f97316; color: white; }
.status-genehmigt { background: #16a34a; color: white; }
.status-abgelehnt { background: #ef4444; color: white; }
.status-exportiert, .status-uebertragen { background: #8b5cf6; color: white; }
.status-bezahlt { background: #06b6d4; color: white; }

/* --- FAB Button --- */
.fab-button {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, oklch(0.7227 0.1920 149.5793), oklch(0.6500 0.1700 145));
    color: white;
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 200ms ease;
    border: none;
    text-decoration: none;
}
.fab-button:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 35px rgba(0,0,0,0.3);
}
.fab-button svg {
    transition: transform 300ms ease;
    width: 28px;
    height: 28px;
}
.fab-button:hover svg {
    transform: rotate(90deg);
}

/* --- Bottom Navigation (Mobile) --- */
@media (min-width: 768px) {
    .bottom-nav { display: none !important; }
}
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    height: calc(72px + env(safe-area-inset-bottom, 0px));
    padding-top: 6px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.04);
}
.dark .bottom-nav {
    background: rgba(32, 39, 55, 0.92);
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.2);
}
.bottom-nav-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    font-size: 0.68rem;
    color: var(--muted-foreground);
    text-decoration: none;
    transition: color 200ms ease;
    padding: 2px 4px;
}
.bottom-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 20px;
    transition: all 250ms cubic-bezier(0.4, 0, 0.2, 1);
}
.bottom-nav-icon svg {
    width: 22px;
    height: 22px;
    transition: transform 200ms ease;
}
.bottom-nav-label {
    transition: font-weight 200ms ease;
    line-height: 1.1;
}

/* Active state: pill background hinter dem Icon */
.bottom-nav-item.active {
    color: var(--primary);
}
.bottom-nav-item.active:not(.bottom-nav-fab) .bottom-nav-icon {
    background: rgba(84, 154, 56, 0.14);
}
.bottom-nav-item.active .bottom-nav-label {
    font-weight: 600;
}
.bottom-nav-item:not(.active):not(.bottom-nav-fab):hover .bottom-nav-icon {
    background: rgba(84, 154, 56, 0.06);
}

/* "Neu" FAB-Style: Im normalen Fluss, nur mit Circle-Fuellung */
.bottom-nav-fab .bottom-nav-icon {
    background: linear-gradient(135deg, oklch(0.7227 0.1920 149.5793), oklch(0.6500 0.1700 145));
    box-shadow: 0 3px 10px rgba(84, 154, 56, 0.3);
}
.bottom-nav-fab .bottom-nav-icon svg {
    color: white;
    width: 24px;
    height: 24px;
}
.bottom-nav-fab .bottom-nav-label {
    color: var(--primary);
    font-weight: 600;
}
.bottom-nav-fab:hover .bottom-nav-icon {
    transform: scale(1.05);
    box-shadow: 0 4px 14px rgba(84, 154, 56, 0.4);
}
.bottom-nav-fab:active .bottom-nav-icon {
    transform: scale(0.97);
}
.bottom-nav-fab.active .bottom-nav-icon {
    background: linear-gradient(135deg, oklch(0.6800 0.1920 149.5793), oklch(0.6000 0.1700 145));
}

/* --- Collapsed Sidebar (Desktop) --- */
.sidebar-collapsed p,
.sidebar-collapsed hr + nav p {
    display: none !important;
}
.sidebar-collapsed a > span:not(.nav-icon-box),
.sidebar-collapsed button > span {
    display: none !important;
}
/* Dropdown-Pfeil in NavGroups ausblenden (letztes svg im button) */
.sidebar-collapsed button > svg:last-child {
    display: none !important;
}
/* NavLinks und NavGroup-Buttons zentrieren */
.sidebar-collapsed a,
.sidebar-collapsed button {
    justify-content: center !important;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
    gap: 0 !important;
}
/* NavGroup Children (eingeklappt) ausblenden */
.sidebar-collapsed .ml-5 {
    display: none !important;
}
/* Mandant-Card kompakter */
.sidebar-collapsed .mx-2 {
    display: none !important;
}
/* Trenner schmaler */
.sidebar-collapsed hr {
    margin-left: 12px !important;
    margin-right: 12px !important;
}
/* Tooltip via native title-Attribut wuerde helfen - nicht umgesetzt ohne Code-Aenderung */

/* --- Flexbox-Overflow-Fix fuer main (alle Breakpoints) --- */
/* main ist ein flex-1 Kind; ohne min-width:0 waechst es ueber die verfuegbare Breite hinaus
   wenn der Content breiter ist als die Flex-Basis. */
main {
    min-width: 0 !important;
}

/* --- Mobile Responsive --- */
@media (max-width: 767px) {
    main {
        padding-bottom: calc(140px + env(safe-area-inset-bottom, 0px)) !important;
        /* Sicherheitsnetz: kein horizontales Scrollen auf Mobile */
        overflow-x: hidden;
        max-width: 100vw;
    }
    /* FAB auf Mobile ausblenden - BottomNav hat bereits einen "+" Button */
    .fab-button { display: none !important; }

    /* BelegPositionen Tabelle: auf Mobile zu Cards transformieren */
    .beleg-positionen table,
    .beleg-positionen tbody,
    .beleg-positionen tr,
    .beleg-positionen td {
        display: block !important;
        width: 100% !important;
    }
    .beleg-positionen thead { display: none !important; }
    .beleg-positionen tbody tr {
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 12px !important;
        margin: 0 0 10px 0 !important;
        background: var(--card);
        position: relative;
    }
    .beleg-positionen tbody tr:last-child {
        /* Gesamtbetrag-Zeile */
        background: var(--primary) !important;
        color: var(--primary-foreground) !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        font-weight: 700;
        margin-bottom: 0 !important;
    }
    .beleg-positionen tbody tr:last-child td {
        display: inline !important;
        width: auto !important;
        padding: 0 !important;
        text-align: left !important;
        color: var(--primary-foreground) !important;
    }
    .beleg-positionen tbody tr:last-child td:last-child {
        text-align: right !important;
    }
    .beleg-positionen tbody td {
        padding: 6px 0 !important;
        text-align: left !important;
        border: none !important;
    }
    /* Pos. Nummer als kleines Badge oben rechts */
    .beleg-positionen tbody tr:not(:last-child) > td:first-child {
        position: absolute;
        top: 8px;
        right: 10px;
        width: auto !important;
        padding: 0 8px !important;
        background: var(--muted);
        color: var(--muted-foreground);
        border-radius: 10px;
        font-size: 0.7rem;
        font-weight: 600;
        line-height: 1.4rem;
    }
    /* Leere Cells verstecken */
    .beleg-positionen tbody tr:not(:last-child) > td:empty {
        display: none !important;
        padding: 0 !important;
    }

    /* ThemePicker: Popover fixed im Viewport, damit er nicht abgeschnitten wird.
       Zwei Selektoren: .theme-picker (wenn Razor-Aenderung aktiv) und header-basiert als Fallback */
    .theme-picker > div.absolute,
    header > div.relative > div.absolute {
        position: fixed !important;
        top: calc(64px + env(safe-area-inset-top, 0px)) !important;
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        max-width: calc(100vw - 16px) !important;
        margin-top: 0 !important;
    }
    .theme-picker .theme-picker-content,
    header > div.relative > div.absolute > div[class*="w-\\[240px\\]"] {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* --- Active NavLink Icon Box --- */
.nav-active .nav-icon-box {
    background: rgba(84, 154, 56, 0.15) !important;
}

/* --- OTP Input --- */
.otp-field input {
    text-align: center !important;
    font-size: 1.75rem !important;
    font-weight: 700 !important;
    padding: 0 !important;
    height: 64px !important;
    line-height: 64px !important;
}
