:root {
  --fondo: #f3f4f6;
  --tarjeta: #ffffff;
  --texto: #1f2933;
  --tenue: #6b7280;
  --borde: #d1d5db;
  --entrada: #ffffff;
  --primario: #2563eb;
  --primario-texto: #ffffff;
  --ok: #15803d;
  --error: #b91c1c;
  --pendiente: #c2410c;
  --venta-fondo: #d1e7dd;
  --venta-texto: #0f5132;
  --compra-fondo: #f8d7da;
  --compra-texto: #842029;
  --mio: #d9f2d9;
  --registro: #f9fafb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #111418;
    --tarjeta: #1b1f24;
    --texto: #e5e7eb;
    --tenue: #9ca3af;
    --borde: #374151;
    --entrada: #111418;
    --primario: #3b82f6;
    --ok: #4ade80;
    --error: #f87171;
    --pendiente: #fb923c;
    --venta-fondo: #12372a;
    --venta-texto: #86efac;
    --compra-fondo: #3f1a1d;
    --compra-texto: #fca5a5;
    --mio: #14532d;
    --registro: #0d1013;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fondo);
  color: var(--texto);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
.tenue { color: var(--tenue); font-weight: normal; font-size: .9em; }
.error { color: var(--error); min-height: 1.2em; margin: .5rem 0 0; }

button, input, select {
  font: inherit; color: inherit;
  border: 1px solid var(--borde); border-radius: 6px;
  background: var(--entrada);
}
input, select { padding: .4rem .5rem; min-width: 0; }
button { padding: .45rem .9rem; cursor: pointer; background: var(--tarjeta); }
button:disabled { opacity: .5; cursor: default; }
button.chico { padding: .25rem .6rem; font-size: .9em; }
button.primario { background: var(--primario); color: var(--primario-texto); border-color: var(--primario); }
button.peligro { background: #b91c1c; color: #fff; border-color: #b91c1c; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--primario); outline-offset: 1px; }

.tarjeta {
  background: var(--tarjeta); border: 1px solid var(--borde); border-radius: 10px;
  padding: 1rem; min-width: 0;
}

/* ---- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-tarjeta { width: 100%; max-width: 340px; display: grid; gap: .8rem; }
.login-tarjeta label { display: grid; gap: .25rem; }

/* ---- barra */
.barra {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  padding: .6rem 16px; background: var(--tarjeta); border-bottom: 1px solid var(--borde);
}
.espacio { flex: 1; }

.contenido { display: grid; gap: 12px; padding: 12px 16px 32px; max-width: 1280px; margin: 0 auto; }
.titulo-seccion { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .6rem; }
.titulo-seccion h2 { margin: 0; flex: 1; }

/* ---- anuncios */
.lista-anuncios { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }
.anuncio {
  text-align: left; display: grid; gap: .3rem; padding: .7rem; border-width: 2px;
}
.anuncio.elegido { border-color: var(--primario); }
.anuncio .fila { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.lado { padding: .15rem .5rem; border-radius: 4px; font-weight: 700; font-size: .85em; white-space: nowrap; }
.lado.SELL { background: var(--venta-fondo); color: var(--venta-texto); }
.lado.BUY { background: var(--compra-fondo); color: var(--compra-texto); }
.pildora { font-size: .8em; padding: .1rem .45rem; border-radius: 999px; border: 1px solid var(--borde); white-space: nowrap; }
.pildora.ok { color: var(--ok); border-color: currentColor; }
.pildora.error { color: var(--error); border-color: currentColor; }
.pildora.real { color: #fff; background: #b91c1c; border-color: #b91c1c; }

/* ---- panel del anuncio */
.controles { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.controles.derecha { justify-content: flex-end; margin-top: 1rem; }
.interruptor { display: flex; gap: .4rem; align-items: center; cursor: pointer; }
.interruptor input { width: 1.1rem; height: 1.1rem; }
.estado { margin: .7rem 0; font-weight: 600; color: var(--tenue); }
.estado.ok { color: var(--ok); }
.estado.error { color: var(--error); }
.estado.pendiente { color: var(--pendiente); }

.columnas { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.columnas.abajo { grid-template-columns: 3fr 2fr; }
@media (max-width: 800px) {
  .columnas, .columnas.abajo { grid-template-columns: 1fr; }
}
fieldset { border: 1px solid var(--borde); border-radius: 8px; margin: 0; padding: .6rem .8rem; min-width: 0; }
legend { font-weight: 600; padding: 0 .3rem; }

.campo { display: grid; grid-template-columns: 1fr auto; gap: .2rem .6rem; align-items: center; padding: .3rem 0; }
.campo label { display: flex; gap: .3rem; align-items: center; }
.campo .ayuda-texto { grid-column: 1 / -1; margin: 0; font-size: .85em; color: var(--tenue); white-space: pre-line; }
.ayuda { border: none; background: none; padding: 0 .2rem; color: var(--tenue); font-size: .95em; }
.stepper { display: flex; }
.stepper input { width: 8.5rem; border-radius: 6px 0 0 6px; text-align: right; }
.stepper button { padding: 0 .55rem; border-radius: 0; border-left: none; }
.stepper button:last-child { border-radius: 0 6px 6px 0; }
.campo select { max-width: 15rem; }

.campo .etiqueta { display: flex; gap: .3rem; align-items: center; }
.campo-bancos .fila-bancos { display: flex; gap: .5rem; align-items: center; justify-content: flex-end; min-width: 0; }
.campo-bancos #bancos-resumen { overflow-wrap: anywhere; text-align: right; }
.bancos-panel {
  grid-column: 1 / -1; display: grid; gap: .1rem .8rem; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  border: 1px solid var(--borde); border-radius: 6px; padding: .5rem; margin-top: .3rem;
}
.banco { display: flex; gap: .45rem; align-items: center; padding: .25rem 0; cursor: pointer; }
.banco input { width: 1.1rem; height: 1.1rem; flex: none; }
.banco-todos { grid-column: 1 / -1; font-weight: 600; border-bottom: 1px solid var(--borde); padding-bottom: .4rem; }
.campo-linea { display: grid; gap: .3rem; }
.fila-entrada { display: flex; gap: .4rem; }
.fila-entrada input { flex: 1; }

.lista-blacklist { list-style: none; margin: .5rem 0 0; padding: 0; max-height: 14rem; overflow-y: auto; }
.lista-blacklist li {
  display: flex; justify-content: space-between; align-items: center; gap: .4rem;
  padding: .25rem .4rem; border-bottom: 1px solid var(--borde); overflow-wrap: anywhere;
}

/* ---- tabla */
.tabla-desplazable { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9em; }
th, td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid var(--borde); white-space: nowrap; }
td.num, th.num { text-align: right; }
tr.mio td { background: var(--mio); font-weight: 700; }

/* ---- registro */
.registro {
  height: 18rem; overflow-y: auto; background: var(--registro); border: 1px solid var(--borde);
  border-radius: 6px; padding: .5rem; font: 12.5px/1.45 ui-monospace, Consolas, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.registro .linea-ad { color: var(--tenue); }

/* ---- modal y aviso */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-caja { max-width: 420px; width: 100%; }
.aviso {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20;
  max-width: calc(100% - 32px); padding: .6rem 1rem; border-radius: 8px;
  background: var(--error); color: #fff; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.aviso.ok { background: #15803d; }

/* ---- teléfono */
@media (max-width: 600px) {
  /* iPhone hace zoom solo al tocar un campo con letra de menos de 16px. */
  input, select, button { font-size: 16px; }
  .barra { padding: .5rem 12px; }
  .tarjeta { padding: .8rem; }
  fieldset { padding: .5rem .6rem; }
  /* Etiqueta arriba y campo abajo, a todo el ancho. */
  .campo { grid-template-columns: 1fr; }
  .campo select { max-width: none; width: 100%; }
  .stepper input { flex: 1; width: auto; }
  /* Dedos: botones de al menos ~44px. */
  .stepper button { min-width: 44px; min-height: 44px; }
  .ayuda { min-width: 36px; min-height: 36px; }
  .controles > button { flex: 1 1 auto; min-height: 44px; }
  .interruptor { flex-basis: 100%; }
  .interruptor input { width: 1.4rem; height: 1.4rem; }
  .lista-blacklist li button, td button.chico { min-height: 36px; }
  .registro { height: 14rem; font-size: 12px; }
  .campo-bancos .fila-bancos { justify-content: space-between; }
  .campo-bancos #bancos-resumen { text-align: left; }
  .bancos-panel { grid-template-columns: 1fr; }
  .banco { min-height: 40px; }
  .banco input { width: 1.4rem; height: 1.4rem; }
}
