:root {
  --bg: #0f172a;
  --card: #ffffff;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --ok: #16a34a;
  --err: #dc2626;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(160deg, #0f172a, #1e293b);
  color: var(--text);
  min-height: 100vh;
}
.view { min-height: 100vh; }
.hidden { display: none !important; }

/* LOGIN */
.login-view, #login-view { display: flex; align-items: center; justify-content: center; }
.login-card { max-width: 360px; width: 90%; margin: 12vh auto; }
.login-card h1 { margin: 0 0 4px; font-size: 1.5rem; }

/* CARDS */
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 16px; font-size: 1.2rem; }

/* TOPBAR */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px; background: rgba(255,255,255,.06); color: #fff;
}
.brand { font-weight: 600; font-size: 1.1rem; }
.container { max-width: 720px; margin: 24px auto; padding: 0 16px; }

/* FORM */
label { display: block; margin-bottom: 14px; font-size: .9rem; font-weight: 500; }
input, select {
  width: 100%; padding: 10px 12px; margin-top: 6px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 1rem;
  background: #fff; color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--primary); }
.row { display: flex; gap: 14px; }
.col { flex: 1; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
.muted { color: var(--muted); font-size: .85rem; }

/* ITEMS */
.items { margin: 18px 0; }
.items-head, .item-row {
  display: grid; grid-template-columns: 104px 1fr 78px 104px 36px; gap: 8px; align-items: center;
}
.item-row select.i-tipo { margin-top: 0; padding: 9px 8px; }
.items-head { font-size: .8rem; color: var(--muted); margin-bottom: 6px; }
.item-row { margin-bottom: 8px; }
.item-row input { margin-top: 0; }
.btn-del {
  border: none; background: #fee2e2; color: var(--err); border-radius: 8px;
  height: 38px; cursor: pointer; font-size: 1.1rem;
}
.total-row { text-align: right; font-size: 1.1rem; margin: 12px 0 18px; }

/* BUTTONS */
button { font-family: inherit; }
.btn-primary {
  display: inline-block; width: 100%; text-align: center; text-decoration: none;
  padding: 12px; background: var(--primary); color: #fff; border: none;
  border-radius: 9px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: var(--primary-d); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-ghost {
  padding: 9px 14px; background: transparent; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); cursor: pointer; font-size: .9rem;
}
.btn-ghost:hover { background: #f1f5f9; }
#btn-add-item { width: 100%; margin-top: 4px; }

/* MESSAGES */
.error, .msg { font-size: .9rem; margin-top: 10px; min-height: 1em; }
.error, .msg.err { color: var(--err); }
.msg.ok { color: var(--ok); }
.card.success { border-top: 4px solid var(--ok); }
.card.success code { display: block; padding: 8px; background: #f1f5f9; border-radius: 6px; word-break: break-all; margin-bottom: 14px; }

/* HISTORIAL */
.hist-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: .9rem;
}
.hist-item:last-child { border-bottom: none; }
.badge { padding: 2px 8px; border-radius: 20px; font-size: .75rem; font-weight: 600; }
.badge.exitoso { background: #dcfce7; color: var(--ok); }
.badge.fallido { background: #fee2e2; color: var(--err); }
.badge.pendiente { background: #fef9c3; color: #ca8a04; }

/* OVERLAY */
.overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.75);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; z-index: 100;
}
.spinner {
  width: 48px; height: 48px; border: 5px solid rgba(255,255,255,.25);
  border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .row { flex-direction: column; gap: 0; }
  .items-head { display: none; }
  .item-row { grid-template-columns: 1fr 1fr; }
  .item-row .i-desc { grid-column: 1 / -1; }
}
