:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff4ff;
  --primary-contrast: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --sidebar: #111827;
  --sidebar-text: #cbd5e1;
  --sidebar-hover: rgba(255,255,255,.08);
  --sidebar-line: rgba(255,255,255,.12);
  --primary-light: #60a5fa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
h1 { font-size: 22px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 12px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: inherit;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input:disabled, select:disabled { background: #f3f4f6; color: var(--muted); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
label > input, label > select { color: var(--text); font-weight: 400; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn .icon { flex-shrink: 0; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 16px; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: #f3f4f6; color: var(--text); }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 4px 10px 18px; border-bottom: 1px solid var(--sidebar-line); margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.brand-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { max-width: 44px; max-height: 44px; border-radius: 6px; object-fit: contain; flex-shrink: 0; }
.brand-name { color: var(--sidebar-text); font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.brand-sub { font-size: 12px; color: var(--sidebar-text); opacity: .7; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--sidebar-text); }
.nav-link:hover { background: var(--sidebar-hover); text-decoration: none; color: var(--sidebar-text); }
.nav-link.active { background: var(--primary); color: var(--primary-contrast); }
.nav-icon { width: 20px; text-align: center; }
.sidebar-footer { border-top: 1px solid var(--sidebar-line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.user-chip { padding: 0 6px; display: flex; align-items: center; gap: 10px; }
.user-name { overflow-wrap: anywhere; }
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; object-fit: cover; flex-shrink: 0; vertical-align: middle; background: #e5e7eb; }
.avatar-initials { background: var(--primary); color: var(--primary-contrast); font-weight: 700; }
.user-name { color: var(--sidebar-text); font-weight: 600; }
.user-role { font-size: 12px; color: var(--sidebar-text); opacity: .7; }
.sidebar .btn { background: transparent; color: var(--sidebar-text); border-color: var(--sidebar-line); }
.sidebar .btn:hover { background: var(--sidebar-hover); }
.menu-toggle { color: var(--sidebar-text) !important; }
.menu-toggle { display: none; }
.content { flex: 1; min-width: 0; }
.page { padding: 24px 28px; max-width: 1400px; }
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; overflow-x: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 > .card { margin-bottom: 0; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 24px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--muted); font-size: 12px; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid #f1f2f4; vertical-align: middle; }
.table tbody tr:hover { background: #fafbfc; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-warning { background: var(--warning-soft); }
.row-warning:hover { background: #fef3c7 !important; }
.row-muted td { color: var(--muted); text-decoration: line-through; }
.row-muted td:last-child, .row-muted td:nth-last-child(2) { text-decoration: none; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.cell-input { width: 90px; padding: 4px 6px; text-align: right; }
.thumb { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; background: #f3f4f6; vertical-align: middle; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: #f3f4f6; color: var(--muted); }
.badge-info { background: var(--primary-soft); color: var(--primary); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-right { text-align: right; }

.alert { padding: 10px 12px; border-radius: 8px; margin-top: 12px; border: 1px solid; }
.alert-danger { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.alert-success { background: var(--success-soft); border-color: #bbf7d0; color: #166534; }
.alert-warning { background: var(--warning-soft); border-color: #fde68a; color: #92400e; }

.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filters input[type=search], .filters input.grow { flex: 1; min-width: 220px; }
.filters select, .filters input[type=date] { width: auto; min-width: 160px; }
.checkbox-label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); cursor: pointer; }
.checkbox-label input { width: auto; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 12px; color: var(--muted); }

/* Forms / modals */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.span-2 { grid-column: span 2; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal-overlay { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal-box { background: #fff; border-radius: 12px; width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; }
.modal-body { padding: 18px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { border: none; background: none; padding: 10px 14px; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.toast-stack { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { padding: 10px 14px; border-radius: 8px; color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.15); max-width: 360px; animation: slide .2s ease-out; }
.toast-success { background: #15803d; }
.toast-error { background: #b91c1c; }
.toast-info { background: #1e40af; }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(135deg, var(--primary-dark), var(--primary) 60%, var(--primary-light)); }
.login-copy { margin: 6px 0 0; padding-top: 12px; border-top: 1px solid var(--border); text-align: center; font-size: 12px; color: var(--muted); line-height: 1.6; }
.login-logo { display: block; max-width: 160px; max-height: 90px; margin: 0 auto; object-fit: contain; }
.login-card { background: #fff; padding: 32px; border-radius: 14px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { text-align: center; }
.login-card .muted { text-align: center; margin: -8px 0 6px; }

/* POS */
.pos-grid { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
.checkout-card { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 18px; }
.checkout-card h3 { margin: 0; }
.search-wrap { position: relative; margin-bottom: 14px; }
.search-results { position: absolute; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.12); z-index: 10; max-height: 360px; overflow-y: auto; margin-top: 4px; }
.search-result-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid #f3f4f6; }
.search-result-item:hover, .search-result-item.active { background: var(--primary-soft); }
.search-result-item.disabled { opacity: .5; cursor: not-allowed; }
.totals { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 6px; }
.totals > div { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.totals-grand { font-size: 18px; font-weight: 700; border-top: 1px dashed var(--border); padding-top: 8px; }

/* Charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.chart .grid line { stroke: #eef0f3; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--c); margin-right: 6px; }
.chart-tip { position: fixed; pointer-events: none; background: #111827; color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 12px; z-index: 200; white-space: nowrap; }

/* Apariencia */
.logo-box { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.logo-preview { width: 140px; height: 90px; border: 1px dashed var(--border); border-radius: 8px; display: flex; align-items: center; justify-content: center; background: #fafafa; color: var(--muted); font-size: 12px; overflow: hidden; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.color-row { display: flex; align-items: center; gap: 8px; }
.color-row input[type=color] { width: 46px; height: 38px; padding: 2px; cursor: pointer; flex-shrink: 0; }
.presets { display: flex; gap: 10px; flex-wrap: wrap; }
.preset { border: 2px solid var(--border); border-radius: 10px; padding: 4px; cursor: pointer; background: #fff; display: flex; flex-direction: column; align-items: center; gap: 4px; font: inherit; font-size: 12px; color: var(--muted); }
.preset:hover { border-color: var(--primary); }
.preset .sw { display: flex; width: 64px; height: 28px; border-radius: 6px; overflow: hidden; }
.preset .sw i { flex: 1; }
.theme-preview { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; height: 150px; }
.theme-preview .tp-side { width: 34%; padding: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.theme-preview .tp-link { padding: 5px 8px; border-radius: 6px; }
.theme-preview .tp-main { flex: 1; padding: 14px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.theme-preview .tp-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 12px; width: 100%; }
.theme-preview .tp-btn { padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600; }

.empty { padding: 30px; text-align: center; color: var(--muted); }

@media (max-width: 980px) {
  .pos-grid, .grid-2 { grid-template-columns: 1fr; }
  .checkout-card { position: static; }
}
@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: sticky; z-index: 20; padding: 10px 12px; }
  .brand { display: flex; justify-content: space-between; align-items: center; border: 0; margin: 0; padding: 0 4px; }
  .menu-toggle { display: inline-flex; }
  .sidebar nav, .sidebar-footer { display: none; }
  .sidebar.open nav, .sidebar.open .sidebar-footer { display: flex; margin-top: 10px; }
  .page { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .filters select, .filters input[type=date] { flex: 1; }
}

@page { margin: 12mm; }
@media print {
  /* Solo se imprime el comprobante abierto: se oculta la pantalla de fondo */
  html, body { background: #fff !important; }
  #root, .toast-stack, .chart-tip, .no-print { display: none !important; }
  .modal-overlay { position: static; inset: auto; display: block; background: none; padding: 0; overflow: visible; }
  .modal-overlay:not(:last-child) { display: none !important; }
  .modal-box { box-shadow: none; max-width: none !important; border-radius: 0; }
  .modal-header { border: 0; padding: 0 0 8px; }
  .modal-body { padding: 0; }
  .table tr, .totals { break-inside: avoid; }
}
