:root {
  --bg: #eef3f1;
  --bg-tint-1: #e7f3ee;
  --bg-tint-2: #eaf1f7;
  --surface: #ffffff;
  --surface-2: #f4f8f6;
  --surface-3: #e9f1ed;
  --ink: #0c1a13;
  --ink-2: #2c4a3c;
  --muted: #647d72;
  --line: #dde8e2;
  --line-soft: #e8f0ec;
  --accent: #0e9e72;
  --accent-dark: #0a7a58;
  --accent-light: #dcf6ec;
  --accent-2: #2563a8;
  --accent-2-light: #dcecfb;
  --accent-grad: linear-gradient(135deg, #14b886 0%, #0a7a58 100%);
  --accent-grad-soft: linear-gradient(135deg, #2de8b0 0%, #0cc87a 100%);
  --ok: #0f8a45;
  --ok-light: #d6f5e4;
  --warn: #9a6200;
  --warn-light: #fdf0cf;
  --danger: #c5341f;
  --danger-light: #fde4df;
  --shadow-xs: 0 1px 2px rgba(12,40,28,0.06);
  --shadow-sm: 0 2px 8px rgba(12,40,28,0.06), 0 1px 2px rgba(12,40,28,0.04);
  --shadow: 0 10px 30px rgba(12,40,28,0.10), 0 3px 8px rgba(12,40,28,0.05);
  --shadow-lg: 0 30px 70px rgba(8,28,20,0.22), 0 10px 24px rgba(8,28,20,0.10);
  --shadow-glow: 0 8px 24px rgba(14,158,114,0.28);
  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 22px;
  --side-bg-top: #0a1f16;
  --side-bg-bottom: #0e2c1d;
  --side-active: rgba(45,232,176,0.14);
  --side-hover: rgba(255,255,255,0.05);
  --side-text: #9dc4b3;
  --side-text-active: #f2fdf8;
  --ease: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: 0.34s cubic-bezier(0.34, 1.56, 0.64, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { min-width: 320px; }

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, 'Segoe UI', Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 620px at 100% -8%, var(--bg-tint-2) 0%, transparent 55%),
    radial-gradient(900px 560px at -6% 4%, var(--bg-tint-1) 0%, transparent 50%);
  background-attachment: fixed;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
svg { display: block; fill: currentColor; }

/* ─── App shell ───────────────────────────── */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
}

/* ─── Sidebar ─────────────────────────────── */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: linear-gradient(165deg, var(--side-bg-top) 0%, var(--side-bg-bottom) 100%);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  gap: 22px;
  z-index: 20;
  border-right: 1px solid rgba(255,255,255,0.05);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: var(--accent-grad-soft);
  color: #063a22;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(13,200,122,0.4), inset 0 1px 0 rgba(255,255,255,0.4);
}

.brand-mark svg { width: 23px; }

.brand strong {
  display: block;
  color: var(--side-text-active);
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.brand span {
  display: block;
  color: #7eb39d;
  font-size: 0.78rem;
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-item {
  border: 0;
  background: transparent;
  color: var(--side-text);
  padding: 11px 13px;
  border-radius: 11px;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background var(--ease), color var(--ease), transform var(--ease);
  cursor: pointer;
  position: relative;
}

.nav-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: #2de8b0;
  border-radius: 0 3px 3px 0;
  transition: height var(--ease);
}

.nav-item .icon { color: #6fa590; transition: color var(--ease); }
.nav-item:hover { background: var(--side-hover); color: #d4ede5; }
.nav-item:hover .icon { color: #9fd9c3; }
.nav-item.is-active {
  background: var(--side-active);
  color: var(--side-text-active);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(45,232,176,0.18);
}
.nav-item.is-active .icon { color: #2de8b0; }
.nav-item.is-active::before { height: 56%; }

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
}

.icon svg { width: 18px; height: 18px; }

.compliance-note {
  margin-top: auto;
  padding: 14px 15px;
  border-radius: var(--radius);
  background: linear-gradient(150deg, rgba(45,232,176,0.08), rgba(255,255,255,0.03));
  border: 1px solid rgba(255,255,255,0.08);
  display: grid;
  gap: 5px;
  line-height: 1.45;
}

.compliance-note strong { color: var(--side-text-active); font-size: 0.82rem; }
.compliance-note span { color: #7eb39d; font-size: 0.8rem; }

/* ─── Workspace ───────────────────────────── */

.workspace {
  min-width: 0;
  padding: 26px 28px;
  overflow-x: hidden;
}

/* ─── Topbar ──────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 26px;
}

.menu-button {
  display: none;
  width: 44px;
  height: 44px;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
  justify-content: center;
  align-items: center;
}

.topbar-title { min-width: 0; flex: 1; }

.topbar-title span {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: block;
}

.topbar-title h1 {
  margin: 4px 0 0;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.arca-status {
  margin-left: auto;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 15px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 2.4s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(15,138,69,0.28); }
  50% { box-shadow: 0 0 0 6px rgba(15,138,69,0.0); }
}

/* ─── Views ───────────────────────────────── */

.view { display: none; }

.view.is-visible {
  display: block;
  animation: fadeIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
}

.section-head h2 { margin: 0; font-size: 1.3rem; font-weight: 800; letter-spacing: -0.02em; }

.section-head p { color: var(--muted); margin: 4px 0 0; font-size: 0.88rem; }

.section-head-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

/* ─── Buttons ─────────────────────────────── */

.primary-action,
.secondary-action,
.ghost-action,
.menu-button,
.qty-button {
  border: 0;
  border-radius: var(--radius-sm);
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background var(--ease), color var(--ease), box-shadow var(--ease), transform var(--ease), border-color var(--ease);
}

.primary-action, .secondary-action, .ghost-action {
  padding: 0 18px;
  font-weight: 600;
  font-size: 0.88rem;
}

.primary-action {
  background: var(--accent-grad);
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}

.primary-action:hover {
  box-shadow: 0 12px 30px rgba(14,158,114,0.36);
  transform: translateY(-2px);
}

.primary-action:active { transform: translateY(0) scale(0.98); }

.secondary-action {
  background: var(--surface);
  color: var(--accent-dark);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
}

.secondary-action:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-2px);
}

.ghost-action {
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 0.82rem;
  min-height: 36px;
  padding: 0 14px;
}

.ghost-action:hover { background: var(--surface-3); color: var(--accent-dark); }

button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── Metric cards ────────────────────────── */

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.metric {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform var(--ease), box-shadow var(--ease);
}

.metric:hover { transform: translateY(-3px); box-shadow: var(--shadow); }

.metric::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--accent);
}

.metric::after {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  opacity: 0.08;
  background: var(--accent);
}

.metric:nth-child(4n+1)::before, .metric:nth-child(4n+1)::after { background: #3b82f6; }
.metric:nth-child(4n+2)::before, .metric:nth-child(4n+2)::after { background: #8b5cf6; }
.metric:nth-child(4n+3)::before, .metric:nth-child(4n+3)::after { background: #10b981; }
.metric:nth-child(4n+4)::before, .metric:nth-child(4n+4)::after { background: #f59e0b; }

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.metric strong {
  display: block;
  font-size: 1.65rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.metric small {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  margin-top: 8px;
  line-height: 1.4;
}

/* ─── Panels ──────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  min-width: 0;
  overflow: hidden;
}

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

.panel h3 { margin: 0; font-size: 0.98rem; font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }

/* ─── Layouts ─────────────────────────────── */

.split-layout, .settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, 0.9fr);
  gap: 18px;
}

.catalog-forms { margin-bottom: 18px; }

/* ─── Tables ──────────────────────────────── */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
}

table { width: 100%; border-collapse: collapse; }

th {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1.5px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
  font-size: 0.88rem;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--ease); }
tbody tr:hover { background: var(--surface-2); }

/* ─── Status badges ───────────────────────── */

.status {
  border-radius: 999px;
  padding: 4px 11px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status.Autorizado { background: var(--ok-light); color: var(--ok); }
.status.Autorizado::before { background: var(--ok); }
.status.Pendiente { background: var(--warn-light); color: var(--warn); }
.status.Pendiente::before { background: #d97706; }
.status.Rechazado { background: var(--danger-light); color: var(--danger); }
.status.Rechazado::before { background: var(--danger); }

/* ─── Action links ────────────────────────── */

.action-link {
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--ease);
}

.action-link:hover { background: var(--accent-light); }
.action-link.danger { color: var(--danger); }
.action-link.danger:hover { background: var(--danger-light); }

/* ─── Alert / Strategy / Flow cards ──────── */

.alert-list, .strategy-list, .integration-flow { display: grid; gap: 11px; }

.alert-list > div, .strategy-list > div, .integration-flow > div {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  background: var(--surface-2);
  display: grid;
  gap: 4px;
  transition: transform var(--ease), box-shadow var(--ease);
}

.alert-list > div:hover, .strategy-list > div:hover, .integration-flow > div:hover {
  transform: translateX(2px);
  box-shadow: var(--shadow-xs);
}

.alert-list > div:nth-child(2) { border-left-color: #f59e0b; }
.alert-list > div:nth-child(3) { border-left-color: #3b82f6; }

.alert-list strong, .strategy-list strong, .integration-flow strong {
  display: block;
  font-size: 0.88rem;
}

.alert-list span, .strategy-list span, .integration-flow span {
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.82rem;
}

.flow-index {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  margin-bottom: 6px;
  box-shadow: 0 3px 8px rgba(14,158,114,0.3);
}

/* ─── Sale layout ─────────────────────────── */

.sale-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  gap: 18px;
  align-items: start;
}

.sale-form, .ticket-panel { display: grid; gap: 16px; }

.ticket-panel {
  position: sticky;
  top: 16px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
}

.step-block {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.step-label {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
  margin-top: 8px;
  box-shadow: 0 3px 8px rgba(14,158,114,0.28);
}

/* ─── Forms ───────────────────────────────── */

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

.field-grid.single { grid-template-columns: 1fr; margin-top: 14px; }

.form-submit { grid-column: 1 / -1; min-height: 46px; }

label {
  display: grid;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: 0.01em;
}

input, select {
  width: 100%;
  min-height: 44px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  padding: 0 13px;
  font-weight: 500;
  transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
}

input:hover, select:hover { border-color: #c2d4cb; }

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(14,158,114,0.13);
}

input::placeholder { color: #aebdb7; font-weight: 400; }

/* ─── Product picker ──────────────────────── */

.product-picker { display: grid; gap: 12px; }

.product-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.product-card {
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 13px;
  display: grid;
  gap: 6px;
  transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
}

.product-card:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(14,158,114,0.14);
  transform: translateY(-2px);
}

.product-card strong { font-size: 0.88rem; line-height: 1.25; }

.product-card span { color: var(--muted); font-size: 0.76rem; line-height: 1.35; }

.product-card button {
  border: 0;
  background: var(--accent-2);
  color: #ffffff;
  border-radius: var(--radius-sm);
  min-height: 36px;
  font-weight: 700;
  font-size: 0.82rem;
  transition: background var(--ease), transform var(--ease), box-shadow var(--ease);
}

.product-card button:hover {
  background: #1d5391;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37,99,168,0.3);
}

.product-card.stock-low { border-color: #fcd34d; }
.product-card.stock-low::after {
  content: 'Stock bajo';
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--warn);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-2);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

/* ─── Ticket / Cart ───────────────────────── */

.pill {
  background: var(--accent-light);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--accent-dark);
}

.cart-list { min-height: 160px; display: grid; gap: 8px; align-content: start; }

.cart-empty {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  min-height: 140px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.84rem;
  padding: 20px;
  line-height: 1.5;
  background: rgba(255,255,255,0.5);
}

.cart-row {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  background: var(--surface);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.cart-row:hover { border-color: var(--accent); box-shadow: var(--shadow-xs); }

.cart-main strong { display: block; font-size: 0.88rem; line-height: 1.25; }
.cart-main span { color: var(--muted); font-size: 0.76rem; }

.qty-controls { display: inline-flex; align-items: center; gap: 6px; }

.qty-button {
  width: 32px;
  height: 32px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 800;
  font-size: 1rem;
  display: grid;
  place-items: center;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
}

.qty-button:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent-dark); }

.qty-controls strong {
  width: 28px;
  text-align: center;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

.totals {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: grid;
  gap: 8px;
}

.total-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.84rem;
}

.total-line.strong {
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 800;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}

.emit-button {
  width: 100%;
  min-height: 50px;
  font-size: 0.95rem;
  border-radius: var(--radius);
}

.emit-button.is-loading { pointer-events: none; opacity: 0.82; }

.emit-spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.emit-button.is-loading .emit-spinner { display: block; }
.emit-button.is-loading .emit-icon,
.emit-button.is-loading .emit-label { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }

.helper-text { color: var(--muted); font-size: 0.76rem; line-height: 1.5; text-align: center; }

/* ─── Invoices / filters ──────────────────── */

.filter-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-row label { width: min(260px, 100%); }

/* ─── Tax metrics ─────────────────────────── */

.tax-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ─── Margin hint ─────────────────────────── */

.margin-hint {
  font-size: 0.78rem;
  color: var(--accent-dark);
  font-weight: 600;
  margin: 0;
  min-height: 18px;
}

/* ─── Danger zone panel ───────────────────── */

.danger-zone {
  border-color: var(--danger-light);
  background: linear-gradient(180deg, #fffafa, #fff5f4);
}

.danger-zone .panel-head h3 { color: var(--danger); }

/* ─── Modal ───────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8,22,15,0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.modal-backdrop.is-open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(700px, 100%);
  max-height: min(90vh, 820px);
  display: flex;
  flex-direction: column;
  transform: translateY(24px) scale(0.96);
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.is-open .modal { transform: translateY(0) scale(1); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.modal-head h3 { margin: 0; font-size: 1.05rem; font-weight: 700; }

.modal-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: var(--surface-2);
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background var(--ease), color var(--ease), transform var(--ease);
  flex-shrink: 0;
}

.modal-close:hover { background: var(--danger-light); color: var(--danger); transform: rotate(90deg); }
.modal-close svg { width: 16px; height: 16px; }

.modal-body { padding: 24px; overflow-y: auto; flex: 1; }

/* Invoice detail inside modal */

.inv-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
  gap: 16px;
  flex-wrap: wrap;
}

.inv-type-badge { font-size: 1.45rem; font-weight: 900; letter-spacing: -0.02em; }
.inv-type-sub { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

.inv-meta { text-align: right; }

.inv-number { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.inv-date { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }

.inv-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
}

.inv-party-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 6px;
}

.inv-party-name { font-weight: 700; font-size: 0.9rem; margin-bottom: 3px; }
.inv-party-meta { font-size: 0.8rem; color: var(--muted); }

.inv-items-table { width: 100%; margin-bottom: 16px; }
.inv-items-table th { font-size: 0.68rem; padding: 8px 10px; }
.inv-items-table td { padding: 9px 10px; font-size: 0.84rem; }

.inv-totals {
  max-width: 280px;
  margin-left: auto;
  display: grid;
  gap: 8px;
  padding-top: 14px;
  border-top: 2px solid var(--line);
}

.inv-total-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.84rem;
  color: var(--ink-2);
}

.inv-total-row.grand {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
  border-top: 1px solid var(--line);
  padding-top: 8px;
  margin-top: 4px;
}

.inv-footer {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 14px;
}

.cae-block { font-size: 0.78rem; color: var(--muted); }
.cae-block strong { display: block; font-size: 0.88rem; color: var(--ink); font-variant-numeric: tabular-nums; margin-top: 2px; }

.inv-payment-label { font-size: 0.78rem; color: var(--muted); }
.inv-payment-label strong { display: block; font-size: 0.88rem; color: var(--ink); margin-top: 2px; }

/* ─── Toast ───────────────────────────────── */

.toast {
  position: fixed;
  right: 22px;
  bottom: 26px;
  background: var(--ink);
  color: #f0faf6;
  border-radius: var(--radius);
  padding: 13px 17px;
  box-shadow: var(--shadow-lg);
  border-left: 3px solid #2de8b0;
  opacity: 0;
  transform: translateY(14px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  max-width: min(360px, calc(100vw - 32px));
  line-height: 1.4;
  font-size: 0.88rem;
  z-index: 60;
}

.toast.is-visible { opacity: 1; transform: translateY(0); }

/* ─── Responsive ──────────────────────────── */

@media (max-width: 1100px) {
  .metric-grid, .tax-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sale-layout, .split-layout, .settings-grid { grid-template-columns: 1fr; }
  .ticket-panel { position: static; }
}

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(288px, 88vw);
    transform: translateX(-110%);
    transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.is-open { transform: translateX(0); }

  .workspace { padding: 18px; }
  .menu-button { display: inline-flex; }
  .arca-status { display: none; }

  .section-head { flex-direction: column; align-items: stretch; }
  .section-head-actions { flex-wrap: wrap; }
  .section-head .primary-action,
  .section-head .secondary-action,
  .section-head-actions > button { flex: 1; justify-content: center; }

  .field-grid, .product-list { grid-template-columns: 1fr; }

  .step-block { grid-template-columns: 1fr; }
  .step-label { display: none; }

  .filter-row { flex-direction: column; align-items: stretch; }
  .filter-row label { width: 100%; }
}

@media (max-width: 560px) {
  .workspace { padding: 13px; }

  .metric-grid, .tax-metrics { grid-template-columns: 1fr; }

  .panel { padding: 16px; }

  .topbar { gap: 10px; margin-bottom: 18px; }
  .topbar-title h1 { font-size: 1.25rem; }

  .cart-row { grid-template-columns: 1fr; }
  .qty-controls { justify-content: space-between; }

  .toast { right: 12px; bottom: 12px; }

  .modal-body { padding: 18px; }
  .inv-parties { grid-template-columns: 1fr; }
  .inv-detail-header { flex-direction: column; }
  .inv-meta { text-align: left; }
  .inv-meta .status { margin-top: 6px; }

  table { min-width: 520px; }
}

/* ─── Login ─────────────────────────────────────────────────────────────────── */
/* El atributo [hidden] debe ganarle a display:flex/grid de las clases. */
[hidden] { display: none !important; }
.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg, #0f1115);
  z-index: 1000;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface, #1a1d24);
  border: 1px solid var(--border, #2a2e38);
  border-radius: 16px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.login-brand { font-size: 1.3rem; font-weight: 700; color: var(--ink, #0c1a13); }
.login-sub { color: var(--muted, #647d72); margin: 0 0 4px; font-size: 0.9rem; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--ink-2, #2c4a3c); }
.login-card input {
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line, #cfd4dd);
  background: #ffffff;
  color: #111418;
  font-size: 0.95rem;
}
.login-card input::placeholder { color: #9aa1ad; }
.login-card .primary-action { margin-top: 6px; justify-content: center; }
.login-error {
  background: rgba(220, 60, 60, 0.12);
  border: 1px solid var(--danger, #dc3c3c);
  color: var(--danger, #dc3c3c);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
}
#logoutButton { margin-left: 12px; }
