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

:root {
  --bg:       #f0f2f7;
  --surface:  #ffffff;
  --brand:    #1a1a2e;
  --brand-lt: #2d2d5e;
  --accent:   #4f46e5;
  --accent-lt:#6366f1;
  --success:  #16a34a;
  --danger:   #dc2626;
  --border:   #e2e8f0;
  --muted:    #64748b;
  --radius:   12px;
  --shadow:   0 1px 6px rgba(0,0,0,.09);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--brand);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  background: var(--brand);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

.header-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.3px;
}

nav { display: flex; gap: 24px; }
nav a {
  color: rgba(255,255,255,.7);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color .15s;
}
nav a:hover { color: #fff; }

/* ── Main layout ──────────────────────────────────────────────────────────── */
main {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 56px;
}

.section h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

/* ── Upload card ──────────────────────────────────────────────────────────── */
.upload-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  outline: none;
}
.dropzone:hover,
.dropzone:focus,
.dropzone.drag-over {
  border-color: var(--accent);
  background: #f5f3ff;
}

.drop-icon { width: 44px; height: 44px; color: var(--muted); margin: 0 auto 12px; }
.drop-primary { font-weight: 600; font-size: 0.95rem; }
.drop-secondary { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.browse-link { color: var(--accent); text-decoration: underline; cursor: pointer; }
.drop-hint { font-size: 0.75rem; color: #94a3b8; margin-top: 8px; }

/* File preview row */
.file-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}
.file-preview svg { width: 22px; height: 22px; color: var(--accent); flex-shrink: 0; }
.file-info { flex: 1; overflow: hidden; }
.file-name { display: block; font-weight: 600; font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 0.78rem; color: var(--muted); }
.clear-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background .15s;
}
.clear-btn:hover { background: var(--border); }

/* Upload button */
.upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 13px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
}
.upload-btn:hover:not(:disabled) { background: var(--accent-lt); }
.upload-btn:active:not(:disabled) { transform: scale(.98); }
.upload-btn:disabled { opacity: .45; cursor: not-allowed; }

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2.5px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result card ──────────────────────────────────────────────────────────── */
.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid #d1fae5;
}

.result-header {
  background: #ecfdf5;
  color: var(--success);
  padding: 14px 20px;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.result-header svg { width: 18px; height: 18px; }

.result-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.result-row { display: flex; flex-direction: column; gap: 2px; }
.result-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.result-value { font-size: 0.875rem; word-break: break-all; }
.result-value.mono { font-family: 'SF Mono', 'Fira Code', monospace; font-weight: 600; }
.result-value.link { color: var(--accent); text-decoration: none; }
.result-value.link:hover { text-decoration: underline; }

.result-actions {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background .2s;
}
.btn-primary:hover { background: var(--accent-lt); }

.btn-secondary {
  display: inline-block;
  background: transparent;
  color: var(--brand);
  text-decoration: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  border: 1.5px solid var(--border);
  transition: border-color .2s, background .2s;
}
.btn-secondary:hover { border-color: var(--accent); background: #f5f3ff; }

/* ── Error banner ─────────────────────────────────────────────────────────── */
.error-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: 9px;
  padding: 14px 16px;
  font-size: 0.875rem;
}
.error-banner svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }

/* ── History section ──────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.section-header h2 { margin-bottom: 0; }

.refresh-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--brand);
  transition: border-color .15s, background .15s;
}
.refresh-btn:hover { border-color: var(--accent); background: #f5f3ff; }
.refresh-btn svg { width: 14px; height: 14px; }

.history-list { display: flex; flex-direction: column; gap: 12px; }

.history-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.history-item .invoice-id { font-family: 'SF Mono', 'Fira Code', monospace; font-weight: 700; font-size: 0.9rem; }
.history-item .invoice-date { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.history-item .history-actions { display: flex; gap: 10px; }
.history-link {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1.5px solid transparent;
  transition: background .15s, border-color .15s;
}
.history-link:hover { background: #f5f3ff; border-color: var(--accent); }

.empty-state { color: var(--muted); font-size: 0.875rem; text-align: center; padding: 32px 0; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 540px) {
  .header-inner { padding: 0 16px; }
  main { padding: 28px 16px 64px; }
  .result-actions { flex-direction: column; }
  .result-actions a { text-align: center; }
}
