:root {
    --bg: #f3efe6;
    --bg-deep: #e7e0d2;
    --ink: #1c2421;
    --muted: #5c6a64;
    --line: #c9c0b0;
    --card: #fbf8f1;
    --accent: #0f6b5c;
    --accent-dark: #0a4f44;
    --danger: #9b2c2c;
    --ok: #1f6b3a;
    --warn: #8a5a12;
    --shadow: 0 12px 30px rgba(28, 36, 33, 0.08);
    --radius: 14px;
    --font: "Roboto", sans-serif;
    --display: "Roboto", sans-serif;
}

* { box-sizing: border-box; }

html {
    font-size: 14px;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 0.9286rem; /* ~13px */
    line-height: 1.45;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(15, 107, 92, 0.08), transparent 28%),
        linear-gradient(160deg, #f7f3ea 0%, #ebe3d4 55%, #e4ddd0 100%);
    min-height: 100vh;
}

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.5rem;
    background: rgba(28, 36, 33, 0.94);
    color: #f7f3ea;
    position: sticky;
    top: 0;
    z-index: 200;
    overflow: visible;
    backdrop-filter: blur(8px);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-family: var(--display);
    font-weight: 700;
}

.brand-mark {
    width: 1.85rem;
    height: 1.85rem;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--accent);
    font-size: 0.75rem;
}

.topbar-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    overflow: visible;
}

.topbar-nav a,
.nav-drop-btn {
    color: #d8d2c6;
    padding: 0.4rem 0.65rem;
    border-radius: 999px;
    text-decoration: none;
    font: inherit;
    font-size: 0.82rem;
    background: transparent;
    border: none;
    cursor: pointer;
}

.topbar-nav a:hover,
.topbar-nav a.is-active,
.nav-drop-btn:hover,
.nav-drop-btn.is-active,
.nav-drop.is-current > .nav-drop-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.topbar-nav .nav-logout {
    color: #f0b4b4;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.nav-drop {
    position: relative;
    overflow: visible;
}

.nav-drop-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.nav-caret {
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    opacity: 0.7;
}

.nav-drop-menu {
    display: none;
    position: absolute;
    top: calc(100% - 2px);
    left: 0;
    min-width: 230px;
    padding: 0.5rem 0.4rem 0.4rem;
    margin: 0;
    background: #1c2421;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.28);
    z-index: 300;
}

.nav-drop.is-open > .nav-drop-menu {
    display: grid;
    gap: 0.15rem;
}

.nav-drop-menu a {
    display: block;
    border-radius: 8px;
    white-space: nowrap;
}

.nav-drop-menu a:hover,
.nav-drop-menu a.is-active,
.nav-drop-menu a:focus {
    background: rgba(15, 107, 92, 0.45);
    color: #fff;
    outline: none;
}

.page {
    width: min(1120px, calc(100% - 2rem));
    margin: 1.5rem auto 3rem;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.page-head h1 {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(1.2rem, 2vw, 1.45rem);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.page-head p {
    margin: 0.35rem 0 0;
    color: var(--muted);
    font-size: 0.857rem;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.15rem 1.25rem;
    margin-bottom: 1rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}

.stat {
    padding: 1rem 1.1rem;
}

.stat .label {
    color: var(--muted);
    font-size: 0.75rem;
}

.stat .value {
    font-family: var(--display);
    font-size: 1.25rem;
    margin-top: 0.25rem;
    font-weight: 700;
}

.is-negative {
    color: var(--danger);
}

.stat .value.is-negative,
.stat .value .is-negative {
    color: var(--danger);
}

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.857rem;
}

th, td {
    text-align: left;
    padding: 0.75rem 0.6rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

tr:hover td { background: rgba(15, 107, 92, 0.04); }

.item-group-row td {
    background: rgba(15, 107, 92, 0.08);
    border-bottom-color: rgba(15, 107, 92, 0.18);
    padding-top: 0.85rem;
    padding-bottom: 0.85rem;
}

.item-group-row:hover td {
    background: rgba(15, 107, 92, 0.1);
}

.item-lot-row td.lot-indent {
    padding-left: 1.5rem;
}

.item-lot-row td {
    color: var(--ink);
}

.transfer-lines-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.55rem;
}

.transfer-lines {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.transfer-blocks {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.transfer-block {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.75rem;
    background: rgba(15, 107, 92, 0.03);
}

.transfer-block-head {
    display: flex;
    align-items: flex-end;
    gap: 0.65rem;
    margin-bottom: 0.65rem;
}

.transfer-block-item {
    flex: 1;
    min-width: 0;
}

.transfer-block-head > .btn {
    margin-bottom: 0.05rem;
}

.transfer-stock-wrap {
    margin: 0;
}

.transfer-stock-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.transfer-stock-table th,
.transfer-stock-table td {
    padding: 0.45rem 0.5rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.transfer-stock-table th:last-child,
.transfer-stock-table td:last-child {
    width: 9.5rem;
}

.transfer-stock-table input[type="number"] {
    width: 100%;
    max-width: 8.5rem;
}

.transfer-stock-empty {
    margin: 0;
    font-size: 0.85rem;
}

.transfer-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 140px auto;
    gap: 0.55rem;
    align-items: start;
    padding: 0.65rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(15, 107, 92, 0.03);
}

.transfer-line-item-first {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.95fr) minmax(0, 0.95fr) 110px auto;
}

.purchase-line {
    grid-template-columns: minmax(0, 1.4fr) 120px 130px auto;
}

.reception-line {
    grid-template-columns: minmax(0, 1.4fr) 140px auto;
}

.modal-dialog-remision {
    width: min(1240px, calc(100% - 1.5rem));
    max-width: 1240px;
}

.reception-remision-wrap {
    max-height: min(52vh, 420px);
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
}

.reception-remision-table {
    min-width: 1080px;
    margin: 0;
}

.reception-remision-table th,
.reception-remision-table td {
    vertical-align: middle;
    white-space: nowrap;
    font-size: 0.82rem;
    padding: 0.4rem 0.35rem;
}

.reception-remision-table thead th {
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 1;
}

.reception-remision-table input,
.reception-remision-table select {
    width: 100%;
    min-width: 0;
    font-size: 0.82rem;
    padding: 0.35rem 0.4rem;
}

.reception-remision-table td:nth-child(1) { min-width: 130px; }
.reception-remision-table td:nth-child(2),
.reception-remision-table td:nth-child(3),
.reception-remision-table td:nth-child(4) { min-width: 88px; }
.reception-remision-table td:nth-child(5) { min-width: 72px; }
.reception-remision-table td:nth-child(6),
.reception-remision-table td:nth-child(7),
.reception-remision-table td:nth-child(8),
.reception-remision-table td:nth-child(9),
.reception-remision-table td:nth-child(10) { min-width: 78px; }
.reception-remision-table td:nth-child(11) { min-width: 70px; }

.reception-line-remove {
    padding-top: 0;
    text-align: center;
}

.reception-remision-table tfoot td {
    font-weight: 600;
    border-top: 1px solid var(--line);
}

.transfer-line input.is-readonly,
input.is-readonly {
    background: var(--bg-deep);
    color: var(--ink);
    cursor: default;
}

.transfer-line-remove {
    padding-top: 1.45rem;
}

@media (max-width: 700px) {
    .transfer-line,
    .transfer-line-item-first,
    .purchase-line {
        grid-template-columns: 1fr;
    }
    .transfer-line-remove {
        padding-top: 0;
    }
}


.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    border: none;
    border-radius: 10px;
    padding: 0.65rem 1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    background: var(--accent);
    color: #fff;
}

.btn > i {
    font-size: 0.92em;
    line-height: 1;
    width: 1em;
    text-align: center;
}

.btn:hover {
    background: var(--accent-dark);
    text-decoration: none;
    color: #fff;
}

.btn-secondary {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
}

.btn-secondary:hover {
    background: var(--bg-deep);
    color: var(--ink);
}

.btn-danger {
    background: var(--danger);
}

.btn-sm {
    padding: 0.35rem 0.6rem;
    font-size: 0.785rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem 1rem;
}

.form-grid .full { grid-column: 1 / -1; }

.label-like {
    display: block;
    font-size: 0.785rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.perm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.45rem 0.8rem;
}

.perm-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.857rem;
    font-weight: 500;
    margin-bottom: 0;
    cursor: pointer;
    min-height: 2.35rem;
}

.perm-item input,
.perm-item input[type="checkbox"] {
    width: 1.05rem;
    height: 1.05rem;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.form-grid .field-check .label-like {
    margin-bottom: 0.35rem;
}

.readonly-value {
    display: flex;
    align-items: center;
    min-height: 2.35rem;
    padding: 0.55rem 0.7rem;
    border: 1px dashed var(--line);
    border-radius: 10px;
    background: var(--bg-deep, #f4f6f5);
    font-size: 0.857rem;
    font-weight: 600;
}

.topbar-user {
    color: #a8b0aa;
    font-size: 0.72rem;
    padding: 0.45rem 0.5rem;
}

label {
    display: block;
    font-size: 0.785rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
    font: inherit;
    font-size: 0.857rem;
    background: #fff;
    color: var(--ink);
}

textarea { min-height: 90px; resize: vertical; }

input:focus, select:focus, textarea:focus {
    outline: 2px solid rgba(15, 107, 92, 0.25);
    border-color: var(--accent);
}

.form-actions {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.flash {
    padding: 0.85rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.flash-ok {
    background: #e8f6ec;
    color: var(--ok);
    border-color: #b7dfc3;
}

.flash-error {
    background: #fdecec;
    color: var(--danger);
    border-color: #f0c2c2;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--bg-deep);
    color: var(--muted);
}

.badge-ok { background: #e8f6ec; color: var(--ok); }
.badge-warn { background: #fff3dd; color: var(--warn); }
.badge-muted { background: #eceae4; color: var(--muted); }

.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.login-card {
    width: min(420px, 100%);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 2rem 1.6rem;
}

.login-card h1 {
    margin: 0 0 0.35rem;
    font-family: var(--display);
    font-size: 1.35rem;
    font-weight: 700;
}

.login-card .sub {
    color: var(--muted);
    margin: 0 0 1.4rem;
    font-size: 0.857rem;
}

.muted { color: var(--muted); }
.stack { display: grid; gap: 0.85rem; }
.inline-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.section-title {
    margin: 0 0 0.75rem;
    font-family: var(--display);
    font-size: 1rem;
    font-weight: 700;
}

.empty {
    color: var(--muted);
    padding: 0.5rem 0;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.modal-quick {
    z-index: 130;
}

.field-with-add {
    display: flex;
    gap: 0.4rem;
    align-items: stretch;
}

.field-with-add select,
.field-with-add input {
    flex: 1;
    min-width: 0;
}

.btn-plus {
    flex: 0 0 2.35rem;
    width: 2.35rem;
    padding: 0;
    font-size: 1.15rem;
    line-height: 1;
    font-weight: 600;
}

.config-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

a.config-card {
    color: inherit;
    text-decoration: none;
    display: block;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

a.config-card:hover {
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.config-card h2 {
    margin: 0 0 0.4rem;
    font-family: var(--display);
    font-size: 1rem;
    font-weight: 700;
}

.config-card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.modal[hidden] {
    display: none !important;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(28, 36, 33, 0.55);
    backdrop-filter: blur(3px);
}

.modal-dialog {
    position: relative;
    z-index: 1;
    width: min(560px, 100%);
    max-height: calc(100vh - 2rem);
    overflow: auto;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 24px 48px rgba(28, 36, 33, 0.22);
    padding: 1.25rem 1.3rem 1.4rem;
}

.modal-dialog-wide {
    width: min(980px, calc(100% - 2rem));
    max-width: 980px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.modal-close {
    border: none;
    background: transparent;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    padding: 0.15rem 0.4rem;
    border-radius: 8px;
}

.modal-close:hover {
    background: var(--bg-deep);
    color: var(--ink);
}

body.modal-open {
    overflow: hidden;
}

.filters-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem 1rem;
    align-items: end;
    margin: 0 0 1rem;
    padding: 0.9rem 1rem;
    background: rgba(251, 248, 241, 0.85);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.filters-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.empty-guide {
    padding: 0.85rem 0.2rem;
    color: var(--muted);
}

.empty-guide strong {
    display: block;
    color: var(--ink);
    margin-bottom: 0.25rem;
}

.empty-guide p {
    margin: 0 0 0.65rem;
}

.stat-action {
    margin: 0.45rem 0 0;
    font-size: 0.75rem;
}

.stat-action a {
    color: var(--accent-dark);
}

.doc-codes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1rem;
    margin: 0.55rem 0 0;
    font-size: 0.75rem;
}

.doc-codes span {
    white-space: nowrap;
}

.nav-toggle {
    display: none;
    border: 1px solid rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.08);
    color: #fff;
    border-radius: 10px;
    width: 2.25rem;
    height: 2.25rem;
    font-size: 1.05rem;
    cursor: pointer;
}

code {
    font-size: 0.85em;
    background: var(--bg-deep);
    padding: 0.1rem 0.35rem;
    border-radius: 6px;
}

@media (max-width: 980px) {
    .topbar {
        flex-wrap: wrap;
    }
    .nav-toggle {
        display: inline-grid;
        place-items: center;
        margin-left: auto;
    }
    .topbar-nav {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
        padding-top: 0.5rem;
    }
    .topbar-nav.is-open {
        display: flex;
    }
    .nav-drop-menu {
        position: static;
        box-shadow: none;
        border: none;
        background: rgba(255,255,255,0.06);
        margin: 0.2rem 0 0.4rem;
        border-radius: 10px;
    }
    .nav-drop.is-open .nav-drop-menu {
        display: grid;
    }
    .topbar-user {
        order: 20;
    }
}

@media (max-width: 800px) {
    .grid-2, .grid-3, .form-grid {
        grid-template-columns: 1fr;
    }
    .page-head {
        flex-direction: column;
        align-items: start;
    }
}
