/* =========================================================
   FDDrive UI — sistema de diseño compartido
   Se carga después de fd-theme.css (paleta) y aporta:
   escalas, accesibilidad global y componentes base .fd-*
   ========================================================= */
:root {
    /* Tipografía */
    --fd-font-ui: "Nunito", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    --fd-font-display: "Manrope", "Nunito", "Segoe UI", sans-serif;
    --fd-font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
    --fd-text-xs: .75rem;
    --fd-text-sm: .8125rem;
    --fd-text-md: .875rem;
    --fd-text-lg: 1rem;
    --fd-text-xl: 1.25rem;
    --fd-text-2xl: 1.625rem;

    /* Espaciado (base 4px) */
    --fd-space-1: .25rem;
    --fd-space-2: .5rem;
    --fd-space-3: .75rem;
    --fd-space-4: 1rem;
    --fd-space-5: 1.5rem;
    --fd-space-6: 2rem;

    /* Radios y elevación */
    --fd-radius-sm: 6px;
    --fd-radius-md: 10px;
    --fd-radius-lg: 16px;
    --fd-radius-pill: 999px;
    --fd-shadow-1: 0 1px 2px rgba(var(--fd-ui-shadow-rgb, 20, 38, 62), .08);
    --fd-shadow-2: 0 6px 18px rgba(var(--fd-ui-shadow-rgb, 20, 38, 62), .12);
    --fd-shadow-3: 0 20px 48px rgba(var(--fd-ui-shadow-rgb, 20, 38, 62), .24);

    /* Capas */
    --fd-z-sticky: 20;
    --fd-z-dropdown: 1000;
    --fd-z-modal: 3000;
    --fd-z-toast: 4000;

    /* Movimiento */
    --fd-ease: cubic-bezier(.2, .7, .2, 1);
    --fd-dur-fast: 120ms;
    --fd-dur: 200ms;

    /* Interacción */
    --fd-focus-ring: 0 0 0 3px rgba(var(--fd-ui-link-rgb, 24, 87, 160), .45);
    --fd-control-h: 2.375rem;
    --fd-touch-min: 44px;
}

/* ---------- Accesibilidad global ---------- */
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--fd-font-ui); line-height: 1.5; -webkit-font-smoothing: antialiased; }

:where(a, button, input, select, textarea, summary, [tabindex], [role="button"], [role="tab"], [role="menuitem"]):focus-visible {
    outline: 2px solid var(--fd-ui-link, #1857a0);
    outline-offset: 2px;
    box-shadow: var(--fd-focus-ring);
}
:where(input, select, textarea):focus-visible { outline-offset: 0; }

.fd-skip-link {
    position: fixed;
    top: -4rem;
    left: var(--fd-space-4);
    z-index: calc(var(--fd-z-toast) + 1);
    padding: var(--fd-space-2) var(--fd-space-4);
    border-radius: var(--fd-radius-sm);
    background: var(--fd-ui-primary, #1a4b84);
    color: var(--fd-ui-on-solid, #fff);
    font-weight: 700;
    text-decoration: none;
    transition: top var(--fd-dur-fast) var(--fd-ease);
}
.fd-skip-link:focus { top: var(--fd-space-3); }

/* Los enlaces dentro del contenido se distinguen sin depender solo del color */
.content a:not([class]) { text-decoration: underline; text-underline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Objetivos táctiles cómodos en pantallas táctiles */
@media (pointer: coarse) {
    :where(button, .fd-btn, .shipment-button, select, input:not([type="checkbox"]):not([type="radio"])) {
        min-height: var(--fd-touch-min);
    }
}

/* ---------- Botones ---------- */
.fd-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--fd-space-2);
    min-height: var(--fd-control-h);
    padding: 0 var(--fd-space-4);
    border: 1px solid var(--fd-ui-border);
    border-radius: var(--fd-radius-sm);
    background: var(--fd-ui-surface);
    color: var(--fd-ui-text);
    font: 600 var(--fd-text-md)/1 var(--fd-font-ui);
    cursor: pointer;
    text-decoration: none;
    transition: background-color var(--fd-dur-fast) var(--fd-ease), border-color var(--fd-dur-fast) var(--fd-ease), transform var(--fd-dur-fast) var(--fd-ease);
}
.fd-btn:hover { background: var(--fd-ui-soft); border-color: var(--fd-ui-link); }
.fd-btn:active { transform: translateY(1px); }
.fd-btn[disabled], .fd-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.fd-btn--primary { background: var(--fd-ui-primary); border-color: var(--fd-ui-primary); color: var(--fd-ui-on-solid); }
.fd-btn--primary:hover { background: var(--fd-ui-primary-hover); border-color: var(--fd-ui-primary-hover); }
.fd-btn--danger { background: var(--fd-ui-danger-solid); border-color: var(--fd-ui-danger-solid); color: var(--fd-ui-on-solid); }
.fd-btn--danger:hover { filter: brightness(.92); background: var(--fd-ui-danger-solid); }
.fd-btn--ghost { background: transparent; border-color: transparent; color: var(--fd-ui-link); }
.fd-btn--sm { min-height: 2rem; padding: 0 var(--fd-space-3); font-size: var(--fd-text-sm); }

/* Botones de Envíos: misma escala que .fd-btn */
.shipment-button {
    min-height: var(--fd-control-h);
    border-radius: var(--fd-radius-sm);
    letter-spacing: .01em;
    transition: background-color var(--fd-dur-fast) var(--fd-ease), border-color var(--fd-dur-fast) var(--fd-ease), transform var(--fd-dur-fast) var(--fd-ease);
}
.shipment-button:hover:not([disabled]) { border-color: var(--fd-ui-link); filter: brightness(1.04); }
.shipment-button:active:not([disabled]) { transform: translateY(1px); }

/* ---------- Campos ---------- */
.fd-field { display: grid; gap: var(--fd-space-1); }
.fd-label { font-size: var(--fd-text-sm); font-weight: 700; color: var(--fd-ui-text); }
.fd-input, .fd-select, .fd-textarea {
    width: 100%;
    min-height: var(--fd-control-h);
    padding: .4rem var(--fd-space-3);
    border: 1px solid var(--fd-ui-border);
    border-radius: var(--fd-radius-sm);
    background: var(--fd-ui-surface);
    color: var(--fd-ui-text);
    font: 400 var(--fd-text-md)/1.4 var(--fd-font-ui);
}
.fd-input::placeholder, .fd-textarea::placeholder { color: var(--fd-ui-muted); opacity: .8; }
.fd-input:hover, .fd-select:hover, .fd-textarea:hover { border-color: var(--fd-ui-link); }
.fd-input[aria-invalid="true"], .fd-select[aria-invalid="true"], .fd-textarea[aria-invalid="true"] { border-color: var(--fd-ui-danger-solid); }
.fd-help { font-size: var(--fd-text-xs); color: var(--fd-ui-muted); }
.fd-error { font-size: var(--fd-text-xs); color: var(--fd-ui-danger-ink); font-weight: 600; }

/* ---------- Badges de estado (icono + texto, no solo color) ---------- */
.fd-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .15rem .6rem;
    border-radius: var(--fd-radius-pill);
    font-size: var(--fd-text-xs);
    font-weight: 700;
    line-height: 1.4;
    background: var(--fd-ui-soft);
    color: var(--fd-ui-text);
}
.fd-badge::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
.fd-badge--success { background: var(--fd-ui-success-soft); color: var(--fd-ui-success-ink); }
.fd-badge--warning { background: var(--fd-ui-warning-soft); color: var(--fd-ui-warning-ink); }
.fd-badge--danger { background: var(--fd-ui-danger-soft); color: var(--fd-ui-danger-ink); }
.fd-badge--info { background: var(--fd-ui-info-soft); color: var(--fd-ui-info-ink); }

/* ---------- Tablas ---------- */
.fd-table-wrap, .shipment-table-wrap { overflow: auto; max-width: 100%; border-radius: var(--fd-radius-sm); }
.shipment-table-wrap { max-height: 70vh; }
.shipment-table thead th, .fd-table thead th { position: sticky; top: 0; z-index: var(--fd-z-sticky); }
.shipment-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--fd-ui-soft) 45%, var(--fd-ui-surface)); }
.shipment-table tbody tr:hover td { background: var(--fd-ui-soft); }
.shipment-table th { text-transform: none; font-weight: 700; letter-spacing: .01em; }
.fd-table { width: 100%; border-collapse: collapse; font-size: var(--fd-text-md); }
.fd-table th { background: var(--fd-ui-soft); color: var(--fd-ui-text); text-align: left; padding: .55rem .75rem; font-weight: 700; }
.fd-table td { padding: .55rem .75rem; border-top: 1px solid var(--fd-ui-border); }
.fd-table tbody tr:hover td { background: var(--fd-ui-soft); }
.fd-empty { padding: var(--fd-space-6); text-align: center; color: var(--fd-ui-muted); }

/* Indicador de estado de envío: forma distinta además del color */
.shipment-status-dot--ok::after, .shipment-status-dot--warn::after {
    content: ""; display: block; width: 100%; height: 100%;
    background: no-repeat center / 62% 62%;
}
.shipment-status-dot--ok::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3 3 7-7' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.shipment-status-dot--warn::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 4l8 8M12 4l-8 8' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E"); }

/* ---------- Diálogos y tarjetas ---------- */
.fd-card { background: var(--fd-ui-surface); border: 1px solid var(--fd-ui-border); border-radius: var(--fd-radius-md); box-shadow: var(--fd-shadow-1); padding: var(--fd-space-5); }
.fd-confirm-dialog { z-index: var(--fd-z-modal); }

/* Tamaño mínimo legible en textos auxiliares del shell */
.content small, .content .hint { font-size: max(1em, var(--fd-text-xs)); }

/* Foco visible aunque un componente antiguo declare outline:none */
html :is(a, button, input, select, textarea, summary, [role="button"], [role="tab"]):focus-visible {
    outline: 2px solid var(--fd-ui-link, #1857a0) !important;
    outline-offset: 2px;
}
.sidebar :focus-visible { outline-color: #fff !important; box-shadow: 0 0 0 3px rgba(255, 255, 255, .35); }
.content:focus { outline: none; box-shadow: none; }

/* Barra superior: apila en pantallas medianas y pequeñas */
@media (max-width: 1100px) {
    .topbar { grid-template-columns: 1fr auto; }
    .topbar-search { grid-column: 1 / -1; order: 3; }
}
@media (max-width: 680px) {
    .content { padding: var(--fd-space-4); }
    .topbar { padding: var(--fd-space-3) var(--fd-space-4); }
}

/* Pantallas ≤1100px: barra lateral más angosta y barra superior no fija para no consumir altura útil */
@media (max-width: 1100px) {
    :root { --sidebar-width: 232px; }
    .topbar { position: static; }
}

/* Paginación de tablas: controles compactos y alineados */
.report-pagination { display: flex; flex-wrap: wrap; align-items: center; gap: var(--fd-space-2); padding: var(--fd-space-2) 0; }
.report-pagination .shipment-toolbar__action {
    min-height: 2rem; padding: 0 var(--fd-space-3); border-radius: var(--fd-radius-sm);
    border: 1px solid var(--fd-ui-border); background: var(--fd-ui-surface); color: var(--fd-ui-text);
    font: 600 var(--fd-text-sm)/1 var(--fd-font-ui); cursor: pointer;
}
.report-pagination .shipment-toolbar__action:hover:not([disabled]) { background: var(--fd-ui-soft); border-color: var(--fd-ui-link); }
.report-pagination .shipment-toolbar__action[disabled] { opacity: .45; cursor: not-allowed; }
.report-pagination select { min-height: 2rem; border: 1px solid var(--fd-ui-border); border-radius: var(--fd-radius-sm); background: var(--fd-ui-surface); color: var(--fd-ui-text); }

/* Barras de desplazamiento y controles nativos siguen el tema */
html[data-fd-theme="dark"] { color-scheme: dark; }
html[data-fd-theme="light"] { color-scheme: light; }
