/* ==========================================
   POS Mercado Chiapas - Design System
   ========================================== */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap');

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #0f172a;
    --accent: #10b981;
    --accent-light: #d1fae5;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --info: #06b6d4;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --sidebar-width: 260px;
    --header-height: 60px;
    --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ===== LAYOUT ===== */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--secondary);
    color: #fff;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
    overflow-y: auto;
}

.sidebar-brand {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand img { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; }
.sidebar-brand h2 { font-size: 1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-brand small { display: block; font-size: 0.7rem; color: var(--text-muted); font-weight: 400; }

.sidebar-nav { padding: 12px 0; flex: 1; }
.sidebar-nav .nav-section { padding: 8px 20px 4px; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em; color: rgba(255,255,255,0.35); font-weight: 600; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 20px; color: rgba(255,255,255,0.65);
    font-size: 0.9rem; font-weight: 500;
    transition: all var(--transition); border-left: 3px solid transparent;
}
.sidebar-nav a:hover { color: #fff; background: rgba(255,255,255,0.06); }
.sidebar-nav a.active { color: #fff; background: rgba(37,99,235,0.2); border-left-color: var(--primary); }
.sidebar-nav a svg, .sidebar-nav a i { width: 18px; height: 18px; opacity: 0.7; flex-shrink: 0; }
.sidebar-nav a.active svg, .sidebar-nav a.active i { opacity: 1; }

.sidebar-nav .badge-nav {
    margin-left: auto; background: var(--danger); color: #fff; font-size: 0.65rem;
    padding: 1px 6px; border-radius: 10px; font-weight: 600;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===== HEADER ===== */
.top-header {
    height: var(--header-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.top-header .menu-toggle { display: none; background: none; border: none; cursor: pointer; padding: 8px; color: var(--text); }
.top-header .header-title { font-size: 1.1rem; font-weight: 600; }
.top-header .header-actions { display: flex; align-items: center; gap: 12px; }
.top-header .header-actions .btn-icon { width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--surface-2); color: var(--text-secondary); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all var(--transition); }
.top-header .header-actions .btn-icon:hover { background: var(--primary-light); color: var(--primary); }
.user-menu { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius); transition: background var(--transition); }
.user-menu:hover { background: var(--surface-2); }
.user-menu .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 0.85rem; }
.user-menu .user-info { line-height: 1.2; }
.user-menu .user-name { font-weight: 600; font-size: 0.85rem; }
.user-menu .user-role { font-size: 0.7rem; color: var(--text-muted); }

.page-content { padding: 24px; flex: 1; }

/* ===== CARDS ===== */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-header h3 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ===== STAT CARDS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    box-shadow: var(--shadow);
    transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-icon {
    width: 44px; height: 44px; border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; flex-shrink: 0;
}
.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--accent-light); color: var(--accent); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-icon.yellow { background: var(--warning-light); color: var(--warning); }
.stat-info h4 { font-size: 0.75rem; color: var(--text-secondary); font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-info .stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; margin-top: 2px; }
.stat-info .stat-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
    font-family: inherit; font-size: 0.85rem; font-weight: 600;
    cursor: pointer; transition: all var(--transition); white-space: nowrap; text-decoration: none;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-success { background: var(--accent); color: #fff; }
.btn-success:hover { background: #059669; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.btn-outline:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-block { display: flex; width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.form-control {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-family: inherit; font-size: 0.9rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--surface);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.form-control-lg { padding: 12px 16px; font-size: 1.05rem; }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }
.form-text { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.input-group { display: flex; }
.input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.form-inline { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }

/* ===== TABLES ===== */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
table th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); font-weight: 600; text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); background: var(--surface-2); white-space: nowrap; }
table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.88rem; vertical-align: middle; }
table tr:hover { background: rgba(37,99,235,0.02); }
table .text-right { text-align: right; }
table .text-center { text-align: center; }

/* ===== BADGES ===== */
.badge {
    display: inline-flex; padding: 2px 8px; border-radius: 20px;
    font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em;
}
.badge-success { background: var(--accent-light); color: #065f46; }
.badge-danger { background: var(--danger-light); color: #991b1b; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-info { background: #e0f2fe; color: #075985; }
.badge-default { background: #f1f5f9; color: #475569; }

/* ===== ALERTS ===== */
.alert {
    padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px;
    font-size: 0.88rem; display: flex; align-items: center; gap: 10px;
}
.alert-success { background: var(--accent-light); color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: none; align-items: center; justify-content: center;
    z-index: 2000; padding: 16px; backdrop-filter: blur(2px);
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--surface); border-radius: var(--radius-lg);
    width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-lg); animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px; }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ===== POS SPECIFIC ===== */
.pos-layout { display: grid; grid-template-columns: 1fr 380px; gap: 0; height: calc(100vh - var(--header-height)); }
.pos-products { padding: 16px; overflow-y: auto; background: var(--bg); }
.pos-cart { background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; }
.pos-search { display: flex; gap: 8px; margin-bottom: 16px; }
.pos-search .form-control { flex: 1; }
.pos-categories { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.pos-categories .cat-btn { padding: 5px 12px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); font-size: 0.8rem; cursor: pointer; transition: all var(--transition); }
.pos-categories .cat-btn.active, .pos-categories .cat-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.pos-product {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px; cursor: pointer; transition: all var(--transition); text-align: center;
}
.pos-product:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.pos-product .prod-name { font-weight: 600; font-size: 0.82rem; margin-bottom: 4px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pos-product .prod-price { color: var(--primary); font-weight: 700; font-size: 1rem; }
.pos-product .prod-stock { font-size: 0.7rem; color: var(--text-muted); }
.pos-product .prod-stock.low { color: var(--danger); }

.cart-header { padding: 16px; border-bottom: 1px solid var(--border); }
.cart-header h3 { font-size: 1rem; font-weight: 600; }
.cart-items { flex: 1; overflow-y: auto; padding: 0; }
.cart-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.cart-item .item-info { flex: 1; min-width: 0; }
.cart-item .item-name { font-weight: 600; font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item .item-price { font-size: 0.78rem; color: var(--text-secondary); }
.cart-item .item-qty { display: flex; align-items: center; gap: 4px; }
.cart-item .item-qty button { width: 26px; height: 26px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.cart-item .item-qty input { width: 40px; text-align: center; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; font-size: 0.85rem; }
.cart-item .item-total { font-weight: 700; white-space: nowrap; min-width: 70px; text-align: right; }
.cart-item .item-remove { color: var(--danger); cursor: pointer; padding: 4px; background: none; border: none; font-size: 1.1rem; }

.cart-summary { padding: 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.cart-summary .summary-row { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 0.88rem; }
.cart-summary .summary-total { font-size: 1.3rem; font-weight: 700; color: var(--primary); border-top: 2px solid var(--border); padding-top: 8px; margin-top: 4px; }
.cart-actions { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.cart-actions .btn { padding: 14px; font-size: 1rem; }

/* ===== TICKET ===== */
.ticket { width: 80mm; margin: 0 auto; padding: 10px; font-family: 'Courier New', monospace; font-size: 12px; }
.ticket .ticket-center { text-align: center; }
.ticket .ticket-line { border-top: 1px dashed #000; margin: 5px 0; }
.ticket table { width: 100%; font-size: 11px; }
.ticket table td { padding: 2px 0; }

/* ===== DROPDOWN ===== */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; top: 100%; right: 0; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); min-width: 180px; display: none;
    z-index: 1001; overflow: hidden;
}
.dropdown-menu.show { display: block; }
.dropdown-menu a, .dropdown-menu button {
    display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px 14px;
    border: none; background: none; font-size: 0.85rem; color: var(--text);
    cursor: pointer; text-align: left; font-family: inherit;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-2); }
.dropdown-divider { border-top: 1px solid var(--border); margin: 4px 0; }

/* ===== UTILITIES ===== */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--accent); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.fw-bold { font-weight: 700; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.hidden { display: none !important; }
.w-100 { width: 100%; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.3; }
.empty-state h4 { font-size: 1.1rem; color: var(--text-secondary); margin-bottom: 4px; }
.empty-state p { font-size: 0.88rem; }

/* ===== PAGINATION ===== */
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 16px; }
.pagination a, .pagination span { padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.85rem; }
.pagination a:hover { background: var(--surface-2); }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== LOADING ===== */
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { position: absolute; inset: 0; background: rgba(255,255,255,0.8); display: flex; align-items: center; justify-content: center; z-index: 10; }

/* ===== TOAST ===== */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    padding: 12px 16px; border-radius: var(--radius); font-size: 0.88rem; font-weight: 500;
    box-shadow: var(--shadow-lg); animation: toastIn 0.3s ease; min-width: 280px; max-width: 400px;
    display: flex; align-items: center; gap: 8px;
}
.toast-success { background: #065f46; color: #fff; }
.toast-error { background: #991b1b; color: #fff; }
.toast-warning { background: #92400e; color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateX(100%); } }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .top-header .menu-toggle { display: flex; }
    .pos-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .pos-cart { border-left: none; border-top: 1px solid var(--border); max-height: 50vh; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    html { font-size: 13px; }
    .page-content { padding: 16px; }
    .stats-grid { grid-template-columns: 1fr; }
    .pos-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
    .pos-product { padding: 8px; }
    .pos-product .prod-name { font-size: 0.75rem; }
    table th, table td { padding: 8px 6px; font-size: 0.8rem; }
    .btn { padding: 8px 12px; font-size: 0.8rem; }
    .form-row { grid-template-columns: 1fr; }
    .cart-actions .btn { padding: 12px; }
}

@media print {
    .sidebar, .top-header, .no-print { display: none !important; }
    .main-content { margin-left: 0; }
    .page-content { padding: 0; }
    .card { border: none; box-shadow: none; }
}
