* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f0f1a;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app { height: 100%; width: 100%; position: relative; }

/* ===== Screens ===== */
.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0; left: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; }

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  padding: 14px 24px;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.3; cursor: default; }

.btn-primary { background: #e94560; color: #fff; }
.btn-small { padding: 10px 16px; font-size: 0.85rem; }
.btn-large { width: 100%; padding: 18px; font-size: 1.2rem; letter-spacing: 1px; }
.btn-success { background: #27ae60; color: #fff; }

.btn-icon {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}

.btn-back {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px 0;
}

/* ===== Screen Header ===== */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  flex-shrink: 0;
}

.screen-bottom {
  padding: 16px;
  flex-shrink: 0;
  margin-top: auto;
}

/* ===== Register / Config ===== */
#screen-register {
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}

.register-container {
  width: 100%;
  max-width: 400px;
  padding: 24px;
  text-align: center;
}

.reg-header-row {
  text-align: left;
  margin-bottom: 8px;
}

.logo {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 2px;
  margin-bottom: 4px;
}
.logo span {
  color: #e94560;
  margin-left: 4px;
}

.register-subtitle {
  opacity: 0.5;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.error-msg {
  color: #e94560;
  font-size: 0.85rem;
  margin-top: 4px;
  margin-bottom: 8px;
  min-height: 20px;
}

/* Device list */
.device-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.device-list-loading,
.device-list-empty {
  opacity: 0.4;
  font-size: 0.85rem;
  padding: 24px 0;
}

.device-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  color: #fff;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
}
.device-card:active {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.25);
}
.device-card-active {
  border-color: #27ae60;
  background: rgba(39,174,96,0.08);
}

.device-card-info {
  display: flex;
  flex-direction: column;
}

.device-card-name {
  font-size: 1rem;
  font-weight: 700;
}

.device-card-event {
  font-size: 0.75rem;
  opacity: 0.4;
}

.device-card-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: #27ae60;
  padding: 4px 10px;
  border: 1px solid rgba(39,174,96,0.3);
  border-radius: 8px;
}

.device-card-select {
  font-size: 0.75rem;
  opacity: 0.4;
}

/* Create toggle */
.btn-show-create {
  background: none;
  border: 1px dashed rgba(255,255,255,0.15);
  border-radius: 12px;
  color: rgba(255,255,255,0.5);
  font-size: 0.85rem;
  padding: 12px;
  width: 100%;
  cursor: pointer;
  margin-bottom: 12px;
}
.btn-show-create:active { color: #fff; border-color: rgba(255,255,255,0.3); }

/* Create form */
.create-device-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.create-device-form label {
  font-size: 0.8rem;
  opacity: 0.5;
  margin-top: 8px;
}

.create-device-form input,
.create-device-form select {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-size: 1rem;
  outline: none;
}
.create-device-form input:focus,
.create-device-form select:focus {
  border-color: #e94560;
}

.create-device-form select option { background: #1a1a2e; color: #fff; }

.create-device-form .btn { margin-top: 16px; }

/* ===== Scan Screen ===== */
.scan-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  flex-shrink: 0;
}

.scan-header-info {
  display: flex;
  flex-direction: column;
}

.device-name {
  font-size: 0.95rem;
  font-weight: 700;
}

.event-name {
  font-size: 0.75rem;
  opacity: 0.4;
}

.config-hint {
  font-size: 0.65rem;
  opacity: 0.3;
  color: #e94560;
}

.scanner-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  min-height: 0;
}

#qr-reader {
  width: 100%;
  max-width: 400px;
  border-radius: 16px;
  overflow: hidden;
}

#qr-reader__scan_region { min-height: 250px !important; }
#qr-reader__dashboard { display: none !important; }
#qr-reader img[alt="Info icon"] { display: none !important; }
#qr-reader__header_message { display: none !important; }

.scan-footer {
  padding: 12px 16px 20px;
  flex-shrink: 0;
}

.manual-input-row {
  display: flex;
  gap: 8px;
}

.manual-input-row input {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-size: 0.9rem;
  outline: none;
}

/* ===== Scanner Idle / Active ===== */
.scanner-container {
  position: relative;
}

#qr-reader { display: none; }
.scanner-container.camera-active #qr-reader { display: block; }
.scanner-container.camera-active .scanner-idle { display: none; }

.scanner-idle {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.btn-scan {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 48px;
  border: 2px solid rgba(233,69,96,0.3);
  border-radius: 20px;
  background: rgba(233,69,96,0.08);
  color: #e94560;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-scan:active {
  background: rgba(233,69,96,0.2);
  border-color: #e94560;
}

.btn-scan svg { stroke: #e94560; }

.zebra-hidden {
  position: absolute;
  left: -9999px;
  opacity: 0;
  width: 1px;
  height: 1px;
}

/* Zebra scanner ready state */
.scanner-container.zebra-ready .scanner-idle { display: flex; }
.scanner-container.zebra-ready #qr-reader { display: none; }
.scanner-container.zebra-ready .btn-scan {
  border-color: rgba(39,174,96,0.3);
  background: rgba(39,174,96,0.08);
  color: #27ae60;
  pointer-events: none;
}
.scanner-container.zebra-ready .btn-scan svg { stroke: #27ae60; }

/* ===== Account + Charge Screen (merged) ===== */
.acc-header-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.acc-cedula {
  font-size: 0.9rem;
  font-weight: 700;
}

.acc-phone {
  font-size: 0.75rem;
  opacity: 0.4;
}

.balance-bar {
  display: flex;
  justify-content: space-between;
  margin: 0 16px;
  padding: 14px 18px;
  background: rgba(255,255,255,0.06);
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
}

.balance-bar-left,
.balance-bar-right {
  display: flex;
  flex-direction: column;
}

.balance-bar-right { align-items: flex-end; }

.balance-label {
  font-size: 0.65rem;
  opacity: 0.4;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.balance-amount {
  font-size: 1.5rem;
  font-weight: 900;
  color: #27ae60;
}
.balance-amount.balance-zero {
  color: #e94560;
}

.balance-remaining {
  text-align: center;
  font-size: 0.8rem;
  padding: 6px 16px;
  opacity: 0.5;
}
.balance-remaining.negative { color: #e94560; opacity: 1; }

.zero-banner {
  display: none;
  margin: 0 16px;
  padding: 14px;
  background: rgba(233,69,96,0.15);
  border: 2px solid #e94560;
  border-radius: 12px;
  color: #e94560;
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: 3px;
  text-align: center;
}

/* ===== Charge Items ===== */
.charge-items {
  flex: 1;
  padding: 0 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.charge-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  background: rgba(255,255,255,0.04);
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.06);
  gap: 6px;
}

.charge-item-name {
  font-size: 1.1rem;
  font-weight: 700;
}

.charge-item-price {
  font-size: 0.85rem;
  opacity: 0.45;
}

.qty-controls {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 4px;
}

.qty-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-size: 1.6rem;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.qty-btn:active { background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.4); }

.qty-value {
  font-size: 2rem;
  font-weight: 900;
  min-width: 40px;
  text-align: center;
}

.charge-footer {
  padding: 16px;
  flex-shrink: 0;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.charge-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 1rem;
}

.charge-total {
  font-size: 1.6rem;
  font-weight: 900;
}

.charge-total.over-budget { color: #e94560; }

/* ===== Confirm Countdown Bar ===== */
.confirm-bar {
  width: 100%;
  position: relative;
}

.confirm-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn-cancel-charge {
  flex: 1;
  padding: 16px;
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 12px;
  background: transparent;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-cancel-charge:active { background: rgba(255,255,255,0.1); }

.confirm-countdown {
  flex: 1;
  text-align: center;
  font-size: 1rem;
  opacity: 0.7;
}
.confirm-countdown b {
  font-size: 1.4rem;
  color: #27ae60;
}

.confirm-timer {
  height: 4px;
  width: 100%;
  background: #27ae60;
  border-radius: 2px;
  margin-top: 10px;
  transform-origin: left;
}
.confirm-timer.running {
  animation: shrink 3s linear forwards;
}

/* ===== Result Screen ===== */
#screen-result {
  align-items: center;
  justify-content: center;
}

#screen-result.success { background: #27ae60; }
#screen-result.error { background: #c0392b; }

.result-content { text-align: center; padding: 24px; }

.result-icon { font-size: 5rem; line-height: 1; margin-bottom: 16px; }
.result-title { font-size: 2.5rem; font-weight: 900; letter-spacing: 3px; margin-bottom: 16px; }
.result-amount { font-size: 1.8rem; font-weight: 700; margin-bottom: 8px; }
.result-detail { font-size: 1.1rem; opacity: 0.8; line-height: 1.5; white-space: pre-line; }

.tap-hint {
  position: absolute;
  bottom: 28px;
  font-size: 0.8rem;
  opacity: 0.5;
}

.timer-bar {
  position: absolute;
  bottom: 0; left: 0;
  height: 5px;
  width: 100%;
  background: rgba(255,255,255,0.4);
  transform-origin: left;
}
.timer-bar.running { animation: shrink 3s linear forwards; }
.timer-bar.paused { animation-play-state: paused; }

@keyframes shrink {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* ===== History Screen ===== */
.history-title {
  font-size: 0.9rem;
  font-weight: 600;
}

.history-summary {
  margin: 0 16px 12px;
  padding: 16px;
  background: rgba(255,255,255,0.06);
  border-radius: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.summary-item {
  text-align: center;
}

.summary-label {
  font-size: 0.7rem;
  opacity: 0.4;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-value {
  font-size: 1.3rem;
  font-weight: 800;
  margin-top: 2px;
}
.summary-value.green { color: #27ae60; }

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  padding: 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.06);
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.history-time { font-size: 0.8rem; opacity: 0.5; }
.history-amount { font-weight: 700; }
.history-amount.purchase { color: #27ae60; }
.history-amount.refund { color: #e94560; }

.history-item-products {
  font-size: 0.8rem;
  opacity: 0.5;
  line-height: 1.4;
}

.history-device {
  font-size: 0.7rem;
  opacity: 0.3;
  display: block;
  margin-top: 4px;
}

.history-empty {
  text-align: center;
  padding: 40px;
  opacity: 0.3;
  font-size: 0.9rem;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(15,15,26,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.loading-overlay.visible { display: flex; }

.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: #e94560;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Safe area ===== */
@supports (padding-top: env(safe-area-inset-top)) {
  .scan-header,
  .screen-header { padding-top: calc(12px + env(safe-area-inset-top)); }
  #screen-register { padding-top: env(safe-area-inset-top); }
}
