/* COMPARTILHADO ERP/OPS — cópia canônica: portoazul/public/css/app.css — versão 9 — alterar nos dois */
/*
 * Estilos dos helpers de interface (toast, modal, acessibilidade).
 * Consome apenas tokens de partials/_tokens.blade.php — nenhum valor cravado.
 * Estilos de layout (header, nav, cards) ficam em cada layout; componentes em
 * resources/views/components.
 */

/* ---------- Utilitários ---------- */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }

/* ---------- Acessibilidade ---------- */
.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;
}

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ---------- Toast (PortoAzul.notify) — canto inferior direito ---------- */
.toast-region {
    position: fixed;
    inset-block-end: var(--space-5);
    inset-inline-end: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    z-index: 2000;
    pointer-events: none;
    width: min(400px, calc(100vw - 2 * var(--space-5)));
}

.toast {
    --toast-cor: var(--info);
    position: relative;
    overflow: hidden;
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: 14px 14px 16px 14px;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-popover), 0 0 0 1px color-mix(in srgb, var(--toast-cor) 12%, transparent);
    opacity: 0;
    transform: translateX(32px) scale(0.98);
    transition: opacity 0.3s cubic-bezier(.2,.8,.2,1), transform 0.3s cubic-bezier(.2,.8,.2,1);
}
.toast.is-visible { opacity: 1; transform: translateX(0) scale(1); }
.toast.is-leaving { transform: translateX(32px) scale(0.98); }

.toast-icon {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: color-mix(in srgb, var(--toast-cor) 18%, transparent);
    color: var(--toast-cor);
    font-size: var(--font-size-base);
}
.toast-body { flex: 1; min-width: 0; padding-top: 2px; }
.toast-title { font-weight: 600; font-size: var(--font-size-base); color: var(--text-strong); line-height: 1.3; }
.toast-text { font-size: var(--font-size-md); color: var(--text-secondary); line-height: 1.45; margin-top: 2px; overflow-wrap: anywhere; }
.toast-close {
    background: transparent; border: 0; color: var(--text-muted); cursor: pointer;
    width: 28px; height: 28px; border-radius: var(--radius-xs); flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center; margin: -4px -4px 0 0;
    transition: var(--transition);
}
.toast-close:hover { background: var(--bg-hover); color: var(--text-strong); }

.toast-progress {
    position: absolute; inset-inline: 0; bottom: 0; height: 3px;
    background: var(--toast-cor);
    transform-origin: left;
    animation: toast-progress var(--toast-ms, 5000ms) linear forwards;
}
.toast.is-paused .toast-progress { animation-play-state: paused; }
@keyframes toast-progress { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.toast-success { --toast-cor: var(--success); }
.toast-danger  { --toast-cor: var(--danger); }
.toast-warning { --toast-cor: var(--warning); }
.toast-info    { --toast-cor: var(--info); }

@media (max-width: 480px) {
    .toast-region { inset-block-end: var(--space-3); inset-inline-end: var(--space-3); inset-inline-start: var(--space-3); width: auto; }
}
@media (prefers-reduced-motion: reduce) {
    .toast { transition: opacity 0.2s; transform: none; }
    .toast-progress { animation: none; display: none; }
}

/* ---------- Modal (PortoAzul.openModal / confirmar / x-modal) ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-5);
    background: rgba(0, 0, 0, 0.6);
    z-index: 1500;
}
.modal-overlay.is-open { display: flex; }
body.has-modal { overflow: hidden; }

.modal {
    width: 100%;
    max-width: 640px;
    max-height: calc(100vh - 2 * var(--space-5));
    overflow: auto;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: var(--space-6);
}
.modal-sm { max-width: 420px; }
.modal-lg { max-width: 900px; }

.modal-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--space-3);
}
.modal-body { color: var(--text-primary); margin-bottom: var(--space-5); line-height: 1.5; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    flex-wrap: wrap;
}

@media (max-width: 480px) {
    .modal { padding: var(--space-4); border-radius: var(--radius); }
    .modal-actions .btn { flex: 1 1 auto; justify-content: center; }
}

/* ======================================================================
   COMPONENTES DO CATÁLOGO (resources/views/components) — v2
   Só o que o componente acrescenta sobre as classes-base do layout
   (.btn, .alert, .form-control, .table, .empty-state, .page-header).
   Escopado ao markup do componente: não altera telas que ainda usam
   as classes legadas sem componente (§2.4).
   ====================================================================== */

/* ---------- x-page-header ----------
   .page-header, -title, -subtitle, -actions ficam no LAYOUT de cada repositório
   (como no ERP), com os mesmos valores. Aqui nada. */

/* ---------- x-btn ----------
   Regras com duas classes (.btn.btn-x) para vencer o .btn base do layout, que é
   carregado depois deste arquivo. */
.btn.btn-warning { background: var(--warning); color: var(--text-on-primary); }
.btn.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border-color); }
.btn.btn-ghost:hover { background: var(--bg-hover); color: var(--text-strong); border-color: var(--border-strong); }
.btn.btn-icon-only { padding: 0; width: 40px; height: 40px; justify-content: center; }
.btn.btn-icon-only.btn-sm { width: 32px; height: 32px; font-size: var(--font-size-sm); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn.is-loading { pointer-events: none; }
.btn.btn-success:hover { filter: brightness(0.92); }
.btn.btn-danger:hover { background: var(--danger-hover); }
.btn.btn-warning:hover { filter: brightness(0.92); }

/* ---------- x-alert ---------- */
.alert-body { flex: 1; min-width: 0; }
.alert-warning { background: var(--warning-soft); border: 1px solid var(--warning); color: var(--warning); }
.alert-info { background: var(--primary-soft); border: 1px solid var(--info); color: var(--info); }
.alert-close {
    background: transparent; border: 0; color: inherit; opacity: 0.7; cursor: pointer;
    padding: var(--space-1); margin-inline-start: auto; border-radius: var(--radius-xs); line-height: 1;
}
.alert-close:hover { opacity: 1; background: var(--bg-hover); }

/* ---------- x-field ---------- */
.field .form-label { display: flex; gap: var(--space-1); align-items: baseline; }
.field-required { color: var(--danger); }
.field .is-invalid { border-color: var(--danger); }
.field .is-invalid:focus { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-tint); }
.field .invalid-feedback { color: var(--danger); font-size: var(--font-size-md); margin-top: var(--space-1); }
.field-help { color: var(--text-muted); font-size: var(--font-size-md); margin-top: var(--space-1); }
.field-finalidade { color: var(--text-muted); font-size: var(--font-size-sm); margin-top: var(--space-1); display: flex; gap: var(--space-1); align-items: center; }
.field-checkbox-label { display: inline-flex; gap: var(--space-2); align-items: center; cursor: pointer; }
.field-checkbox-label input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ---------- x-file-input ---------- */
.file-input { display: flex; align-items: center; gap: var(--space-3); min-height: 38px; }
.file-input-botao { cursor: pointer; margin: 0; }
.file-input input:focus-visible + .file-input-botao { outline: 2px solid var(--primary); outline-offset: 2px; }
.file-input-nome { font-size: var(--font-size-md); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-input-nome.is-preenchido { color: var(--text-secondary); }

/* ---------- x-empty-state ---------- */
.empty-state-title { font-size: var(--font-size-lg); color: var(--text-primary); margin-bottom: var(--space-1); }
.empty-state-text { font-size: var(--font-size-base); color: var(--text-muted); }
.empty-state-action { margin-top: var(--space-4); }

/* ---------- x-data-table ---------- */
.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-responsive .table { min-width: 600px; }
@media (max-width: 480px) { .table-responsive .table { min-width: 480px; } }

/* ---------- x-modal ---------- */
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.modal-header .modal-title { margin-bottom: 0; }
.modal-close {
    background: transparent; border: 0; color: var(--text-muted); cursor: pointer;
    width: 32px; height: 32px; border-radius: var(--radius-xs); display: inline-flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-strong); }

/* ---------- x-search-bar (barra de busca/filtro padrão — §6) ----------
   Valores idênticos aos da barra original do ERP, via tokens --searchbar-*. */
.search-bar { position: relative; display: flex; align-items: center; background: var(--searchbar-bg); border-radius: var(--radius-lg); height: 52px; margin-bottom: var(--space-6); border: 1px solid var(--searchbar-border); box-shadow: var(--searchbar-shadow); }
.search-segment { display: flex; align-items: center; gap: 10px; padding: 0 18px; height: 100%; cursor: text; position: relative; }
.search-segment.busca { flex: 1; min-width: 0; }
.search-segment:not(.busca) { border-inline-start: 1px solid var(--searchbar-border); }
.search-segment svg.seg-icon { width: 16px; height: 16px; color: var(--searchbar-icon); flex-shrink: 0; transition: color 0.15s; }
.search-segment:focus-within svg.seg-icon { color: var(--primary); }
.search-segment.filtro-ativo svg.seg-icon,
.search-segment.filtro-ativo .custom-select-btn { color: var(--primary); }
.filtro-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); flex-shrink: 0; box-shadow: 0 0 4px var(--primary-soft); }
.search-input { flex: 1; background: transparent; border: none; color: var(--searchbar-text); font-size: var(--font-size-base); outline: none; min-width: 0; height: 100%; padding: 0; }
.search-input::placeholder { color: var(--searchbar-placeholder); }
.search-select { flex: 1; background: transparent; border: none; color: var(--searchbar-filter-text); font-size: var(--font-size-md); font-weight: 500; outline: none; cursor: pointer; height: 100%; padding: 0; appearance: none; -webkit-appearance: none; min-width: 0; }
.search-select option { background: var(--searchbar-option-bg); color: var(--searchbar-text); }
.search-clear { display: none; align-items: center; justify-content: center; background: none; border: none; padding: var(--space-1); cursor: pointer; border-radius: 50%; transition: all 0.15s; color: var(--color-gray-500); flex-shrink: 0; }
.search-clear svg { width: 14px; height: 14px; }
.search-clear:hover { background: var(--bg-hover); color: var(--searchbar-filter-text); }
.search-clear.visible { display: flex; }
.search-actions { display: flex; align-items: center; gap: 2px; padding: 0 10px; border-inline-start: 1px solid var(--searchbar-border); height: 100%; flex-shrink: 0; }
.action-btn { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; background: none; border: none; color: var(--searchbar-icon); cursor: pointer; border-radius: var(--radius); transition: all 0.15s; text-decoration: none; }
.action-btn:hover { background: var(--searchbar-hover); color: var(--searchbar-hover-text); }
.action-btn:active { transform: scale(0.95); }
.action-btn svg { width: 17px; height: 17px; }
.action-btn.submit { color: var(--primary); }
.action-btn.submit:hover { background: var(--primary-soft); color: var(--primary); }
.action-btn.clear-all { color: var(--searchbar-clear-all); }
.action-btn.clear-all:hover { background: var(--searchbar-clear-all-soft); color: var(--searchbar-clear-all); }

/* Dropdown customizado (x-search-bar.select) */
.custom-select-btn { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 6px; background: none; border: none; color: var(--searchbar-filter-text); font-size: var(--font-size-md); font-weight: 500; cursor: pointer; padding: 0; width: 100%; text-align: start; white-space: nowrap; overflow: hidden; }
.custom-select-btn span { overflow: hidden; text-overflow: ellipsis; }
.custom-select-btn .chevron-icon { width: 14px; height: 14px; color: var(--searchbar-placeholder); flex-shrink: 0; transition: transform 0.15s; }
.custom-select-btn[aria-expanded="true"] .chevron-icon { transform: rotate(180deg); }
.custom-dropdown { display: none; position: absolute; top: calc(100% + 6px); inset-inline-start: 0; min-width: 100%; background: var(--searchbar-dropdown-bg); border: 1px solid var(--searchbar-border); border-radius: var(--radius-md); box-shadow: var(--shadow-popover); z-index: 999; max-height: 280px; overflow-y: auto; }
.custom-dropdown.open { display: block; }
.custom-dropdown-item { padding: 9px 14px; font-size: var(--font-size-md); color: var(--searchbar-dropdown-text); cursor: pointer; transition: background 0.1s, color 0.1s; white-space: nowrap; }
.custom-dropdown-item:hover, .custom-dropdown-item:focus { background: var(--searchbar-dropdown-hover); color: var(--text-strong); outline: none; }
.custom-dropdown-item.active { color: var(--primary); font-weight: 600; }
.custom-dropdown-item.active:hover { background: var(--primary-soft); }
.custom-dropdown::-webkit-scrollbar { width: 4px; }
.custom-dropdown::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: var(--radius-xs); }

/* Cabeçalhos ordenáveis (a barra reanexa o clique a cada busca) */
.th-ordenavel { cursor: pointer; user-select: none; }
.th-ordenavel:hover { background: var(--searchbar-th-hover); }
.th-ordenavel:hover .icone-ordem i { color: var(--primary); }

/* Celular (§11): segmentos extras quebram para baixo e ocupam a largura */
@media (max-width: 768px) {
    .search-bar { flex-wrap: wrap; height: auto; padding-bottom: 0; }
    .search-segment.busca { flex: 1 1 100%; height: 52px; }
    .search-segment:not(.busca) { flex: 1 1 auto; width: auto !important; height: 44px; border-inline-start: none; border-top: 1px solid var(--searchbar-border); }
    .search-actions { height: 44px; border-top: 1px solid var(--searchbar-border); border-inline-start: none; margin-inline-start: auto; }
}

/* ---------- x-dropdown-pill (etiqueta com dropdown; cores via data-status da tela) ---------- */
.dropdown-pill { position: relative; display: inline-block; --status-cor: var(--text-muted); --status-cor-soft: var(--neutral-soft); }
.pill-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px var(--space-3); border-radius: var(--radius-pill);
    border: 1px solid color-mix(in srgb, var(--status-cor) 33%, transparent);
    background: color-mix(in srgb, var(--status-cor) 13%, transparent);
    color: var(--status-cor);
    font-size: var(--font-size-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
    cursor: pointer; white-space: nowrap; transition: var(--transition);
}
.pill-btn:hover { background: color-mix(in srgb, var(--status-cor) 22%, transparent); }
.pill-btn .chevron-icon { width: 10px; height: 10px; flex-shrink: 0; transition: transform 0.15s; }
.pill-btn[aria-expanded="true"] .chevron-icon { transform: rotate(180deg); }
.dropdown-pill-menu { min-width: 170px; padding: 6px; }
.dropdown-pill-menu .custom-dropdown-item { display: flex; align-items: center; gap: 10px; border-radius: var(--radius-sm); padding: 9px 12px; }
.dropdown-pill-menu .custom-dropdown-item.active { background: color-mix(in srgb, var(--status-cor) 12%, transparent); color: var(--status-cor); }
.dropdown-pill-menu .status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--status-cor, var(--text-muted)); flex-shrink: 0; box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-cor, var(--text-muted)) 20%, transparent); }
.custom-dropdown.is-fixed { position: fixed; top: auto; inset-inline-start: auto; }
