:root {
  --bg: #0f1222;
  --panel: #171a2b;
  --text: #e7e9ef;
  --muted: #a8b0c3;
  --primary: #5b8cff;
  --primary-700: #416fe0;
  --accent: #22d3ee;
  --success: #10b981;
  --danger: #ef4444;
  --border: #2a2f45;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica Neue, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: radial-gradient(1200px 700px at 80% -10%, #1a1f3d, transparent),
              radial-gradient(900px 600px at 0% 100%, #0b1529, transparent),
              var(--bg);
}

.app-header { text-align: center; padding: 20px 16px 6px; }
.app-header h1 { margin: 0; font-weight: 700; font-size: 22px; letter-spacing: 0.2px; }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.container {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 20px;
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .container { grid-template-columns: 1fr; }
}

.scanner { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.video-wrapper { position: relative; border-radius: 10px; overflow: hidden; background: #0c0f1e; border: 1px solid var(--border); }

#canvas { display: block; width: 100%; height: auto; }

.overlay { position: absolute; inset: 0; pointer-events: none; display: grid; place-items: center; }
.scan-area {
  width: min(80vmin, 520px);
  height: min(80vmin, 520px);
  max-width: 90%;
  max-height: 90%;
  border-radius: 18px;
  position: relative;
  outline: 2px dashed rgba(255,255,255,0.25);
  outline-offset: -14px;
}
.scan-area::before {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.35);
  box-shadow: inset 0 0 0 9999px rgba(0,0,0,0.25);
}
.scan-area::after {
  content: "";
  position: absolute;
  left: 24px; right: 24px; top: 24px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  filter: drop-shadow(0 0 6px var(--accent));
  animation: sweep 2.2s linear infinite;
}
@keyframes sweep { from { transform: translateY(0); } to { transform: translateY(calc(100% - 48px)); } }

.status { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  background: rgba(0,0,0,0.55); border: 1px solid var(--border); padding: 6px 10px; border-radius: 10px; font-size: 13px; color: var(--text); }

.controls { display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 4px 4px; }
.btn {
  appearance: none; border: 1px solid var(--border); background: #1f2440; color: var(--text);
  padding: 10px 14px; border-radius: 10px; cursor: pointer; transition: 120ms ease; font-weight: 600; font-size: 14px;
}
.btn:hover { background: #242b4d; border-color: #33406a; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary { background: #161a2f; }

.file-btn { display: inline-flex; align-items: center; justify-content: center; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 16px; min-height: 200px; }
.panel h2 { margin: 4px 0 10px; font-size: 16px; color: var(--text); }

.resultado {
  min-height: 60px; border: 1px dashed var(--border); background: #0e1225; border-radius: 10px; padding: 12px; color: var(--text);
  word-break: break-word; white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.result-actions { display: flex; gap: 10px; margin: 10px 0 16px; }

.historial { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 300px; overflow: auto; }
.historial li { display: grid; gap: 6px; border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: #0e1225; }
.hist-item-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hist-text { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-word; color: var(--text); }
.hist-meta { color: var(--muted); font-size: 12px; }
.hist-actions { display: flex; gap: 8px; }

.checkbox { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.panel-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }