:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #1d252d;
    --muted: #687482;
    --line: #dfe5ea;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --danger: #b42318;
    --warning: #b7791f;
    --ok: #137333;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background: var(--bg);
}
a { color: inherit; text-decoration: none; }
small { display: block; color: var(--muted); margin-top: 3px; }

.app-shell {
    display: grid;
    grid-template-columns: 250px 1fr;
    min-height: 100vh;
}
.sidebar {
    background: #16212b;
    color: #eef4f5;
    padding: 22px 16px;
}
.brand {
    display: block;
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 24px;
}
.sidebar nav {
    display: grid;
    gap: 10px;
}
.sidebar a:not(.brand) {
    border-radius: 8px;
    color: #cbd5df;
    padding: 9px 12px;
}
.sidebar a.active,
.sidebar a:hover {
    background: rgba(255,255,255,.1);
    color: #fff;
}
.menu-group {
    border-bottom: 1px solid rgba(255,255,255,.08);
    padding-bottom: 8px;
}
.menu-group:last-child { border-bottom: 0; }
.menu-group summary {
    align-items: center;
    color: #f8fbfc;
    cursor: pointer;
    display: flex;
    font-size: 12px;
    font-weight: 700;
    justify-content: space-between;
    letter-spacing: .04em;
    list-style: none;
    padding: 7px 4px;
    text-transform: uppercase;
}
.menu-group summary::-webkit-details-marker { display: none; }
.menu-group summary::after {
    border-bottom: 2px solid currentColor;
    border-right: 2px solid currentColor;
    content: "";
    height: 7px;
    transform: rotate(45deg);
    transition: transform .15s ease;
    width: 7px;
}
.menu-group[open] summary::after {
    transform: rotate(225deg);
}
.submenu {
    display: grid;
    gap: 3px;
    margin-top: 2px;
}
.submenu a {
    font-size: 14px;
    margin-left: 4px;
}
.main { padding: 24px; min-width: 0; }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}
.topbar h1 { margin: 0; font-size: 26px; }
.topbar p { margin: 4px 0 0; color: var(--muted); }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 18px;
}
.panel h2 { margin: 0 0 14px; font-size: 18px; }
.panel h3 { margin: 18px 0 10px; font-size: 15px; }
.narrow { max-width: 900px; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.form-list { grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); align-items: start; }
.grid.compact { gap: 12px; }
.section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
}
.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.metrics.stacked { grid-template-columns: 1fr; }
.metrics article {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}
.metrics span { color: var(--muted); font-size: 13px; }
.metrics strong { display: block; margin-top: 8px; font-size: 24px; }
.product-detail-grid { grid-template-columns: minmax(280px, 420px) minmax(0, 1fr); align-items: start; }
.product-detail-photo img,
.image-placeholder {
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 7px;
    background: #eef2f5;
}
.product-detail-photo img { display: block; object-fit: cover; }
.image-placeholder {
    align-items: center;
    color: var(--muted);
    display: flex;
    font-weight: 700;
    justify-content: center;
}
.product-detail-info > .section-head p {
    color: var(--muted);
    margin: 5px 0 0;
}
.product-description {
    border-bottom: 1px solid var(--line);
    margin-bottom: 16px;
    padding-bottom: 12px;
}
.product-description p { color: #344150; line-height: 1.55; margin: 0; }
.product-metrics { margin-bottom: 0; }
.product-metrics article { padding: 13px; }
.product-metrics strong { font-size: 18px; }
.product-form-panel .section-head,
.entity-form-panel .section-head {
    align-items: center;
}
.product-form-panel .section-head p,
.entity-form-panel .section-head p {
    color: var(--muted);
    margin: 5px 0 0;
}
.product-form-grid,
.entity-form-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
.product-form-grid .field-wide { grid-column: span 2; }
.product-form-grid .field-photo { grid-column: span 2; }
.entity-form-grid.lower {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 12px;
}
.current-photo {
    align-items: center;
    color: var(--muted);
    display: flex;
    gap: 10px;
    margin-top: 12px;
}
.form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
}
.product-thumb {
    border: 1px solid var(--line);
    border-radius: 7px;
    display: block;
    height: 58px;
    object-fit: cover;
    width: 58px;
}
.product-thumb.large {
    height: 76px;
    width: 76px;
}
.product-thumb.placeholder {
    align-items: center;
    background: #eef2f5;
    color: var(--muted);
    display: flex;
    font-size: 11px;
    font-weight: 700;
    justify-content: center;
    line-height: 1.15;
    text-align: center;
}
.product-table th:first-child,
.product-table td:first-child {
    width: 78px;
}

label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
    color: #344150;
}
input, select, textarea {
    width: 100%;
    border: 1px solid #cdd6df;
    border-radius: 7px;
    color: var(--text);
    font: inherit;
    padding: 10px 11px;
    background: #fff;
}
textarea { min-height: 84px; resize: vertical; }
.searchable-select {
    display: grid;
    gap: 6px;
    min-width: 0;
    width: 100%;
}
.searchable-select input[type="search"] {
    background: #f8fafb;
}
.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}
.check input { width: auto; }
.filters, .inline-form {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.filters input { min-width: 220px; }
.inline-form input, .inline-form select { width: auto; min-width: 150px; }
.inline-form .searchable-select {
    width: min(320px, 100%);
}
.inline-form .searchable-select select,
.inline-form .searchable-select input {
    width: 100%;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--brand);
    border-radius: 7px;
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    line-height: 1;
    min-height: 39px;
    padding: 10px 14px;
}
.button:hover { background: var(--brand-dark); }
.button.ghost {
    background: #fff;
    color: var(--brand);
}
.button.ghost:hover { background: #eef7f6; }
.button.tiny {
    min-height: 30px;
    padding: 7px 9px;
    font-size: 12px;
}
.button.full { width: 100%; }
.button.danger {
    background: var(--danger);
    border-color: var(--danger);
}
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #f8fafb; }
.entity-modal {
    border: 0;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(22, 33, 43, .22);
    color: var(--text);
    max-width: min(620px, calc(100vw - 28px));
    padding: 0;
    width: 100%;
}
.entity-modal::backdrop {
    background: rgba(22, 33, 43, .42);
}
.modal-head {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 16px 18px;
}
.modal-head h2 {
    font-size: 20px;
    margin: 0;
}
.modal-close {
    align-items: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 7px;
    cursor: pointer;
    display: inline-flex;
    font-weight: 700;
    height: 34px;
    justify-content: center;
    width: 34px;
}
.detail-list {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 16px 18px;
}
.detail-list div {
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 4px;
    padding-bottom: 10px;
}
.detail-list div:last-child { border-bottom: 0; padding-bottom: 0; }
.detail-list dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}
.detail-list dd {
    margin: 0;
    overflow-wrap: anywhere;
}
.modal-actions {
    border-top: 1px solid var(--line);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 16px 18px;
}

.alert {
    border-radius: 8px;
    margin-bottom: 14px;
    padding: 12px 14px;
}
.alert.success { background: #e7f6ed; color: #14532d; }
.alert.danger { background: #fde8e8; color: var(--danger); }
.badge {
    display: inline-block;
    border-radius: 999px;
    background: #e9eef3;
    color: #344150;
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 700;
}
.badge.danger, .badge.anulado { background: #fde8e8; color: var(--danger); }
.badge.pagado { background: #e7f6ed; color: var(--ok); }
.badge.pendiente { background: #fff5d6; color: var(--warning); }

.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    border-bottom: 1px solid var(--line);
    padding: 10px;
    text-align: left;
    vertical-align: top;
}
th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}
td.actions, .actions {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
}

.line-items { display: grid; gap: 8px; margin: 12px 0; }
.line-row {
    display: grid;
    grid-template-columns: minmax(220px, 1.8fr) .6fr .7fr .7fr .6fr auto;
    gap: 8px;
    align-items: center;
}
.line-row.purchase-row {
    grid-template-columns: minmax(220px, 1.7fr) .55fr .65fr .65fr .65fr auto;
}
.line-row.header {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.login-body {
    display: grid;
    min-height: 100vh;
    place-items: center;
    background: #e9eef3;
}
.login-panel {
    width: min(420px, calc(100vw - 32px));
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    display: grid;
    gap: 14px;
}
.login-panel h1 { margin: 0; }
.login-panel p { margin: 0; color: var(--muted); }

.catalog-body { background: #f7f8fa; }
.catalog-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 22px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}
.catalog-header h1 { margin: 0; }
.catalog-header p { margin: 6px 0 0; color: var(--muted); }
.catalog-filters {
    display: grid;
    grid-template-columns: 1fr 220px auto auto;
    gap: 10px;
    padding: 16px 22px;
}
.catalog-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 18px;
    padding: 0 22px 22px;
    align-items: start;
}
.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}
.product-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    grid-template-rows: auto 1fr auto;
    overflow: hidden;
}
.product-card-photo img,
.product-card-photo .image-placeholder {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 0;
    background: #eef2f5;
}
.product-card-body,
.product-card-foot { padding: 14px; }
.product-card-body {
    display: grid;
    gap: 7px;
}
.product-card h2 { margin: 0; font-size: 17px; }
.product-card p { margin: 0; color: var(--muted); line-height: 1.45; min-height: 62px; }
.product-card span { color: var(--brand); font-size: 12px; font-weight: 700; }
.product-card-foot {
    align-items: center;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 12px;
    justify-content: space-between;
}
.product-card-foot strong { display: block; font-size: 18px; }
.cart-panel {
    position: sticky;
    top: 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    display: grid;
    gap: 12px;
}
.cart-empty {
    border: 1px dashed var(--line);
    border-radius: 7px;
    color: var(--muted);
    padding: 13px;
    text-align: center;
}
.cart-line {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    gap: 6px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 8px;
}
.cart-line button {
    width: 28px;
    height: 28px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
}

@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; }
    .sidebar nav { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
    .menu-group { border-bottom: 0; }
    .grid.two, .grid.four, .grid.form-list, .catalog-layout, .product-detail-grid { grid-template-columns: 1fr; }
    .product-form-grid,
    .entity-form-grid,
    .entity-form-grid.lower { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .product-form-grid .field-wide,
    .product-form-grid .field-photo { grid-column: span 2; }
    .catalog-filters { grid-template-columns: 1fr; }
    .line-row, .line-row.purchase-row { grid-template-columns: 1fr 1fr; }
    .line-row.header { display: none; }
    .cart-panel { position: static; }
}

@media (max-width: 720px) {
    .main { padding: 16px; }
    .topbar {
        align-items: stretch;
        flex-direction: column;
    }
    .topbar form,
    .topbar .button,
    .filters,
    .filters input,
    .filters .button,
    .inline-form .searchable-select,
    .modal-actions .button,
    .form-actions .button {
        width: 100%;
    }
    .section-head {
        align-items: stretch;
        flex-direction: column;
    }
    .product-form-grid,
    .entity-form-grid,
    .entity-form-grid.lower {
        grid-template-columns: 1fr;
    }
    .product-form-grid .field-wide,
    .product-form-grid .field-photo {
        grid-column: auto;
    }
    .form-actions { justify-content: stretch; }
    .product-table,
    .stacked-table { overflow-x: visible; }
    .product-table table,
    .product-table thead,
    .product-table tbody,
    .product-table tr,
    .product-table td,
    .stacked-table table,
    .stacked-table thead,
    .stacked-table tbody,
    .stacked-table tr,
    .stacked-table td {
        display: block;
        width: 100%;
    }
    .product-table thead,
    .stacked-table thead { display: none; }
    .product-table tr,
    .stacked-table tr {
        border: 1px solid var(--line);
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 12px;
    }
    .product-table td,
    .stacked-table td {
        border-bottom: 0;
        padding: 6px 0;
    }
    .product-table td:first-child { width: 100%; }
    .product-table td::before,
    .stacked-table td::before {
        color: var(--muted);
        content: attr(data-label);
        display: block;
        font-size: 11px;
        font-weight: 700;
        margin-bottom: 3px;
        text-transform: uppercase;
    }
    .product-table td:first-child::before,
    .stacked-table td:first-child::before { display: none; }
    .product-table .product-thumb {
        height: 92px;
        width: 92px;
    }
    .product-table td.actions,
    .stacked-table td.actions {
        display: grid;
        grid-template-columns: 1fr;
    }
    .modal-actions {
        flex-direction: column;
    }
}

@media print {
    .sidebar, .topbar, .button, .alert { display: none !important; }
    .app-shell { display: block; }
    .main { padding: 0; }
    .panel { border: 0; }
}
