:root {
    --bg: #f4f6f9;
    --card: #fff;
    --primary: #0d6efd;
    --success: #198754;
    --border: #dee2e6;
    --text-muted: #6c757d;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    background: var(--bg);
    color: #212529;
    line-height: 1.4;
}

.topbar {
    background: #1a1d21;
    color: #fff;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.topbar h1 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
}

.badge-status {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    background: #495057;
}

.badge-status.online { background: var(--success); }
.badge-status.offline { background: #dc3545; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn-primary { background: var(--primary); }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem;
}

.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 900px) {
    .grid { grid-template-columns: 1fr; }
}

.card {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    padding: 1rem;
    margin-bottom: 1rem;
}

.card h2 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    font-weight: 600;
}

.muted { color: var(--text-muted); font-size: 0.875rem; }

input[type="text"],
input[type="number"],
input[type="search"],
input[type="file"] {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}

input:focus {
    outline: 2px solid rgba(13, 110, 253, 0.35);
    border-color: var(--primary);
}

.btn {
    display: inline-block;
    border: none;
    border-radius: 8px;
    padding: 0.55rem 1rem;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    color: #fff;
    background: var(--primary);
}

.btn:hover { filter: brightness(0.95); }
.btn-secondary { background: #6c757d; }
.btn-success { background: var(--success); }
.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.btn-danger { background: #dc3545; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }
.btn.disabled,
.btn.disabled:hover {
    opacity: 0.45;
    pointer-events: none;
    cursor: not-allowed;
    filter: none;
}

.row-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.75rem;
}

.search-results {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 0.5rem;
}

.search-item {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.search-item:hover { background: #f8f9fa; }
.search-item:last-child { border-bottom: none; }

.search-item strong { display: block; }
.search-item small { color: var(--text-muted); }

.tag {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}
.tag-und { background: #e7f1ff; color: #0d6efd; }
.tag-peso { background: #fff3cd; color: #856404; }

.producto-pick {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: #e8f5e9;
    border-radius: 8px;
    border: 1px solid #c8e6c9;
}

.precio-pick {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--success);
    white-space: nowrap;
}

.pago-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: center;
}

.pagos-resumen {
    margin-top: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
}
.pagos-resumen.ok { background: #e8f5e9; color: #1b5e20; }
.pagos-resumen.warn { background: #fff3cd; color: #856404; }

.factura-pre {
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.qty-field { width: 5.5rem; text-align: right; }

.table-wrap { overflow-x: auto; }

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

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

th { background: #f8f9fa; font-weight: 600; }
td.num, th.num { text-align: right; }

.total-box {
    background: #e8f5e9;
    border: 1px solid #c8e6c9;
    border-radius: 10px;
    padding: 1rem;
    text-align: right;
}

.total-box .amount {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--success);
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-info {
    background: #cff4fc;
    border: 1px solid #9eeaf9;
}

.alert-warning {
    background: #fff3cd;
    border: 1px solid #ffecb5;
}

.hidden { display: none !important; }

#toast {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    background: #212529;
    color: #fff;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1000;
    max-width: 90vw;
}

#toast.show { opacity: 1; }
