/* ===== DESIGN TOKENS ===== */
:root {
  /* Color Palette — Finance Trust */
  --color-bg: #f8f9fb;
  --color-surface: #ffffff;
  --color-text-primary: #1a1d26;
  --color-text-secondary: #6b7280;
  --color-text-muted: #9ca3af;
  --color-accent: #059669;          /* Emerald green */
  --color-accent-hover: #047857;
  --color-accent-light: rgba(5, 150, 105, 0.08);
  --color-accent-glow: rgba(5, 150, 105, 0.25);
  --color-border: #e5e7eb;
  --color-border-hover: #d1d5db;
  --color-dropzone-active: rgba(5, 150, 105, 0.12);
  --color-success: #10b981;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.1);
  --shadow-accent: 0 4px 20px rgba(5, 150, 105, 0.2);

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

/* ===== LAYOUT ===== */
.app-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
  flex: 1;
}

/* ===== HEADER ===== */
.app-header {
  text-align: center;
  margin-bottom: var(--space-3xl);
  animation: fadeSlideDown 0.6s var(--transition-base) both;
}

.app-header__logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.app-header__icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--color-accent), #34d399);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-accent);
  flex-shrink: 0;
}

.app-header__icon svg {
  width: 24px;
  height: 24px;
  color: #fff;
}

.app-header__title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text-primary);
}

.app-header__title span {
  color: var(--color-accent);
}

.app-header__subtitle {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  max-width: 420px;
  margin: 0 auto;
  line-height: 1.5;
}

/* Privacy badge */
.privacy-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--space-md);
  padding: 6px 14px;
  background: var(--color-accent-light);
  border: 1px solid rgba(5, 150, 105, 0.15);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-accent);
  letter-spacing: 0.01em;
}

.privacy-badge svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ===== DROPZONE ===== */
.dropzone-wrapper {
  width: 100%;
  animation: fadeSlideUp 0.6s 0.15s var(--transition-base) both;
}

.dropzone {
  position: relative;
  width: 100%;
  min-height: 260px;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-2xl) var(--space-lg);
  cursor: pointer;
  transition:
    border-color var(--transition-base),
    background-color var(--transition-base),
    box-shadow var(--transition-base),
    transform var(--transition-fast);
  overflow: hidden;
}

.dropzone::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  background: radial-gradient(circle at 50% 40%, var(--color-accent-light), transparent 70%);
  opacity: 0;
  transition: opacity var(--transition-slow);
  pointer-events: none;
}

.dropzone:hover {
  border-color: var(--color-border-hover);
  box-shadow: var(--shadow-md);
}

.dropzone:hover::before {
  opacity: 0.5;
}

/* Active drag-over state */
.dropzone--active {
  border-color: var(--color-accent) !important;
  background-color: var(--color-dropzone-active) !important;
  box-shadow: 0 0 0 4px var(--color-accent-glow), var(--shadow-lg) !important;
  transform: scale(1.01);
}

.dropzone--active::before {
  opacity: 1;
}

.dropzone--active .dropzone__icon {
  transform: translateY(-4px) scale(1.1);
  color: var(--color-accent);
}

.dropzone--active .dropzone__text {
  color: var(--color-accent);
}

/* Dropzone icon */
.dropzone__icon {
  width: 56px;
  height: 56px;
  color: var(--color-text-muted);
  transition:
    transform var(--transition-base),
    color var(--transition-base);
}

.dropzone:hover .dropzone__icon {
  transform: translateY(-2px);
  color: var(--color-text-secondary);
}

/* Dropzone text */
.dropzone__text {
  text-align: center;
  transition: color var(--transition-base);
}

.dropzone__text-main {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-text-primary);
  margin-bottom: 4px;
}

.dropzone__text-sub {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* Hidden file input */
.dropzone__input {
  display: none;
}

/* ===== TOAST / FEEDBACK ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--color-text-primary);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-xl);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity var(--transition-base),
    transform var(--transition-base);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast__icon {
  width: 18px;
  height: 18px;
  color: var(--color-success);
  flex-shrink: 0;
}

/* ===== FILE COUNTER ===== */
.file-counter {
  display: none;
  text-align: center;
  margin-top: var(--space-md);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  padding: 6px 16px;
  background: var(--color-accent-light);
  border-radius: 999px;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
  transition: opacity var(--transition-base);
}

.file-counter--visible {
  display: block;
  animation: fadeSlideUp 0.25s ease both;
}

/* ===== GALLERY ===== */
.gallery {
  display: none;
  width: 100%;
  margin-top: var(--space-lg);
}

.gallery--visible {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-md);
  animation: fadeSlideUp 0.3s ease both;
}

/* ===== GALLERY CARD ===== */
.gallery-card {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  transition:
    border-color var(--transition-base),
    box-shadow var(--transition-base),
    transform var(--transition-fast);
  animation: cardSlideIn 0.35s ease both;
}

.gallery-card:hover {
  border-color: var(--color-border-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* Card entrance stagger (JS adds cards sequentially, this adds polish) */
@keyframes cardSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Card removal animation */
.gallery-card--removing {
  animation: cardSlideOut 0.3s ease forwards;
}

@keyframes cardSlideOut {
  to {
    opacity: 0;
    transform: translateY(-8px) scale(0.9);
  }
}

/* ── Delete button ── */
.gallery-card__remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.8);
  transition:
    opacity var(--transition-fast),
    transform var(--transition-fast),
    background-color var(--transition-fast);
  z-index: 2;
}

.gallery-card__remove svg {
  width: 14px;
  height: 14px;
}

.gallery-card:hover .gallery-card__remove {
  opacity: 1;
  transform: scale(1);
}

.gallery-card__remove:hover {
  background: #ef4444;
}

/* ── Thumbnail ── */
.gallery-card__img-wrap {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

.gallery-card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--transition-slow);
}

.gallery-card:hover .gallery-card__img {
  transform: scale(1.04);
}

/* ── Card info ── */
.gallery-card__info {
  padding: 0 2px;
  min-width: 0;
}

.gallery-card__name {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.gallery-card__size {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  margin-top: 1px;
}

/* ── Status badge ── */
.gallery-card__status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--color-accent);
  padding: 0 2px;
  transition: color var(--transition-base);
}

.gallery-card__status svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

/* Processing state: orange + pulse animation */
.gallery-card__status--processing {
  color: #f59e0b;
}

.gallery-card__status--processing svg {
  animation: spin 1.2s linear infinite;
}

/* Done state: bold green */
.gallery-card__status--done {
  color: #059669;
}

/* Error state: red */
.gallery-card__status--error {
  color: #ef4444;
}

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

/* ===== ACTION SECTION ===== */
.action-section {
  width: 100%;
  margin-top: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  animation: fadeSlideUp 0.6s 0.3s var(--transition-base) both;
}

/* ── Filename Input ── */
.filename-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filename-row__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.filename-row__label svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.filename-row__input-wrap {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  overflow: hidden;
  transition:
    border-color var(--transition-base),
    box-shadow var(--transition-base);
}

.filename-row__input-wrap:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-glow);
}

.filename-row__input {
  flex: 1;
  padding: 10px 14px;
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  color: var(--color-text-primary);
  background: transparent;
  min-width: 0;
}

.filename-row__input::placeholder {
  color: var(--color-text-muted);
}

.filename-row__suffix {
  display: flex;
  align-items: center;
  padding: 0 14px;
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  border-left: 1px solid var(--color-border);
  user-select: none;
}

/* ── Currency Selector ── */
.currency-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  color: var(--color-text-primary);
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  transition:
    border-color var(--transition-base),
    box-shadow var(--transition-base);
}

.currency-select:hover {
  border-color: var(--color-border-hover);
}

.currency-select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-glow);
}

.btn-download {
  width: 100%;
  padding: 16px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition:
    background-color var(--transition-base),
    box-shadow var(--transition-base),
    transform var(--transition-fast),
    opacity var(--transition-base);
  position: relative;
  overflow: hidden;
}

.btn-download::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.1));
  opacity: 0;
  transition: opacity var(--transition-base);
}

.btn-download:hover:not(:disabled)::after {
  opacity: 1;
}

/* Disabled state */
.btn-download:disabled {
  background: var(--color-border);
  color: var(--color-text-muted);
  cursor: not-allowed;
  box-shadow: none;
}

/* Active/enabled state */
.btn-download--ready {
  background: linear-gradient(135deg, var(--color-accent), #34d399);
  color: #fff;
  box-shadow: var(--shadow-accent);
}

.btn-download--ready:hover {
  background: linear-gradient(135deg, var(--color-accent-hover), #059669);
  box-shadow: 0 6px 24px rgba(5, 150, 105, 0.3);
  transform: translateY(-1px);
}

.btn-download--ready:active {
  transform: translateY(0);
  box-shadow: var(--shadow-accent);
}

/* Success state: Ready to Save (Green/Emerald gradient with pulse) */
.btn-download--success {
  background: linear-gradient(135deg, #10b981, #059669); /* Emerald shades */
  color: #fff;
  box-shadow: 0 10px 30px -10px rgba(16, 185, 129, 0.5);
  animation: pulsateSuccess 2s infinite ease-in-out;
}

.btn-download--success:hover {
  background: linear-gradient(135deg, #059669, #047857);
  box-shadow: 0 15px 35px -10px rgba(16, 185, 129, 0.6);
  transform: translateY(-1px);
}

@keyframes pulsateSuccess {
  0% { box-shadow: 0 10px 30px -10px rgba(16, 185, 129, 0.5); }
  50% { box-shadow: 0 10px 45px -5px rgba(16, 185, 129, 0.7); }
  100% { box-shadow: 0 10px 30px -10px rgba(16, 185, 129, 0.5); }
}

.btn-download__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* Processing state: amber gradient + spinner */
.btn-download--processing {
  background: linear-gradient(135deg, #f59e0b, #fbbf24) !important;
  color: #fff !important;
  cursor: wait !important;
  box-shadow: 0 4px 20px rgba(245, 158, 11, 0.3) !important;
}

.btn-download__spinner {
  animation: spin 1s linear infinite;
}

/* ===== OCR DEBUG PANEL ===== */
.ocr-debug-panel {
  display: none;
  width: 100%;
  margin-top: var(--space-lg);
  border: 1px solid #fbbf24;
  border-radius: var(--radius-md);
  background: #fffbeb;
  overflow: hidden;
  animation: fadeSlideUp 0.4s var(--transition-base) both;
}

.ocr-debug-panel__title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  border-bottom: 1px solid #fde68a;
}

.ocr-debug-panel__entries {
  max-height: 400px;
  overflow-y: auto;
}

.ocr-debug-entry {
  border-bottom: 1px solid #fde68a;
}

.ocr-debug-entry:last-child {
  border-bottom: none;
}

.ocr-debug-entry__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px 6px;
  font-size: 0.78rem;
  color: #78350f;
}

.ocr-debug-entry__header span {
  font-size: 0.72rem;
  color: #a16207;
}

.ocr-debug-entry__text {
  margin: 0;
  padding: 8px 16px 14px;
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  color: #451a03;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  background: rgba(255, 251, 235, 0.5);
}

/* ===== MODEL PROGRESS BAR ===== */
.model-progress {
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-xl);
  box-shadow: var(--shadow-md);
  animation: fadeSlideDown 0.4s ease both;
}

.model-progress__header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  color: var(--color-accent);
}

.model-progress__label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

.model-progress__bar {
  width: 100%;
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: var(--space-sm);
}

.model-progress__fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #059669, #10b981, #34d399);
  background-size: 200% 100%;
  animation: progressShimmer 1.5s ease infinite;
  transition: width 0.3s ease;
}

.model-progress__text {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-accent);
  text-align: right;
  display: block;
}

@keyframes progressShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== FOOTER ===== */
.app-footer {
  text-align: center;
  padding: var(--space-xl) var(--space-lg);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  animation: fadeSlideUp 0.6s 0.45s var(--transition-base) both;
}

.app-footer a {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
}

.app-footer a:hover {
  text-decoration: underline;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeSlideDown {
  from {
    opacity: 0;
    transform: translateY(-16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .app-container {
    padding: var(--space-lg) var(--space-md);
  }

  .app-header {
    margin-bottom: var(--space-2xl);
  }

  .app-header__title {
    font-size: 1.4rem;
  }

  .app-header__subtitle {
    font-size: 0.82rem;
  }

  .dropzone {
    min-height: 220px;
    padding: var(--space-xl) var(--space-md);
  }

  .dropzone__icon {
    width: 44px;
    height: 44px;
  }

  .dropzone__text-main {
    font-size: 0.88rem;
  }

  .btn-download {
    padding: 14px 20px;
    font-size: 0.9rem;
  }

  .gallery--visible {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: var(--space-sm);
  }

  .gallery-card__name {
    font-size: 0.72rem;
  }
}

@media (max-width: 380px) {
  .app-header__logo {
    flex-direction: column;
    gap: var(--space-xs);
  }

  .app-header__title {
    font-size: 1.25rem;
  }
}
