:root {
  --bg: #0f1015;
  --row: #191a21;
  --row-hover: #1f2029;
  --border: #2b2c35;
  --text: #ecebf0;
  --muted: #8a8b96;
  --gold: #f4c84f;
  --green: #22b14c;
  --green-hover: #27c457;
  --red: #ef4b4b;
  --radius: 4px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.boot {
  min-height: 100vh;
}

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

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px;
  background: var(--row);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.2s, background-color 0.4s, box-shadow 0.4s;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.login-card input {
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  font-size: 15px;
  transition: border-color 0.2s;
}

.login-card input:focus {
  border-color: #4a4b57;
}

.login-card button {
  margin-top: 6px;
  padding: 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  transition: background-color 0.2s, opacity 0.2s;
}

.login-card button:disabled {
  opacity: 0.7;
  cursor: default;
}

.login-msg {
  margin: 0;
  min-height: 18px;
  font-size: 13px;
  color: var(--red);
  text-align: center;
}

.login-card.is-error {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(239, 75, 75, 0.15);
}

.login-card.is-error input {
  border-color: rgba(239, 75, 75, 0.6);
}

.login-card.is-error h1 {
  color: var(--red);
}

/* Éxito: la tarjeta se ilumina y un velo blanco cubre la pantalla un instante */
.login-success .login-card {
  background: #f4f4f6;
  border-color: #fff;
  color: var(--bg);
  box-shadow: 0 0 60px rgba(255, 255, 255, 0.25);
}

.login-success .login-card label,
.login-success .login-card input {
  color: var(--bg);
}

.login-success .login-card input {
  background: #fff;
  border-color: #dcdce2;
}

.flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.login-success .flash {
  animation: flash 0.65s ease-out forwards;
}

@keyframes flash {
  0% {
    opacity: 0;
  }
  45% {
    opacity: 0.35;
  }
  100% {
    opacity: 0;
  }
}

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

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 16px 64px;
  animation: fade-in 0.35s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.total {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.total-label {
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.total-value {
  font-size: clamp(36px, 7vw, 56px);
  font-weight: 700;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.logout {
  padding: 8px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
}

.logout:hover {
  color: var(--text);
  border-color: #42434e;
}

.sync-error {
  margin: -12px 0 20px;
  padding: 10px 14px;
  border: 1px solid rgba(239, 75, 75, 0.5);
  border-radius: var(--radius);
  background: rgba(239, 75, 75, 0.08);
  color: #ff8a8a;
  font-size: 14px;
}

/* Panel de añadir */

.composer {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 24px;
  padding: 22px;
  margin-bottom: 28px;
  background: var(--row);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.composer-left {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 26px;
}

.arrow {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0 0 4px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
  user-select: none;
}

.arrow:hover {
  color: var(--text);
  border-color: #4a4b57;
  background: var(--row-hover);
}

.arrow:active {
  transform: scale(0.94);
}

.amount,
.amount-input {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 32px;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.amount:hover {
  border-color: var(--border);
}

.amount-input {
  border-color: #4a4b57;
  background: var(--bg);
  outline: none;
}

.add {
  flex: 1;
  min-height: 96px;
  border: 0;
  border-radius: var(--radius);
  background: var(--green);
  color: #08240f;
  font-size: 20px;
  font-weight: 700;
  transition: background-color 0.15s, opacity 0.15s, transform 0.1s;
}

.add:hover:not(:disabled) {
  background: var(--green-hover);
}

.add:active:not(:disabled) {
  transform: scale(0.98);
}

.add:disabled {
  opacity: 0.35;
  cursor: default;
}

.composer-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.composer-right span {
  font-size: 22px;
  font-weight: 700;
}

.composer-right textarea {
  flex: 1;
  min-height: 140px;
  padding: 12px 14px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  font-size: 15px;
  line-height: 1.45;
}

.composer-right textarea:focus {
  border-color: #4a4b57;
}

/* Lista de entradas (estilo filas) */

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entry {
  display: grid;
  grid-template-columns: 110px 1fr auto auto;
  align-items: center;
  gap: 16px;
  min-height: 52px;
  padding: 0 12px 0 22px;
  background: var(--row);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 15px;
  font-weight: 500;
  animation: row-in 0.25s ease-out;
  transition: background-color 0.15s, opacity 0.2s;
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.entry:hover {
  background: var(--row-hover);
}

.entry.is-pending {
  opacity: 0.55;
}

.entry-amount {
  color: var(--gold);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.entry-desc {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-desc.is-empty {
  color: var(--muted);
  font-style: italic;
  font-weight: 400;
}

.entry-date {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
}

.entry-del {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background-color 0.15s, border-color 0.15s;
}

.entry:hover .entry-del,
.entry-del:focus-visible,
.entry-del.is-confirm {
  opacity: 1;
}

.entry-del:hover {
  color: var(--red);
}

.entry-del.is-confirm {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}

.entry-del:disabled {
  visibility: hidden;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 4px;
}

/* Móvil */

@media (hover: none) {
  .entry-del {
    opacity: 1;
  }
}

@media (max-width: 680px) {
  .composer {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .stepper {
    margin-top: 0;
  }

  .add {
    min-height: 56px;
  }

  .composer-right textarea {
    min-height: 90px;
  }

  .entry {
    grid-template-columns: 90px 1fr auto;
    gap: 10px;
    padding-left: 14px;
  }

  .entry-date {
    display: none;
  }
}

[hidden] {
  display: none !important;
}

/* ---------- Interacción: sin resaltado azul y con animación al pulsar ---------- */

* {
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: rgba(244, 200, 79, 0.35);
  color: #fff;
}

input,
textarea {
  caret-color: var(--gold);
}

a,
button {
  color: inherit;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button,
input,
textarea {
  outline: none;
}

button {
  transition: transform 0.12s ease, background-color 0.15s, border-color 0.15s, color 0.15s,
    opacity 0.15s, box-shadow 0.2s;
}

button:active:not(:disabled) {
  transform: scale(0.95);
}

button:focus-visible {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px rgba(244, 200, 79, 0.6);
}

input,
textarea {
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

input:focus,
textarea:focus {
  box-shadow: 0 0 0 3px rgba(244, 200, 79, 0.12);
}

.login-card button:hover:not(:disabled) {
  background: #fff;
}

.amount:active {
  transform: scale(0.94);
  background: var(--row-hover);
}

.entry {
  transition: background-color 0.15s, opacity 0.2s, transform 0.15s;
}

.entry:active {
  transform: scale(0.995);
}

.entry-del:active:not(:disabled) {
  transform: scale(0.88);
}

.logout:active {
  transform: scale(0.94);
}

/* Destello rápido al pulsar (para pantallas táctiles sin hover) */
@keyframes press {
  0% {
    filter: brightness(1);
  }
  40% {
    filter: brightness(1.25);
  }
  100% {
    filter: brightness(1);
  }
}

button:active:not(:disabled) {
  animation: press 0.25s ease-out;
}

/* ---------- APK: aviso de actualización ---------- */

.update-card p {
  margin: 0;
  font-size: 16px;
  line-height: 1.45;
}

.update-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.update-actions button {
  flex: 1;
  margin-top: 0;
}

.login-card .btn-primary {
  background: var(--green);
  color: #08240f;
}

.login-card .btn-primary:hover:not(:disabled) {
  background: var(--green-hover);
}

.login-card .btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.login-card .btn-secondary:hover:not(:disabled) {
  background: var(--row-hover);
  border-color: #4a4b57;
}

/* Todas las transiciones de botones incluyen el "press" (transform) */
.arrow,
.add,
.amount,
.logout,
.entry-del,
.login-card button {
  transition: transform 0.12s ease, background-color 0.15s, border-color 0.15s, color 0.15s,
    opacity 0.15s, box-shadow 0.2s;
}
