html {
    min-width: 320px;
    scroll-padding-top: 4rem;
}

body {
    overflow-x: hidden;
}

img,
video,
canvas,
svg {
    max-width: 100%;
}

main,
main > div,
main > div > div {
    min-width: 0;
}

@media (max-width: 1023px) {
    #sidebar.mobile-open {
        display: flex !important;
        position: fixed;
        top: 3.5rem;
        left: 0;
        z-index: 50;
        width: min(20rem, 88vw);
        height: calc(100vh - 3.5rem);
        height: calc(100dvh - 3.5rem);
        box-shadow: 1rem 0 3rem rgb(0 0 0 / 35%);
    }

    body.sidebar-mobile-open {
        overflow: hidden;
    }

    main > div > div {
        padding-left: clamp(0.75rem, 3vw, 1.5rem);
        padding-right: clamp(0.75rem, 3vw, 1.5rem);
        padding-top: clamp(1rem, 3vw, 2rem);
    }

    table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    input,
    select,
    textarea {
        max-width: 100%;
    }
}

@media (max-width: 639px) {
    header > div {
        gap: 0.375rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    header #negocio-select-wrap > button,
    header #sucursal-select-wrap > button,
    header #negocio-select-wrap > a,
    header #sucursal-select-wrap > a {
        max-width: 8.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    header #negocio-select-wrap > button > div,
    header #sucursal-select-wrap > button > div,
    header #negocio-select-wrap > a > div,
    header #sucursal-select-wrap > a > div {
        max-width: 5.25rem;
    }

    header #negocio-select-wrap > button > span:first-child,
    header #sucursal-select-wrap > button > span:first-child,
    header #negocio-select-wrap > a > span:first-child,
    header #sucursal-select-wrap > a > span:first-child {
        display: none;
    }

    #modalContainer {
        align-items: flex-start;
        overflow-y: auto;
        padding: max(0.75rem, env(safe-area-inset-top)) 0.75rem max(0.75rem, env(safe-area-inset-bottom));
    }

    #modalBox {
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: 32rem;
        max-height: calc(100vh - 1.5rem);
        max-height: calc(100dvh - 1.5rem);
        margin: auto 0;
        overflow-y: auto;
    }

    #modalBox > .p-6 {
        overflow-y: auto;
    }

    #modalHeader,
    #modalBox > .p-6,
    #modalFooter {
        padding: 1rem;
    }

    #modalFooter {
        flex-wrap: wrap;
    }

    #modalFooter button {
        flex: 1 1 8rem;
    }

    #rey-palette {
        padding-top: max(0.75rem, env(safe-area-inset-top));
    }

    #rey-palette > div.relative {
        max-height: calc(100dvh - 1.5rem);
        overflow-y: auto;
    }

    [role="dialog"],
    [aria-modal="true"] {
        max-width: calc(100vw - 1.5rem);
        max-height: calc(100vh - 1.5rem);
        max-height: calc(100dvh - 1.5rem);
        overflow-y: auto;
    }

    [class~="fixed"][class~="inset-0"] > :is(div, section, form)[class*="max-w-"] {
        max-width: calc(100vw - 1.5rem);
        max-height: calc(100vh - 1.5rem);
        max-height: calc(100dvh - 1.5rem);
        overflow-y: auto;
    }

    #modalEditarInventario {
        align-items: flex-start;
        overflow-y: auto;
    }

    #modalEditarInventario > section {
        display: flex;
        flex-direction: column;
        max-height: calc(100vh - 2rem);
        max-height: calc(100dvh - 2rem);
    }

    #modalEditarInventario > section > form {
        overflow-y: auto;
    }
}

@media (max-width: 480px) {
    header #negocio-select-wrap,
    header #sucursal-select-wrap {
        display: none;
    }
}

.rs-ai-launcher {
    position: fixed;
    right: 1rem;
    bottom: max(1rem, env(safe-area-inset-bottom));
    z-index: 90;
    display: grid;
    width: 3.25rem;
    height: 3.25rem;
    place-items: center;
    border: 1px solid rgb(147 197 253 / 35%);
    border-radius: 50%;
    color: #fff;
    background: #1152d4;
    box-shadow: 0 8px 24px rgb(0 0 0 / 35%);
    cursor: pointer;
}

.rs-ai-launcher .material-symbols-outlined { font-size: 1.65rem; }
.rs-ai-launcher:focus-visible, .rs-ai-panel button:focus-visible, .rs-ai-panel input:focus-visible { outline: 3px solid #93c5fd; outline-offset: 3px; }

.rs-ai-panel {
    position: fixed;
    right: 1rem;
    bottom: calc(4.75rem + env(safe-area-inset-bottom));
    z-index: 89;
    display: flex;
    width: min(25rem, calc(100vw - 2rem));
    height: min(35rem, calc(100dvh - 6rem));
    min-height: 18rem;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #334155;
    border-radius: 0.75rem;
    color: #e2e8f0;
    background: #101622;
    box-shadow: 0 20px 60px rgb(0 0 0 / 50%);
}

.rs-ai-panel[hidden] { display: none !important; }
.rs-ai-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem; border-bottom: 1px solid #334155; }
.rs-ai-header h2 { margin: 0; color: #f8fafc; font-size: 0.95rem; font-weight: 800; }
.rs-ai-header p { margin: 0.2rem 0 0; color: #94a3b8; font-size: 0.75rem; }
.rs-ai-close, .rs-ai-send { display: grid; width: 2.5rem; height: 2.5rem; flex: 0 0 auto; place-items: center; border: 1px solid #334155; border-radius: 0.5rem; color: #e2e8f0; background: #1e293b; cursor: pointer; }
.rs-ai-messages { display: flex; flex: 1; flex-direction: column; gap: 0.75rem; overflow-y: auto; padding: 1rem; overscroll-behavior: contain; }
.rs-ai-message { max-width: 88%; padding: 0.7rem 0.8rem; border-radius: 0.65rem; background: #1e293b; color: #e2e8f0; font-size: 0.875rem; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; }
.rs-ai-message[data-role="user"] { align-self: flex-end; color: #fff; background: #174ea6; }
.rs-ai-message[data-role="assistant"] { align-self: flex-start; }
.rs-ai-form { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem; border-top: 1px solid #334155; }
.rs-ai-input { min-width: 0; min-height: 2.75rem; flex: 1; padding: 0.65rem 0.75rem; border: 1px solid #475569; border-radius: 0.5rem; color: #f8fafc; background: #0b1220; font: inherit; font-size: 0.875rem; }
.rs-ai-input::placeholder { color: #94a3b8; }
.rs-ai-send { border-color: #2563eb; color: #fff; background: #1152d4; }
.rs-ai-send:disabled { cursor: wait; opacity: 0.6; }
.rs-ai-status { min-height: 1.25rem; padding: 0 1rem 0.5rem; color: #94a3b8; font-size: 0.75rem; }

@media (max-width: 480px) {
    .rs-ai-panel { right: max(0.75rem, env(safe-area-inset-right)); bottom: calc(4.5rem + env(safe-area-inset-bottom)); left: max(0.75rem, env(safe-area-inset-left)); width: auto; height: min(34rem, calc(100dvh - 5.5rem)); }
    .rs-ai-launcher { right: 0.75rem; }
}
