/* ==========================================================================
   Monako · Sistema de diseño compartido
   ========================================================================== */
:root {
  --brand: #E8541E; --brand-600: #C9420F; --brand-700: #A8360C; --brand-50: #FFF1EA; --brand-100: #FFE0D1;
  --accent: #FFB020; --accent-50: #FFF6E0;
  --ink: #1F1A17; --ink-2: #3D3733; --muted: #8A837E; --muted-2: #B5AEA8;
  --line: #ECE7E3; --line-2: #F3EFEC; --bg: #F7F5F3; --card: #FFFFFF; --cream: #FFF7F0;
  --green: #16A34A; --green-50: #E9F8EF; --green-100: #CDEFD9;
  --red: #DC2626; --red-50: #FDECEC;
  --blue: #2563EB; --blue-50: #EAF1FE;
  --violet: #7C3AED; --violet-50: #F1EBFE;
  --amber: #D97706; --amber-50: #FEF5E6;
  --teal: #0F9488; --teal-50: #E6F6F4;
  --r-sm: 10px; --r: 14px; --r-lg: 20px; --r-xl: 28px;
  --sh-sm: 0 1px 2px rgba(31, 26, 23, .06);
  --sh: 0 6px 24px -8px rgba(31, 26, 23, .14);
  --sh-lg: 0 24px 60px -20px rgba(31, 26, 23, .28);
  --f-display: "Playfair Display", Georgia, serif;
  --f-body: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--f-body); font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
p { margin: 0; }
::selection { background: var(--brand-100); }
.serif { font-family: var(--f-display); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.bold { font-weight: 700; }
.semi { font-weight: 600; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { color: var(--brand); }
.green { color: var(--green); } .red { color: var(--red); } .amber { color: var(--amber); }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Layout utils */
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-16 { gap: 16px; } .gap-20 { gap: 20px; } .gap-24 { gap: 24px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-all { grid-column: 1 / -1; }
.mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.p-16 { padding: 16px; } .p-20 { padding: 20px; } .p-24 { padding: 24px; }
@media (max-width: 1100px) { .g4, .g5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .g2, .g3, .g4, .g5 { grid-template-columns: 1fr; } .span-2, .span-3 { grid-column: auto; } }

/* Iconos */
.ic { width: 19px; height: 19px; flex: none; fill: currentColor; stroke: none; vertical-align: middle; }
.ic [opacity] { opacity: .22; }
.ic.sm { width: 16px; height: 16px; } .ic.lg { width: 24px; height: 24px; } .ic.xl { width: 34px; height: 34px; }

/* Botones */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 12px; font-weight: 600; font-size: 14px; white-space: nowrap; border: 1px solid transparent; transition: background .15s, transform .1s, box-shadow .15s, border-color .15s; user-select: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 6px 16px -6px rgba(232, 84, 30, .6); }
.btn-primary:hover { background: var(--brand-600); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { background: #000; }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--line-2); }
.btn-outline { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--muted-2); background: #fffdfb; }
.btn-soft { background: var(--brand-50); color: var(--brand-600); }
.btn-soft:hover { background: var(--brand-100); }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger-soft { background: var(--red-50); color: var(--red); }
.btn-accent { background: var(--accent); color: var(--ink); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn-xs { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 8px; gap: 5px; }
.btn-lg { height: 50px; padding: 0 24px; font-size: 15px; border-radius: 14px; }
.btn-xl { height: 58px; padding: 0 28px; font-size: 17px; border-radius: 16px; }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; } .btn-icon.btn-xs { width: 26px; }
.btn-block { width: 100%; }
.btn-pill { border-radius: 999px; }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.field .help { font-size: 11.5px; color: var(--muted); }
.input, .select, .textarea { width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; }
.textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(232, 84, 30, .12); }
.input.sm, .select.sm { height: 34px; border-radius: 10px; font-size: 13px; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238A837E' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.input-icon { position: relative; }
.input-icon .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon .input { padding-left: 38px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 40px; height: 23px; border-radius: 99px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: var(--sh-sm); transition: transform .2s var(--ease); }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(17px); }
.qty { display: inline-flex; align-items: center; gap: 2px; background: var(--line-2); border-radius: 999px; padding: 3px; }
.qty button { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: #fff; box-shadow: var(--sh-sm); }
.qty button:hover { color: var(--brand); }
.qty span { min-width: 26px; text-align: center; font-weight: 700; }
.qty.dark button { background: var(--ink); color: #fff; }

/* Tarjetas */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.card-head h3 { font-size: 15px; font-weight: 700; }
.card-body { padding: 20px; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--line-2); }
.divider { height: 1px; background: var(--line); margin: 12px 0; }

/* Chips y badges */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-weight: 600; font-size: 13px; color: var(--ink-2); white-space: nowrap; transition: all .15s; }
.chip:hover { border-color: var(--muted-2); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip.brand.active { background: var(--brand); border-color: var(--brand); }
.chip .count { background: rgba(0, 0, 0, .08); border-radius: 99px; padding: 0 7px; font-size: 11px; line-height: 18px; }
.chip.active .count { background: rgba(255, 255, 255, .22); }
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; background: var(--line-2); color: var(--ink-2); }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-brand { background: var(--brand-50); color: var(--brand-600); }
.b-green { background: var(--green-50); color: var(--green); }
.b-red { background: var(--red-50); color: var(--red); }
.b-blue { background: var(--blue-50); color: var(--blue); }
.b-violet { background: var(--violet-50); color: var(--violet); }
.b-amber { background: var(--amber-50); color: var(--amber); }
.b-teal { background: var(--teal-50); color: var(--teal); }
.b-dark { background: var(--ink); color: #fff; }
.b-solid-brand { background: var(--brand); color: #fff; }
.b-solid-green { background: var(--green); color: #fff; }
.b-solid-red { background: var(--red); color: #fff; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--line-2); color: var(--ink-2); }

/* Tablas */
.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fff; position: sticky; top: 0; z-index: 1; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: #FCFAF8; }
.table tr.clickable { cursor: pointer; }
.table .thumb { width: 38px; height: 38px; border-radius: 10px; object-fit: cover; background: var(--line-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tfoot td { font-weight: 700; border-top: 1px solid var(--line); background: #FCFAF8; }

/* Tabs y segmentados */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 12px 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-color: var(--brand); }
.seg { display: inline-flex; padding: 4px; background: var(--line-2); border-radius: 12px; gap: 2px; }
.seg button { height: 32px; padding: 0 14px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.seg button.active { background: #fff; color: var(--ink); box-shadow: var(--sh-sm); }

/* KPI */
.kpi { padding: 18px 20px; }
.kpi .k-label { font-size: 13px; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.kpi .k-value { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; align-items: center; }
.kpi .k-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); }
.delta-up { color: var(--green); font-weight: 700; } .delta-down { color: var(--red); font-weight: 700; }
.kpi-strip { display: grid; grid-template-columns: repeat(4, 1fr); }
.kpi-strip > * + * { border-left: 1px solid var(--line); }
@media (max-width: 900px) { .kpi-strip { grid-template-columns: repeat(2, 1fr); } .kpi-strip > *:nth-child(3) { border-left: 0; } .kpi-strip > *:nth-child(n+3) { border-top: 1px solid var(--line); } }

/* Avatares */
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--brand-50); color: var(--brand-600); display: inline-grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; overflow: hidden; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; } .avatar.lg { width: 56px; height: 56px; font-size: 18px; } .avatar.xl { width: 84px; height: 84px; font-size: 26px; }

/* Modal, drawer y toasts */
.overlay { position: fixed; inset: 0; background: rgba(24, 18, 15, .42); backdrop-filter: blur(3px); z-index: 900; display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .2s; }
.modal { background: #fff; border-radius: 22px; width: 100%; max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: var(--sh-lg); animation: pop .25s var(--ease); overflow: hidden; }
.modal.lg { max-width: 820px; } .modal.xl { max-width: 1100px; } .modal.sm { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line-2); gap: 12px; }
.modal-head h3 { font-size: 17px; font-weight: 700; }
.modal-body { padding: 22px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line-2); background: #FDFCFB; }
.overlay.drawer-wrap { justify-content: flex-end; padding: 0; align-items: stretch; }
.drawer { background: #fff; width: min(560px, 100vw); height: 100%; display: flex; flex-direction: column; box-shadow: var(--sh-lg); animation: slide .3s var(--ease); }
.drawer.lg { width: min(760px, 100vw); } .drawer.xl { width: min(980px, 100vw); }
.drawer .modal-body { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 14px; box-shadow: var(--sh-lg); font-weight: 500; max-width: 380px; animation: pop .25s var(--ease); }
.toast.success .t-ic { color: #4ADE80; } .toast.error { background: #7F1D1D; } .toast.info .t-ic { color: var(--accent); }
@media (max-width: 640px) { .toasts { left: 12px; right: 12px; bottom: 84px; } .toast { max-width: none; } }

/* Estados vacíos y carga */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .e-ic { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; margin: 0 auto 12px; background: var(--line-2); color: var(--muted); }
.empty h4 { color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; }
.loading { display: grid; place-items: center; padding: 60px; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--line-2), #fff, var(--line-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 10px; }
@keyframes sk { to { background-position: -200% 0; } }

/* Imagen de producto con fallback */
.pimg { position: relative; background: linear-gradient(135deg, #FFE7D9, #FFF6EE); overflow: hidden; }
.pimg img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s var(--ease); }
.pimg .fallback { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; }
.pimg.broken img { display: none; }

/* Gráficos */
.chart { width: 100%; }
.chart text { font-family: var(--f-body); font-size: 11px; fill: var(--muted); }
.chart .bar { transition: opacity .15s; cursor: pointer; }
.chart .bar:hover { opacity: .85; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tooltip { position: fixed; z-index: 1100; pointer-events: none; background: var(--ink); color: #fff; padding: 8px 11px; border-radius: 10px; font-size: 12px; box-shadow: var(--sh-lg); white-space: nowrap; }

/* Progreso */
.progress { height: 8px; border-radius: 99px; background: var(--line-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

/* Desplazamiento horizontal */
.hscroll { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.hscroll::-webkit-scrollbar { display: none; }

/* Impresión */
@media print {
  body { background: #fff; }
  .no-print, .sidebar, .topbar, .toasts { display: none !important; }
  .main { margin: 0 !important; padding: 0 !important; }
  .card { border: 0; }
}

/* Modales en móvil: hoja inferior y sin desbordes */
.modal, .drawer { min-width: 0; max-width: min(var(--mw, 560px), 100%); }
.modal.lg { --mw: 820px; } .modal.xl { --mw: 1100px; } .modal.sm { --mw: 420px; }
.modal-foot { flex-wrap: wrap; }
.modal-foot .btn { white-space: normal; }
@media (max-width: 640px) {
  .overlay:not(.drawer-wrap) { align-items: flex-end; padding: 0; }
  .overlay:not(.drawer-wrap) .modal { max-width: 100%; border-radius: 22px 22px 0 0; max-height: 94vh; animation: up .3s var(--ease); }
  .modal-foot { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn-lg { flex: 1; }
  .drawer { width: 100vw; }
}
