/* ============================================
   HandwerkerBuddy — Shared UX Fixes
   Based on UI/UX Pro Max Audit 2026-03-10
   Updated 2026-04-23: Unified to design-system-v2 palette
   ============================================ */

/* === 1. ACCESSIBILITY: Focus-Visible (CRITICAL) === */
:focus-visible {
    outline: 2px solid var(--primary, #1E3A5F);
    outline-offset: 2px;
    border-radius: 4px;
}
/* Sidebar focus: light outline on dark bg */
.sidebar a:focus-visible,
.sidebar button:focus-visible,
.sidebar-user:focus-visible {
    outline-color: #93C5FD;
}
/* Remove default outlines only when :focus-visible is supported */
:focus:not(:focus-visible) {
    outline: none;
}

/* === 2. ACCESSIBILITY: Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* === 3. ACCESSIBILITY: Skip Link === */
.skip-link {
    position: absolute;
    top: -100%;
    left: 16px;
    z-index: 9999;
    padding: 12px 24px;
    background: #1E3A5F;
    color: #fff;
    border-radius: 0 0 8px 8px;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    transition: top 0.2s ease;
}
.skip-link:focus {
    top: 0;
}

/* === 4. ACCESSIBILITY: Screen-Reader Only === */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* === 5. CONTRAST FIX (CRITICAL): Ensure 4.5:1 minimum === */
.text-3 { color: #475569 !important; }

/* Sidebar: secondary text contrast fix */
.sidebar-user span,
.sidebar .nav-section-title {
    color: rgba(255,255,255,0.65);
}

/* === 6. TOUCH TARGETS: Minimum 44px === */
.header-btn,
.tab-btn,
.dash-tab-btn,
.btn-google,
.btn-apple,
.upload-btn,
.credits-buy-btn,
.detail-close,
.package-buy,
.modal-close,
.pos-del-btn,
.pos-note-btn,
.del-btn,
.add-btn,
.btn-pdf,
.price-btn,
.plan-card-btn,
.btn-save,
.btn-analyze,
.faq-item summary,
.qs-chip,
button[onclick] {
    min-height: 44px;
    min-width: 44px;
}
.del-btn,
.pos-del-btn,
.modal-close {
    padding: 8px;
}

/* === 7. TOUCH: Active/Press States === */
.btn-primary:active,
.btn-save:active,
.plan-upgrade-btn:active,
.action-btn:active,
.header-btn:active,
.tab-btn:active,
.btn-google:active,
.btn-apple:active {
    transform: scale(0.97);
    opacity: 0.85;
}

/* === 8. TRANSITION OPTIMIZATION === */
.btn-primary {
    transition: background-color 0.2s ease, transform 0.15s ease;
}
.action-btn {
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}
.header-btn {
    transition: border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

/* === 9. MODAL TRANSITIONS === */
.modal-overlay {
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}
.modal-overlay.show {
    opacity: 1;
    pointer-events: all;
}
.modal-overlay .modal {
    transform: scale(0.95) translateY(10px);
    transition: transform 0.25s ease;
}
.modal-overlay.show .modal {
    transform: scale(1) translateY(0);
}

/* === 10. TOAST ACCESSIBILITY === */
.toast[role="status"],
.saved-toast[role="status"] {
    /* Ensure screen readers announce */
}

/* === 11. RESPONSIVE: Extra breakpoints === */
@media (max-width: 500px) {
    .field-row,
    .steuernr-row {
        flex-direction: column;
        gap: 0;
    }
    .field-half {
        flex: none;
    }
}

@media (max-width: 600px) {
    .header {
        padding: 10px 14px;
    }
    .header-user {
        display: none;
    }
    .header-right {
        gap: 6px;
    }
    .header-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
}

/* === 12. UNIFIED NAVIGATION — TAB STYLE === */
.unified-nav {
    position: sticky;
    top: 0;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 0 20px;
    z-index: 100;
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    height: 52px;
}
.nav-left {
    display: flex;
    align-items: stretch;
    gap: 0;
}
.nav-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: #1E3A5F;
    font-weight: 800;
    font-size: 0.9375rem;
    letter-spacing: -0.02em;
    padding-right: 16px;
    margin-right: 4px;
    border-right: 1px solid #e5e7eb;
}
.nav-logo img {
    width: 30px;
    height: 30px;
    border-radius: 8px;
}
.nav-logo span {
    font-weight: 800;
    font-size: 0.9375rem;
}
.nav-links {
    display: flex;
    gap: 0;
    align-items: stretch;
}
.nav-link {
    padding: 0 16px;
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 700;
    color: #9ca3af;
    transition: color 0.2s ease, border-color 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    min-width: 120px;
    text-align: center;
}
.nav-link:hover {
    color: #4b5563;
    background: none;
}
.nav-link.active {
    color: #1E3A5F;
    border-bottom-color: #1E3A5F;
    background: none;
}
.nav-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.nav-user {
    font-size: 0.8125rem;
    color: #6b7280;
}
.header-btn {
    background: #1E3A5F;
    border: 1px solid #1E3A5F;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    color: #fff;
    font-weight: 600;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.12);
    min-height: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.header-btn:hover {
    background: #162d4a;
    border-color: #162d4a;
    box-shadow: 0 3px 8px rgba(0,0,0,0.18);
}

/* Language Switcher */
.lang-switcher {
    position: relative;
}
.lang-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #4b5563;
    min-height: 38px;
    height: 38px;
    transition: border-color 0.2s ease;
}
.lang-btn:hover {
    border-color: #9ca3af;
}
.lang-flag {
    font-size: 1.125rem;
    line-height: 1;
}
.lang-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    min-width: 200px;
    max-height: 360px;
    overflow-y: auto;
    z-index: 200;
    padding: 6px;
}
.lang-dropdown.open {
    display: block;
}
.lang-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #1f2937;
    transition: background-color 0.15s ease;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: 'Inter', sans-serif;
    min-height: 44px;
}
.lang-option:hover {
    background: #f3f4f6;
}
.lang-option.active {
    background: #eff6ff;
    color: #2563EB;
    font-weight: 700;
}

/* Mobile Nav */
@media (max-width: 600px) {
    .nav-links {
        display: none;
    }
    .nav-user {
        display: none;
    }
    .unified-nav {
        height: 50px;
        padding: 0 12px;
    }
    .lang-dropdown {
        right: -12px;
        min-width: 180px;
    }
}

/* === 13a. FORMS: Required field indicator === */
label[data-required]::after,
.field-required::after {
    content: " *";
    color: #EF4444;
    font-weight: 700;
}

/* === 13b. FORMS: Better disabled states === */
button:disabled,
input:disabled,
select:disabled,
.btn-save:disabled,
.btn-analyze:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* === 13c. FORMS: Input focus consistency === */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: none;
    border-color: var(--primary, #1E3A5F);
    box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.15);
}

/* === 13d. MODAL ACCESSIBILITY === */
.modal[role="dialog"] {
    /* Ensure modals trap focus visually */
}
.modal-close:focus-visible {
    outline: 2px solid var(--primary, #1E3A5F);
    outline-offset: 2px;
}

/* === 13e. TYPOGRAPHY: Minimum readable sizes === */
.pos-field label,
.edit-hint {
    font-size: max(0.6875rem, 11px);
}

/* === 13f. LOADING BUTTON STATE === */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}
.btn-loading::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    top: 50%;
    left: 50%;
    margin: -9px 0 0 -9px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
}
@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

/* === 13g. EMPTY STATE STYLING === */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--fg-muted, #64748B);
}
.empty-state-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    opacity: 0.4;
}
.empty-state-title {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 8px;
}
.empty-state-text {
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: 16px;
}

/* === 13h. CURSOR POINTER on all clickables === */
a[href],
button:not(:disabled),
[role="button"],
[role="tab"],
[role="radio"],
[role="option"],
summary,
.trade-card,
.qs-chip,
.feature-card,
.price-card .price-btn,
.tab-btn,
.sidebar-link {
    cursor: pointer;
}

/* === 13i. SIDEBAR: Active link highlight === */
.sidebar-link.active,
.sidebar a.active {
    background: rgba(37, 99, 235, 0.2);
    color: #93C5FD;
}

/* === 13j. TOAST: Proper positioning + a11y === */
.toast,
.saved-toast {
    z-index: 10000;
}

/* === 13. SAFE AREA === */
@supports (padding: env(safe-area-inset-top)) {
    .unified-nav,
    .header {
        padding-top: env(safe-area-inset-top);
    }
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* === 14. RTL SUPPORT for Arabic languages === */
[dir="rtl"] body,
body.rtl {
    direction: rtl;
    text-align: right;
}
[dir="rtl"] .unified-nav,
[dir="rtl"] .nav-left,
[dir="rtl"] .nav-right,
[dir="rtl"] .nav-links {
    flex-direction: row-reverse;
}
[dir="rtl"] .nav-links {
    margin-left: 0;
    margin-right: 12px;
}
[dir="rtl"] .lang-dropdown {
    right: auto;
    left: 0;
}
[dir="rtl"] .lang-option {
    text-align: right;
}
[dir="rtl"] .field input,
[dir="rtl"] .field textarea,
[dir="rtl"] .field select {
    text-align: right;
}
[dir="rtl"] .trade-grid {
    direction: rtl;
}
[dir="rtl"] .pos-table th,
[dir="rtl"] .pos-table td {
    text-align: right;
}
[dir="rtl"] .pos-table th:last-child,
[dir="rtl"] .pos-table td:last-child {
    text-align: left;
}
[dir="rtl"] .customer-section,
[dir="rtl"] .result-card,
[dir="rtl"] .login-card {
    text-align: right;
}
[dir="rtl"] .tab-row {
    flex-direction: row-reverse;
}
[dir="rtl"] .btn-google,
[dir="rtl"] .btn-apple {
    flex-direction: row-reverse;
}
[dir="rtl"] .edit-hint {
    text-align: right;
}
[dir="rtl"] .total-bar {
    text-align: left;
}
@media (max-width: 600px) {
    [dir="rtl"] .lang-dropdown {
        left: -12px;
        right: auto;
    }
}

/* === 15. FOCUS-VISIBLE: Trade cards, upload areas === */
.trade-card:focus-visible,
.upload-area:focus-visible,
.qs-chip:focus-visible,
.trade-chip:focus-visible {
    outline: 2px solid var(--primary, #1E3A5F);
    outline-offset: 2px;
    border-radius: 8px;
}

/* === 16. KEYBOARD-ACCESSIBLE DIVS === */
[role="radio"]:focus-visible,
[role="button"]:focus-visible,
[role="option"]:focus-visible {
    outline: 2px solid var(--primary, #1E3A5F);
    outline-offset: 2px;
}

/* === 17. SECTION-LABEL CONTRAST FIX === */
.section-label {
    color: #1E3A5F !important;
}

/* === 18. BOTTOM NAV SVG ALIGNMENT === */
.bottom-nav svg,
.bottom-nav .nav-icon svg {
    display: inline-block;
    vertical-align: middle;
}
.bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

/* === 19. INLINE SVG SIZING IN BUTTONS === */
button svg,
a svg,
.action-btn svg,
.btn svg {
    flex-shrink: 0;
    vertical-align: middle;
}

/* === 20. PROGRESS BAR ACCESSIBILITY === */
[role="progressbar"] {
    position: relative;
}

/* === 21. iOS BANNER CLOSE: Touch target fix === */
.ios-banner-close {
    min-width: 44px !important;
    min-height: 44px !important;
}

/* === 22. FOOTER LINKS: Touch target padding === */
.footer-column a {
    padding: 6px 0;
    display: inline-block;
}

/* === 23. IN-APP HELP TOOLTIPS === */
.help-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #e5e7eb;
    color: #6b7280;
    font-size: 11px;
    font-weight: 700;
    cursor: help;
    margin-left: 4px;
    vertical-align: middle;
}
.help-tooltip:hover::after,
.help-tooltip:focus::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    white-space: normal;
    width: max-content;
    max-width: 260px;
    z-index: 999;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    pointer-events: none;
}
.help-tooltip:hover::before,
.help-tooltip:focus::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1f2937;
    z-index: 999;
}

/* === 24. SORT BUTTONS === */
.sort-btn { transition: all 0.15s ease; }
.sort-btn:hover { background: #e5e7eb !important; }
.sort-btn.active { background: #1E3A5F !important; color: #fff !important; border-color: #1E3A5F !important; }

/* === 25. SEARCH BAR CONSISTENCY === */
.search-bar {
    width: 100%;
    padding: 10px 12px 10px 38px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    font-size: 13px;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.2s;
}
.search-bar:focus {
    outline: none;
    border-color: var(--primary, #1E3A5F);
    box-shadow: 0 0 0 3px rgba(30,58,95,0.12);
}

/* === 26. COLLAPSIBLE SECTIONS === */
.section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    cursor: pointer;
    user-select: none;
}
.section-toggle .chevron {
    transition: transform 0.2s ease;
}
.section-toggle.collapsed .chevron {
    transform: rotate(-90deg);
}

/* === 27. EMPTY STATE CONSISTENCY === */
.empty-state-guide {
    background: #e8eef6;
    border: 2px dashed #1E3A5F;
    border-radius: 16px;
    padding: 24px;
    text-align: center;
}

/* === 28. BUTTON TYPE DEFAULT === */
button:not([type]) { /* CSS marker only */ }

/* === 29. GRAY-500 CONTRAST UPGRADE === */
.text-gray-500, .text-muted-sm {
    color: #4b5563 !important;
}