/* ============================================================
   DilitiumProcesos - Estilos responsive globales (móvil primero)
   ============================================================ */

:root {
    --app-header-height: 3.5rem;
    --app-nav-button-width: 2.75rem;
    --app-content-padding-x: 0.75rem;
    --app-content-padding-y: 0.5rem;
    --app-touch-min: 44px;
}

/* Contenedor de página */
.page-mobile {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 100%;
    padding: var(--app-content-padding-y) var(--app-content-padding-x);
    box-sizing: border-box;
}

/* Header de página (reutilizable en todas las vistas) */
.page-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #1666DC, #121080);
    border-radius: 12px;
    color: white;
    box-shadow: 0 3px 12px rgba(0, 120, 212, 0.25);
    width: 100%;
    box-sizing: border-box;
}

.page-header .header-icon {
    font-size: 1.4rem;
    line-height: 1;
    flex-shrink: 0;
}

.page-header h2,
.page-header h3 {
    margin: 0 !important;
    font-size: 1.05rem !important;
    font-weight: 600 !important;
    color: white !important;
    line-height: 1.25;
    word-break: break-word;
    flex: 1 1 auto;
    min-width: 0;
}

/* Toolbar: apila en móvil */
.page-toolbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
    width: 100%;
    padding: 0.65rem;
    background: var(--neutral-layer-1);
    border-radius: 12px;
    border: 1px solid var(--neutral-stroke-rest);
    box-sizing: border-box;
}

.page-toolbar-title {
    margin: 0;
    font-size: 1rem;
    color: #1666DC;
    word-break: break-word;
}

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    width: 100%;
}

.toolbar-actions ::deep fluent-button {
    flex: 1 1 auto;
    min-width: min(100%, 8rem);
    min-height: var(--app-touch-min);
}

.toolbar-actions-compact ::deep fluent-button {
    flex: 0 1 auto;
    min-width: auto;
}

/* Panel de detalle / badges */
.detail-panel {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
    width: 100%;
}

.detail-panel-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.detail-panel-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
}

.detail-panel-fields > * {
    flex: 1 1 100%;
    min-width: 0;
}

/* Tarjetas de sección */
.section-card {
    border-radius: 12px !important;
    width: 100%;
    box-sizing: border-box;
}

.section-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: #1666DC;
    margin-bottom: 0.75rem;
}

/* Data grids en móvil */
.data-grid-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: min(60dvh, 520px);
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.responsive-data-grid {
    width: 100%;
    min-width: 640px; /* fuerza scroll horizontal en pantallas estrechas */
}

.responsive-data-grid ::deep table {
    font-size: 0.82rem;
}

/* Acciones en celdas de grid */
.grid-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.grid-actions ::deep fluent-button {
    min-height: var(--app-touch-min);
}

/* Diálogos modales */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    box-sizing: border-box;
}

.dialog-panel {
    background: var(--neutral-layer-1, #fff);
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 520px;
    max-height: min(90dvh, 720px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1rem;
    box-sizing: border-box;
}

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
    width: 100%;
}

.dialog-actions ::deep fluent-button {
    flex: 1 1 auto;
    min-height: var(--app-touch-min);
}

/* Fluent stacks horizontales → columna en móvil */
@media (max-width: 640px) {
    .page-mobile {
        padding: 0.4rem 0.5rem;
        gap: 0.5rem;
    }

    .page-header {
        padding: 0.65rem 0.85rem;
        border-radius: 10px;
    }

    .page-header h2,
    .page-header h3 {
        font-size: 0.95rem !important;
    }

    .toolbar-actions ::deep fluent-button {
        flex: 1 1 calc(50% - 0.2rem);
        min-width: 0;
        width: 100%;
    }

    .detail-panel-fields > * {
        flex: 1 1 100%;
    }

    .data-grid-container {
        max-height: min(55dvh, 480px);
    }

    .dialog-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .dialog-panel {
        max-width: 100%;
        max-height: 88dvh;
        border-radius: 16px 16px 0 0;
        padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
    }

    .dialog-actions {
        flex-direction: column-reverse;
    }

    .dialog-actions ::deep fluent-button {
        width: 100%;
    }

    /* Stacks inline del layout */
    .stack-mobile-column ::deep .fluent-stack {
        flex-direction: column !important;
        align-items: stretch !important;
    }
}

/* Configuración de lotes: formulario compacto y lectura tipo tarjeta en móvil. */
.config-lote-page {
    max-width: 980px;
}

.config-lote-card {
    padding: 1rem;
}

.config-lote-intro h3,
.config-lote-list-header h3 {
    margin: 0;
    color: #1666DC;
    font-size: 1.05rem;
}

.config-lote-intro p,
.config-lote-list-header p {
    margin: 0.35rem 0 0;
    color: var(--neutral-foreground-rest);
    font-size: 0.86rem;
}

.config-lote-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.8rem;
    margin-top: 1rem;
}

.config-lote-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
    font-size: 0.82rem;
    font-weight: 600;
}

.config-lote-select {
    min-height: var(--app-touch-min);
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--neutral-stroke-rest);
    border-radius: 6px;
    background: var(--neutral-layer-1);
    color: var(--neutral-foreground-rest);
    box-sizing: border-box;
}

.config-lote-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: var(--app-touch-min);
    font-size: 0.85rem;
}

.config-lote-check input {
    width: 1.1rem;
    height: 1.1rem;
}

.config-lote-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.8rem;
    margin-top: 1rem;
}

.config-lote-option-group {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0.75rem;
    border: 1px solid var(--neutral-stroke-divider-rest);
    border-radius: 8px;
    background: var(--neutral-layer-2);
}

.config-lote-option-group h4 {
    margin: 0 0 0.15rem;
    color: #1666DC;
    font-size: 0.9rem;
}

.config-lote-option-help {
    margin: 0;
    color: #52616b;
    font-size: 0.74rem;
    line-height: 1.35;
}

.config-lote-input {
    min-height: 38px;
    width: 100%;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--neutral-stroke-rest);
    border-radius: 6px;
    background: var(--neutral-layer-1);
    color: var(--neutral-foreground-rest);
    box-sizing: border-box;
}

.config-lote-input:disabled {
    opacity: 0.55;
}

.config-lote-suffix {
    max-width: 5rem;
    text-transform: uppercase;
}

.config-lote-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1rem;
    padding: 0.8rem 0.9rem;
    border-left: 4px solid #1666DC;
    border-radius: 6px;
    background: #eef7ff;
}

.config-lote-preview h4 {
    margin: 0;
    color: #121080;
    font-size: 0.92rem;
}

.config-lote-preview p {
    margin: 0.25rem 0 0;
    color: #3b4a54;
    font-size: 0.78rem;
}

.config-lote-preview-code {
    padding: 0.55rem 0.7rem;
    border-radius: 6px;
    background: #fff;
    color: #121080;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    word-break: break-all;
}

.config-lote-preview-rule {
    flex-basis: 100%;
    color: #52616b;
    font-size: 0.75rem;
}

.config-lote-preview-quantity {
    flex-basis: 100%;
    color: #121080;
    font-size: 0.82rem;
}

.config-lote-actions {
    justify-content: flex-end;
    margin-top: 1rem;
}

.config-lote-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}

.config-lote-table-wrap {
    overflow-x: auto;
}

.config-lote-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}

.config-lote-table th,
.config-lote-table td {
    padding: 0.65rem 0.5rem;
    border-bottom: 1px solid var(--neutral-stroke-divider-rest);
    text-align: left;
    vertical-align: middle;
}

.config-lote-table th {
    color: #1666DC;
    font-weight: 700;
}

.config-lote-row-actions {
    white-space: nowrap;
    text-align: right !important;
}

.config-lote-grid-format {
    min-width: 260px;
}

.config-lote-grid-format span,
.config-lote-grid-format code {
    display: block;
}

.config-lote-grid-format span {
    color: var(--neutral-foreground-rest);
    font-size: 0.76rem;
    line-height: 1.35;
}

.config-lote-grid-format code {
    width: fit-content;
    margin-top: 0.25rem;
    padding: 0.18rem 0.35rem;
    border-radius: 4px;
    background: #eef7ff;
    color: #121080;
    font-size: 0.78rem;
    font-weight: 700;
}

.config-lote-empty {
    padding: 1rem;
    border-radius: 8px;
    background: var(--neutral-layer-2);
    color: var(--neutral-foreground-rest);
    font-size: 0.86rem;
}

@media (max-width: 640px) {
    .config-lote-card {
        padding: 0.75rem;
    }

    .config-lote-form {
        grid-template-columns: 1fr;
        gap: 0.6rem;
    }

    .config-lote-options {
        grid-template-columns: 1fr;
        gap: 0.6rem;
    }

    .config-lote-preview {
        align-items: flex-start;
        flex-direction: column;
    }

    .config-lote-preview-code {
        width: 100%;
        box-sizing: border-box;
        text-align: center;
    }

    .config-lote-list-header {
        align-items: flex-start;
    }

    .config-lote-table thead {
        display: none;
    }

    .config-lote-table,
    .config-lote-table tbody,
    .config-lote-table tr,
    .config-lote-table td {
        display: block;
        width: 100%;
        box-sizing: border-box;
    }

    .config-lote-table tr {
        padding: 0.55rem 0;
        border-bottom: 1px solid var(--neutral-stroke-divider-rest);
    }

    .config-lote-table td {
        display: flex;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.28rem 0;
        border: 0;
    }

    .config-lote-table td::before {
        content: attr(data-label);
        color: var(--neutral-foreground-hint);
        font-weight: 600;
    }

    .config-lote-table td.config-lote-row-actions {
        justify-content: flex-end;
        padding-top: 0.5rem;
    }

    .config-lote-table td.config-lote-row-actions::before {
        display: none;
    }
}

@media (min-width: 641px) {
    .page-mobile {
        padding: 0.75rem 1rem;
    }

    .page-toolbar {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .toolbar-actions ::deep fluent-button {
        flex: 0 1 auto;
        min-width: auto;
    }

    .detail-panel {
        align-items: flex-end;
    }

    .detail-panel-fields > * {
        flex: 1 1 150px;
        max-width: 220px;
    }

    .data-grid-container {
        max-height: 65vh;
    }
}

@media (min-width: 900px) {
    .page-mobile {
        padding: 1rem 1.5rem;
        max-width: 1400px;
        margin: 0 auto;
    }

    .data-grid-container {
        max-height: 70vh;
    }
}

/* Área táctil */
@media (hover: none) and (pointer: coarse) {
    fluent-button,
    .toolbar-actions ::deep fluent-button,
    .grid-actions ::deep fluent-button {
        touch-action: manipulation;
    }

    .responsive-data-grid ::deep tbody tr:active {
        background-color: var(--neutral-layer-2);
    }
}

/* Todas las grillas deben poder desplazarse dentro de la pantalla, nunca
   ampliar el layout completo del teléfono. */
.table-responsive,
.data-grid-container,
.procesar-grid-wrap,
.warehouse-table-wrap,
.table-wrap,
.wrap,
.grid-scroll,
.responsive-table {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {
    .page-mobile,
    .procesar-page,
    .params,
    .route-page,
    .orders-page,
    .purchase-page,
    .notification-page {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding-left: var(--app-content-padding-x);
        padding-right: var(--app-content-padding-x);
    }

    .page-header,
    .section-header,
    .section-heading,
    .purchase-hero,
    .route-page > header {
        min-width: 0;
    }

    .page-header h1,
    .page-header h2,
    .page-header h3,
    .section-header h1,
    .section-header h2,
    .section-header h3,
    .purchase-hero h1,
    .purchase-hero h2 {
        overflow-wrap: anywhere;
    }

    .toolbar-actions,
    .actions,
    .warehouse-action-row,
    .modal-actions,
    .warehouse-modal-actions {
        width: 100%;
        max-width: 100%;
    }

    .toolbar-actions > *,
    .actions > *,
    .warehouse-action-row > *,
    .modal-actions > *,
    .warehouse-modal-actions > * {
        min-width: 0;
        max-width: 100%;
    }

    table { min-width: 0; }
}
