/* ============ POS-ROPA · ModaMinimarket ============ */
:root {
  --bs-primary: #6366f1;
  --bs-primary-rgb: 99,102,241;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;
  --sidebar: #0f1729;
  --sidebar-2: #1a2238;
  --sidebar-text: #94a3b8;
  --text: #1a1f36;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e5e7eb;
  --border-light: #f1f5f9;
  --bg: #f8fafc;
  --card: #ffffff;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --info: #3b82f6;
  --info-light: #dbeafe;
}

* { box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #f1f3f8; color: var(--text); font-size: 14px;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}

/* ============ TEMA OSCURO ============ */
html[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --border: #334155;
  --border-light: #1e293b;
  --primary-50: rgba(99,102,241,.15);
  --primary-100: rgba(99,102,241,.25);
}
html[data-theme="dark"] body { background: #0f172a; color: #e2e8f0; }
html[data-theme="dark"] .data-card,
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .modal-box,
html[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection,
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .input-group-text {
  background: #1e293b !important; color: #e2e8f0 !important; border-color: #334155 !important;
}
html[data-theme="dark"] .cfg-side,
html[data-theme="dark"] .cfg-stat,
html[data-theme="dark"] .cfg-theme-card,
html[data-theme="dark"] .cfg-api-card,
html[data-theme="dark"] .cfg-user-card { background: #1e293b !important; border-color: #334155 !important; }
html[data-theme="dark"] .menu-btn { background: #1e293b; border-color: #334155; color: #94a3b8; }
html[data-theme="dark"] .menu-btn:hover { background: var(--primary-50); color: var(--primary); }
html[data-theme="dark"] .nav-tabs .nav-link { color: #94a3b8; }
html[data-theme="dark"] .table { color: #e2e8f0; --bs-table-bg: transparent; }
html[data-theme="dark"] .form-control:focus, html[data-theme="dark"] .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 0.2rem var(--primary-100); }
html[data-theme="dark"] .topbar-search input { background: #0f172a; border-color: #334155; color: #e2e8f0; }
html[data-theme="dark"] .cfg-logo-preview { background: #0f172a; border-color: #334155; }
html[data-theme="dark"] .dropzone { background: linear-gradient(135deg, #0f172a, #1e293b); border-color: #334155; }
html[data-theme="dark"] .cfg-cert-box { background: #0f172a; border-color: #334155; }
html[data-theme="dark"] .text-primary { color: var(--primary) !important; }
html[data-theme="dark"] .text-muted { color: #94a3b8 !important; }

/* Animaciones reducidas */
html.reduce-anim *, html.reduce-anim *::before, html.reduce-anim *::after {
  transition: none !important; animation-duration: 0.001s !important;
}

/* Bootstrap overrides */
.btn-primary { background-color: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background-color: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background-color: var(--primary); border-color: var(--primary); }
.text-primary { color: var(--primary) !important; }
.bg-primary { background-color: var(--primary) !important; }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 .2rem rgba(99,102,241,.15); }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }

/* ============ APP LAYOUT ============ */
.app-wrap { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 256px; background: var(--sidebar);
  display: flex; flex-direction: column; flex-shrink: 0; z-index: 50;
  transition: width .25s, transform .25s;
}

/* ============ SIDEBAR COLAPSADO (desktop) ============ */
.app-wrap.sidebar-collapsed .sidebar { width: 64px; overflow: visible; }
.app-wrap.sidebar-collapsed .sidebar .sb-brand-text,
.app-wrap.sidebar-collapsed .sidebar .nav-label,
.app-wrap.sidebar-collapsed .sidebar .badge-mini,
.app-wrap.sidebar-collapsed .sidebar .sb-user-info,
.app-wrap.sidebar-collapsed .sidebar .nav-section-label { display: none; }
.app-wrap.sidebar-collapsed .sidebar .sidebar-header { padding: 16px 8px; }
.app-wrap.sidebar-collapsed .sidebar .sb-brand { justify-content: center; }
.app-wrap.sidebar-collapsed .sidebar .sb-brand .brand-icon { width: 38px; height: 38px; }

/* Scrollbar invisible cuando colapsado */
.app-wrap.sidebar-collapsed .sidebar .sb-nav {
  padding: 10px 6px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.app-wrap.sidebar-collapsed .sidebar .sb-nav::-webkit-scrollbar { display: none; width: 0; }

/* Items: cuadrados redondeados, más compactos */
.app-wrap.sidebar-collapsed .sidebar .nav-item {
  justify-content: center; padding: 0; position: relative;
  width: 44px; height: 44px; border-radius: 12px;
  margin: 4px auto; gap: 0;
}
.app-wrap.sidebar-collapsed .sidebar .nav-item.nav-sub { padding: 0; opacity: .7; }
.app-wrap.sidebar-collapsed .sidebar .nav-item.nav-sub:hover { opacity: 1; }
.app-wrap.sidebar-collapsed .sidebar .nav-item i { font-size: 17px; }
.app-wrap.sidebar-collapsed .sidebar .nav-item.active {
  border-left: none; padding-left: 0;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  box-shadow: 0 4px 10px rgba(99,102,241,.4);
}
.app-wrap.sidebar-collapsed .sidebar .nav-item.active i { color: #fff; }
.app-wrap.sidebar-collapsed .sidebar .nav-item.active::before { display: none; }

/* Tooltip moderno con flecha */
.app-wrap.sidebar-collapsed .sidebar .nav-item::after {
  content: attr(title);
  position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%) translateX(-6px);
  background: #1e293b; color: #fff; padding: 7px 12px; border-radius: 8px; white-space: nowrap;
  font-size: 12px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .15s, transform .15s; z-index: 200;
  box-shadow: 0 8px 20px rgba(0,0,0,.25);
}
.app-wrap.sidebar-collapsed .sidebar .nav-item::before {
  content: ''; position: absolute; left: calc(100% + 6px); top: 50%; transform: translateY(-50%);
  border: 6px solid transparent; border-right-color: #1e293b;
  opacity: 0; transition: opacity .15s; z-index: 200; pointer-events: none;
}
.app-wrap.sidebar-collapsed .sidebar .nav-item:hover::after { opacity: 1; transform: translateY(-50%) translateX(0); }
.app-wrap.sidebar-collapsed .sidebar .nav-item:hover::before { opacity: 1; }

/* Footer compacto */
.app-wrap.sidebar-collapsed .sidebar .sb-footer { padding: 8px; }
.app-wrap.sidebar-collapsed .sidebar .sb-user { justify-content: center; padding: 0; margin-bottom: 6px; }
.app-wrap.sidebar-collapsed .sidebar .sb-avatar { width: 38px; height: 38px; }
.app-wrap.sidebar-collapsed .sidebar .sb-logout {
  width: 44px; height: 44px; padding: 0; border-radius: 12px; margin: 0 auto;
  display: grid; place-items: center;
}
.app-wrap.sidebar-collapsed .sidebar .sb-logout .nav-label { display: none; }

/* ============ SIDEBAR OCULTO ============ */
.app-wrap.sidebar-hidden .sidebar {
  width: 0; opacity: 0; pointer-events: none; overflow: hidden;
}
.app-wrap.sidebar-hidden .sidebar > * { opacity: 0; }
/* Botón flotante para mostrar el sidebar */
.sidebar-show-btn {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 60;
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6); color: #fff;
  border: none; box-shadow: 0 6px 16px rgba(99,102,241,.4);
  cursor: pointer; font-size: 18px;
  transition: all .2s;
  align-items: center; justify-content: center;
}
.sidebar-show-btn:hover { transform: scale(1.08); box-shadow: 0 10px 22px rgba(99,102,241,.5); }
.app-wrap.sidebar-hidden .sidebar-show-btn { display: flex; animation: fadeInLeft .25s ease-out; }
@keyframes fadeInLeft { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: none; } }
.sidebar-header { padding: 22px 20px; border-bottom: 1px solid rgba(255,255,255,.06); }
.sb-brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.sb-brand .brand-icon { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, #6366f1, #4f46e5); display: grid; place-items: center; }
.sb-brand .brand-icon i { font-size: 22px; color: #fff; }
.sb-brand h3 { font-family: 'Plus Jakarta Sans', sans-serif; font-size: 17px; font-weight: 700; margin: 0; }
.sb-brand span { font-size: 11px; color: var(--sidebar-text); }
.sb-nav { flex: 1; overflow-y: auto; padding: 16px 12px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.sb-nav::-webkit-scrollbar { width: 6px; }
.sb-nav::-webkit-scrollbar-track { background: transparent; }
.sb-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }
.sb-nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.2); }
.nav-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #475569; padding: 0 12px; margin: 14px 0 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: 10px; color: var(--sidebar-text); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all .15s; margin-bottom: 2px; border: none; background: none; width: 100%; text-align: left;
  text-decoration: none;
}
.nav-item i { font-size: 18px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active {
  background: linear-gradient(90deg, rgba(99,102,241,.2), rgba(99,102,241,.05));
  color: #fff; border-left: 3px solid var(--primary); padding-left: 9px;
}
.nav-item .badge-mini { margin-left: auto; background: var(--primary); color: #fff; font-size: 10px; padding: 2px 7px; border-radius: 10px; font-weight: 700; }
.nav-item.nav-sub { padding-left: 32px; font-size: 13px; opacity: .85; }
.nav-item.nav-sub i { font-size: 14px; }
.nav-item.nav-sub.active { padding-left: 29px; }

/* ============ SELECT2 ============ */
.select2-container--bootstrap-5 .select2-selection {
  min-height: 38px !important; border: 1px solid var(--border) !important; border-radius: 8px !important;
  font-size: 14px;
}
.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered { line-height: 36px !important; padding-left: 12px; }
.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection { border-color: var(--primary) !important; box-shadow: 0 0 0 0.2rem rgba(99,102,241,.15) !important; }
.select2-dropdown.select2-dropdown--below, .select2-dropdown.select2-dropdown--above { border-color: var(--primary) !important; border-radius: 8px !important; }
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice { background: var(--primary-50) !important; border-color: var(--primary-100) !important; color: var(--primary) !important; }
.select2-container .select2-results__option--highlighted[aria-selected] { background: var(--primary) !important; }

/* ============ DROPZONE UPLOADER ============ */
.dropzone {
  position: relative; border: 2px dashed var(--border); border-radius: 16px;
  background: linear-gradient(135deg, #fafbff 0%, #f5f7ff 100%);
  padding: 28px 20px; text-align: center; cursor: pointer; transition: all .2s;
}
.dropzone:hover { border-color: var(--primary); background: var(--primary-50); }
.dropzone.dragover { border-color: var(--primary); background: var(--primary-100); transform: scale(1.01); }
.dropzone .dz-icon { width: 56px; height: 56px; border-radius: 50%; background: var(--primary-50); display: grid; place-items: center; margin: 0 auto 12px; color: var(--primary); font-size: 24px; transition: all .2s; }
.dropzone:hover .dz-icon { background: var(--primary); color: #fff; transform: translateY(-2px); }
.dropzone .dz-title { font-weight: 600; color: var(--text); font-size: 15px; margin-bottom: 4px; }
.dropzone .dz-subtitle { font-size: 12px; color: var(--text-muted); }
.dropzone .dz-browse { color: var(--primary); font-weight: 600; text-decoration: underline; }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.img-tile {
  position: relative; aspect-ratio: 1/1; border-radius: 12px; overflow: hidden;
  border: 2px solid var(--border-light); background: #fff;
  transition: all .2s;
}
.img-tile:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 8px 16px rgba(99,102,241,.15); }
.img-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-tile .tile-actions {
  position: absolute; inset: auto 0 0 0; padding: 8px;
  background: linear-gradient(to top, rgba(0,0,0,.7), transparent);
  display: flex; justify-content: space-between; align-items: center;
  opacity: 0; transition: opacity .2s;
}
.img-tile:hover .tile-actions { opacity: 1; }
.img-tile .tile-status { position: absolute; top: 8px; right: 8px; padding: 4px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; color: #fff; }
.img-tile .tile-status.pending  { background: rgba(245,158,11,.95); }
.img-tile .tile-status.uploading{ background: rgba(59,130,246,.95); }
.img-tile .tile-status.error    { background: rgba(239,68,68,.95); }
.img-tile .tile-status.ok       { background: rgba(16,185,129,.95); }
.img-tile .tile-progress { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--primary); width: 0%; transition: width .2s; }
.img-tile .tile-btn { background: rgba(255,255,255,.95); border: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: var(--danger); }
.img-tile .tile-btn:hover { background: var(--danger); color: #fff; }
.img-tile.is-cover { border-color: var(--primary); }
.img-tile .cover-badge { position: absolute; top: 8px; left: 8px; background: var(--primary); color: #fff; padding: 4px 10px; border-radius: 20px; font-size: 10px; font-weight: 700; letter-spacing: .5px; }

.img-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px;
}
@media (max-width: 768px) { .img-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); } }
.sb-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.06); background: var(--sidebar-2); }
.sb-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; margin-bottom: 8px; }
.sb-user:hover { background: rgba(255,255,255,.05); }
.sb-avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, #f472b6, #c084fc); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; }
.sb-user-info { flex: 1; min-width: 0; color: #fff; }
.sb-user-info strong { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-info span { display: block; font-size: 11px; color: var(--sidebar-text); }
.sb-logout { width: 100%; padding: 9px; border: none; background: rgba(239,68,68,.1); color: #f87171; border-radius: 8px; font-size: 13px; font-weight: 500; display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; }
.sb-logout:hover { background: rgba(239,68,68,.2); }

/* ============ MAIN AREA ============ */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar {
  height: 64px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 16px; flex-shrink: 0;
}
.menu-btn {
  display: flex; width: 38px; height: 38px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border);
  align-items: center; justify-content: center; cursor: pointer;
  transition: all .15s; color: var(--text-muted); flex-shrink: 0;
}
.menu-btn:hover { background: var(--primary-50); border-color: var(--primary-100); color: var(--primary); }
.menu-btn:active { transform: scale(.92); }
.menu-btn i { transition: transform .25s; }
.app-wrap.sidebar-collapsed .menu-btn i { transform: rotate(90deg); }
.topbar-search { flex: 1; max-width: 500px; position: relative; }
.topbar-search-spacer { flex: 1; }
.topbar-search i.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.topbar-search input { width: 100%; padding: 10px 14px 10px 40px; border: 1.5px solid var(--border); border-radius: 10px; font-size: 14px; background: var(--bg); }
.topbar-search input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.topbar-btn { width: 38px; height: 38px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); display: grid; place-items: center; cursor: pointer; }
.topbar-btn:hover { background: var(--primary-50); border-color: var(--primary-100); }
.topbar-btn i { font-size: 16px; color: var(--text); }
.topbar-info { display: flex; flex-direction: column; align-items: flex-end; padding: 0 8px; border-right: 1px solid var(--border); margin-right: 4px; }
.topbar-info .time { font-size: 13px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.topbar-info .date { font-size: 11px; color: var(--text-muted); }

.content { flex: 1; overflow-y: auto; background: var(--bg); }
.module-page { padding: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-head h2 { font-family: 'Plus Jakarta Sans'; font-size: 22px; font-weight: 700; margin: 0; }
.page-head p { font-size: 13px; color: var(--text-muted); margin-top: 2px; margin-bottom: 0; }
.btn-add { padding: 9px 18px; background: var(--primary); color: #fff; border: none; border-radius: 10px; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.btn-add:hover { background: var(--primary-dark); color: #fff; }

/* KPIs */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: #fff; padding: 18px; border-radius: 14px; border: 1px solid var(--border); display: flex; align-items: center; gap: 14px; }
.kpi-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; flex-shrink: 0; }
.kpi-icon.green { background: var(--success-light); color: var(--success); }
.kpi-icon.blue  { background: var(--info-light); color: var(--info); }
.kpi-icon.purple{ background: var(--primary-100); color: var(--primary); }
.kpi-icon.orange{ background: var(--warning-light); color: #b45309; }
.kpi-icon.red   { background: var(--danger-light); color: var(--danger); }
.kpi-data span { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi-data strong { display: block; font-size: 22px; font-weight: 800; font-family: 'Plus Jakarta Sans'; margin-top: 2px; }

/* Data card with DataTable */
.data-card { background: #fff; border-radius: 14px; border: 1px solid var(--border); overflow: hidden; padding: 16px; }
table.dataTable { width: 100% !important; border-collapse: collapse; }
table.dataTable thead th { background: var(--bg); padding: 12px 14px; text-align: left; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
table.dataTable tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border-light); font-size: 13px; }
table.dataTable tbody tr:hover { background: var(--bg); }
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select { border: 1.5px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate { font-size: 12px; color: var(--text-muted); padding-top: 12px; }
.dataTables_wrapper .paginate_button { padding: 4px 10px !important; border-radius: 6px !important; margin: 0 2px; }
.dataTables_wrapper .paginate_button.current { background: var(--primary) !important; color: #fff !important; border-color: var(--primary) !important; }

.icon-btn { width: 30px; height: 30px; border-radius: 7px; background: var(--bg); border: none; display: inline-grid; place-items: center; cursor: pointer; color: var(--text-muted); font-size: 13px; margin: 0 2px; }
.icon-btn:hover { background: var(--primary-50); color: var(--primary); }
.icon-btn.danger:hover { background: var(--danger-light); color: var(--danger); }
.icon-btn.warning:hover { background: var(--warning-light); color: #b45309; }

.status-badge { font-size: 11px; padding: 3px 10px; border-radius: 10px; font-weight: 600; display: inline-block; }
.status-badge.green { background: var(--success-light); color: var(--success); }
.status-badge.orange { background: var(--warning-light); color: #b45309; }
.status-badge.red { background: var(--danger-light); color: var(--danger); }
.status-badge.gray { background: var(--border-light); color: var(--text-muted); }
.status-badge.blue { background: var(--info-light); color: var(--info); }

/* Forms */
.form-grp { margin-bottom: 14px; }
.form-grp label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.form-grp .form-control, .form-grp .form-select { padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 14px; }

/* Modales custom */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,41,.5); display: none; align-items: center; justify-content: center; z-index: 1050; padding: 20px; backdrop-filter: blur(4px); }
.modal-overlay.active { display: flex; }
.modal-box { background: #fff; border-radius: 16px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal-box.lg { max-width: 720px; }
.modal-box.xl { max-width: 960px; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-family: 'Plus Jakarta Sans'; font-size: 17px; font-weight: 700; margin: 0; }
.modal-close { width: 30px; height: 30px; border-radius: 8px; background: var(--bg); border: none; display: grid; place-items: center; cursor: pointer; font-size: 18px; }
.modal-close:hover { background: var(--danger-light); color: var(--danger); }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* Sidebar overlay mobile */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
.sidebar-overlay.show { display: block; }

/* ============ RESPONSIVE TABLET/MÓVIL ============ */
@media (max-width: 992px) {
  /* Sidebar como drawer */
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; transform: translateX(-100%); width: 280px !important; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: flex; }
  .topbar-search { max-width: none; }
  .topbar-info { display: none; }
  body { overflow: auto; }
  .app-wrap { height: auto; min-height: 100vh; overflow: visible; }
  .main { overflow: visible; min-height: 100vh; }
  .topbar { position: sticky; top: 0; z-index: 30; padding: 0 12px; gap: 8px; }
  .content { padding: 12px !important; overflow-x: hidden; }
  .module-page { padding: 0; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-head h2 { font-size: 20px; }
  .page-head p { font-size: 12px; }
  .data-card { padding: 12px; }

  /* Tablas con scroll horizontal */
  .dataTable_wrapper { overflow-x: auto; }
  table.dataTable { font-size: 12px; }
  table.dataTable th, table.dataTable td { padding: 8px 6px; white-space: nowrap; }

  /* Filtros y grids */
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .row.g-3 > [class*='col-'], .row.g-2 > [class*='col-'] { width: 100% !important; max-width: 100% !important; flex: 0 0 100% !important; }

  /* Modales: full width en mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box { max-width: 100% !important; width: 100% !important; border-radius: 16px 16px 0 0 !important; max-height: 92vh; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; min-width: 130px; }

  /* Botones más táctiles */
  .btn { min-height: 38px; padding: 8px 14px; }
  .form-control, .form-select { font-size: 14px; padding: 9px 12px; }
  .icon-btn { min-width: 32px; min-height: 32px; }
}

@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  table.dataTable th, table.dataTable td { padding: 6px 4px; font-size: 11px; }
  .topbar { height: 56px; }
  .menu-btn { width: 36px; height: 36px; }
}

@media (max-width: 768px) {
  /* Compat con regla antigua */
  .menu-toggle { display: flex; }
}

/* Toast */
#toast-wrap { position: fixed; top: 80px; right: 20px; z-index: 1500; display: flex; flex-direction: column; gap: 8px; }
.toast-msg { background: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 500; min-width: 260px; max-width: 380px; border-left: 4px solid var(--info); animation: toast-in .3s ease-out; }
.toast-msg.success { border-left-color: var(--success); }
.toast-msg.error   { border-left-color: var(--danger); }
.toast-msg.warning { border-left-color: var(--warning); }
.toast-msg i { font-size: 18px; }
.toast-msg.success i { color: var(--success); }
.toast-msg.error   i { color: var(--danger); }
.toast-msg.warning i { color: var(--warning); }
.toast-msg.info    i { color: var(--info); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* Charts */
.chart-wrap { background: #fff; border-radius: 14px; padding: 20px; border: 1px solid var(--border); }
.chart-wrap h4 { font-family: 'Plus Jakarta Sans'; font-size: 14px; font-weight: 700; margin-bottom: 12px; }

/* Ticket / comprobante (estilo térmico 80mm · SUNAT) */
.ticket-print { font-family: 'Courier New', monospace; font-size: 12px; color: #111; background: #fff; padding: 18px 16px; border: 1px dashed var(--border); border-radius: 10px; max-width: 340px; margin: 0 auto; line-height: 1.45; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.ticket-print .center { text-align: center; }
.ticket-print .row-tk { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.ticket-print hr { border: none; border-top: 1px dashed #999; margin: 8px 0; }
.ticket-print .tk-logo-box { display: inline-flex; align-items: center; justify-content: center; padding: 8px 14px; margin: 0 auto 8px; background: #f8fafc; border: 1px solid #eef2f7; border-radius: 12px; }
.ticket-print .tk-logo { max-width: 170px; max-height: 80px; object-fit: contain; display: block; }
.ticket-print .tk-empresa { font-size: 14px; font-weight: 800; line-height: 1.2; }
.ticket-print .tk-nc { font-size: 11px; font-style: italic; color: #444; }
.ticket-print .tk-info { font-size: 11px; line-height: 1.4; }
.ticket-print .tk-b { font-weight: 800; }
.ticket-print .tk-line-bold { border-top: 2px solid #000; margin: 6px 0; }
.ticket-print .tk-tipo { font-weight: 800; font-size: 13px; margin-top: 4px; text-transform: uppercase; }
.ticket-print .tk-corr { font-weight: 800; font-size: 16px; letter-spacing: .03em; }
.ticket-print .tk-meta { font-size: 11px; line-height: 1.6; }
.ticket-print .tk-itemname { font-weight: 800; font-size: 11.5px; margin-top: 5px; }
.ticket-print .tk-itemsub { font-size: 10.5px; color: #444; }
.ticket-print .tk-total-final { font-size: 15px; font-weight: 800; padding: 6px 0; border-top: 2px solid #000; border-bottom: 2px solid #000; margin: 5px 0; }
.ticket-print .tk-letras { font-size: 10.5px; font-style: italic; padding: 4px 0; }
.ticket-print .tk-qr { text-align: center; margin: 8px 0 4px; }
.ticket-print .tk-qr img { width: 120px; height: 120px; }
.ticket-print .tk-qr small { display: block; font-size: 10px; color: #555; margin-top: 3px; }
.ticket-print .tk-hash { font-size: 8.5px; word-break: break-all; color: #555; text-align: center; }
.ticket-print .tk-estado { text-align: center; font-size: 11px; font-weight: 800; padding: 4px 6px; border-radius: 6px; margin: 6px 0; text-transform: uppercase; }
.ticket-print .tk-estado.aceptado  { background: #d1fae5; color: #065f46; }
.ticket-print .tk-estado.pendiente { background: #fef3c7; color: #92400e; }
.ticket-print .tk-estado.rechazado,
.ticket-print .tk-estado.anulada   { background: #fee2e2; color: #991b1b; }
.ticket-print .tk-estado.anulada   { text-decoration: line-through; }
.ticket-print .tk-leyenda { font-weight: 800; font-size: 10.5px; text-align: center; text-transform: uppercase; margin-bottom: 4px; }
.ticket-print .tk-foot { text-align: center; font-size: 10.5px; margin-top: 6px; line-height: 1.5; }
.ticket-print .tk-gracias { margin-top: 8px; padding: 6px 10px; background: #ede9fe; color: #5b21b6; border-radius: 6px; font-weight: 800; text-align: center; }
@media print {
  /* Márgenes mínimos */
  @page { margin: 6mm; }

  /* Estrategia: invisibilizar TODO con visibility:hidden (mantiene layout, sin riesgo de
     esconder ancestros del ticket) y luego mostrar SOLO la cadena del ticket. El ticket
     se saca del flujo con position:fixed para que se ancle al origen de la página. */
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  body * { visibility: hidden !important; }

  /* Aplanar contenedores que en pantalla usan 100vh / overflow:hidden — sin esto la
     "página vacía" se forma porque el layout sigue reservando viewport completo. */
  html, body, .app-wrap, .main, .content, .pos-wrap, .pos-left, .pos-right {
    height: auto !important; min-height: 0 !important; max-height: none !important;
    overflow: visible !important;
  }
  .app-wrap { display: block !important; }

  /* Mostrar la cadena del ticket */
  .ticket-print, .ticket-print * { visibility: visible !important; }

  /* Anclar el ticket al inicio de la página impresa */
  .ticket-print {
    position: fixed !important;
    top: 0 !important; left: 0 !important; right: 0 !important;
    margin: 0 auto !important;
    width: 80mm !important; max-width: 80mm !important;
    border: none !important; border-radius: 0 !important;
    padding: 2mm !important;
    box-shadow: none !important;
    background: #fff !important;
    page-break-inside: avoid;
  }
  .ticket-print .tk-qr img { width: 100px !important; height: 100px !important; }
}
