:root {
    --green: #168300;
    --green-dark: #0c5f08;
    --green-soft: #eaf5e7;
    --yellow: #f6c514;
    --yellow-soft: #fff8d9;
    --brown: #68451f;
    --brown-soft: #f4eee7;
    --ink: #25291f;
    --muted: #6e766a;
    --line: #dfe6da;
    --bg: #f3f6ef;
    --white: #ffffff;
    --red: #bd4545;
    --blue: #2d67a8;
    --shadow: 0 12px 34px rgba(39, 62, 30, .075);
    --shadow-soft: 0 5px 18px rgba(39, 62, 30, .055);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    background:
        radial-gradient(circle at 8% 0%, rgba(246,197,20,.10), transparent 26rem),
        radial-gradient(circle at 96% 8%, rgba(22,131,0,.08), transparent 28rem),
        var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .58; cursor: wait; }
a { color: inherit; }

.app-shell { width: min(1640px, calc(100% - 30px)); margin: 22px auto 60px; }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 26px;
    padding: 22px 24px;
    border-radius: 22px;
    background: rgba(255,255,255,.94);
    box-shadow: var(--shadow);
    border: 1px solid rgba(218,227,213,.9);
    position: relative;
    overflow: hidden;
}
.topbar::after {
    content: '';
    position: absolute;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: rgba(246,197,20,.13);
    right: -76px;
    top: -105px;
    pointer-events: none;
}
.brand-area { display: flex; align-items: center; gap: 18px; min-width: 0; position: relative; z-index: 1; }
.logo-frame {
    width: 120px;
    height: 72px;
    display: grid;
    place-items: center;
    flex: 0 0 120px;
    background: #fff;
    border: 1px solid #e5eadf;
    border-radius: 16px;
    padding: 8px 10px;
    box-shadow: var(--shadow-soft);
}
.brand-logo { display:block; max-width:100%; max-height:100%; object-fit:contain; }
.brand-kicker { font-size: 11px; font-weight: 900; text-transform: uppercase; color: var(--green); letter-spacing: .11em; }
h1 { margin: 3px 0 4px; font-size: clamp(26px, 3vw, 38px); line-height: 1.02; letter-spacing: -.025em; }
.topbar p { margin: 0; color: var(--muted); font-size: 14px; }
.topbar-right { display: grid; justify-items: end; gap: 12px; position: relative; z-index: 1; }
.account-line { display:flex; flex-wrap:wrap; align-items:center; justify-content:flex-end; gap:9px; font-size:12px; }
.account-line a { text-decoration:none; font-weight:750; color:#566051; }
.account-line a:hover { color:var(--green-dark); text-decoration:underline; }
.account-pill { padding:6px 9px; border-radius:999px; background:var(--green-soft); color:var(--green-dark); font-weight:800; }
.sync-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.btn { border: 0; border-radius: 11px; padding: 11px 15px; font-weight: 800; transition: transform .15s ease, background .15s ease, box-shadow .15s ease; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn-light { background: #f0f3ed; color: #41493e; border:1px solid #e1e6dd; }
.btn-light:hover { background: #e7ece4; }
.btn-primary { background: var(--green); color: var(--white); box-shadow:0 6px 14px rgba(22,131,0,.18); }
.btn-primary:hover { background: var(--green-dark); }
.btn.active-realtime { background: var(--green-soft); color: var(--green-dark); border-color:#c7e2c1; }

.sync-strip {
    display: flex;
    align-items: center;
    gap: 11px;
    margin: 12px 0 16px;
    padding: 11px 15px;
    background: rgba(255,255,255,.72);
    backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    border-radius: 13px;
    font-size: 12.5px;
}
.sync-copy { display:flex; gap:7px; flex-wrap:wrap; align-items:baseline; }
.sync-strip span { color: var(--muted); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #a9afa6; flex: 0 0 10px; }
.status-dot.working { background: var(--yellow); box-shadow: 0 0 0 5px rgba(246,197,20,.18); }
.status-dot.ok { background: var(--green); box-shadow: 0 0 0 5px rgba(22,131,0,.12); }
.status-dot.error { background: var(--red); box-shadow: 0 0 0 5px rgba(189,69,69,.1); }
.last-sync { margin-left: auto; color: var(--muted); white-space: nowrap; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(145px, 1fr)); gap: 11px; margin-bottom: 14px; }
.kpi {
    min-height: 92px;
    display:flex;
    align-items:center;
    gap:12px;
    background: rgba(255,255,255,.96);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 15px 16px;
}
.kpi-icon {
    width:36px;
    height:36px;
    display:grid;
    place-items:center;
    border-radius:11px;
    background:#eff5ec;
    color:var(--green-dark);
    font-weight:900;
    flex:0 0 36px;
}
.kpi span { display: block; color: var(--muted); font-size: 10px; font-weight: 850; text-transform: uppercase; letter-spacing: .055em; }
.kpi strong { display: block; margin-top: 2px; font-size: 25px; line-height:1.05; }
.kpi small { display:block; margin-top:4px; color:var(--muted); font-size:9px; line-height:1.15; }
.kpi-bought { background:linear-gradient(135deg, #fff, #f0f8ed); }
.kpi-bought .kpi-icon { background:#dff1da; }
.kpi-cost { background: linear-gradient(135deg, #fffdf6, #fff7cf); border-color:#eee2a7; }
.kpi-cost .kpi-icon { background:#ffe991; color:#6a4c00; }
.kpi-cost strong { color:#3d430e; }

.filters-card {
    display: flex;
    gap: 12px;
    align-items: end;
    background: rgba(255,255,255,.95);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    box-shadow:var(--shadow-soft);
}
.filter-field { min-width: 165px; }
.filter-field.grow { flex: 1; min-width: 240px; }
.filter-field label { display:block; margin:0 0 5px 2px; font-size:10px; text-transform:uppercase; letter-spacing:.055em; font-weight:850; color:#66705f; }
.filter-field input, .filter-field select {
    width: 100%;
    height: 42px;
    padding: 0 11px;
    border: 1px solid #d7ded2;
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    outline:none;
}
.filter-field input:focus, .filter-field select:focus { border-color:var(--green); box-shadow:0 0 0 3px rgba(22,131,0,.08); }
.filter-note { margin-left:auto; max-width:280px; color:var(--muted); font-size:11.5px; line-height:1.35; align-self:center; }
.tiny-dot { display:inline-block; width:7px; height:7px; border-radius:50%; background:var(--green); margin-right:6px; }

.legend-card {
    display:flex;
    align-items:center;
    gap:18px;
    flex-wrap:wrap;
    margin:10px 0 16px;
    padding:10px 14px;
    border:1px solid #e4e9df;
    border-radius:13px;
    background:rgba(255,255,255,.58);
    color:#656d61;
    font-size:11px;
}
.legend-check { display:inline-block; width:11px; height:11px; border-radius:3px; margin-right:5px; vertical-align:-1px; }
.legend-check.pending { border:1.5px solid #a6aea1; background:#fff; }
.legend-check.partial { background:var(--yellow); }
.legend-check.bought { background:var(--green); }
.legend-print { margin-left:auto; }

.tables-stack { display:grid; gap:16px; }
.summary-card {
    background: rgba(255,255,255,.97);
    border:1px solid var(--line);
    border-radius:18px;
    box-shadow:var(--shadow);
    overflow:hidden;
}
.section-head {
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:20px;
    padding:16px 18px;
    border-bottom:1px solid var(--line);
    background:linear-gradient(180deg, #ffffff, #fbfcfa);
}
.section-title-row { display:flex; align-items:center; gap:9px; }
.category-mark { width:9px; height:28px; border-radius:9px; background:var(--green); }
.category-arnes_antiescape .category-mark { background:#31865a; }
.category-arnes_antitirones .category-mark { background:#8b672a; }
.category-correa .category-mark { background:#3977a7; }
.category-otros .category-mark { background:#777e73; }
.section-head h2 { margin:0; font-size:20px; letter-spacing:-.01em; }
.section-head p { margin:4px 0 0 18px; color:var(--muted); font-size:11px; }
.section-head-actions { display:flex; align-items:center; gap:12px; }
.section-totals { display:flex; gap:7px; }
.section-total { min-width:82px; padding:7px 10px; border-radius:10px; background:#f1f5ef; text-align:right; }
.section-total strong { display:block; font-size:17px; line-height:1; }
.section-total span { display:block; margin-top:3px; font-size:8.5px; text-transform:uppercase; font-weight:850; letter-spacing:.045em; color:var(--muted); }
.section-total.bought { background:var(--green-soft); }
.section-total.cost { min-width:112px; background:var(--yellow-soft); }
.btn-clear-table {
    border:1px solid #d8dfd4;
    background:#fff;
    color:#5d6559;
    border-radius:9px;
    min-height:34px;
    padding:0 10px;
    font-size:10.5px;
    font-weight:800;
}
.btn-clear-table:hover { border-color:var(--green); color:var(--green-dark); background:#f8fbf7; }

.table-wrap { overflow:auto; width:100%; }
table { width:100%; min-width:1230px; border-collapse:separate; border-spacing:0; }
th, td { border-bottom:1px solid #e9ede6; }
td { padding:11px 12px; font-size:12.5px; vertical-align:middle; background:#fff; transition:background .15s ease, opacity .15s ease; }
tbody tr:last-child td { border-bottom:0; }
tbody tr:hover td { background:#fbfdf9; }
.product-cell { font-weight:800; color:#2e342b; min-width:180px; }
.qty-cell { text-align:center; font-weight:850; font-variant-numeric:tabular-nums; }
.pending-cell { color:var(--green-dark); font-size:14px; }
.money-cell { text-align:right; font-variant-numeric:tabular-nums; white-space:nowrap; }
.total-cost-cell { font-weight:900; color:#384019; }
.cost-missing { color:#9a6b23; font-size:10.5px; font-weight:750; }
.orders-cell { min-width:190px; }
.check-col { width:112px; }
.qty-col { width:86px; }
.money-col { width:120px; }
.size-pill { display:inline-flex; min-width:34px; justify-content:center; padding:4px 7px; border-radius:7px; background:#f1f4ef; font-weight:850; }
.shipping-pill { display:inline-flex; align-items:center; min-width:76px; justify-content:center; padding:5px 8px; border-radius:999px; font-size:10.5px; font-weight:850; }
.shipping-santiago { color:#17620e; background:#eaf5e7; border:1px solid #cbe5c6; }
.shipping-regiones { color:#735010; background:#fff5d5; border:1px solid #f0df9a; }
.order-chip {
    display:inline-flex;
    align-items:center;
    gap:5px;
    margin:2px 3px 2px 0;
    padding:4px 7px;
    border-radius:8px;
    background:#f1f4ef;
    color:#3f493a;
    border:1px solid #e0e6dc;
    font-size:10.5px;
    font-weight:800;
    text-decoration:none;
    white-space:nowrap;
}
a.order-chip:hover { border-color:#91c087; background:#edf7ea; color:var(--green-dark); }
.order-print .print-glyph { font-size:11px; }
.order-bought { opacity:.62; background:#eef5ec; }
.order-partial { background:#fff7d9; border-color:#eddfa8; }

.purchase-toggle { display:flex; flex-direction:column; align-items:center; gap:3px; cursor:pointer; user-select:none; }
.purchase-checkbox { position:absolute; opacity:0; pointer-events:none; }
.purchase-box {
    width:25px;
    height:25px;
    border:2px solid #aeb7aa;
    border-radius:8px;
    background:#fff;
    position:relative;
    transition:.16s ease;
    box-shadow:inset 0 0 0 2px rgba(255,255,255,.7);
}
.purchase-checkbox:focus-visible + .purchase-box { outline:3px solid rgba(22,131,0,.18); outline-offset:2px; }
.purchase-checkbox:checked + .purchase-box { background:var(--green); border-color:var(--green); }
.purchase-checkbox:checked + .purchase-box::after {
    content:'✓';
    position:absolute;
    color:#fff;
    font-weight:950;
    font-size:17px;
    left:4px;
    top:-1px;
}
.purchase-toggle small { font-size:8.5px; font-weight:850; color:#757d71; line-height:1; }
.purchase-comprado td { background:#f4faf2; }
.purchase-comprado .product-cell, .purchase-comprado .size-pill { color:#6b7566; }
.purchase-comprado .pending-cell, .purchase-comprado .total-cost-cell { color:#769170; }
.purchase-parcial td { background:#fffdf4; }

.column-label-row th { padding:0; background:#f7f9f5; position:sticky; top:0; z-index:3; }
.sort-button {
    width:100%;
    min-height:40px;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:8px;
    padding:8px 11px;
    border:0;
    background:transparent;
    color:#60685c;
    font-size:9.5px;
    font-weight:900;
    text-transform:uppercase;
    letter-spacing:.055em;
    text-align:left;
}
.sort-button:hover { background:#eef3eb; color:var(--green-dark); }
.sort-icon { position:relative; width:12px; height:18px; flex:0 0 12px; opacity:.3; }
.sort-icon::before, .sort-icon::after { position:absolute; left:2px; font-size:8px; line-height:1; }
.sort-icon::before { content:'▲'; top:1px; }
.sort-icon::after { content:'▼'; bottom:1px; }
.sort-button.sorted .sort-icon { opacity:1; color:var(--green-dark); }
.sort-button.sorted.asc .sort-icon::after { opacity:.18; }
.sort-button.sorted.desc .sort-icon::before { opacity:.18; }
.column-filter-row th { padding:6px 6px 8px; background:#f7f9f5; border-bottom:1px solid var(--line); }
.column-filter {
    width:100%;
    height:31px;
    min-width:78px;
    padding:0 7px;
    border:1px solid #d7ded2;
    border-radius:7px;
    background:#fff;
    color:var(--ink);
    font-size:10px;
    font-weight:650;
    outline:none;
}
.column-filter:focus { border-color:var(--green); box-shadow:0 0 0 2px rgba(22,131,0,.08); }
.column-filter::placeholder { color:#a2aa9e; font-weight:500; }
.no-table-results { padding:24px 14px; text-align:center; color:var(--muted); font-size:12px; background:#fbfcfa; }

.empty-state { padding:54px 20px; text-align:center; color:var(--muted); }
.empty-state.hidden { display:none; }
.empty-icon { width:54px; height:54px; margin:0 auto 9px; border-radius:50%; display:grid; place-items:center; color:#fff; background:var(--green); font-size:25px; font-weight:900; box-shadow:0 8px 20px rgba(22,131,0,.18); }
.empty-state h2 { color:var(--ink); margin:8px 0 3px; }
.empty-state p { margin:0; }

.toast {
    position:fixed;
    right:20px;
    bottom:20px;
    max-width:380px;
    padding:12px 15px;
    border-radius:12px;
    background:#263322;
    color:#fff;
    box-shadow:0 14px 32px rgba(0,0,0,.18);
    font-size:12px;
    font-weight:750;
    opacity:0;
    transform:translateY(12px);
    pointer-events:none;
    transition:.2s ease;
    z-index:100;
}
.toast.show { opacity:1; transform:translateY(0); }
.toast.ok { border-left:4px solid var(--yellow); }

.panel-notice { margin:0 0 12px; padding:11px 14px; border-radius:11px; font-size:13px; font-weight:750; }
.panel-notice.success { background:#edf8ea; color:var(--green-dark); border:1px solid #cfe8c9; }

/* Acceso / cambio de contraseña */
.auth-body {
    min-height:100vh;
    display:grid;
    place-items:center;
    padding:24px;
    background:
        radial-gradient(circle at 20% 10%, rgba(246,197,20,.14), transparent 24rem),
        radial-gradient(circle at 85% 15%, rgba(22,131,0,.11), transparent 28rem),
        var(--bg);
}
.auth-shell { width:min(100%, 440px); }
.auth-card { background:#fff; border:1px solid var(--line); border-top:6px solid var(--green); border-radius:20px; box-shadow:var(--shadow); padding:30px; }
.auth-logo-wrap { display:flex; justify-content:center; margin:-10px 0 12px; }
.auth-logo { width:190px; height:88px; object-fit:contain; }
.auth-brand { font-size:12px; font-weight:900; text-transform:uppercase; letter-spacing:.09em; color:var(--green); }
.auth-card h1 { margin:7px 0 8px; font-size:30px; }
.auth-intro { margin:0 0 22px; color:var(--muted); line-height:1.5; }
.auth-form { display:grid; gap:15px; }
.auth-form label span { display:block; margin-bottom:6px; font-size:11px; font-weight:850; color:#62685f; text-transform:uppercase; letter-spacing:.04em; }
.auth-form input { width:100%; height:46px; padding:0 12px; border:1px solid #d8ddd5; border-radius:10px; outline:none; background:#fff; }
.auth-form input:focus { border-color:var(--green); box-shadow:0 0 0 3px rgba(22,131,0,.08); }
.auth-submit { width:100%; min-height:46px; margin-top:3px; }
.auth-alert { border-radius:10px; padding:11px 12px; margin-bottom:16px; font-size:13px; line-height:1.4; }
.auth-alert.error { background:#fff0f0; color:#922b2b; border:1px solid #f1caca; }
.auth-alert.success { background:#edf8ea; color:var(--green-dark); border:1px solid #cfe8c9; }
.auth-footnote, .password-rules { color:var(--muted); font-size:12px; line-height:1.45; }
.auth-footnote { margin:18px 0 0; text-align:center; }
.password-rules { margin-top:-5px; }
.auth-link { text-align:center; color:var(--green-dark); font-size:13px; font-weight:750; text-decoration:none; }
.auth-link:hover { text-decoration:underline; }

@media (max-width: 1280px) {
    .kpis { grid-template-columns:repeat(3, 1fr); }
    .topbar { align-items:flex-start; }
    .brand-area { align-items:flex-start; }
}
@media (max-width: 900px) {
    .app-shell { width:min(100% - 18px, 1640px); margin-top:10px; }
    .topbar { flex-direction:column; padding:17px; border-radius:17px; }
    .topbar-right { width:100%; justify-items:start; }
    .account-line, .sync-actions { justify-content:flex-start; }
    .filters-card { flex-wrap:wrap; }
    .filter-note { margin-left:0; max-width:none; width:100%; }
    .legend-print { margin-left:0; }
    .section-head { align-items:flex-start; flex-direction:column; }
    .section-head-actions { width:100%; justify-content:space-between; flex-wrap:wrap; }
}
@media (max-width: 640px) {
    .logo-frame { width:92px; height:58px; flex-basis:92px; }
    .brand-area { gap:11px; }
    .topbar p { font-size:12px; }
    .kpis { grid-template-columns:repeat(2, 1fr); }
    .kpi { min-height:82px; padding:12px; gap:8px; }
    .kpi strong { font-size:21px; }
    .filter-field, .filter-field.grow { width:100%; min-width:100%; }
    .sync-strip { align-items:flex-start; flex-wrap:wrap; }
    .last-sync { margin-left:21px; width:100%; }
    .section-totals { width:100%; }
    .section-total { flex:1; }
    .btn-clear-table { order:2; }
    .auth-body { padding:12px; }
    .auth-card { padding:23px 18px; }
}

.product-details { margin-top:6px; font-size:11px; font-weight:400; line-height:1.45; color:var(--muted); white-space:normal; overflow-wrap:anywhere; }
.product-details strong { font-weight:700; }

.manual-dialog { width:min(94vw, 620px); border:1px solid var(--line); border-radius:18px; padding:24px; color:var(--ink); box-shadow:var(--shadow); max-height:90vh; overflow:auto; }
.manual-dialog::backdrop { background:rgba(25,35,22,.45); }
.manual-header, .manual-footer { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.manual-header h2 { margin:0; font-size:23px; }
.manual-intro { color:var(--muted); font-size:12px; line-height:1.5; margin:12px 0 18px; }
.manual-fields, .manual-attributes { display:grid; gap:14px; }
.manual-attributes:empty { display:none; }
.manual-fields .filter-field { min-width:0; }
.manual-fields .filter-field > span { display:block; font-size:11px; font-weight:800; margin-bottom:6px; }
.manual-fields select:disabled { background:#f1f4ef; color:var(--muted); }
.manual-footer { justify-content:flex-end; margin-top:18px; }
@media (min-width: 641px) {
    .manual-fields { grid-template-columns:repeat(2,minmax(0,1fr)); }
    .manual-fields > .filter-field:first-child { grid-column:1 / -1; }
    .manual-attributes { grid-column:1 / -1; grid-template-columns:repeat(2,minmax(0,1fr)); }
}

.row-actions { display:flex; gap:8px; flex-wrap:wrap; margin-top:8px; }
.row-action { border:1px solid #d7ded2; border-radius:7px; padding:5px 7px; background:#fff; color:var(--green-dark); font-size:10px; font-weight:750; }
.row-action:hover { background:#edf7ea; }
.cancel-manual { color:#922b2b; }
.quantity-action { display:block; margin:7px auto 0; }
#quantity-dialog .filter-field > span, #cancel-dialog .filter-field > span { display:block; font-size:11px; font-weight:800; margin-bottom:7px; }
