:root {
  --bg: #eef2f0;
  --surface: #ffffff;
  --surface-2: #f7faf9;
  --ink: #0f1f1b;
  --muted: #5d7169;
  --line: #dfe7e3;
  --primary: #0f766e;
  --primary-dark: #0b5c56;
  --primary-soft: #e2f2ef;
  --accent: #e2621b;
  --accent-dark: #c14f10;
  --danger: #c0392b;
  --shadow-sm: 0 1px 2px rgba(15, 31, 27, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 31, 27, 0.09);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ================= TOPBAR ================= */
.topbar {
  height: 64px;
  flex: 0 0 64px;
  background: #0a3b36;
  color: #eaf5f2;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.16);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 240px; }

.brand-mark {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #14b8a6, #0f766e);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: 0.5px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.4px; }
.brand-sub { font-size: 11px; color: #9fc6c0; }

.tabs { display: flex; gap: 4px; flex: 1; }

.tab {
  border: none;
  background: transparent;
  color: #b9d8d3;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.tab.active { background: #12726a; color: #fff; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.badge {
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(20, 184, 166, 0.16);
  color: #7fe0d3;
  border: 1px solid rgba(20, 184, 166, 0.3);
  white-space: nowrap;
}

.aeat-btn {
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.aeat-btn:hover { background: rgba(20, 184, 166, 0.28); }
.aeat-btn[data-mode="online"] {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.38);
}
.aeat-btn[data-mode="online"]:hover { background: rgba(245, 158, 11, 0.3); }

.lang-switch {
  display: flex;
  background: rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  padding: 2px;
}
.lang-switch button {
  border: none; background: transparent; color: #b9d8d3;
  padding: 4px 9px; border-radius: 6px; font-size: 12px; font-weight: 700;
}
.lang-switch button.active { background: #eaf5f2; color: #0a3b36; }

.icon-btn {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: #dff0ed;
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.14); }

.icon-btn .dot {
  position: absolute; top: -4px; right: -4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  opacity: 0;
}
.icon-btn .dot.on { opacity: 1; }

.version { font-size: 11.5px; color: #8fb8b2; }

/* ================= WORKSPACE ================= */
.workspace { flex: 1; overflow: hidden; position: relative; }

.view { display: none; height: 100%; padding: 18px 20px; overflow: auto; }
.view.active { display: block; }

/* ============ VENTA ============ */
.pos-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 18px;
  height: 100%;
}

.catalog {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.catalog-head { padding: 14px; border-bottom: 1px solid var(--line); }

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap.small { width: 240px; }
.search-icon { position: absolute; left: 12px; color: var(--muted); }
.search-wrap input {
  width: 100%;
  padding: 10px 12px 10px 38px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
  background: #fff;
}

.category-chips {
  display: flex; gap: 7px; flex-wrap: wrap; margin-top: 12px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
}
.chip.active {
  background: var(--primary-soft);
  border-color: rgba(15, 118, 110, 0.35);
  color: var(--primary-dark);
}

.product-grid {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 11px;
  align-content: start;
}

.pcard {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 12px;
  text-align: left;
  transition: transform 0.08s, box-shadow 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 104px;
}
.pcard:hover {
  border-color: rgba(15, 118, 110, 0.4);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.pcard:active { transform: translateY(0); }

.pcard-name {
  font-weight: 700;
  font-size: 13.5px;
  line-height: 1.25;
  color: var(--ink);
  word-break: break-word;
}
.pcard-cat { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.pcard-foot { margin-top: auto; display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.pcard-price { font-weight: 800; font-size: 15px; color: var(--primary-dark); }
.pcard-tax { font-size: 10.5px; color: var(--muted); background: var(--surface-2); padding: 2px 6px; border-radius: 5px; }

/* CARRITO */
.cart {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.cart-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.cart-head h2 { font-size: 14px; margin: 0; font-weight: 700; letter-spacing: 0.2px; }

.link-btn {
  border: none; background: none; color: var(--muted);
  font-size: 12px; text-decoration: underline; padding: 2px;
}
.link-btn:hover { color: var(--danger); }

.cart-items { flex: 1; overflow-y: auto; padding: 8px 12px; }

.cart-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 40px 20px;
}

.citem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 6px;
  border-bottom: 1px solid #f0f4f2;
}
.citem-info { flex: 1; min-width: 0; }
.citem-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.citem-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

.qty-ctrl {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
}
.qty-ctrl button {
  width: 22px; height: 22px; border: none; background: #fff;
  border-radius: 6px; font-size: 14px; line-height: 1; color: var(--ink);
  display: flex; align-items: center; justify-content: center;
}
.qty-ctrl button:hover { background: var(--primary-soft); color: var(--primary-dark); }
.qty-ctrl span { min-width: 22px; text-align: center; font-size: 12.5px; font-weight: 700; }

.citem-amount { font-weight: 700; font-size: 13px; min-width: 58px; text-align: right; }
.citem-del {
  border: none; background: none; color: #b7c6c0; font-size: 15px; padding: 0 2px;
}
.citem-del:hover { color: var(--danger); }

.cart-summary { padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface-2); }
.sum-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 3px 0; }
.sum-row b { color: var(--ink); font-variant-numeric: tabular-nums; }
.sum-row.total { margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 16px; color: var(--ink); font-weight: 800; }
.sum-row.total b { font-size: 20px; color: var(--primary-dark); }

.payment-block { padding: 12px 16px 16px; border-top: 1px solid var(--line); }

.customer-block {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 7px 10px;
  align-items: center;
}
.customer-block label { font-size: 12px; color: var(--muted); font-weight: 600; }
.customer-block input {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}
.customer-block input:focus { outline: 2px solid rgba(15, 118, 110, 0.35); outline-offset: 1px; }

.pay-methods { display: flex; gap: 8px; margin-bottom: 10px; }
.pay-btn {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 9px;
  padding: 9px 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.pay-btn.active {
  background: var(--primary-soft);
  border-color: rgba(15, 118, 110, 0.4);
  color: var(--primary-dark);
}

.cash-row label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 5px; }
#received-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 15px;
  font-weight: 700;
  text-align: right;
  outline: none;
  background: #fff;
}
#received-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12); }

.quick-cash { display: flex; gap: 5px; margin-top: 7px; }
.quick-cash button {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  padding: 5px 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.quick-cash button:hover { background: var(--primary-soft); color: var(--primary-dark); border-color: rgba(15,118,110,.35); }

.change-row { display: flex; justify-content: space-between; margin-top: 9px; font-size: 12.5px; color: var(--muted); }
.change-row b { color: var(--ink); font-size: 14px; }

.checkout-btn {
  width: 100%;
  margin-top: 12px;
  border: none;
  background: linear-gradient(180deg, #ef7025, var(--accent));
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.3px;
  padding: 13px 0;
  border-radius: 10px;
  box-shadow: 0 6px 14px rgba(226, 98, 27, 0.28);
  transition: filter 0.15s, transform 0.08s;
}
.checkout-btn:hover { filter: brightness(1.04); }
.checkout-btn:active { transform: translateY(1px); }
.checkout-btn:disabled { background: #c9d4d0; box-shadow: none; cursor: not-allowed; }

/* ============ PAGE HEAD (productos / historial) ============ */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 16px;
}
.page-head h1 { font-size: 20px; margin: 0 0 3px; letter-spacing: -0.2px; }
.page-sub { margin: 0; color: var(--muted); font-size: 12.5px; }
.page-actions { display: flex; align-items: center; gap: 9px; }

.primary-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 9px;
  box-shadow: 0 3px 10px rgba(15, 118, 110, 0.22);
}
.primary-btn:hover { background: var(--primary-dark); }

.ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 9px;
}
.ghost-btn:hover { background: var(--surface-2); color: var(--ink); }

.danger-btn {
  border: none; background: var(--danger); color: #fff;
  font-weight: 700; font-size: 13px; padding: 9px 16px; border-radius: 9px;
}

.date-input {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--ink);
}
.range-sep { color: var(--muted); font-size: 12px; }

.table-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: auto;
  max-height: calc(100vh - 210px);
}

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead th {
  position: sticky; top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid #f1f5f3; }
.data-table tbody tr:hover { background: #fbfdfc; }
.data-table .right { text-align: right; }
.data-table .center { text-align: center; }
.data-table td.right { font-variant-numeric: tabular-nums; }

.mini-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  font-size: 11.5px;
  padding: 4px 9px;
  color: var(--muted);
  margin: 0 2px;
}
.mini-btn:hover { background: var(--primary-soft); color: var(--primary-dark); border-color: rgba(15,118,110,.35); }
.mini-btn.danger:hover { background: #fdeceb; color: var(--danger); border-color: #f3c3bd; }

.status-pill {
  display: inline-block;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #e6f6f1;
  color: #0b6b52;
  border: 1px solid #bfe7da;
  white-space: nowrap;
}

.tag-pill {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
}

.empty-hint { padding: 34px; text-align: center; color: var(--muted); font-size: 13px; }

/* ============ STATS ============ */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 6px;
}
.stat-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; }
.stat-value { font-size: 24px; font-weight: 800; letter-spacing: -0.4px; color: var(--primary-dark); font-variant-numeric: tabular-nums; }

/* ============ MODALES ============ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(8, 25, 22, 0.45);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 24px;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(8, 25, 22, 0.28);
  width: 100%;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pop 0.14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: scale(0.98) translateY(6px); } to { opacity: 1; transform: none; } }

.ticket-modal { max-width: 460px; }
.form-modal { max-width: 680px; }
.confirm-modal { max-width: 420px; }
.update-modal { max-width: 480px; }
.settings-modal { max-width: 560px; }

/* Ticket: cabecera a dos columnas (empresa | cliente) */
.tk-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.tk-head .tk-biz { flex: 1 1 auto; min-width: 0; }
.tk-head .tk-client { flex: 0 0 auto; max-width: 42%; text-align: right; }
.tk-head .tk-shop { font-size: 14px; font-weight: 800; }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; }

.close-btn {
  border: none; background: none; font-size: 20px; line-height: 1;
  color: var(--muted); padding: 0 4px;
}
.close-btn:hover { color: var(--ink); }

.modal-foot {
  display: flex; justify-content: flex-end; gap: 9px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

/* TICKET */
.ticket-body { padding: 18px; overflow-y: auto; }
.ticket-paper {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 20px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
  color: #16211e;
}
.tk-center { text-align: center; }
.tk-shop { font-size: 15px; font-weight: 800; letter-spacing: 0.4px; }
.tk-muted { color: #61756e; font-size: 11px; }
.tk-sep { border-top: 1px dashed #c8d5d0; margin: 10px 0; }
.tk-row { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.tk-row b { font-variant-numeric: tabular-nums; }
.tk-items { width: 100%; border-collapse: collapse; font-size: 11px; }
.tk-items th { text-align: left; font-weight: 700; color: #61756e; padding-bottom: 4px; font-size: 10px; text-transform: uppercase; }
.tk-items td { padding: 2px 0; vertical-align: top; }
.tk-items .r { text-align: right; }
.tk-items .c { text-align: center; }
.tk-total { font-size: 15px; font-weight: 800; }
.tk-qr { display: flex; justify-content: center; margin: 12px 0 6px; }
.tk-qr img { width: 140px; height: 140px; image-rendering: pixelated; }

/* FORM */
.form-body { padding: 18px; overflow-y: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.form-grid label.span2 { grid-column: span 2; }
.form-grid input, .form-grid select {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
  outline: none;
}
.form-grid input:focus, .form-grid select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.confirm-text { padding: 18px; margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.5; }

/* UPDATE */
.update-body { padding: 18px; }
.update-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; color: var(--muted); }
.update-row b { color: var(--ink); }
.update-notes { font-size: 12.5px; color: var(--muted); white-space: pre-wrap; margin: 10px 0 0; }
.update-status { font-size: 12.5px; color: var(--primary-dark); margin: 12px 0 0; min-height: 18px; }
.update-source { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.update-source label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.source-row { display: flex; gap: 8px; }
.source-row input {
  flex: 1;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 12.5px;
  color: var(--ink);
  background: #fff;
}
.source-row input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.source-row .ghost-btn { flex: 0 0 auto; padding: 0 12px; height: 34px; }
.link-btn {
  margin-top: 8px;
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary-dark);
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: underline;
}

/* TOAST */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #0a3b36;
  color: #eaf5f2;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(8, 25, 22, 0.3);
  z-index: 90;
  max-width: 70vw;
}
.toast[hidden] { display: none; }
.toast.error { background: #8f2b20; }

.web-only { display: none; }
.web-mode .web-only { display: block; }
.web-mode #btn-update { display: none; }
.backup-tools {
  margin: 0 20px 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.backup-tools h4 { margin: 0 0 5px; font-size: 13px; }
.backup-tools p { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.backup-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* SCROLLBARS */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #c9d6d1; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #b3c4be; }
::-webkit-scrollbar-track { background: transparent; }

@media print {
  body * { visibility: hidden; }
  .ticket-paper, .ticket-paper * { visibility: visible; }
  .ticket-paper { position: absolute; left: 0; top: 0; border: none; }
}
