/* ============================================
   BEM COMPONENTS
   ============================================ */

/* --- Button --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    line-height: var(--leading-tight);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    cursor: pointer;
    border: 1px solid transparent;
    min-height: 40px;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn--primary {
    background: var(--color-primary);
    color: var(--color-text-inverse);
}

.btn--primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.btn--secondary {
    background: transparent;
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn--secondary:hover:not(:disabled) {
    background: var(--color-surface-hover);
    border-color: var(--color-border-hover);
}

.btn--danger {
    background: var(--color-danger);
    color: var(--color-text-inverse);
}

.btn--danger:hover:not(:disabled) {
    background: #b91c1c;
}

.btn--ghost {
    background: transparent;
    color: var(--color-text-secondary);
}

.btn--ghost:hover:not(:disabled) {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.btn--outline {
    background: transparent;
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn--outline:hover:not(:disabled) {
    background: var(--color-surface-hover);
    border-color: var(--color-border-hover);
}

.btn--success {
    background: var(--color-success);
    color: var(--color-text-inverse);
}

.btn--success:hover:not(:disabled) {
    filter: brightness(0.9);
}

.btn--warning {
    background: var(--color-warning);
    color: var(--color-text-inverse);
}

.btn--warning:hover:not(:disabled) {
    filter: brightness(0.9);
}

.btn--xs {
    padding: 2px var(--space-2);
    font-size: 11px;
    min-height: 26px;
    gap: var(--space-1);
}

.btn--sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
    min-height: 32px;
}

.btn--lg {
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-base);
    min-height: 48px;
}

.btn--full {
    width: 100%;
}

.btn--icon {
    width: 40px;
    padding: 0;
}

.btn--icon.btn--sm {
    width: 32px;
}

/* --- Form --- */
.form__group {
    margin-bottom: var(--space-4);
}

.form__label {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--color-text);
    margin-bottom: var(--space-1);
}

.form__input,
.input,
.form-control,
.form-select {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    min-height: 42px;
    font-family: inherit;
}

.form__input::placeholder,
.input::placeholder,
.form-control::placeholder {
    color: var(--input-placeholder);
}

.form__input:focus,
.input:focus,
.form-control:focus,
.form-select:focus {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px var(--input-focus-ring);
}

.form__input--error {
    border-color: var(--color-danger);
}

.form__input--error:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.25);
}

.form__hint {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

.form__error {
    font-size: var(--text-xs);
    color: var(--color-danger);
    margin-top: var(--space-1);
}

.form__divider {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin: var(--space-6) 0;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
}

.form__divider::before,
.form__divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

/* --- Card --- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}

.card__title {
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
}

.card__body {
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
}

/* --- Alert --- */
.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.alert--error {
    background: var(--color-danger-light);
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
}

.alert--success {
    background: var(--color-success-light);
    color: var(--color-success);
    border: 1px solid var(--color-success);
}

.alert--warning {
    background: var(--color-warning-light);
    color: var(--color-warning);
    border: 1px solid var(--color-warning);
}

.alert--info {
    background: var(--color-info-light);
    color: var(--color-info);
    border: 1px solid var(--color-info);
}

/* --- Badge --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-2);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    border-radius: var(--radius-full);
}

.badge--primary {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.badge--success {
    background: var(--color-success-light);
    color: var(--color-success);
}

.badge--warning {
    background: var(--color-warning-light);
    color: var(--color-warning);
}

.badge--danger {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

/* --- Avatar --- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: var(--font-semibold);
    overflow: hidden;
}

.avatar--sm {
    width: 32px;
    height: 32px;
    font-size: var(--text-xs);
}

.avatar--md {
    width: 40px;
    height: 40px;
    font-size: var(--text-sm);
}

.avatar--lg {
    width: 56px;
    height: 56px;
    font-size: var(--text-lg);
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* --- Modal --- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.modal--active {
    display: flex;
}

.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal__content {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-xl);
    animation: modalSlideIn var(--transition-base);
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}

.modal__title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* --- Stat Card --- */
.stat {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.stat__label {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    text-transform: uppercase;
    font-weight: var(--font-medium);
    letter-spacing: 0.05em;
}

.stat__value {
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    color: var(--color-text);
}

.stat__change {
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
}

.stat__change--up {
    color: var(--color-success);
}

.stat__change--down {
    color: var(--color-danger);
}

/* --- Table --- */
.table-wrap,
.table-responsive {
    overflow-x: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

.table {
    width: 100%;
    font-size: var(--text-sm);
}

.table th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    font-weight: var(--font-medium);
    color: var(--color-text-secondary);
    background: var(--color-bg-alt);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover td {
    background: var(--color-surface-hover);
}

/* --- Tooltip (CSS-only) --- */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    white-space: nowrap;
    background: var(--color-text);
    color: var(--color-text-inverse);
    border-radius: var(--radius-sm);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    z-index: var(--z-tooltip);
}

[data-tooltip]:hover::after {
    opacity: 1;
}

/* ============================================
   RESPONSIVO — Mobile (< 768px)
   Tables become stacked cards.
   ABNT accessibility: min body font 14px, auxiliary 12px.
   WCAG AA contrast ratios enforced via CSS vars.
   ============================================ */

/* Accessibility: minimum font sizes (ABNT NBR 9050) + Mobile Responsive */
@media (max-width: 768px) {
    body { font-size: 14px; }

    /* CRITICAL: prevent ALL horizontal overflow on mobile */
    * { max-width: 100%; box-sizing: border-box; }
    img, video, iframe, canvas, svg { max-width: 100%; height: auto; }
    pre, code { overflow-x: auto; max-width: 100%; white-space: pre-wrap; word-break: break-all; }

    /* Inline style overrides — force elements with fixed widths to be fluid */
    [style*="width:"], [style*="max-width:"], [style*="min-width:"] {
        max-width: 100% !important;
    }
    /* Force flex containers to wrap EXCEPT buttons row (flex-shrink:0 children) */
    [style*="display:flex"] { flex-wrap: wrap !important; }
    /* Buttons inside flex containers: don't force wrap (keep side-by-side) */
    .btn { flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: none; }

    /* Tables → scrollable on mobile (don't stack — keeps data readable) */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
    .table { min-width: 480px; }

    /* Grid adjustments */
    .grid--2, .grid--3, .grid--4 {
        grid-template-columns: 1fr !important;
    }

    /* Page header stack */
    .page-header__row {
        flex-direction: column;
        gap: var(--space-2);
        align-items: flex-start !important;
    }
    .page-header__actions {
        width: 100%;
        flex-wrap: wrap;
        gap: var(--space-2);
    }
    .page-header__actions .btn {
        max-width: none;
        flex: 0 0 auto;
    }

    /* Cards: reduce padding + prevent overflow */
    .card { padding: var(--space-3); overflow: hidden; max-width: 100%; }
    .card__header { padding: var(--space-3); }

    /* Buttons: only --lg go full width */
    .btn--lg { width: 100%; }

    /* Alerts: wrap text */
    .alert { flex-wrap: wrap; word-break: break-word; }

    /* Forms: ensure inputs don't overflow */
    .form__input, select, textarea { max-width: 100%; box-sizing: border-box; }

    /* Badges: allow wrapping */
    .badge { white-space: normal; word-break: break-word; }

    /* Modal: full width on mobile */
    .modal__content { max-width: calc(100vw - 2rem); width: 100%; }

    /* Stat cards: smaller text */
    .stat__value { font-size: var(--text-xl); }

    /* Horizontal scroll tabs */
    [role="tablist"], .tabs, .central__tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        scrollbar-width: none;
    }
    [role="tablist"]::-webkit-scrollbar,
    .central__tabs::-webkit-scrollbar { display: none; }

    /* Filter rows with multiple selects/inputs: stack vertically */
    form[style*="display:flex"] .form__input,
    form[style*="display:flex"] select {
        flex: 1 1 120px;
        min-width: 120px;
    }
}

/* Touch targets: min 44px (WCAG 2.5.5) */
@media (pointer: coarse) {
    .btn { min-height: 44px; min-width: 44px; }
    .form__input, .form__select { min-height: 44px; }
    .sidebar__link { min-height: 44px; }
}

/* Focus visible: keyboard accessibility */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius);
}

/* Reduced motion: respect user preference */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* --- Central Tabs (7 Centrais) --- */
.central__tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 2px solid var(--border);
    margin-bottom: var(--space-5);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.central__tabs::-webkit-scrollbar { display: none; }
.central__tab {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}
.central__tab:hover { color: var(--text-primary); }
.central__tab--active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.central__tab__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 var(--space-1);
    margin-left: var(--space-1);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    color: var(--white);
    background: var(--danger);
    border-radius: var(--radius-full);
}

/* --- Export Buttons --- */
.export-buttons {
    display: inline-flex;
    gap: var(--space-1);
    margin-left: auto;
}

/* =========================================================
   A11Y — WCAG 2.1 AA (adicionado 2026-04-15)
   ========================================================= */

/* 2.4.7 Focus Visible — safety net global para keyboard users */
*:focus-visible {
    outline: var(--focus-outline, 2px solid #2563eb);
    outline-offset: 2px;
    border-radius: 4px;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible {
    outline: var(--focus-outline, 2px solid #2563eb);
    outline-offset: 2px;
    box-shadow: var(--focus-ring, 0 0 0 3px rgba(37, 99, 235, 0.45));
}

/* 2.5.5 Target Size (mínimo 44×44 px em mobile) */
@media (pointer: coarse) {
    button, [role="button"], a.btn, input[type="checkbox"], input[type="radio"], .tab, .chip {
        min-height: 44px;
    }
}

/* 2.3.3 Respect 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;
    }
}

/* 1.4.3 Ensure placeholder has sufficient contrast — depende de tokens */
::placeholder { color: var(--input-placeholder, #6b7280); opacity: 1; }

/* Push notification opt-in banner */
.push-banner {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--color-primary);
    color: #fff;
    font-size: var(--text-sm);
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 9998;
    box-shadow: 0 -2px 12px rgba(0,0,0,.2);
}
.push-banner i { font-size: 20px; flex-shrink: 0; }
.push-banner span { flex: 1; min-width: 0; }
.push-banner__btn {
    padding: var(--space-1) var(--space-3);
    background: #fff;
    color: var(--color-primary);
    border: 0;
    border-radius: var(--radius);
    font-weight: var(--font-semibold);
    font-size: var(--text-sm);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.push-banner__close {
    background: none;
    border: 0;
    color: rgba(255,255,255,.7);
    font-size: 20px;
    cursor: pointer;
    padding: 0 var(--space-1);
    flex-shrink: 0;
}
.push-banner__close:hover { color: #fff; }

/* Skip-link — visually hidden até receber foco (WCAG 2.4.1) */
.skip-link {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}
.skip-link:focus {
    position: fixed; top: 8px; left: 8px;
    width: auto; height: auto;
    padding: 10px 16px; margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    background: var(--color-primary, #6366f1);
    color: #fff;
    border-radius: 8px;
    text-decoration: none;
    z-index: 99999;
    font-weight: 600;
    font-size: .875rem;
    outline: 3px solid #fff;
    outline-offset: -3px;
}

/* ============================================
   APK Android Toast (Capacitor in-app)
   ============================================ */
.apk-toast {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(-120%);
    z-index: 99999;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 2px solid var(--color-primary);
    border-radius: var(--radius-lg, 12px);
    padding: 14px 18px;
    min-width: 280px;
    max-width: 90vw;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    transition: transform 350ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.apk-toast--visible {
    transform: translateX(-50%) translateY(0);
}
.apk-toast__icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}
.apk-toast__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.apk-toast__title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}
.apk-toast__body {
    font-size: 0.82rem;
    color: var(--text-secondary);
}
@media (prefers-reduced-motion: reduce) {
    .apk-toast { transition: none; }
}

/* ============================================
   APK Android — Update Modal + Base
   ============================================ */
html.is-apk [data-channel="web_push"],
html.is-apk .web-push-toggle { display: none !important; }

.apk-update-modal { position: fixed; inset: 0; z-index: 100000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.apk-update-modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.65); backdrop-filter: blur(4px); }
.apk-update-modal__box { position: relative; background: var(--color-surface, #fff); color: var(--color-text, #0f172a); border: 1px solid var(--color-border, #e2e8f0); border-radius: var(--radius-xl, 1rem); padding: 2rem; max-width: 440px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,0.28); }
.apk-update-modal__close { position: absolute; top: .75rem; right: .75rem; background: transparent; border: none; cursor: pointer; color: var(--color-text-muted, #64748b); font-size: 1.25rem; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-md, .5rem); transition: background .15s; }
.apk-update-modal__close:hover, .apk-update-modal__close:focus-visible { background: var(--color-bg-alt, #f1f5f9); outline: 2px solid var(--color-primary, #6366f1); outline-offset: 2px; }
.apk-update-modal__box h2 { margin: 0 0 .5rem; font-size: 1.4rem; color: var(--color-text, #0f172a); padding-right: 2.5rem; }
.apk-update-modal__box p { color: var(--color-text-secondary, #475569); margin: .25rem 0; }
.apk-update-modal__box ul { margin: 1rem 0; padding-left: 1.5rem; color: var(--color-text-secondary, #475569); font-size: .95rem; }
.apk-update-modal__box li { margin-bottom: .4rem; }
.apk-update-modal__actions { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1.5rem; flex-wrap: wrap; }
.apk-btn { padding: .7rem 1.4rem; border-radius: var(--radius-md, .5rem); border: none; font-weight: 600; cursor: pointer; font-size: 1rem; min-height: 44px; transition: opacity .15s, background .15s; }
.apk-btn--primary { background: var(--color-primary, #6366f1); color: #fff; }
.apk-btn--primary:hover, .apk-btn--primary:focus-visible { background: var(--color-primary-hover, #4f46e5); outline: 2px solid var(--color-primary, #6366f1); outline-offset: 2px; }
.apk-btn--ghost { background: transparent; color: var(--color-text-secondary, #475569); border: 1px solid var(--color-border, #e2e8f0); }
.apk-btn--ghost:hover, .apk-btn--ghost:focus-visible { background: var(--color-bg-alt, #f1f5f9); outline: 2px solid var(--color-text-muted, #64748b); outline-offset: 2px; }
/* Alerta visual para update obrigatório */
.apk-update-modal--force .apk-update-modal__box { border-color: var(--color-warning, #d97706); }
.apk-update-modal--force .apk-update-modal__close { opacity: .45; cursor: default; pointer-events: none; }
.apk-update-modal__force-note { font-size: .8rem; color: var(--color-warning, #d97706); margin-top: .5rem; font-weight: 600; }

/* ── Splash Screen (mobile/APK only) ─────────── */
.splash-screen {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}
.splash-screen--hidden {
    opacity: 0;
    pointer-events: none;
}
.splash-screen__video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.splash-screen__skip {
    position: absolute;
    bottom: max(2rem, env(safe-area-inset-bottom, 1rem));
    right: 1.5rem;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--radius-md, 0.5rem);
    padding: 0.5rem 1.2rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 44px;
    display: flex;
    align-items: center;
}
.splash-screen__skip:hover,
.splash-screen__skip:focus-visible {
    background: rgba(255, 255, 255, 0.3);
    outline: 2px solid #fff;
    outline-offset: 2px;
}
/* Desktop: nunca mostra splash */
@media (min-width: 1024px) {
    .splash-screen { display: none !important; }
}
/* Prefers reduced motion: skip animation */
@media (prefers-reduced-motion: reduce) {
    .splash-screen { display: none !important; }
}
