:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --bg: #f9fafb;
    --danger: #dc2626;
    --success: #16a34a;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--store-muted, var(--muted)); }
h1, h2, h3 { line-height: 1.2; }
img { max-width: 100%; }
.store-body { background: var(--store-bg, var(--bg)); color: var(--store-text, var(--text)); }

/* ---- Admin ---- */
/* ---- Admin: sidebar ---- */
.admin-topbar { display: none; }
.admin-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 220px; overflow-y: auto;
    background: #111827; color: #fff; padding: 20px 0; z-index: 50;
    display: flex; flex-direction: column;
}
.admin-sidebar-brand { font-weight: 700; font-size: 18px; padding: 0 20px 20px; color: #fff; }
.admin-sidebar a { color: #d1d5db; padding: 12px 20px; font-size: 14px; display: block; }
.admin-sidebar a:hover { background: #1f2937; color: #fff; text-decoration: none; }
.admin-sidebar a.active { background: #1f2937; color: #fff; border-left: 3px solid var(--primary); }
.sidebar-overlay { display: none; }
.admin-main { max-width: 960px; padding: 32px 20px; margin-left: 0; }
.admin-sidebar ~ .admin-main { margin-left: 220px; }

.auth-card, .card {
    background: var(--store-surface, #fff); border: 1px solid var(--store-border, var(--border)); border-radius: 10px;
    padding: 28px; margin-bottom: 24px; color: inherit;
}
.card.highlight { border-color: var(--primary); background: var(--store-surface, #eff6ff); }
.auth-card { max-width: 420px; margin: 40px auto; }

label { display: block; margin: 14px 0 6px; font-weight: 600; font-size: 14px; }
input, select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 14px; font-family: inherit;
}
input[type=color] { padding: 4px; height: 42px; }
textarea { resize: vertical; }

.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 12px 0 4px; }
.checkbox-label input { width: auto; }

.btn {
    display: inline-block; padding: 10px 18px; border-radius: 6px; border: none;
    font-size: 14px; font-weight: 600; cursor: pointer; text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; color: #fff; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: #e5e7eb; color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-link { background: none; border: none; color: var(--danger); cursor: pointer; padding: 0; font-size: 13px; }
.form-actions { margin-top: 20px; display: flex; flex-wrap: wrap; gap: 10px; }

.btn-whatsapp { display: inline-block; background: #25D366; color: #fff; padding: 10px 18px; border-radius: 6px; font-weight: 600; margin-top: 10px; }
.btn-whatsapp:hover { background: #1ebe5b; text-decoration: none; color: #fff; }
.whatsapp-float {
    position: fixed; bottom: 20px; right: 20px; background: #25D366; color: #fff;
    width: 56px; height: 56px; border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-size: 26px; box-shadow: 0 4px 14px rgba(0,0,0,.25);
    z-index: 999; text-decoration: none;
}
.whatsapp-float:hover { text-decoration: none; filter: brightness(1.05); }

.oauth-buttons { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.btn-oauth {
    display: flex; align-items: center; justify-content: center; gap: 10px; padding: 11px;
    border-radius: 6px; font-weight: 600; font-size: 14px;
}
.btn-oauth svg { flex-shrink: 0; }
.btn-google { background: #fff; color: #3c4043; border: 1px solid #dadce0; }
.btn-google:hover { background: #f7f8f8; box-shadow: 0 1px 3px rgba(0,0,0,.15); text-decoration: none; }
.btn-facebook { background: #1877F2; color: #fff; border: 1px solid #1877F2; }
.btn-facebook:hover { background: #166fe0; text-decoration: none; color: #fff; }
.divider { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: 13px; margin: 16px 0; }
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--border); }
.divider span { padding: 0 10px; }

.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 20px; font-size: 14px; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 16px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 20px; text-align: center; }
.stat-number { display: block; font-size: 26px; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--muted); font-size: 13px; }

.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 14px; white-space: nowrap; }
.store-body .table th, .store-body .table td { border-bottom-color: var(--store-border, var(--border)); }

.badge { padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.badge-pendiente { background: #fef3c7; color: #92400e; }
.badge-pagado { background: #dcfce7; color: #166534; }
.badge-cancelado { background: #fee2e2; color: #991b1b; }

.image-grid { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.image-thumb { position: relative; width: 90px; height: 90px; }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.image-thumb a { position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff; border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-size: 12px; }
.preview-sm { max-width: 120px; display: block; margin-top: 8px; border-radius: 6px; }

.order-block { border-bottom: 1px solid var(--border); padding: 16px 0; }
.order-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: start; gap: 8px; }
.order-items { margin: 8px 0; padding-left: 18px; font-size: 14px; }
.inline-form { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }

/* ---- Tienda pública ---- */
.store-header { background: var(--store-surface, #fff); border-bottom: 1px solid var(--store-border, var(--border)); }
.store-header-inner { max-width: 1100px; margin: 0 auto; padding: 16px 20px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
.store-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; color: var(--store-text, var(--text)); }
.store-brand img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.store-brand-name { color: var(--primary); }
.cart-link { font-weight: 600; color: var(--store-text, var(--text)); }
.store-main { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }
.store-footer { text-align: center; padding: 24px; color: var(--store-muted, var(--muted)); font-size: 13px; }
.store-banner img { width: 100%; max-height: 320px; object-fit: cover; border-radius: 10px; }
.store-intro { margin: 20px 0; }
.store-intro h1 { color: var(--primary); }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 20px; margin-top: 20px; }
.product-card { background: var(--store-surface, #fff); border: 1px solid var(--store-border, var(--border)); border-radius: 10px; overflow: hidden; color: var(--store-text, var(--text)); display: block; }
.product-card:hover { border-color: var(--primary); text-decoration: none; }
.product-thumb { aspect-ratio: 1; background: var(--store-border, #f3f4f6); }
.product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-placeholder { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--store-muted, var(--muted)); font-size: 13px; }
.thumb-placeholder.large { aspect-ratio: 1; }
.product-info { padding: 12px; }
.product-info h3 { font-size: 15px; margin: 0 0 6px; }
.price { font-weight: 700; color: var(--primary); }
.tag { display: inline-block; background: #eef2ff; color: #4338ca; font-size: 11px; padding: 2px 8px; border-radius: 10px; margin-left: 6px; }

.product-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
.main-image { width: 100%; border-radius: 10px; object-fit: cover; aspect-ratio: 1; }
.thumb-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumb-small { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; cursor: pointer; border: 1px solid var(--store-border, var(--border)); }
.price-lg { font-size: 24px; font-weight: 700; color: var(--primary); }
.out-of-stock { color: var(--danger); font-weight: 600; }
.product-summary h1 { color: var(--primary); }

.checkout-layout { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; align-items: start; }
.order-summary .summary-line { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; border-bottom: 1px solid var(--store-border, var(--border)); }
.order-summary .total { font-weight: 700; font-size: 16px; border-bottom: none; }
.total-line { font-size: 18px; margin: 16px 0; }

/* ---- Selector de tema claro/oscuro (en Mi tienda) ---- */
.theme-options { display: flex; gap: 16px; margin: 8px 0 16px; flex-wrap: wrap; }
.theme-option { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; margin: 0; cursor: pointer; }
.theme-option input { width: auto; }
.theme-swatch {
    display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
    border-radius: 6px; border: 1px solid var(--border); font-size: 12px; font-weight: 700;
}
.theme-swatch-light { background: #ffffff; color: #1f2937; }
.theme-swatch-dark { background: #0f172a; color: #f1f5f9; }

/* ---- Responsive ---- */
@media (max-width: 860px) {
    .product-detail, .checkout-layout { grid-template-columns: 1fr; }

    .admin-topbar {
        display: flex; align-items: center; gap: 14px; background: #111827; color: #fff;
        padding: 14px 18px; position: sticky; top: 0; z-index: 60;
    }
    .sidebar-toggle { background: none; border: none; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 0; }
    .admin-topbar-brand { font-weight: 700; font-size: 16px; }
    .admin-sidebar { width: 240px; transform: translateX(-100%); transition: transform .2s ease; }
    .admin-sidebar.open { transform: translateX(0); }
    .admin-main, .admin-sidebar ~ .admin-main { margin-left: 0; padding: 20px 14px; }
    .sidebar-overlay {
        display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45);
        opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 40;
    }
    .sidebar-overlay.visible { opacity: 1; pointer-events: auto; }
}

@media (max-width: 600px) {
    .admin-main, .store-main { padding: 20px 14px; }
    .auth-card, .card { padding: 18px; }
    h1 { font-size: 22px; }
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
    .whatsapp-float { width: 50px; height: 50px; font-size: 22px; bottom: 14px; right: 14px; }
    /* Evita el zoom automático de iOS al enfocar campos de formulario */
    input, select, textarea { font-size: 16px; }
}
