:root {
  --primary: #e94560;
  --primary-hover: #d63851;
  --bg-dark: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --text: #eee;
  --text-muted: #a0a0b0;
  --success: #00c853;
  --error: #ff5252;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* Header */
header {
  text-align: center;
  padding: 20px 16px 8px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

/* Main */
main {
  flex: 1;
  padding: 16px;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

.intro-card {
  text-align: center;
}

.intro-card p {
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}

.scan-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* Buttons */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px 32px;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  width: 100%;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid #334;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: #1a4a80;
}

.btn-gallery {
  width: 100%;
  margin-top: 10px;
}

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid #555;
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}

/* Manual Input */
.manual-card {
  padding: 16px 24px;
}

.manual-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}

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

.manual-input-group input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid #334;
  color: var(--text);
  padding: 12px;
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
}

.manual-input-group input:focus {
  border-color: var(--primary);
}

.manual-input-group input::placeholder {
  color: #667;
}

/* Camera */
#screen-camera {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #000;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

#camera-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#camera-feed {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#scan-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 85%;
  height: 20%;
  border: 2px dashed var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  pointer-events: none;
}

.overlay-label {
  color: var(--primary);
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 8px;
  border-radius: 4px;
}

.camera-controls {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.8);
  justify-content: center;
  align-items: center;
}

.btn-capture {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary);
  border: 4px solid white;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s;
}

.btn-capture:active {
  transform: scale(0.9);
}

/* Processing */
.processing-card {
  text-align: center;
}

#preview-canvas {
  width: 100%;
  max-height: 250px;
  object-fit: contain;
  border-radius: 8px;
  margin-bottom: 16px;
  background: #000;
}

#progress-container {
  width: 100%;
  height: 6px;
  background: #334;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}

#progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
}

#progress-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Result */
.result-card {
  text-align: center;
}

.result-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
}

.success-icon {
  color: var(--success);
}

.error-icon {
  color: var(--error);
}

.result-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  margin-top: 12px;
}

.result-tracking {
  font-family: 'Courier New', monospace;
  font-size: 0.95rem;
  color: var(--text);
  word-break: break-all;
}

.result-account {
  font-size: 1.8rem;
  color: var(--success);
  font-weight: 700;
  margin-top: 4px;
}

.result-monto {
  font-size: 1.5rem;
  color: #ffd700;
  font-weight: 700;
  margin-top: 4px;
}

.result-status {
  margin-top: 12px;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.85rem;
}

.just-received {
  background: rgba(0, 200, 83, 0.15);
  color: var(--success);
  border: 1px solid var(--success);
}

.already-received {
  background: rgba(255, 165, 0, 0.15);
  color: #ffa500;
  border: 1px solid #ffa500;
}

.match-type {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 8px;
  font-style: italic;
}

#btn-scan-again {
  margin-top: 16px;
}

/* Error */
.error-card {
  text-align: center;
  border-left: 4px solid var(--error);
}

.error-message {
  color: var(--text);
  line-height: 1.5;
}

#error-debug {
  margin-top: 12px;
  text-align: left;
}

#error-debug details {
  color: var(--text-muted);
  font-size: 0.8rem;
}

#error-debug summary {
  cursor: pointer;
  margin-bottom: 8px;
}

#error-debug pre {
  background: var(--bg-dark);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.75rem;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.error-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.error-actions .btn-primary {
  flex: 1;
}

.error-actions .btn-secondary {
  flex: 1;
}

/* Total Bar (fija abajo) */
.total-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 2px solid #ffd700;
  z-index: 50;
  max-height: 50vh;
  overflow-y: auto;
}

.account-list {
  padding: 10px 16px 4px;
}

.account-list:empty {
  display: none;
}

.account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.account-name {
  font-weight: 700;
  color: var(--text);
  flex: 1;
}

.account-count {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 0 12px;
}

.account-total {
  color: #ffd700;
  font-weight: 700;
  font-size: 1rem;
}

.total-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid #ffd700;
  background: rgba(255, 215, 0, 0.08);
}

.total-info {
  display: flex;
  gap: 20px;
  font-size: 1rem;
}

.total-info strong {
  color: #ffd700;
  font-size: 1.1rem;
}

.btn-clear {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
}

/* Add bottom padding to main when total bar is visible */
body:has(.total-bar:not(.hidden)) main {
  padding-bottom: 140px;
}

/* Responsive */
@media (min-width: 600px) {
  main {
    padding: 24px;
  }
}

/* ============================================
   Calculadora dimensional (en pantalla resultado)
   ============================================ */
.calc-card {
  margin-top: 4px;
}
.calc-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
}
.calc-unit-toggle {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid #1e4080;
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 14px;
}
.calc-unit-toggle button {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  padding: 6px 14px;
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
.calc-unit-toggle button.active {
  background: var(--primary);
  color: #fff;
}
.calc-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.calc-field label {
  display: block;
  font-size: 0.75rem;
  margin-bottom: 5px;
  color: var(--text-muted);
}
.calc-field input {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid #1e4080;
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.calc-field input:focus {
  border-color: var(--primary);
}
.calc-value {
  margin-top: 12px;
}
.calc-result {
  margin-top: 16px;
  padding: 14px;
  background: var(--bg-input);
  border-radius: 8px;
  text-align: center;
}
.calc-result-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.calc-result-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary);
  font-family: monospace;
}
.calc-hint {
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: monospace;
}
.calc-breakdown {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.calc-sub {
  background: var(--bg-input);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}
.calc-sub-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.calc-sub-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  font-family: monospace;
}
.calc-total {
  margin-top: 10px;
  padding: 14px;
  background: #0f4d2e;
  border-radius: 8px;
  text-align: center;
}
.calc-total.loss {
  background: #5a1a1a;
}
.calc-total-label {
  font-size: 0.75rem;
  color: #a7f3d0;
  margin-bottom: 3px;
}
.calc-total.loss .calc-total-label {
  color: #fecaca;
}
.calc-total-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--success);
  font-family: monospace;
}
.calc-total.loss .calc-total-value {
  color: var(--error);
}
