/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:            #faf9f6;
  --surface:       #ffffff;
  --surface-2:     #f4f2ee;
  --border:        #e6e3dd;
  --border-soft:   #f0ede8;
  --text:          #18170f;
  --text-muted:    #928f88;
  --text-dim:      #c8c4bc;
  --accent:        #c97f0a;
  --accent-hover:  #a86808;
  --accent-light:  rgba(201, 127, 10, 0.08);
  --accent-glow:   rgba(201, 127, 10, 0.12);
  --green:         #16a34a;
  --green-light:   rgba(22, 163, 74, 0.06);
  --green-border:  rgba(22, 163, 74, 0.2);
  --danger:        #dc2626;
  --danger-hover:  #b91c1c;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 1px 2px rgba(0,0,0,.06), 0 3px 10px rgba(0,0,0,.05);
  --shadow-md:     0 4px 20px rgba(0,0,0,.08);
  --font-sans:     'Nunito', -apple-system, sans-serif;
  --font-display:  'Nunito', sans-serif;
  --font-mono:     'Fira Code', monospace;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ============================================================
   Nav
   ============================================================ */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 54px;
  background: rgba(250, 249, 246, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.nav-logo {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.04em;
}
.nav-logo::after {
  content: '.';
  color: var(--accent);
}
.nav-logo:hover { color: var(--text); }

.nav-links { display: flex; gap: 0.15rem; }

.nav-link {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  font-family: var(--font-sans);
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

/* ============================================================
   Layout
   ============================================================ */
.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1.25rem 5rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.view-header h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

/* ============================================================
   Tabs
   ============================================================ */
.tabs {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}

.tab {
  flex: 1;
  background: none;
  color: var(--text-muted);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
  font-family: var(--font-sans);
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab--active {
  color: var(--accent);
  background: var(--accent-light);
}

.tab-panel { }
.hidden { display: none; }

/* ============================================================
   Search box
   ============================================================ */
.search-box {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-box input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  border: none;
  border-radius: var(--radius-sm);
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
}
.search-box input::placeholder { color: var(--text-muted); }

/* ============================================================
   Buttons
   ============================================================ */
button {
  padding: 0.55rem 1.1rem;
  font-size: 0.86rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--text);
  color: var(--bg);
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
  font-family: var(--font-sans);
  letter-spacing: 0.01em;
}
button:hover:not(:disabled) {
  background: #2e2d24;
  transform: translateY(-1px);
}
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.25);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(220, 38, 38, 0.06);
  border-color: rgba(220, 38, 38, 0.4);
  transform: none;
}

/* ============================================================
   Card (generic)
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow);
}
.card h3 {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

/* ============================================================
   Barcode result
   ============================================================ */
.product-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.product-header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, transparent 60%);
}

.product-ean {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.1em;
  margin-bottom: 0.45rem;
  text-transform: uppercase;
}

.product-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text);
  letter-spacing: -0.015em;
}

.product-header + .table-wrap { margin-top: 1.25rem; }

/* Price table */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.price-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

.price-table thead tr {
  background: var(--bg);
}

.price-table th {
  text-align: left;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
}

.price-table th:last-child { text-align: right; }

.price-table td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.price-table tbody tr:last-child td { border-bottom: none; }

.row--best td { background: var(--green-light); }
.row--na { opacity: 0.4; }

.td-provider {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-muted);
}
.td-provider a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dashed var(--border);
  transition: color 0.15s, border-color 0.15s;
}
.td-provider a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.row--best .td-provider {
  font-weight: 600;
  color: var(--green);
}
.row--best .td-provider a:hover {
  color: var(--accent);
}

.td-price {
  text-align: right;
  font-size: 1.25rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  letter-spacing: -0.03em;
  white-space: nowrap;
}
.row--best .td-price {
  color: var(--green);
  font-size: 1.5rem;
}
.row--na .td-price {
  font-size: 0.88rem;
  font-weight: 400;
  font-family: var(--font-sans);
  color: var(--text-muted);
}

.promo-price {
  font-size: 0.82rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--green);
  margin-top: 0.2rem;
  letter-spacing: -0.02em;
}
.promo-label {
  display: inline-block;
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--green);
  background: var(--green-light);
  border: 1px solid var(--green-border);
  padding: 0.1rem 0.35rem;
  border-radius: 99px;
  margin-right: 0.35rem;
  vertical-align: middle;
  font-family: var(--font-sans);
}
.best-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 0.55rem;
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--green);
  background: var(--green-light);
  border: 1px solid var(--green-border);
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  vertical-align: middle;
}

/* ============================================================
   Keyword results
   ============================================================ */
.results-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.results-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.result-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  background: var(--surface);
  transition: background 0.12s;
  cursor: default;
}
.result-item:hover { background: #fdfcfa; }

.result-thumb {
  width: 50px;
  height: 50px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--bg);
  flex-shrink: 0;
  padding: 4px;
}
.result-thumb--empty {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  background: var(--bg);
  flex-shrink: 0;
}

.result-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.result-name {
  font-size: 0.87rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text);
}
.result-brand {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 400;
}
.result-ean {
  font-size: 0.62rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
  margin-top: 0.1rem;
  letter-spacing: 0.06em;
}

.result-price-col {
  text-align: right;
  flex-shrink: 0;
}
.result-price {
  font-size: 1.05rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
  letter-spacing: -0.02em;
}
.result-list-price {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-decoration: line-through;
  font-family: var(--font-mono);
}

/* ============================================================
   Settings
   ============================================================ */
.token-input {
  width: 100%;
  min-height: 80px;
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  outline: none;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  line-height: 1.7;
}
.token-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--surface-2);
  color: var(--accent);
  padding: 0.12em 0.45em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* ============================================================
   Misc
   ============================================================ */
.status-msg {
  padding: 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}
.status-msg.error { color: var(--danger); }
.hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.65;
}

/* ============================================================
   Curl modal
   ============================================================ */
.row--inspectable { cursor: default; }
.row--inspectable:hover td { background: color-mix(in srgb, var(--surface-2) 80%, transparent); }

#curl-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
#curl-modal.curl-modal--open { display: flex; }

.curl-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(2px);
}

.curl-dialog {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 680px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.curl-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.curl-title {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.curl-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  transform: none;
}
.curl-close:hover { background: var(--surface-2); color: var(--text); transform: none; }

.curl-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.curl-body pre {
  margin: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  overflow-x: auto;
}

.curl-body code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text);
  background: none;
  border: none;
  padding: 0;
  white-space: pre;
  letter-spacing: 0;
}

/* ============================================================
   Search actions (scan + buscar row)
   ============================================================ */
.search-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.btn-scan {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-scan:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--text-muted);
  transform: none;
}
.btn-scan:active:not(:disabled) { transform: none; }

/* ============================================================
   Scanner overlay (bottom sheet)
   ============================================================ */
#scanner-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: flex-end;
}

.scanner-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.scanner-overlay--open .scanner-backdrop { opacity: 1; }

.scanner-sheet {
  position: relative;
  width: 100%;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 0 1.25rem 2rem;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 92vh;
  overflow: hidden;
}
.scanner-overlay--open .scanner-sheet { transform: translateY(0); }

.scanner-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  margin: 0.75rem auto 1.25rem;
}

.scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.1rem;
}

.scanner-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.scanner-close {
  background: var(--surface-2);
  color: var(--text-muted);
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.scanner-close:hover { background: var(--border); color: var(--text); transform: none; }

#scanner-region {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}
/* Override html5-qrcode internal elements */
#scanner-region video {
  width: 100% !important;
  height: auto !important;
  border-radius: var(--radius);
  display: block;
}

.scanner-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 1rem;
  padding: 0 1rem;
}

/* ============================================================
   Mobile
   ============================================================ */
@media (max-width: 480px) {
  nav { padding: 0 1rem; }
  .view { padding: 1.25rem 1rem 3rem; }
  .search-box { flex-direction: column; }
  .view-header { flex-direction: column; }
  .result-item { padding: 0.75rem 0.9rem; }
  .td-price { font-size: 1.1rem; }
  .row--best .td-price { font-size: 1.3rem; }
}
