:root {
    --canvas: #f8f5f2;
    --paper: #ffffff;
    --ink: #2b2520;
    --muted: #70655c;
    --line: #e6ddd6;
    --primary: #693f2d;
    --primary-dark: #4e2d20;
    --accent: #d8ab78;
    --danger: #a72d2d;
    --success: #17633e;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
a { color: var(--primary); font-weight: 650; text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--primary-dark); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
small { display: block; color: var(--muted); margin-top: .25rem; }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); letter-spacing: -.03em; margin-bottom: 0; }
h2 { font-size: 1.1rem; margin-bottom: 1rem; }

.skip-link { position: fixed; left: -999rem; top: .5rem; z-index: 10; background: var(--paper); padding: .75rem; }
.skip-link:focus { left: .5rem; }
.site-header { background: var(--ink); color: #fff; box-shadow: 0 2px 12px #2b252033; }
.header-inner { max-width: 1240px; min-height: 4.5rem; padding: .75rem 1.25rem; margin: auto; display: flex; align-items: center; gap: 1.25rem; }
.brand { color: #fff; font-size: 1.2rem; text-decoration: none; white-space: nowrap; }
.brand span { color: var(--accent); }
.brand-logo { border-radius: .25rem; display: inline-block; height: 2.25rem; margin-right: .55rem; max-width: 10rem; object-fit: contain; vertical-align: middle; width: auto; }
.site-nav { display: flex; gap: 1rem; flex: 1; }
.site-nav a { color: #f7eee7; text-decoration: none; padding: .5rem 0; }
.site-nav a:hover { color: var(--accent); }
.account { display: flex; align-items: center; gap: .75rem; font-size: .85rem; color: #e7dbd2; }
.account form, .actions form, .action-panel form { display: inline; margin: 0; }
.nav-toggle { display: none; color: #fff; background: transparent; border: 1px solid #ffffff80; border-radius: .35rem; padding: .4rem .65rem; }
.link-button { appearance: none; border: 0; padding: 0; background: transparent; color: var(--primary); font-weight: 650; text-decoration: underline; text-underline-offset: 2px; }
.account .link-button { color: var(--accent); }
.danger { color: var(--danger); }
.page-shell { max-width: 1240px; padding: 2rem 1.25rem 3rem; margin: auto; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 1.5rem; }
.eyebrow { color: var(--primary); font-size: .8rem; font-weight: 800; letter-spacing: .1em; margin-bottom: .3rem; text-transform: uppercase; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: .8rem; box-shadow: 0 4px 18px #2b25200b; padding: clamp(1rem, 3vw, 1.5rem); margin-bottom: 1.25rem; }
.panel-heading { display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.panel-heading h2 { margin: 0; }
.stat-grid { display: grid; gap: 1rem; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 1.25rem; }
.stat-card { background: var(--paper); border: 1px solid var(--line); border-radius: .8rem; padding: 1.2rem; }
.stat-card span { display: block; color: var(--muted); font-size: .9rem; }
.stat-card strong { display: block; color: var(--primary); font-size: 1.75rem; margin-top: .35rem; }
.button { border: 1px solid transparent; border-radius: .4rem; display: inline-flex; align-items: center; justify-content: center; min-height: 2.5rem; padding: .55rem .9rem; text-decoration: none; white-space: nowrap; }
.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-dark); color: #fff; }
.button-secondary { background: #fff; border-color: #b7a79c; color: var(--primary-dark); }
.button-secondary:hover { background: #f5eee8; color: var(--primary-dark); }
.button-danger { background: var(--danger); color: #fff; }
.button-danger:hover { background: #7d2020; color: #fff; }
.button-block { width: 100%; }
.button-group, .form-actions, .action-panel { display: flex; gap: .7rem; flex-wrap: wrap; }
.alert { border-radius: .5rem; border: 1px solid; margin: 0 0 1rem; padding: .8rem 1rem; }
.alert ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.alert-success { color: #0d4b2d; border-color: #a3d7bb; background: #e7f7ed; }
.alert-error { color: #7f1e1e; border-color: #e7adad; background: #fff0f0; }
.search-form { display: flex; gap: .65rem; margin-bottom: 1.25rem; }
.inline-form { align-items: end; display: flex; gap: .7rem; }
.search-form input { flex: 1; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; min-width: 650px; width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: .8rem .7rem; text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .77rem; letter-spacing: .04em; text-transform: uppercase; }
td small { max-width: 21rem; }
.actions { white-space: nowrap; display: flex; gap: .65rem; align-items: center; }
.low-stock { color: var(--danger); font-weight: 800; }
.status { border-radius: 999px; display: inline-block; font-size: .75rem; font-weight: 800; padding: .28rem .55rem; }
.status-confirmado { background: #dff5e8; color: #0d5d36; }
.status-cancelado { background: #fce4e4; color: #8e2828; }
.status-borrador, .status-pendiente { background: #eef0f3; color: #3d4450; }
.status-activo { background: #e1ecfb; color: #1d4f91; }
.status-en-mora, .status-vencido { background: #fdf0d8; color: #8a5a00; }
.status-liquidado, .status-pagado { background: #dff5e8; color: #0d5d36; }
.empty-state { color: var(--muted); padding: 1.5rem 0; text-align: center; }
.stacked-form { display: grid; gap: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.field { display: grid; gap: .4rem; }
.field-wide { grid-column: 1 / -1; }
label, legend { color: #433931; font-size: .9rem; font-weight: 750; }
input, select, textarea { background: #fff; border: 1px solid #bfb1a6; border-radius: .35rem; color: var(--ink); padding: .62rem .68rem; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px #693f2d21; outline: 0; }
textarea { resize: vertical; }
.checkbox-field { align-items: center; display: flex; gap: .55rem; margin-top: 1.5rem; }
.checkbox-field input { height: 1rem; width: 1rem; }
.pagination { display: flex; flex-wrap: wrap; gap: .35rem; list-style: none; margin: 1rem 0 0; padding: 0; }
.pagination li a, .pagination li span { border: 1px solid var(--line); border-radius: .3rem; display: block; padding: .35rem .6rem; text-decoration: none; }
.pagination .active a { background: var(--primary); color: #fff; }
.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.money-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem 2rem; margin: 1.25rem 0 0 auto; max-width: 34rem; }
.money-summary div { border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; }
.money-summary dd, .money-summary dt { margin: 0; }
.money-summary .emphasis { color: var(--primary); font-size: 1.05rem; font-weight: 800; }
.notes { border-top: 1px solid var(--line); margin: 1.25rem 0 0; padding-top: 1rem; }
.order-lines { border: 1px solid var(--line); border-radius: .5rem; margin: 0; padding: 1rem; }
.order-lines legend { padding: 0 .3rem; }
.order-line { align-items: end; border-bottom: 1px solid var(--line); display: grid; gap: .75rem; grid-template-columns: minmax(12rem, 1fr) 6rem 8rem 10rem 7rem 2.5rem; padding: .75rem 0; }
.order-line:last-child { margin-bottom: .75rem; }
.line-total { padding: .62rem 0; text-align: right; white-space: nowrap; }
.icon-button { background: transparent; border: 1px solid #bfb1a6; border-radius: .35rem; color: var(--danger); font-size: 1.4rem; height: 2.6rem; line-height: 1; padding: 0; width: 2.5rem; }
.totals-inputs { margin-top: 1rem; }
.order-summary { background: #f7eee7; border-radius: .5rem; display: grid; gap: .5rem; grid-template-columns: repeat(5, 1fr); margin-top: 1rem; padding: 1rem; }
.order-summary span { color: var(--muted); display: grid; font-size: .82rem; gap: .2rem; }
.order-summary strong { color: var(--ink); font-size: 1rem; }
.auth-page { align-items: center; background: linear-gradient(140deg, #e9ddd1, #f8f5f2 60%); display: flex; justify-content: center; min-height: 100vh; padding: 1.25rem; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: .85rem; box-shadow: 0 18px 55px #2b252026; max-width: 27rem; padding: 2.2rem; text-align: center; width: 100%; }
.auth-card .stacked-form { margin-top: 1.5rem; text-align: left; }
.auth-card h1 { margin: .7rem 0 .3rem; }
.brand-mark { align-items: center; background: var(--primary); border-radius: .75rem; color: #fff; display: inline-flex; font-family: Georgia, serif; font-size: 2rem; font-weight: bold; height: 3.4rem; justify-content: center; width: 3.4rem; }
.auth-logo { display: block; height: 4rem; margin: 0 auto; max-width: 14rem; object-fit: contain; width: auto; }
.logo-preview { align-items: center; display: flex; gap: 1rem; }
.logo-preview img { border: 1px solid var(--line); border-radius: .5rem; height: 5rem; max-width: 15rem; object-fit: contain; padding: .35rem; width: auto; }
.category-list { display: grid; gap: .55rem; margin-bottom: 1rem; }
.category-list > div { align-items: center; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; padding: .55rem 0; }
.category-list form { margin: 0; }
.image-fieldset { border: 1px solid var(--line); border-radius: .5rem; margin: 0; padding: 1rem; }
.image-fieldset legend { padding: 0 .3rem; }
.product-gallery { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); margin-top: 1rem; }
.product-gallery figure { margin: 0; }
.product-gallery img { aspect-ratio: 4 / 3; border: 1px solid var(--line); border-radius: .5rem; display: block; object-fit: cover; width: 100%; }
.product-gallery figcaption { align-items: center; display: flex; font-size: .82rem; justify-content: space-between; padding-top: .35rem; }
.product-gallery form { margin: 0; }
.product-thumbnail { border: 1px solid var(--line); border-radius: .35rem; height: 3.5rem; object-fit: cover; width: 4.5rem; }
.muted { color: var(--muted); }
.sr-only { height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; clip: rect(0, 0, 0, 0); }

@media (max-width: 880px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .account span { display: none; }
    .order-summary { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 680px) {
    .header-inner { flex-wrap: wrap; }
    .nav-toggle { display: block; margin-left: auto; }
    .site-nav { display: none; flex-basis: 100%; flex-direction: column; gap: 0; order: 4; }
    .site-nav.is-open { display: flex; }
    .site-nav a { border-top: 1px solid #ffffff22; }
    .account { margin-left: auto; }
    .page-shell { padding: 1.25rem .85rem 2rem; }
    .page-heading { align-items: start; flex-direction: column; }
    .form-grid, .details-grid { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
    .checkbox-field { margin-top: 0; }
    .inline-form { align-items: stretch; flex-direction: column; }
    .order-line { grid-template-columns: minmax(0, 1fr) 5.5rem 2.5rem; }
    .order-line .product-field { grid-column: 1 / -1; }
    .order-line .price-field, .order-line .line-discount-field { grid-column: 1 / 3; }
    .line-total { text-align: left; }
    .order-summary { grid-template-columns: repeat(2, 1fr); }
    .money-summary { grid-template-columns: 1fr; }
    .search-form { align-items: stretch; flex-direction: column; }
}
