/* ============================================================
   BE Bill Renamer – style.css  (v3 – polished & bug-fixed)
   ============================================================ */

/* ── Reset & Variables ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:             #060912;
  --surface:        rgba(255,255,255,0.04);
  --surface-hover:  rgba(255,255,255,0.07);
  --surface-card:   rgba(255,255,255,0.035);
  --border:         rgba(255,255,255,0.08);
  --border-focus:   rgba(99,102,241,0.6);
  --primary:        #6366f1;
  --primary-light:  #818cf8;
  --primary-glow:   rgba(99,102,241,0.22);
  --accent:         #22d3ee;
  --success:        #10b981;
  --success-bg:     rgba(16,185,129,0.08);
  --success-border: rgba(16,185,129,0.25);
  --warning:        #f59e0b;
  --danger:         #ef4444;
  --text:           #f1f5f9;
  --text-muted:     #94a3b8;
  --text-faint:     #475569;
  --radius:         14px;
  --radius-sm:      9px;
  --radius-xs:      6px;
  --shadow:         0 20px 40px -12px rgba(0,0,0,0.7);
  --transition:     0.2s cubic-bezier(0.4,0,0.2,1);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Animated Orbs ───────────────────────────────────────────── */
.bg-orbs { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.12;
  animation: orbFloat 22s ease-in-out infinite;
}
.orb-1 { width: 640px; height: 640px; background: radial-gradient(circle, #6366f1, transparent); top: -220px; left: -220px; animation-delay: 0s; }
.orb-2 { width: 520px; height: 520px; background: radial-gradient(circle, #22d3ee, transparent); bottom: -160px; right: -160px; animation-delay: -8s; }
.orb-3 { width: 420px; height: 420px; background: radial-gradient(circle, #a855f7, transparent); top: 45%; left: 50%; transform: translate(-50%,-50%); animation-delay: -16s; }

@keyframes orbFloat {
  0%,100% { transform: translate(0,0) scale(1); }
  33%      { transform: translate(28px,-28px) scale(1.04); }
  66%      { transform: translate(-18px,18px) scale(0.96); }
}

/* ── Layout ──────────────────────────────────────────────────── */
.app-wrapper {
  position: relative;
  z-index: 1;
  max-width: 920px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

/* ── Header ──────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 14px;
}

.logo { display: flex; align-items: center; gap: 14px; }

.logo-icon {
  font-size: 2.2rem;
  filter: drop-shadow(0 0 16px rgba(99,102,241,0.55));
  animation: iconPulse 3s ease-in-out infinite;
}

@keyframes iconPulse {
  0%,100% { filter: drop-shadow(0 0 16px rgba(99,102,241,0.55)); }
  50%     { filter: drop-shadow(0 0 28px rgba(99,102,241,0.85)); }
}

.logo-title {
  font-size: 1.65rem;
  font-weight: 800;
  background: linear-gradient(135deg, #f1f5f9, var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.logo-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 1px;
}

.header-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 7px 14px;
  font-size: 0.77rem;
  font-weight: 500;
  color: var(--text-muted);
}

.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 7px var(--success);
  animation: dotBlink 2s ease-in-out infinite;
}

@keyframes dotBlink {
  0%,100% { opacity: 1; }
  50%     { opacity: 0.45; }
}

/* ── Upload Zone ─────────────────────────────────────────────── */
.upload-section { margin-bottom: 28px; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 52px 28px;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  user-select: none;
}

.drop-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, var(--primary-glow), transparent 70%);
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--border-focus);
  background: var(--surface-hover);
  transform: translateY(-2px);
  box-shadow: 0 0 0 1px var(--primary-glow), var(--shadow);
}

.drop-zone:hover::before,
.drop-zone.drag-over::before { opacity: 1; }

.drop-zone.drag-over {
  border-style: solid;
  border-color: var(--primary);
}

.drop-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  color: var(--primary);
  opacity: 0.75;
  animation: iconFloat 4s ease-in-out infinite;
}

@keyframes iconFloat {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-7px); }
}

.drop-icon svg { width: 100%; height: 100%; }

.drop-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.drop-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.browse-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 24px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 0 24px var(--primary-glow);
  position: relative;
  z-index: 1;
}

.browse-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 36px rgba(99,102,241,0.5);
}

/* ── Queue Section ───────────────────────────────────────────── */
.queue-section { margin-bottom: 28px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.section-title-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 7px;
}

.title-icon { font-size: 1rem; }

.stats-bar {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-faint);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 3px 12px;
  font-family: 'JetBrains Mono', monospace;
  transition: var(--transition);
}

.stats-bar.has-done { color: var(--success); border-color: var(--success-border); background: var(--success-bg); }

.queue-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 0 18px var(--primary-glow);
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 0 28px rgba(99,102,241,0.45); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
}

.btn-secondary:hover { background: var(--surface-hover); color: var(--text); border-color: rgba(255,255,255,0.14); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text-faint);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
}

.btn-ghost:hover { background: rgba(239,68,68,0.08); color: var(--danger); }

/* ── File Cards ──────────────────────────────────────────────── */
.file-list { display: flex; flex-direction: column; gap: 10px; }

.file-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 52px 1fr auto auto;
  align-items: center;
  gap: 14px;
  transition: var(--transition);
  animation: cardIn 0.3s cubic-bezier(0.34,1.4,0.64,1);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.file-card:hover { background: var(--surface-hover); }

/* Done state */
.file-card.card-done {
  border-left-color: var(--success);
  background: var(--success-bg);
}
.file-card.card-done:hover { background: rgba(16,185,129,0.12); }

/* Error state */
.file-card.card-error {
  border-left-color: var(--danger);
  background: rgba(239,68,68,0.05);
}

/* ── Thumbnail ───────────────────────────────────────────────── */
.file-thumb {
  width: 44px;
  height: 52px;
  border-radius: var(--radius-xs);
  background: rgba(99,102,241,0.1);
  border: 1px solid rgba(99,102,241,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
  overflow: hidden;
}

.file-thumb canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  display: block;
}

/* ── File Info ───────────────────────────────────────────────── */
.file-info { min-width: 0; }

/* Pending/processing state */
.file-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.file-meta {
  font-size: 0.74rem;
  color: var(--text-faint);
  margin-bottom: 4px;
}

/* Progress bar */
.progress-bar-wrap {
  height: 3px;
  background: rgba(255,255,255,0.05);
  border-radius: 100px;
  overflow: hidden;
  display: none;
  transition: opacity 0.4s ease;
}

.progress-bar-wrap.active { display: block; }
.progress-bar-wrap.fade-out { opacity: 0; }

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 100px;
  width: 0;
  transition: width 0.35s ease;
}

/* Done state info */
.file-name-old {
  font-size: 0.7rem;
  color: var(--text-faint);
  text-decoration: line-through;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.file-name-new {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--success);
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 1px;
  letter-spacing: -0.01em;
}

.file-bill {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ── Status Badge ────────────────────────────────────────────── */
.status-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 100px;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-pending    { background: rgba(148,163,184,0.09); color: var(--text-faint);  border: 1px solid rgba(148,163,184,0.18); }
.status-processing { background: rgba(99,102,241,0.12);  color: var(--primary-light); border: 1px solid rgba(99,102,241,0.28); animation: pulseBadge 1.5s ease-in-out infinite; }
.status-done       { background: var(--success-bg);       color: var(--success);   border: 1px solid var(--success-border); }
.status-error      { background: rgba(239,68,68,0.1);     color: var(--danger);    border: 1px solid rgba(239,68,68,0.25); }

@keyframes pulseBadge {
  0%,100% { opacity: 1; }
  50%     { opacity: 0.55; }
}

/* ── File Actions ────────────────────────────────────────────── */
.file-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

.action-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.action-btn:hover             { background: var(--surface-hover); color: var(--text); }
.action-btn.danger:hover      { background: rgba(239,68,68,0.12); color: var(--danger); border-color: rgba(239,68,68,0.28); }

/* Inline download button (in card after done) */
.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
  border-radius: var(--radius-xs);
  padding: 7px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
}

.download-btn:hover {
  background: rgba(16,185,129,0.18);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16,185,129,0.2);
}

/* ── Modals ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: #0c1018;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 18px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 40px 80px rgba(0,0,0,0.85);
  animation: modalIn 0.28s cubic-bezier(0.34,1.4,0.64,1);
  overflow: hidden;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.93) translateY(18px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h3 { font-size: 0.95rem; font-weight: 700; }

.modal-close {
  width: 30px; height: 30px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}

.modal-close:hover { background: var(--surface-hover); color: var(--text); }

/* Preview modal specifics */
.preview-modal { max-width: 720px; }

.modal-body {
  padding: 20px;
  overflow: auto;
  flex: 1;
}

.canvas-wrap {
  position: relative;
  display: inline-block;
  width: 100%;
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
}

/* OCR region overlay — positioned relative to .canvas-wrap */
.ocr-region-box {
  position: absolute;
  border: 2px solid var(--accent);
  border-radius: 4px;
  background: rgba(34,211,238,0.07);
  pointer-events: none;
  display: none;
  box-shadow: 0 0 0 1px rgba(34,211,238,0.2);
}

.region-label {
  position: absolute;
  top: -22px;
  left: 0;
  font-size: 0.67rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(34,211,238,0.12);
  border: 1px solid rgba(34,211,238,0.3);
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.modal-footer {
  padding: 18px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex-shrink: 0;
}

.detected-info label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.bill-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  font-weight: 600;
  transition: var(--transition);
  outline: none;
}

.bill-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.bill-input::placeholder { color: var(--text-faint); font-weight: 400; }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Format Picker ───────────────────────────────────────────── */
.format-modal { max-width: 460px; }

.format-body {
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.format-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
}

.format-desc span { color: var(--primary-light); font-weight: 700; }

.format-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.format-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  transition: var(--transition);
  font-family: 'Inter', sans-serif;
  color: var(--text);
}

.format-card:hover {
  background: var(--surface-hover);
  border-color: var(--primary);
  transform: translateY(-3px);
  box-shadow: 0 0 0 1px var(--primary-glow), 0 8px 24px rgba(0,0,0,0.4);
}

.fmt-icon  { font-size: 2rem; line-height: 1; }
.fmt-title { font-size: 0.9rem; font-weight: 700; }
.fmt-sub   { font-size: 0.73rem; color: var(--text-muted); text-align: center; line-height: 1.4; }

.format-note {
  font-size: 0.73rem;
  color: var(--text-faint);
  text-align: center;
  padding: 10px 14px;
  background: rgba(245,158,11,0.05);
  border: 1px solid rgba(245,158,11,0.14);
  border-radius: var(--radius-xs);
  line-height: 1.5;
}

/* ── Footer ──────────────────────────────────────────────────── */
.footer {
  margin-top: 48px;
  text-align: center;
  font-size: 0.74rem;
  color: var(--text-faint);
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.footer strong { color: var(--text-muted); font-weight: 600; }

.footer-link {
  color: var(--primary-light);
  text-decoration: none;
  transition: var(--transition);
}

.footer-link:hover { color: var(--text); text-decoration: underline; }

.footer-sub { color: var(--text-faint); font-size: 0.7rem; }

/* ── Toast notifications ─────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #131926;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.82rem;
  font-weight: 500;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 9px;
  animation: toastIn 0.35s cubic-bezier(0.34,1.4,0.64,1);
  box-shadow: var(--shadow);
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--primary); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(28px) scale(0.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.09); border-radius: 100px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.16); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  .header        { flex-direction: column; align-items: flex-start; }
  .section-header{ flex-direction: column; align-items: flex-start; }
  .file-card     { grid-template-columns: 44px 1fr; grid-template-rows: auto auto; }
  .file-card .status-badge,
  .file-card .file-actions { grid-column: 2; }
  .modal-actions { flex-direction: column; }
  .format-options{ grid-template-columns: 1fr; }
}