:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #059669;
    --primary-hover: #047857;
    --primary-soft: #ecfdf5;
    --accent: #0284c7;
    --accent-soft: #e0f2fe;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --navy: #0f172a;
    --radius: 12px;
    --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
}

.num, .money {
    font-variant-numeric: tabular-nums;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout App */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 256px;
    background: var(--navy);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
}

.sidebar-brand {
    padding: 20px 18px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.15rem;
    font-weight: 800;
    color: #fff;
    text-decoration: none;
}

.logo-badge {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, #10b981, #0284c7);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #fff;
}

.sidebar-sub {
    margin-top: 6px;
    font-size: 0.78rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    padding: 12px 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 9px;
    color: #cbd5e1;
    font-size: 0.92rem;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, color .15s;
}

.nav-link:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
    text-decoration: none;
}

.nav-link.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.nav-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #64748b;
    padding: 12px 12px 4px;
    font-weight: 700;
}

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.82rem;
}

.main-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-toggle {
    display: none;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 11px;
    font-size: 1.05rem;
    cursor: pointer;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.bcv-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--accent-soft);
    color: #0369a1;
    border: 1px solid #bae6fd;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.86rem;
    font-weight: 700;
}

.sub-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.sub-pill.demo { background: var(--warning-soft); color: #92400e; }
.sub-pill.active { background: var(--primary-soft); color: #065f46; }

.page-content {
    padding: 22px;
    max-width: 1420px;
    width: 100%;
    margin: 0 auto;
}

/* Cards & Grids */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 18px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.card-title {
    margin: 0;
    font-size: 1.06rem;
    font-weight: 700;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

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

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.stat-value {
    font-size: 1.45rem;
    font-weight: 800;
    margin: 6px 0 2px;
    color: var(--text);
}

.stat-sub {
    font-size: 0.84rem;
    color: var(--muted);
}

/* Forms & Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 9px 15px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
    font-family: inherit;
}

.btn:hover { text-decoration: none; filter: brightness(0.96); }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; border-radius: 7px; }
.btn-lg { padding: 12px 20px; font-size: 1rem; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--muted); }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.form-group {
    margin-bottom: 12px;
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: #334155;
    margin-bottom: 5px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.92rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.14);
}

/* Tables */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.89rem;
}

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

th {
    background: var(--surface-alt);
    color: #475569;
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

tr:hover td { background: #f8fafc; }

/* Badges & Alerts */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-green { background: var(--primary-soft); color: #065f46; }
.badge-blue { background: var(--accent-soft); color: #075985; }
.badge-amber { background: var(--warning-soft); color: #92400e; }
.badge-red { background: var(--danger-soft); color: #991b1b; }
.badge-gray { background: #e2e8f0; color: #334155; }

.alert {
    padding: 12px 15px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 0.92rem;
    border: 1px solid transparent;
}

.alert-success { background: var(--primary-soft); color: #065f46; border-color: #a7f3d0; }
.alert-error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.alert-info { background: var(--accent-soft); color: #075985; border-color: #bae6fd; }
.alert-warning { background: var(--warning-soft); color: #92400e; border-color: #fde68a; }

.thumb {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #f8fafc;
}

.thumb-placeholder {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px dashed #cbd5e1;
    background: #f8fafc;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: 700;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.58);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 60;
}

.modal-backdrop.open { display: flex; }

.modal-box {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 560px;
    max-height: 92vh;
    overflow-y: auto;
    padding: 20px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.28);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

/* POS Specific */
.pos-layout {
    display: grid;
    grid-template-columns: 1.45fr 1fr;
    gap: 18px;
    align-items: start;
}

.quick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: 10px;
}

.quick-item {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 10px;
    padding: 10px;
    text-align: left;
    cursor: pointer;
    transition: transform .1s, border-color .15s;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.quick-item:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
}

.quick-item img {
    width: 100%;
    height: 74px;
    object-fit: cover;
    border-radius: 7px;
}

.cart-panel {
    position: sticky;
    top: 74px;
}

/* Recortador Táctil y Guía de Escáner */
.crop-stage {
    position: relative;
    width: 100%;
    background: #0f172a;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.crop-stage canvas {
    display: block;
    max-width: 100%;
    touch-action: none;
    cursor: crosshair;
}

.crop-toolbar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
    justify-content: center;
}

.live-scan-guide {
    position: absolute;
    left: 10%;
    right: 10%;
    top: 26%;
    bottom: 26%;
    border: 2px solid #10b981;
    border-radius: 10px;
    box-shadow: 0 0 0 999px rgba(15, 23, 42, 0.45);
    pointer-events: none;
}

.live-scan-guide::after {
    content: "";
    position: absolute;
    left: 6%;
    right: 6%;
    top: 50%;
    height: 2px;
    background: rgba(239, 68, 68, 0.8);
}

.sidebar-brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sidebar-close {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.56);
    z-index: 45;
    display: none;
}

.sidebar-overlay.open {
    display: block;
}

/* Guías de Uso */
.guides-hero {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
}

.guide-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.guides-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.guide-card {
    margin-bottom: 0;
    padding: 0;
    overflow: hidden;
}

.guide-summary {
    list-style: none;
    cursor: pointer;
    padding: 15px 18px;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 12px;
    user-select: none;
    background: #ffffff;
}

.guide-summary::-webkit-details-marker { display: none; }

.guide-summary::after {
    content: "▾";
    margin-left: auto;
    color: var(--muted);
    font-size: 1.05rem;
    transition: transform .15s;
}

.guide-card[open] .guide-summary {
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
}

.guide-card[open] .guide-summary::after {
    transform: rotate(180deg);
}

.guide-num {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--primary-soft);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.88rem;
    flex-shrink: 0;
}

.guide-body {
    padding: 15px 18px 18px;
    font-size: 0.94rem;
    color: #334155;
    line-height: 1.6;
}

.guide-body ul, .guide-body ol {
    margin: 8px 0 12px;
    padding-left: 20px;
}

.guide-body li {
    margin-bottom: 6px;
}

/* Responsive */
@media (max-width: 1080px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .pos-layout { grid-template-columns: 1fr; }
    .cart-panel { position: static; }
}

@media (max-width: 820px) {
    .sidebar {
        position: fixed;
        left: -270px;
        z-index: 50;
        transition: left .2s ease;
    }
    .sidebar.open { left: 0; }
    .sidebar-close { display: inline-flex; }
    .menu-toggle { display: inline-flex; }
    .grid-3, .grid-2, .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
    .grid-4 { grid-template-columns: 1fr; }
    .page-content { padding: 14px; }
    .topbar { padding: 10px 14px; gap: 8px; }
    .bcv-pill { font-size: 0.78rem; padding: 5px 9px; }
    .sub-pill { font-size: 0.75rem; padding: 5px 9px; }
}
