:root {
  --bg: #17181c;
  --surface: #1f2126;
  --surface-2: #26282e;
  --border: #34363d;
  --text: #edeae2;
  --text-dim: #9c9890;
  --accent: #d4a54a;
  --accent-dim: #8a7239;
  --good: #7fa87a;
  --bad: #c1665a;

  --serif: 'Source Serif 4', Georgia, serif;
  --mono: 'IBM Plex Mono', 'Courier New', monospace;
  --sans: 'Inter', -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100%;
}

.hidden { display: none !important; }

.eyebrow {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 4px;
}

.status-text {
  font-size: 13px;
  color: var(--text-dim);
  min-height: 18px;
}

.mono { font-family: var(--mono); }

/* ---------- Login ---------- */

.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.login-brand {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.brand-mark { color: var(--accent); margin-bottom: 24px; }
.brand-name {
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 600;
  line-height: 1.15;
  margin: 0 0 20px;
  color: var(--text);
}
.brand-tagline { color: var(--text-dim); font-size: 15px; max-width: 340px; margin: 0 0 28px; line-height: 1.5; }
.brand-features { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.brand-features li {
  font-size: 13px;
  color: var(--text-dim);
  padding-left: 20px;
  position: relative;
}
.brand-features li::before {
  content: '';
  position: absolute;
  left: 0; top: 6px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.login-form-side {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

@media (max-width: 860px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-brand { display: none; }
}

.login-box {
  width: 100%;
  max-width: 340px;
}

.login-box h1 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 24px;
}

.login-box label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin: 14px 0 6px;
}

.login-box input {
  width: 100%;
}

#login-btn {
  width: 100%;
  margin-top: 22px;
}

/* ---------- Inputs & buttons ---------- */

input, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: var(--sans);
}

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

button {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
  border: none;
  padding: 10px 18px;
}

#login-btn, #search-btn, .primary-btn {
  background: var(--accent);
  color: #17181c;
}
#login-btn:hover, #search-btn:hover, .primary-btn:hover { background: #e0b25c; }

.toggle-mode {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 14px;
}
.toggle-mode a {
  color: var(--accent);
  text-decoration: none;
  margin-left: 4px;
}
.toggle-mode a:hover { text-decoration: underline; }

.ghost-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 100%;
  text-align: left;
  margin-top: 8px;
}
.ghost-btn:hover { border-color: var(--accent-dim); color: var(--text); }
.ghost-btn.logout { margin-top: 24px; }

.secondary-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  margin-top: 10px;
}
.secondary-btn:hover { border-color: var(--accent-dim); }

.text-link {
  display: inline-block;
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
  margin-top: 10px;
}
.text-link:hover { text-decoration: underline; }

/* ---------- App shell ---------- */

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

/* Barra superior fija: las secciones siempre a la vista, sin importar cuanto crezca el historial. */
.topbar {
  grid-column: 1 / -1;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 28px;
  height: 56px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
}
.topnav { display: flex; align-self: stretch; gap: 4px; }
button.topnav-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-dim);
  padding: 0 16px;
  font-size: 14px;
  height: 100%;
}
button.topnav-btn:hover { color: var(--text); }
button.topnav-btn.nav-active { color: var(--accent); border-bottom-color: var(--accent); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
button.topbar-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  font-size: 13px;
}
button.topbar-logout:hover { border-color: var(--accent-dim); color: var(--text); }

.trial-pill {
  font-size: 11px;
  color: var(--accent);
  background: var(--infoBg, rgba(212,165,74,0.12));
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}
.trial-pill.urgent { color: var(--bad); border-color: var(--bad); background: rgba(193,102,90,0.12); }

.paywall-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(23,24,28,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.paywall-card {
  background: var(--surface);
  border: 1px solid var(--accent-dim);
  border-radius: 10px;
  padding: 32px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}
.paywall-card h2 { font-family: var(--serif); font-size: 22px; margin: 6px 0 14px; }
.paywall-text { font-size: 13px; color: var(--text-dim); line-height: 1.6; margin-bottom: 20px; }
.paywall-card .primary-btn { width: 100%; margin-bottom: 10px; }
.paywall-card .ghost-btn { width: 100%; margin-top: 4px; }

/* ---------------- Boton de idioma / prueba, ahora clicable ---------------- */
button.trial-pill { cursor: pointer; }
button.trial-pill:hover { background: rgba(212,165,74,0.22); }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 34px;
  height: 34px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent-dim); color: var(--text); }

/* ---------------- Panel de Ajustes ---------------- */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(23,24,28,0.72);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 24px;
}
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.settings-head h2 { font-family: var(--serif); font-size: 19px; margin: 0; }

.settings-section {
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.settings-section:first-of-type { border-top: none; padding-top: 8px; }
.settings-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 10px;
}
.settings-current-email { font-size: 13px; color: var(--text-dim); margin: 0 0 12px; }
.settings-current-email strong { color: var(--text); }
.settings-sub-status { font-size: 13px; color: var(--text); margin: 0 0 10px; line-height: 1.5; }

.settings-form {
  margin-top: 10px;
  padding: 12px;
  background: var(--surface-2, rgba(255,255,255,0.03));
  border-radius: 8px;
}
.settings-form label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.settings-form label input {
  display: block;
  width: 100%;
  margin-top: 4px;
}

.ghost-btn.small, .primary-btn.small { width: 100%; padding: 8px 14px; font-size: 13px; margin-top: 8px; }
.ghost-btn.danger { color: var(--bad, #c1665a); border-color: var(--bad, #c1665a); }
.ghost-btn.danger:hover { background: rgba(193,102,90,0.1); }

.sidebar {
  position: sticky;
  top: 56px;
  align-self: start;
  height: calc(100vh - 56px);
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 20px;
  background: var(--surface);
}
.sidebar .ghost-btn { margin-top: 0; margin-bottom: 20px; }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.history-item {
  padding: 9px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.35;
  border: 1px solid transparent;
}
.history-item:hover { background: var(--surface-2); color: var(--text); }
.history-item .h-price { font-family: var(--mono); font-size: 11px; color: var(--accent); }

.report {
  padding: 40px 48px;
  max-width: 720px;
}

.dash {
  padding: 32px 40px;
  max-width: 1100px;
  width: 100%;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.lang-toggle {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 10px;
  font-family: var(--sans);
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  letter-spacing: 0;
}
.lang-toggle:hover { border-color: var(--accent-dim); color: var(--accent); }

/* Selector mas especifico + tamanos explicitos: el boton de idioma nunca hereda el tamano de los botones grandes. */
button.lang-toggle {
  display: inline-block;
  width: auto;
  height: auto;
  min-width: 0;
  padding: 3px 8px;
  font-size: 11px;
  line-height: 1.4;
  flex: 0 0 auto;
}
button.lang-toggle-corner { position: absolute; top: 16px; right: 16px; margin: 0; }

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}
.panel-wide { grid-column: 1 / -1; }

@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }

  /* Barra superior en dos filas: marca + acciones arriba, las secciones abajo a todo el ancho. */
  .topbar { flex-wrap: wrap; height: auto; gap: 0 12px; padding: 8px 14px 0; }
  .topbar-brand { order: 1; }
  .topbar-actions { order: 2; }
  .topnav { order: 3; width: 100%; height: 44px; margin-top: 6px; }
  button.topnav-btn { flex: 1; padding: 0 8px; }

  /* El historial pasa a ser una tira horizontal que se desliza. */
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .sidebar .eyebrow { display: none; }
  .sidebar .ghost-btn { width: auto; margin: 0; white-space: nowrap; flex: 0 0 auto; }
  .history-list { flex-direction: row; gap: 6px; margin: 0; }
  .history-item {
    flex: 0 0 auto;
    width: 190px;
    border: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .dash { padding: 20px 16px; }
}

@media (max-width: 760px) {
  .dash-grid { grid-template-columns: 1fr; }
  .dash { padding: 20px; }
  .panel-header { flex-direction: column; }
  .panel-header-price { width: 100%; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 18px 20px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 14px;
}
.panel-title svg { flex-shrink: 0; color: var(--accent); }

.panel-header {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  margin-top: 16px;
}
.panel-header-icon {
  width: 52px; height: 52px;
  border-radius: 6px;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}
.panel-header-text { flex: 1; min-width: 0; }
.panel-header-price { width: 220px; flex-shrink: 0; }

.kv-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.kv-row .kv { flex-direction: column; align-items: flex-start; gap: 4px; border-bottom: none; background: var(--surface-2); border-radius: 4px; padding: 8px 10px; }
.kv-row .kv span:first-child { font-size: 11px; }
.kv-row .kv span:last-child { font-size: 15px; }

.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 4px;
}
.search-row input { flex: 1; }

/* ---------- Report sections ---------- */

.block {
  padding: 22px 0;
  border-bottom: 1px solid var(--border);
}
.block:first-of-type { padding-top: 28px; }

.section-label {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 12px;
  text-transform: none;
}
.section-label .dim { color: #5f5d58; }

#p-title {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 6px;
  line-height: 1.25;
}
.meta { color: var(--text-dim); font-size: 13px; margin: 0 0 10px; }
.price { font-family: var(--mono); font-size: 22px; color: var(--accent); margin: 0; }
.price-input {
  font-family: var(--mono);
  font-size: 22px;
  color: var(--accent);
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 4px 0;
  width: 160px;
}
.price-input:focus { border-bottom-color: var(--accent); outline: none; }
.hint { font-size: 12px; color: var(--text-dim); margin: 6px 0 0; }

.kv {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px dotted var(--border);
}
.kv:last-of-type { border-bottom: none; }
.kv span:first-child { color: var(--text-dim); }

#price-chart { margin: 16px 0 4px; }

.calc-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.calc-row label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.calc-row input, .calc-row select { width: 150px; }
.calc-row .unit { position: relative; top: -26px; left: 42px; font-size: 12px; color: var(--text-dim); }

.calc-results {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.calc-metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 14px;
}
.calc-metric span { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.calc-metric strong { font-size: 18px; font-weight: 500; }
.calc-metric.accent { border-color: var(--accent-dim); }
.calc-metric.accent strong { color: var(--accent); }

.keyword-cloud { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.keyword-cloud span {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 8px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text-dim);
}

.provider-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.supplier-term { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-dim); margin-bottom: 12px; }
.supplier-term input { width: 100%; }
.supplier-group-title { margin: 14px 0 8px; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.provider-link {
  display: block;
  text-decoration: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 9px 10px;
  color: var(--text);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.provider-link:hover { border-color: var(--accent-dim); color: var(--accent); }

.nav-active { border-color: var(--accent-dim); color: var(--accent); }

.dash-title {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 16px;
}

.acct-summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.acct-metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
}
.acct-metric span { display: block; font-size: 10px; color: var(--text-dim); margin-bottom: 4px; }
.acct-metric strong { font-size: 17px; font-weight: 500; }
.acct-metric.bad strong { color: var(--bad); }
.acct-metric.accent { background: var(--surface-2); border-color: var(--accent-dim); }
.acct-metric.accent strong, .acct-metric.accent span { color: var(--accent); }

@media (max-width: 900px) {
  .acct-summary { grid-template-columns: repeat(2, 1fr); }
}

.panel-row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-row-head .panel-title { margin: 0; }

.acct-form {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 10px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.acct-form input, .acct-form select { width: 100%; }
.acct-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.acct-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px dotted var(--border);
  font-size: 12px;
}
.acct-row:last-child { border-bottom: none; }
.acct-row .acct-sub { color: var(--text-dim); font-size: 11px; }

.acct-expenses-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 760px) { .acct-expenses-grid { grid-template-columns: 1fr; } }
.acct-expense-chip {
  display: flex;
  justify-content: space-between;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
}

.good { color: var(--good); }
.bad { color: var(--bad); }

/* ---------- Graficos de precio y ranking (datos de Keepa) ---------- */
.range-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.range-chip {
  width: auto; margin: 0; padding: 5px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-dim); font-family: var(--sans); font-size: 12px; cursor: pointer;
}
.range-chip:hover { border-color: var(--accent-dim); color: var(--text); }
.range-chip.active { color: var(--accent); border-color: var(--accent-dim); }

.chart-block { margin: 0 0 18px; }
.chart-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; margin-bottom: 6px; }
.chart-title { font-size: 12px; color: var(--text-dim); }
.chart-readout { font-family: var(--mono); font-size: 12px; color: var(--text); }
.chart-row { display: flex; }
.chart-y { position: relative; flex: 0 0 74px; height: 170px; }
.chart-y span {
  position: absolute; right: 8px; transform: translateY(-50%);
  font-family: var(--mono); font-size: 10px; color: var(--text-dim); white-space: nowrap;
}
.chart-box {
  position: relative; flex: 1 1 auto; min-width: 0; height: 170px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  overflow: hidden; cursor: crosshair; touch-action: pan-y;
}
.chart-box svg { display: block; width: 100%; height: 100%; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-cursor { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--text-dim); pointer-events: none; }
.chart-dot {
  position: absolute; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px;
  border-radius: 50%; border: 2px solid var(--surface-2); pointer-events: none;
}
.chart-axis { display: flex; justify-content: space-between; margin: 4px 0 0 74px; font-size: 10px; color: var(--text-dim); }
.chart-empty { font-size: 12px; color: var(--text-dim); padding: 6px 0; }
@media (max-width: 520px) {
  .chart-y { flex-basis: 58px; }
  .chart-axis { margin-left: 58px; }
  .chart-y, .chart-box { height: 140px; }
}

/* ---------- Historial: boton de borrar ---------- */
.history-clear {
  width: auto; margin: 0; padding: 4px 8px;
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-family: var(--sans); font-size: 11px; text-align: left;
}
.history-clear:hover { color: var(--bad); text-decoration: underline; }
