/* FIP Warriors Portal - Custom Styles */

/* === ACCESSIBILITY === */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}
.focus\:not-sr-only:focus {
    position: static;
    width: auto;
    height: auto;
    padding: 0;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* === GLOBAL RESETS === */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

img, video, iframe {
    max-width: 100%;
    height: auto;
}

table {
    max-width: 100%;
}

/* Word break for long content */
.break-anywhere {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Text wrap safety */
p, h1, h2, h3, h4, h5, h6, li, td, th, span, a, label {
    overflow-wrap: break-word;
}

/* Pre/Code wrap */
pre, code {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Responsive tables (only inside wrapper, not global – protects Django Admin) */
.table-responsive table {
    display: block;
    overflow-x: auto;
}

/*
 * ===== BREAKPOINT-SYSTEM =====
 * Geraete-Klassen:
 * - Phone:   bis 767px    (iPhone SE bis iPhone Pro Max)
 * - Tablet:  768px-1024px (iPad Mini, iPad, iPad Air - Portrait + Landscape)
 * - Desktop: ab 1025px    (iPad Pro 12.9" Landscape, Laptops, Monitore)
 *
 * Tailwind nutzt md:768px als Mobile/Desktop-Grenze.
 * Fuer Tablets (768-1024px) ueberschreiben wir md:-Klassen,
 * damit Mobile-Layout (Bottom-Nav, Mini-Header) beibehalten wird.
 */

/* PWA-Banner: Nur auf Desktop (ab 1025px) verstecken */
@media (min-width: 1025px) {
    #pwa-install-banner {
        display: none !important;
    }
}

/* === SAFE AREA SUPPORT === */
:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --navbar-height: 4rem;
    --bottom-nav-height: 4rem;
}

/* === PWA STANDALONE MODE === */
@media (display-mode: standalone) {
    /* Mini-Header: safe-area-top beruecksichtigen */
    .mini-header-safe {
        padding-top: calc(12px + var(--safe-area-top, 0px)) !important;
    }
}

/* iPad PWA: Status-Bar Offset */
html.is-ipad.is-pwa .mini-header-safe {
    padding-top: calc(12px + max(env(safe-area-inset-top, 0px), 20px)) !important;
}

/* PWA-only / Browser-only Utility-Klassen */
.pwa-only { display: none !important; }
html.is-pwa .pwa-only { display: block !important; }
html.is-pwa .browser-only { display: none !important; }

/* === CSS CUSTOM PROPERTIES (Theme) === */
:root {
    /* Primary - Green */
    --color-bg-primary: #FFFFFF;
    --color-bg-secondary: #F8FAF9;
    --color-bg-tertiary: #EFF5F2;

    --color-green-50: #ECFDF5;
    --color-green-100: #D1FAE5;
    --color-green-200: #A7F3D0;
    --color-green-300: #6EE7B7;
    --color-green-400: #34D399;
    --color-green-500: #10B981;
    --color-green-600: #059669;
    --color-green-700: #047857;
    --color-green-800: #065F46;
    --color-green-900: #064E3B;

    /* Neutral */
    --color-text-primary: #1F2937;
    --color-text-secondary: #6B7280;
    --color-text-muted: #9CA3AF;
    --color-border: #E5E7EB;
    --color-border-light: #F3F4F6;

    /* Status */
    --color-success: #10B981;
    --color-warning: #F59E0B;
    --color-danger: #EF4444;
    --color-info: #3B82F6;

    /* Button Contrast */
    --btn-secondary-border: #9ca3af;
    --btn-icon-color: #4b5563;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

/* === DARK THEME VARIABLES === */
[data-theme="dark"] {
    --color-bg-primary: #1F2937;
    --color-bg-secondary: #111827;
    --color-bg-tertiary: #1F2937;

    --color-green-50: #064E3B;
    --color-green-100: #065F46;
    --color-green-200: #047857;
    --color-green-300: #059669;
    --color-green-400: #10B981;
    --color-green-500: #34D399;
    --color-green-600: #6EE7B7;
    --color-green-700: #A7F3D0;
    --color-green-800: #D1FAE5;
    --color-green-900: #ECFDF5;

    --color-text-primary: #F9FAFB;
    --color-text-secondary: #D1D5DB;
    --color-text-muted: #9CA3AF;
    --color-border: #374151;
    --color-border-light: #1F2937;

    --color-success: #34D399;
    --color-warning: #FBBF24;
    --color-danger: #F87171;
    --color-info: #60A5FA;

    --btn-secondary-border: #6b7280;
    --btn-icon-color: #d1d5db;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

/* Dark theme component overrides */
[data-theme="dark"] .form-input {
    background: #374151;
    color: #F9FAFB;
    border-color: #4B5563;
}
[data-theme="dark"] .form-input:focus {
    border-color: #34D399;
    box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2);
}
[data-theme="dark"] .form-input::placeholder {
    color: #6B7280;
}
/* btn-secondary dark overrides are in dark-theme.css */

/* === ANIMATIONS === */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === SKELETON LOADING === */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 4px;
}
.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}
.skeleton-text:last-child {
    width: 60%;
}
.skeleton-circle {
    border-radius: 50%;
}
.skeleton-card {
    padding: 1.25rem;
    background: white;
    border-radius: 1rem;
    border: 1px solid #e5e7eb;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
[data-theme="dark"] .skeleton {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
}
[data-theme="dark"] .skeleton-card {
    background: #1f2937;
    border-color: #374151;
}

/* === EMPTY STATE === */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
}
.empty-state-icon {
    width: 5rem;
    height: 5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    background: #fef3c7;
    font-size: 2.5rem;
}
.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.5rem;
}
.empty-state-text {
    font-size: 0.875rem;
    color: #6b7280;
    max-width: 24rem;
    margin: 0 auto;
}
[data-theme="dark"] .empty-state-icon {
    background: #78350f;
}
[data-theme="dark"] .empty-state-title {
    color: #f3f4f6;
}
[data-theme="dark"] .empty-state-text {
    color: #9ca3af;
}

/* === HTMX === */
.htmx-indicator {
    display: none;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-block;
}

/* === RESPONSIVE TABLE WRAPPER === */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

/* === MOBILE SAFE AREAS === */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .mobile-nav-safe {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* === CARD OVERFLOW PROTECTION === */
.card, [class*="rounded-2xl"], [class*="rounded-xl"] {
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* === LIGHTBOX (GLightbox) === */
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    padding: 8px 0;
}
@media (max-width: 480px) {
    .media-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }
}
.media-thumbnail {
    display: block;
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.media-thumbnail:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-md);
}
.media-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.media-thumbnail::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    transition: background-color 0.2s ease;
    pointer-events: none;
}
.media-thumbnail:hover::after {
    background-color: rgba(0, 0, 0, 0.15);
}
.media-more-badge {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
}

/* GLightbox Overrides */
.goverlay {
    background: rgba(0, 0, 0, 0.85) !important;
}
.gclose, .gprev, .gnext {
    background: var(--color-green-600) !important;
    border-radius: var(--radius-full) !important;
}
.gclose:hover, .gprev:hover, .gnext:hover {
    background: var(--color-green-700) !important;
}
.gslide-title {
    font-family: inherit !important;
    color: white !important;
}
.gslide-desc {
    font-family: inherit !important;
    color: rgba(255, 255, 255, 0.7) !important;
}
@media (max-width: 768px) {
    .gprev, .gnext {
        width: 44px !important;
        height: 44px !important;
    }
    .gclose {
        width: 44px !important;
        height: 44px !important;
        top: 12px !important;
        right: 12px !important;
    }
}

/* === RESPONSIVE TABLE OVERFLOW (A.1) === */
main table,
.content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

/* === MOBILE LAYOUT: Kein Top-Bar, Bottom Nav (A.2/A.4) === */
@media (max-width: 767px) {
    main {
        padding-top: 0.5rem !important;
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
    }
    /* Footer auf Mobile ausblenden – Bottom Nav uebernimmt */
    footer {
        display: none;
    }
}

/* === BUTTON ACTIVE STATES (A.3) === */
.btn:active,
.btn-primary:active,
.btn-secondary:active,
.btn-danger:active,
.btn-ghost:active {
    transform: scale(0.97);
    opacity: 0.9;
}
/* Disabled Buttons sichtbar halten */
.btn:disabled,
.btn.disabled,
button:disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}
/* Icon-Buttons Touch-Feedback */
a[title]:active svg,
button:active svg {
    opacity: 0.7;
}

/* === PRINT === */
@media print {
    nav, .no-print { display: none !important; }
    body { font-size: 12pt; }
}

/* === CAPTCHA === */
.captcha { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.captcha img { border-radius: 0.5rem; }

/* === FORM INPUTS (Light Theme) === */
.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: white;
    color: var(--color-text-primary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-input:focus {
    border-color: var(--color-green-500);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}
.form-input::placeholder {
    color: var(--color-text-muted);
}

/* === BUTTON SYSTEM === */
/* Base: Layout-only (no appearance) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.25;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, box-shadow 0.15s, transform 0.1s, opacity 0.1s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* Default appearance = primary */
    background: var(--color-green-600);
    color: #fff;
}
.btn:hover {
    background: var(--color-green-700);
    box-shadow: var(--shadow-md);
}
.btn:active {
    transform: scale(0.97);
    opacity: 0.9;
}

/* Variants: MUST come after .btn base to override */
.btn.btn-primary,
.btn-primary {
    background: var(--color-green-600) !important;
    color: white !important;
    border: none !important;
}
.btn.btn-primary:hover,
.btn-primary:hover {
    background: var(--color-green-700) !important;
    box-shadow: var(--shadow-md);
}
.btn.btn-secondary,
.btn-secondary {
    background: white !important;
    color: var(--color-green-600) !important;
    border: 1px solid var(--color-green-600) !important;
}
.btn.btn-secondary:hover,
.btn-secondary:hover {
    background: var(--color-green-50) !important;
}
.btn.btn-danger,
.btn-danger {
    background: var(--color-danger) !important;
    color: white !important;
    border: none !important;
}
.btn.btn-danger:hover,
.btn-danger:hover {
    background: #DC2626 !important;
}
.btn.btn-warning,
.btn-warning {
    background: var(--color-warning) !important;
    color: #fff !important;
    border: none !important;
}
.btn.btn-warning:hover,
.btn-warning:hover {
    background: #D97706 !important;
}
.btn.btn-ghost,
.btn-ghost {
    background: transparent !important;
    color: var(--color-green-600) !important;
    border: 1px solid var(--color-border) !important;
}
.btn.btn-ghost:hover,
.btn-ghost:hover {
    background: var(--color-green-50) !important;
    border-color: var(--color-green-600) !important;
}
.btn-icon {
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: var(--radius-full);
    background: transparent !important;
    color: var(--btn-icon-color, #4b5563) !important;
}
.btn-icon:hover {
    background: var(--color-green-50) !important;
    color: var(--color-green-600) !important;
}
.btn-sm {
    min-height: 36px;
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
}
.btn-lg {
    min-height: 52px;
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}
.btn-block {
    width: 100%;
}
.btn.loading {
    pointer-events: none;
    opacity: 0.7;
    position: relative;
}
.btn.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
    margin-left: 4px;
}
@keyframes btn-spin {
    to { transform: rotate(360deg); }
}
.form-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: sticky;
    bottom: 0;
    padding: 12px 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--color-bg-primary, white);
    border-top: 1px solid var(--color-border, #E5E7EB);
    margin-top: 16px;
    z-index: 10;
}
@media (min-width: 640px) {
    .form-actions {
        flex-direction: row;
        justify-content: flex-end;
    }
}

/* === MOBILE NAV ACTIVE INDICATOR (legacy, replaced by bottom-nav-item.active) === */
.mobile-nav-active {
    position: relative;
}
.mobile-nav-active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 25%;
    right: 25%;
    height: 2px;
    background: var(--color-green-500);
    border-radius: 1px;
}

/* === SAFARI / iOS FIXES === */
html {
    -webkit-text-size-adjust: 100%;
    height: -webkit-fill-available;
}
body {
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}
/* Prevent Safari zoom on input focus (min 16px) */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
select,
textarea {
    font-size: max(16px, 1em);
}
/* Mobile: Checkboxen und Radio-Buttons groesser */
@media (max-width: 639px) {
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 20px;
        min-height: 20px;
    }
    /* Select-Dropdown Touch-freundlicher */
    select {
        min-height: 44px;
        padding-right: 32px;
    }
    /* Labels besser lesbar */
    label {
        min-height: 24px;
        display: inline-flex;
        align-items: center;
    }
}
/* Disable tap highlight globally */
a, button, [role="button"] {
    -webkit-tap-highlight-color: transparent;
}

/* === MODERATION BADGE === */
.moderation-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    font-size: 0.65rem;
    font-weight: 700;
    color: white;
    background: #F59E0B;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* === OWNER CONTACT CARD === */
.owner-contact-card {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.contact-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    min-height: 44px;
    transition: background 0.15s, transform 0.1s;
}
.contact-btn:active {
    transform: scale(0.97);
}
.contact-btn-phone {
    background: #DBEAFE;
    color: #1D4ED8;
}
.contact-btn-whatsapp {
    background: #D1FAE5;
    color: #065F46;
}
.contact-btn-email {
    background: #FEF3C7;
    color: #92400E;
}

/* === INTERNAL NOTES === */
.note-priority-low { border-left: 3px solid #9CA3AF; }
.note-priority-normal { border-left: 3px solid #3B82F6; }
.note-priority-high { border-left: 3px solid #F59E0B; }
.note-priority-urgent { border-left: 3px solid #EF4444; }
.note-pinned { background: #FFFBEB; }
.note-resolved { opacity: 0.6; }

/* === COMPLIANCE CARD === */
.compliance-ring {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
}

/* === MAP LEGEND === */
.map-legend {
    position: absolute;
    bottom: 16px;
    left: 16px;
    z-index: 1000;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 12px;
    max-width: 280px;
}
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--color-border);
    background: white;
    transition: background 0.15s, border-color 0.15s;
    min-height: 32px;
}
.filter-chip.active {
    background: var(--color-green-50);
    border-color: var(--color-green-500);
    color: var(--color-green-700);
}
.filter-chip:hover {
    background: var(--color-green-50);
}

/* === FLYOUT MENU === */
.flyout-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.flyout-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
.flyout-menu {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 999;
    max-height: 70vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.flyout-menu.open {
    transform: translateY(0);
}
.flyout-handle {
    display: flex;
    justify-content: center;
    padding: 10px 0 6px;
    cursor: grab;
}
.flyout-handle::before {
    content: '';
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #D1D5DB;
}
.flyout-nav {
    padding: 4px 16px 16px;
}
.flyout-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--color-text-primary);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.flyout-item:hover,
.flyout-item:active {
    background: var(--color-green-50);
}
.flyout-item svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    color: var(--color-text-secondary);
}
.flyout-item .flyout-badge {
    margin-left: auto;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    background: var(--color-danger);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}
.flyout-divider {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 4px 12px;
}
.flyout-theme-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--color-text-primary);
}
.flyout-theme-row .theme-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: #D1D5DB;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
    border: none;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
.flyout-theme-row .theme-switch.active {
    background: var(--color-green-500);
}
.flyout-theme-row .theme-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.flyout-theme-row .theme-switch.active::after {
    transform: translateX(20px);
}

/* Bottom nav keyboard hide */
.bottom-nav-hidden {
    transform: translateY(100%);
    transition: transform 0.2s ease;
}

/* === GLOBAL SVG SIZE SAFEGUARD (A.0) === */
/* Verhindert dass SVGs ohne explizite Groesse den ganzen Viewport ausfuellen */
main svg,
.content svg,
article svg {
    max-width: 200px;
    max-height: 200px;
}
a svg,
button svg,
[role="button"] svg {
    max-width: 32px;
    max-height: 32px;
}
/* Ausnahmen fuer gewollt grosse SVGs */
.hero-image svg, .logo svg, .chart-container svg, svg.allow-large,
.leaflet-container svg {
    max-width: none;
    max-height: none;
}

/* Flyout: zusaetzlich visibility hidden wenn nicht offen (iOS fix) */
.flyout-menu:not(.open) {
    visibility: hidden;
}

/* === GLOBAL BACK-BAR === */
.global-back-bar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: #1F2937;
    border-bottom: 1px solid #374151;
}
@media (min-width: 1025px) {
    .global-back-bar {
        top: 4rem; /* Unter Desktop-Nav */
    }
}
[data-theme="dark"] .global-back-bar {
    background: #111827;
    border-bottom-color: #1F2937;
}

/* === URGENCY CARDS === */
.urgency-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border: 1px solid;
}
.urgency-card-critical {
    background: #FEF2F2;
    border-color: #FECACA;
}
.urgency-card-warning {
    background: #FFFBEB;
    border-color: #FDE68A;
}
.urgency-card-info {
    background: #EFF6FF;
    border-color: #BFDBFE;
}
.urgency-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Quick action grid */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
@media (min-width: 640px) {
    .quick-actions {
        grid-template-columns: repeat(4, 1fr);
    }
}
.quick-action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 12px;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--color-text-primary);
    font-size: 0.8125rem;
    font-weight: 600;
    transition: background 0.15s, box-shadow 0.15s;
    min-height: 44px;
}
.quick-action-card:hover {
    background: var(--color-green-50);
    box-shadow: var(--shadow-sm);
}
.quick-action-card svg {
    width: 28px;
    height: 28px;
    color: var(--color-green-600);
}

/* === MAP POPUP STYLES === */
.map-popup-name { color: #111827; font-size: 14px; font-weight: 700; }
.map-popup-detail { color: #374151; font-size: 12px; }
.map-popup-muted { color: #6b7280; font-size: 12px; }
.map-popup-note { color: #6b7280; font-size: 11px; font-style: italic; }
.map-popup-highlight { color: #3b82f6; font-weight: 700; }
.map-popup-badge {
    font-size: 11px; font-weight: 600; padding: 1px 8px;
    border-radius: 9999px; display: inline-block; margin-top: 4px;
}
.map-popup-badge-green { background: #dcfce7; color: #16a34a; }
.map-popup-badge-red { background: #fee2e2; color: #dc2626; }

/* ================================================================
 *  TABLET OVERRIDES (768px - 1024px)
 *  iPad bekommt Mobile-Layout (Bottom-Nav, Mini-Header, Flyout)
 *  statt Desktop-Nav. Tailwind md:-Klassen werden ueberschrieben.
 * ================================================================ */
@media (min-width: 768px) and (max-width: 1024px) {
    /* --- Layout-Switch: Desktop-Nav aus, Mobile-Nav an --- */
    nav.md\:block { display: none !important; }
    .md\:hidden#mobile-nav { display: flex !important; }
    .md\:hidden[id="flyoutOverlay"],
    .md\:hidden[id="flyoutMenu"] { display: block !important; }

    /* Mini-Header (Logo + Glocke) */
    div.md\:hidden { display: flex !important; }

    /* Bottom-Nav Spacer */
    div.md\:hidden[class*="h-16"] { display: block !important; height: 64px; }

    /* Desktop-only Icons (Theme, Messages, Bell, Settings, Profile, Logout) */
    .hidden.md\:block,
    .hidden.md\:inline { display: none !important; }

    /* Content: kein Sticky-Top-Offset von Desktop-Nav */
    #main-content { padding-top: 0; }

    /* Content: Bottom-Padding fuer Bottom-Nav */
    main {
        padding-bottom: calc(80px + var(--safe-area-bottom, 0px)) !important;
    }

    /* Footer auf Tablet ausblenden */
    footer { display: none; }

    /* Statistik-Karten: 2 Spalten */
    .grid.grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Karten-Container min-height */
    #fr-map, #map { min-height: 400px !important; }

    /* Back-Bar: nicht unter Desktop-Nav kleben */
    .global-back-bar { top: 0; }

    /* --- Content-Layout --- */
    /* Tabellen: Echte Tabellenansicht statt Card-Stack */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .table-responsive table {
        display: table;
        width: 100%;
    }

    /* Content max-width etwas einschraenken */
    #main-content {
        max-width: 960px;
    }

    /* Modale/Dialoge: Nicht fullscreen */
    .modal-content {
        max-width: 480px;
        margin: 10vh auto;
        border-radius: var(--radius-lg);
    }

    /* Form-Felder: Touch-optimiert (Safari-Zoom verhindern) */
    select, input[type="text"], input[type="email"], input[type="password"],
    input[type="number"], input[type="date"], textarea {
        font-size: max(16px, 1em);
        min-height: 44px;
    }
    input[type="checkbox"], input[type="radio"] {
        width: 20px;
        height: 20px;
    }
}

/* ================================================================
 *  TABLET PORTRAIT (768px - 1024px, Hochformat)
 *  Kompakteres Layout, zentrierte Bottom-Nav
 * ================================================================ */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    /* Mini-Header: Etwas groesser auf Tablet */
    .mini-header-safe {
        padding-left: 24px;
        padding-right: 24px;
    }

    .mini-header-safe .text-lg {
        font-size: 1.125rem;
    }

    /* Bottom-Nav: Items zentriert, nicht ueber volle Breite */
    #mobile-nav > div {
        max-width: 500px;
        margin: 0 auto;
    }

    /* Bottom-Nav Items: groessere Touch-Targets */
    .bottom-nav-item {
        min-width: 64px;
        padding: 6px 12px;
    }

    /* Formulare zentrieren */
    form:not(.flyout-item):not([action*="logout"]) {
        max-width: 640px;
        margin-left: auto;
        margin-right: auto;
    }

    /* Dashboard-Widgets: 2 Spalten */
    .grid.gap-4,
    .grid.gap-6 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Volle Breite fuer bestimmte Elemente */
    .grid .col-span-full,
    .grid [class*="lg:col-span"] {
        grid-column: 1 / -1;
    }
}

/* ================================================================
 *  TABLET LANDSCAPE (768px - 1024px, Querformat)
 *  Etwas mehr Platz, kompaktere Bottom-Nav
 * ================================================================ */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    /* Mini-Header: Mehr Padding im Querformat */
    .mini-header-safe {
        padding-left: max(24px, var(--safe-area-left, 0px));
        padding-right: max(24px, var(--safe-area-right, 0px));
    }

    /* Bottom-Nav Items: horizontal Layout */
    #mobile-nav > div {
        max-width: 600px;
        margin: 0 auto;
    }

    .bottom-nav-item {
        min-width: 72px;
    }

    /* Flyout: Seitlich statt Fullscreen */
    .flyout-menu {
        left: auto !important;
        right: 0 !important;
        width: 360px !important;
        max-width: 80vw !important;
        border-top-left-radius: var(--radius-lg) !important;
        border-top-right-radius: 0 !important;
        border-bottom-left-radius: var(--radius-lg) !important;
        max-height: 100vh !important;
        top: 0 !important;
        bottom: 0 !important;
        transform: translateX(100%) !important;
    }
    .flyout-menu.open {
        transform: translateX(0) !important;
    }

    /* Statistik-Karten: 3 Spalten im Querformat */
    .grid.grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* Formulare breiter */
    form:not(.flyout-item):not([action*="logout"]) {
        max-width: 720px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* --- Tablet: Bottom-Nav safe-area + PWA --- */
@media (min-width: 768px) and (max-width: 1024px) {
    #mobile-nav {
        padding-bottom: var(--safe-area-bottom, 0px);
        padding-left: var(--safe-area-left, 0px);
        padding-right: var(--safe-area-right, 0px);
    }
}

/* iPad PWA: Zusaetzlicher Bottom-Padding fuer Home-Indicator */
html.is-ipad.is-pwa #mobile-nav {
    padding-bottom: max(env(safe-area-inset-bottom, 0px), 8px);
}

/* Touch-Geraete: Sticky-Hover verhindern */
@media (hover: none) {
    .btn:hover, .btn-primary:hover, .btn-danger:hover, .btn-warning:hover {
        filter: none;
        transform: none;
    }
}

/* ================================================================
 *  DESKTOP (ab 1025px)
 *  Volle Desktop-Nav, keine Bottom-Nav
 * ================================================================ */
@media (min-width: 1025px) {
    /* Bottom-Nav verstecken (Fallback falls md:hidden nicht greift) */
    #mobile-nav {
        display: none !important;
    }
}
