:root {
    --blue: #2563eb;
    --dark: #1e293b;
    --bg: #f4f6f9;
    --border: #e2e8f0;
    --muted: #64748b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: #0f172a;
    background: var(--bg);
}

button, input, select, textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

[hidden] {
    display: none !important;
}

.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    width: 260px;
    height: 100vh;
    background: var(--dark);
    color: white;
}

.brand {
    height: 85px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px;
    border-bottom: 1px solid #334155;
}

.brand h1 {
    font-size: 27px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--blue);
    font-size: 23px;
    font-weight: bold;
}

.sidebar nav {
    display: grid;
    gap: 8px;
    padding: 25px 12px;
}

.nav {
    padding: 15px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #cbd5e1;
    text-align: left;
}

.nav:hover {
    background: #334155;
}

.nav.active {
    background: var(--blue);
    color: white;
    font-weight: bold;
}

.main {
    min-width: 0;
    flex: 1;
    margin-left: 260px;
}

.topbar {
    display: flex;
    align-items: center;
    height: 85px;
    padding: 14px 35px;
    background: white;
    border-bottom: 1px solid var(--border);
}

.search {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 750px;
    width: 100%;
    padding: 6px 8px 6px 18px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.search span {
    font-size: 28px;
    color: var(--muted);
}

.search input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
}

.workspace {
    max-width: 1450px;
    margin: auto;
    padding: 45px;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

h2 {
    margin: 0 0 10px;
    font-size: 36px;
}

h3 {
    margin: 0 0 14px;
}

.subtitle {
    color: var(--muted);
    margin: 0 0 30px;
}

.home-grid {
    display: grid;
    max-width: 1100px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 25px;
}

.home-card {
    display: flex;
    min-height: 250px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 12px;
    padding: 32px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 14px;
    text-align: left;
}

.home-card:hover {
    border-color: #93c5fd;
    box-shadow: 0 5px 20px #0f172a10;
}

.home-card strong {
    font-size: 23px;
}

.home-card small {
    color: var(--muted);
    font-size: 15px;
}

.home-icon {
    display: grid;
    place-items: center;
    width: 75px;
    height: 75px;
    margin-bottom: 15px;
    border-radius: 50%;
    font-size: 35px;
}

.blue { background: #dbeafe; color: #2563eb; }
.orange { background: #ffedd5; color: #ea580c; }
.green { background: #dcfce7; color: #15803d; }
.red { background: #fee2e2; color: #dc2626; }

.panel {
    padding: 30px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 13px;
    margin-bottom: 18px;
}

.form-narrow {
    max-width: 850px;
}

.form-narrow-wide {
    max-width: 1050px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-bottom: 22px;
    font-weight: bold;
    font-size: 14px;
}

label input, label select, label textarea, .location input, .location select, .toolbar select {
    width: 100%;
    min-width: 0;
    padding: 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: white;
    font-weight: normal;
}

textarea {
    resize: vertical;
}

.two-col, .detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px;
}

.wide {
    grid-column: 1 / -1;
}

.location {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 22px;
}

.location input {
    text-align: center;
}

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 11px 17px;
    font-weight: bold;
}

.primary { background: var(--blue); color: white; }
.secondary { background: #f1f5f9; color: #0f172a; border-color: var(--border); }
.outline { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.success { background: #15803d; color: white; }
.danger-text { background: transparent; color: #b91c1c; }

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

.back {
    display: block;
    padding: 0;
    margin-bottom: 25px;
    border: 0;
    background: transparent;
    color: var(--blue);
    font-weight: bold;
}

.actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    margin-top: 25px;
    padding-top: 22px;
    border-top: 1px solid var(--border);
}

.heading-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.heading-row h2, .heading-row h3 {
    margin-bottom: 0;
}

.inline-form, .toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin: 20px 0;
}

.inline-form label {
    flex: 1;
    margin: 0;
}

.toolbar select {
    max-width: 260px;
}

hr {
    height: 1px;
    background: var(--border);
    border: 0;
    margin: 26px 0;
}

.error {
    padding: 12px;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 8px;
}

.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(220px, 1fr);
    gap: 18px;
}

.detail-grid {
    padding: 20px 0;
}

.detail-grid dt {
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 14px;
}

.detail-grid dd {
    margin: 0;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.dates {
    display: flex;
    flex-wrap: wrap;
    gap: 25px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
}

.related {
    display: grid;
    align-content: start;
    gap: 10px;
}

.related button, .result-card {
    display: block;
    width: 100%;
    padding: 20px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    text-align: left;
}

.related button {
    background: #fffbeb;
    border-color: #fcd34d;
}

.result-card {
    max-width: 850px;
    font-size: 20px;
}

.table-scroll {
    overflow-x: auto;
    padding: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
    font-size: 14px;
}

th {
    background: #f8fafc;
    color: #475569;
}

.empty-table {
    padding: 20px;
    color: var(--muted);
}

.status {
    display: inline-block;
    padding: 7px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
}

.status-pendiente, .status-preparar, .status-preparacion { background: #fef3c7; color: #92400e; }
.status-enviado, .status-preparado { background: #dbeafe; color: #1d4ed8; }
.status-ajustado, .status-controlado, .status-enviocerrado, .status-transferido { background: #dcfce7; color: #166534; }

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

.chips span {
    padding: 10px 15px;
    border-radius: 7px;
    background: #eff6ff;
    color: var(--blue);
}

.steps {
    display: flex;
    gap: 16px;
    margin: 25px 0;
}

.steps span {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    background: #f1f5f9;
    text-align: center;
}

.steps .on {
    background: #dbeafe;
    color: #1d4ed8;
    font-weight: bold;
}

.receipt-row, .item-entry {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    align-items: end;
    gap: 12px;
    margin-bottom: 12px;
}

.receipt-row label, .item-entry label {
    margin: 0;
}

.receipt-row select {
    width: 100%;
    padding: 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
}

/* ENVÍOS */
.shipment-list {
    display: grid;
    gap: 15px;
    max-width: 1050px;
}

.shipment-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    width: 100%;
    padding: 25px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: white;
    text-align: left;
}

.shipment-card:hover {
    border-color: #93c5fd;
}

.shipment-card strong {
    font-size: 22px;
}

.shipment-card p {
    color: var(--muted);
    margin: 10px 0 0;
}

.group-card {
    margin-bottom: 18px;
    padding: 25px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.group-card .heading-row {
    margin-bottom: 20px;
}

.group-card h3 {
    font-size: 21px;
}

.group-card .table-scroll {
    margin-bottom: 14px;
}

.item-entry {
    grid-template-columns: minmax(200px, 2fr) minmax(100px, 1fr) auto;
}

.item-entry .btn {
    margin-bottom: 1px;
}

.item-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.send-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 20px;
    max-width: 1050px;
    margin-top: 25px;
}

.send-footer p {
    color: var(--muted);
    font-size: 14px;
}

.modal {
    width: min(95vw, 480px);
    padding: 30px;
    border: none;
    border-radius: 14px;
    box-shadow: 0 15px 60px #0f172a44;
}

.modal::backdrop {
    background: #0f172a88;
}

.modal p {
    line-height: 1.6;
}

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 20;
    padding: 15px 20px;
    border-radius: 8px;
    background: #1e293b;
    color: white;
}

@media (max-width: 1100px) {
    .sidebar {
        width: 215px;
    }

    .main {
        margin-left: 215px;
    }

    .workspace {
        padding: 25px;
    }

    .detail-layout {
        grid-template-columns: 1fr;
    }
}

/* ========================================
   ERRORES DE ETIQUETA
======================================== */

.status-pendiente {
    background: #fef3c7;
    color: #92400e;
}

.status-mensaje {
    background: #dbeafe;
    color: #1d4ed8;
}

.status-buenos_aires {
    background: #ede9fe;
    color: #6d28d9;
}

.status-finalizado {
    background: #dcfce7;
    color: #166534;
}

.tracking-list {
    margin-top: 18px;
    border-left: 3px solid #bfdbfe;
    padding-left: 16px;
}

.tracking-item {
    padding: 10px 0;
    color: #475569;
}

.hint {
    margin: 16px 0;
    font-size: 14px;
    line-height: 1.6;
    color: #64748b;
}

.actions-wrap {
    flex-wrap: wrap;
}


/* ========================================
   EXPOYER - ACCESO PRIVADO (BETA 0.7)
======================================== */

.auth-gate {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
    background: #f4f6f9;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 36px;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    background: white;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.auth-brand {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin-bottom: 18px;
    border-radius: 12px;
    background: #2563eb;
    color: white;
    font-size: 27px;
    font-weight: 700;
}

.auth-card h1 {
    margin-bottom: 8px;
    font-size: 28px;
}

.auth-card p {
    margin-bottom: 22px;
    color: #64748b;
}

.auth-card form {
    display: grid;
    gap: 12px;
}

.auth-card label {
    font-size: 14px;
    font-weight: 600;
}

.auth-card input {
    width: 100%;
    padding: 13px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
}

.auth-card button {
    margin-top: 10px;
}

.auth-card .auth-error {
    margin: 16px 0 0;
    color: #b91c1c;
    font-size: 14px;
}

[hidden] {
    display: none !important;
}

#logoutButton {
    margin-left: 14px;
    white-space: nowrap;
}

/* EXPOYER - ESTADO DE SINCRONIZACIÓN */
.cloud-status {
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #155e75;
    background: #ecfeff;
    border-radius: 8px;
}
.cloud-status[data-state="busy"] {
    color: #854d0e;
    background: #fef9c3;
}
.cloud-status[data-state="error"] {
    color: #991b1b;
    background: #fee2e2;
}

/* ========================================
    EXPOYER - ADAPTACIÓN INICIAL PARA CELULAR
======================================== */
#mobileMenuToggle {
    display: none;
    border: 0;
    border-radius: 8px;
    background: #eff6ff;
    color: #1d4ed8;
    padding: 10px 13px;
    font-size: 22px;
}

@media (max-width: 800px) {
    .sidebar {
        z-index: 110;
        width: min(280px, 85vw);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    #mobileSidebarOverlay:not([hidden]) {
        position: fixed;
        inset: 0;
        z-index: 105;
        background: rgba(15, 23, 42, 0.5);
    }

    #mobileMenuToggle {
        display: block;
    }

    .main {
        margin-left: 0;
        width: 100%;
    }

    .topbar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 12px;
    }

    .search {
        order: 3;
        width: 100%;
        max-width: none;
    }

    .search input {
        min-width: 0;
        flex: 1;
    }

    #logoutButton {
        margin-left: auto;
        padding: 9px;
        font-size: 12px;
    }

    .cloud-status {
        font-size: 11px;
    }

    .workspace {
        padding: 16px 12px;
    }

    .home-grid,
    .two-col,
    .detail-layout,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .home-card {
        min-height: 135px;
    }

    .panel,
    .form-narrow,
    .form-narrow-wide {
        max-width: 100%;
        min-width: 0;
    }

    .heading-row,
    .toolbar,
    .actions {
        flex-wrap: wrap;
    }

    .location {
        gap: 4px;
    }

    .location select,
    .location input {
        width: 15%;
        min-width: 0;
        padding: 9px 4px;
    }

    .table-scroll {
        overflow-x: auto;
    }

    .modal {
        width: min(95vw, 500px);
    }
}
