:root {
  --bg: #16130f;
  --surface: #211c16;
  --surface-2: #2a241c;
  --line: #3a3126;
  --text: #ece3d3;
  --muted: #a3967f;
  --gold: #d4ae62;
  --gold-soft: rgba(212, 174, 98, 0.14);
  --good: #7fb77e;
  --good-soft: rgba(127, 183, 126, 0.14);
  --bad: #d9745f;
  --radius: 10px;
  --display: 'Cormorant Garamond', Georgia, serif;
  --ui: 'Inter', system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--display); font-weight: 700; margin: 0; letter-spacing: 0.01em; }
h1 { font-size: 24px; line-height: 1.1; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
a { color: var(--gold); }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.num { font-variant-numeric: tabular-nums; }

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #1d1813, var(--bg));
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand p { margin: 2px 0 0; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f0d18d, var(--gold) 55%, #8a6a2f);
  box-shadow: inset 0 0 0 3px rgba(32, 26, 18, 0.45);
}
.status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--good); }
.dot.busy { background: var(--gold); animation: pulse 1s infinite alternate; }
.dot.err { background: var(--bad); }
@keyframes pulse { to { opacity: 0.3; } }
.tg-off::before, .tg-on::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.tg-off::before { background: var(--bad); }
.tg-on::before { background: var(--good); }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }

/* Buttons & inputs */
.btn {
  font: 500 13px var(--ui); color: var(--text); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 7px 14px;
}
.btn:hover { border-color: var(--gold); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--gold); color: #1d1710; border-color: var(--gold); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px 8px; }
.icon-btn:hover { color: var(--text); }
input, select {
  font: 14px var(--ui); color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* Search */
.search-wrap { position: relative; margin-bottom: 28px; }
#search { font-size: 16px; padding: 14px 16px; background: var(--surface); border-radius: var(--radius); }
.search-results {
  position: absolute; z-index: 4; left: 0; right: 0; top: calc(100% + 6px);
  list-style: none; margin: 0; padding: 6px; max-height: 60vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}
.search-results li {
  display: grid; grid-template-columns: 36px 1fr auto auto; gap: 12px; align-items: center;
  padding: 8px 10px; border-radius: 8px;
}
.search-results li:hover, .search-results li.active { background: var(--surface-2); }
.search-results .price { text-align: right; }
.search-results .none { color: var(--muted); padding: 12px; display: block; }

.icon {
  position: relative; display: grid; place-items: center; flex: none; overflow: hidden;
  width: 36px; height: 36px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line);
}
.icon::before { content: attr(data-initial); font: 700 18px var(--display); color: var(--gold); }
.icon img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--surface-2); }
.icon.lg { width: 52px; height: 52px; }
.icon.lg::before { font-size: 26px; }
.names { min-width: 0; }
.names b, .names span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.names span { color: var(--muted); font-size: 12px; }

/* Watchlist grid */
.section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 12px; cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: #5a4a33; transform: translateY(-1px); }
.card.hit { border-color: var(--good); box-shadow: 0 0 0 1px var(--good) inset; }
.card-head { display: flex; gap: 12px; align-items: center; }
.card-head .names { flex: 1; }
.big-price { font: 700 30px/1 var(--display); color: var(--gold); }
.big-price small { font: 500 12px var(--ui); color: var(--muted); margin-left: 6px; }
.where { font-size: 12px; color: var(--muted); }
.worlds { display: grid; grid-template-columns: 1fr auto auto; gap: 2px 12px; font-size: 12px; }
.worlds .w { color: var(--muted); }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 99px; background: var(--gold-soft); color: var(--gold);
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.off { background: var(--surface-2); color: var(--muted); }
.spark { width: 100%; height: 34px; display: block; }
.spark path { fill: none; stroke: var(--gold); stroke-width: 1.5; }
.spark .area { fill: var(--gold-soft); stroke: none; }
.empty { text-align: center; padding: 60px 20px; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { margin: 4px 0; }

/* Dialogs */
dialog.panel {
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px 22px; width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog.panel.wide { width: min(1000px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(8, 6, 4, 0.7); backdrop-filter: blur(2px); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.panel-head .card-head { flex: 1; }
.steps { padding-left: 18px; margin: 0 0 16px; }
.steps li { margin-bottom: 4px; }
#settings-msg.ok { color: var(--good); }
#settings-msg.err { color: var(--bad); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.box { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.box h3 { margin-bottom: 10px; }
.box-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.box-head h3 { margin: 0; }
.box-head select { width: auto; padding: 4px 8px; font-size: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 7px 8px; border-bottom: 1px solid rgba(58, 49, 38, 0.5); }
td.r, th.r { text-align: right; }
tr.hit td { background: var(--good-soft); }
.table-scroll { max-height: 380px; overflow: auto; }
.seller-link { background: none; border: 0; padding: 0; color: var(--gold); cursor: pointer; font: 12px ui-monospace, monospace; }
.seller-link:hover { text-decoration: underline; }

.chart { width: 100%; height: 180px; display: block; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--ui); }
.chart .min { fill: none; stroke: var(--gold); stroke-width: 2; }
.chart .avg { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 3; }
.legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 5px; }

.alert-list { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 6px; }
.alert-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface); border-radius: 8px; }
.alert-list li .grow { flex: 1; }
.alert-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: end; }
.switch { position: relative; width: 32px; height: 18px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; cursor: pointer; transition: background 0.15s; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text); transition: transform 0.15s; }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(14px); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--surface-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.toast.err { border-color: var(--bad); }

@media (max-width: 760px) {
  .topbar, main { padding-left: 16px; padding-right: 16px; }
  .status { width: 100%; }
  #status-text { flex: 1 1 calc(100% - 20px); font-size: 12px; }
  .detail-grid { grid-template-columns: 1fr; }
  .alert-form { grid-template-columns: 1fr 1fr; }
  .search-results li { grid-template-columns: 36px 1fr auto; }
  .search-results li .price { display: none; }
}

/* Inicio de sesión */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; padding: 28px; display: flex; flex-direction: column; gap: 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}
.login-card .btn { padding: 10px; }
.err { color: var(--bad); }
.err:empty { display: none; }
.user-chip { color: var(--muted); font-size: 12px; }
.user-chip b { color: var(--text); font-weight: 600; }
