* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f5f7;
  margin: 0;
  padding: 24px 16px;
  color: #1a1a1a;
}
.container { max-width: 640px; margin: 0 auto; }
header { margin-bottom: 24px; }
.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.header-top > div:first-child { text-align: center; flex: 1; }
header h1 { margin: 0 0 4px; font-size: 28px; }
.subtitle { color: #666; margin: 0; }
.user-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; color: #444; }
.user-email { font-size: 11px; color: #888; }
.admin-link { font-size: 12px; color: #4f46e5; text-decoration: none; font-weight: 600; }
.admin-link:hover { text-decoration: underline; }
.sign-out-link {
  font-size: 12px;
  color: #6366f1;
  text-decoration: none;
}
.sign-out-link:hover { text-decoration: underline; }
button.sign-out-link {
  background: transparent;
  color: #6366f1;
  padding: 0;
  font-size: 12px;
  font-weight: 400;
}

/* ── App-owned authentication ── */
.auth-page { min-height: 100vh; display: grid; place-items: center; }
.auth-shell { width: min(100%, 440px); margin: 0 auto; }
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand h1 { margin: 0 0 6px; font-size: 28px; }
.auth-brand p { margin: 0; color: #666; font-size: 14px; line-height: 1.45; }
.auth-card { margin: 0; }
.auth-card h2 { margin: 0 0 6px; font-size: 22px; }
.auth-intro { margin: 0 0 20px; color: #666; font-size: 14px; line-height: 1.45; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; color: #555; font-size: 13px; font-weight: 600; }
.auth-form input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #d8d8e0;
  border-radius: 8px;
  background: #fff;
  color: #1a1a1a;
  font: inherit;
}
.auth-form input:focus { outline: 2px solid #c7c9ff; border-color: #6366f1; }
.auth-switch { margin: 18px 0 0; text-align: center; color: #666; font-size: 13px; }
.auth-switch a { color: #4f46e5; font-weight: 600; }
.verification-reminder {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 16px;
  padding: 13px 16px;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 13px;
}
.verification-reminder > div { display: flex; flex-direction: column; gap: 3px; }
.verification-reminder span { color: #475569; }
.verification-resend {
  white-space: nowrap;
  padding: 8px 11px;
  border: 1px solid #93c5fd;
  border-radius: 7px;
  background: #fff;
  color: #1d4ed8;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.verification-resend:hover { background: #dbeafe; }

/* ── Legacy ownership confirmation ── */
.admin-safety-list { margin: 0; padding-left: 20px; color: #666; font-size: 13px; line-height: 1.8; }

.card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.upload-card form { display: flex; flex-direction: column; gap: 12px; }
input[type="file"] { display: none; }

/* ── Upload step instructions ── */
.upload-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  color: #555;
  flex-wrap: wrap;
}
.upload-step { display: flex; align-items: center; gap: 4px; }
.upload-step-num {
  background: #6366f1;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.upload-step-arrow { color: #bbb; font-size: 16px; }

.file-label {
  border: 2px dashed #ccc;
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  color: #555;
  transition: border-color 0.15s, color 0.15s;
}
.file-label:hover { border-color: #6366f1; color: #6366f1; }
.file-label.file-selected {
  border-color: #6366f1;
  background: #eef2ff;
  color: #4f46e5;
}

/* ── File staged preview (after selection, before submit) ── */
.file-preview {
  border: 1px solid #c7c9ff;
  border-radius: 10px;
  padding: 12px 16px;
  background: #f5f3ff;
  display: flex;
  align-items: center;
  gap: 12px;
}
.file-preview-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  display: block;
}
.file-preview-icon {
  width: 56px;
  height: 56px;
  background: #e0e7ff;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.file-preview-info { flex: 1; min-width: 0; }
.file-preview-name {
  font-size: 13px;
  font-weight: 600;
  color: #3730a3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.file-preview-cta {
  font-size: 12px;
  color: #6366f1;
  margin-top: 2px;
  display: block;
}
button {
  background: #6366f1;
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}
button:hover { background: #4f46e5; }

/* ── Dashboard ── */
.dashboard { display: flex; flex-direction: column; gap: 12px; }
.dashboard-secondary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.total-card { text-align: center; padding: 24px 20px 20px; }
.total-label { display: block; font-size: 12px; color: #888; text-transform: uppercase; letter-spacing: 0.05em; }
.total-headline { display: block; font-size: 36px; font-weight: 700; margin-top: 6px; letter-spacing: -0.5px; }
.total-meta { display: block; font-size: 13px; color: #666; margin-top: 6px; }
.total-breakdown { display: block; font-size: 12px; color: #999; margin-top: 4px; }
.conversion-warning {
  display: block;
  margin-top: 8px;
  color: #b45309;
  font-size: 12px;
  line-height: 1.4;
}

.stat-card { text-align: center; padding: 16px 8px; }
.stat-label { display: block; font-size: 12px; color: #888; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { display: block; font-size: 22px; font-weight: 700; margin-top: 4px; }
.export-link { text-decoration: none; color: inherit; display: flex; align-items: center; justify-content: center; }

/* ── Category breakdown ── */
.category-bars { display: flex; flex-direction: column; gap: 8px; }
.cat-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #eee; }
.cat-row:last-child { border-bottom: none; }
.cat-name { color: #444; }
.cat-amount { font-weight: 600; text-align: right; }

.empty { color: #999; text-align: center; padding: 20px 0; }

/* ── Period filter ── */
.period-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.period-filter-label {
  font-size: 12px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.period-btns {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.period-btn {
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid #e2e2e8;
  background: #fff;
  color: #555;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
}
.period-btn:hover { border-color: #6366f1; color: #4f46e5; }
.period-btn.active {
  background: #6366f1;
  border-color: #6366f1;
  color: #fff;
  font-weight: 600;
}
.period-filter-by {
  font-size: 11px;
  color: #aaa;
  white-space: nowrap;
  margin-left: auto;
}

/* ── Receipt list ── */
.receipt-list { display: flex; flex-direction: column; gap: 8px; }

/* ── Receipt list column header ── */
.receipt-list-header {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(104px, 1fr) minmax(96px, 1fr) minmax(112px, 1.2fr) minmax(115px, auto);
  gap: 16px;
  padding: 4px 12px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid #eee;
  margin-bottom: 4px;
}
.rh-status { text-align: right; }
.receipt-item {
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(104px, 1fr) minmax(96px, 1fr) minmax(112px, 1.2fr) minmax(115px, auto);
  gap: 16px;
  align-items: center;
  font-size: 14px;
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
}
.receipt-item:hover { background: #f9f9fb; border-color: #c7c9ff; }
.receipt-item:focus { outline: 2px solid #6366f1; outline-offset: 1px; }
.r-vendor { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.r-amount { color: #16a34a; text-align: right; white-space: nowrap; }
.r-date { color: #888; }
.r-cat {
  font-size: 12px;
  background: #eef2ff;
  color: #4f46e5;
  padding: 2px 8px;
  border-radius: 20px;
  text-align: center;
}

/* ── Receipt list: badges column ── */
.r-badges { display: flex; flex-direction: column; gap: 3px; align-items: flex-end; }

/* ── Status / duplicate badges ── */
.badge-verified,
.badge-needs-review,
.badge-possible-dup,
.badge-marked-dup {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.badge-verified     { background: #dcfce7; color: #15803d; }
.badge-needs-review { background: #fff7ed; color: #c2410c; }
.badge-possible-dup { background: #fef9c3; color: #854d0e; }
.badge-marked-dup   { background: #f1f5f9; color: #64748b; }

/* ── Document type badges ── */
.badge-doc-type {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.badge-doc-tax-invoice { background: #ede9fe; color: #5b21b6; }
.badge-doc-receipt     { background: #e0f2fe; color: #0369a1; }
.badge-doc-unclear     { background: #f1f5f9; color: #64748b; }

/* ── Dashboard doc-type breakdown ── */
.doc-type-breakdown { font-size: 12px; color: #888; margin-top: 2px; }

/* ── Marked-duplicate list row ── */
.receipt-item.marked-duplicate { opacity: 0.45; }
.receipt-item.marked-duplicate:hover { opacity: 0.65; background: #f9f9fb; }

/* ── Duplicate modal banners ── */
.dup-warning {
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  line-height: 1.4;
}
.dup-marked-banner {
  background: #f1f5f9;
  color: #64748b;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ── Duplicate action section label ── */
.dup-actions-label {
  font-size: 11px;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 14px 0 6px;
}

/* ── Mark as duplicate button ── */
.btn-mark-dup {
  flex: 1;
  padding: 11px;
  font-size: 14px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: #fef2f2;
  color: #dc2626;
}
.btn-mark-dup:hover { background: #fee2e2; }

/* ── Extraction incomplete note ── */
.extraction-note {
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ── Flash messages ── */
.flash {
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.4;
}
.flash-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.flash-warning { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.flash-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* ── Verify button ── */
.btn-verify {
  flex: 1;
  padding: 11px;
  font-size: 14px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: #f0fdf4;
  color: #15803d;
}
.btn-verify:hover { background: #dcfce7; }

/* ── Unverify button (amber outline) ── */
.btn-unverify {
  flex: 1;
  padding: 11px;
  font-size: 14px;
  border-radius: 8px;
  border: 1.5px solid #fbbf24;
  cursor: pointer;
  background: #fff;
  color: #92400e;
}
.btn-unverify:hover { background: #fffbeb; border-color: #f59e0b; }

/* ── Verified lock banner ── */
.verified-lock-banner {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ── Modal overlay ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
@media (min-width: 540px) {
  .modal-overlay { align-items: center; padding: 24px; }
}

.modal-card {
  background: #fff;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 24px 20px 32px;
  position: relative;
}
@media (min-width: 540px) {
  .modal-card { border-radius: 16px; max-height: 88vh; }
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: #f0f0f3;
  color: #444;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: #e4e4e8; }

/* Image / PDF preview */
.modal-image-wrap { margin-bottom: 16px; border-radius: 8px; overflow: hidden; }
.modal-img { width: 100%; max-height: 260px; object-fit: contain; border-radius: 8px; background: #f4f5f7; }
.modal-pdf { width: 100%; height: 260px; border-radius: 8px; border: none; }

.modal-vendor-title { font-size: 20px; font-weight: 700; margin: 0 0 16px; padding-right: 32px; }

/* Detail fields */
.modal-fields { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.mf-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.mf-label { font-size: 12px; color: #888; text-transform: uppercase; letter-spacing: 0.04em; flex-shrink: 0; }
.mf-value { font-size: 15px; font-weight: 500; text-align: right; }
.mf-small { font-size: 12px; color: #999; font-weight: 400; }

/* Modal action buttons */
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn-primary,
.modal-actions .btn-secondary,
.modal-actions .btn-danger { flex: 1; padding: 11px; font-size: 14px; border-radius: 8px; border: none; cursor: pointer; }
.btn-primary { background: #6366f1; color: #fff; }
.btn-primary:hover { background: #4f46e5; }
.btn-secondary { background: #f0f0f3; color: #333; }
.btn-secondary:hover { background: #e4e4e8; }
.btn-danger { background: #fef2f2; color: #dc2626; }
.btn-danger:hover { background: #fee2e2; }

/* Edit form inside modal */
.edit-form-modal { display: flex; flex-direction: column; gap: 14px; }
.edit-form-modal label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: #666;
  gap: 5px;
}
.edit-form-modal input,
.edit-form-modal select {
  padding: 9px 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 15px;
  width: 100%;
  background: #fff;
}
.edit-form-modal input:focus,
.edit-form-modal select:focus {
  outline: 2px solid #6366f1;
  border-color: transparent;
}
.tax-disclaimer {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
}

@media (max-width: 480px) {
  .dashboard-secondary { grid-template-columns: 1fr 1fr; }
  .receipt-list-header { display: none; }
  .receipt-item {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "vendor amount"
      "date category"
      "badges badges";
    gap: 9px 12px;
    padding: 14px 12px;
  }
  .r-vendor { grid-area: vendor; }
  .r-amount { grid-area: amount; align-self: start; }
  .r-date { grid-area: date; }
  .r-cat { grid-area: category; justify-self: end; }
  .r-badges { grid-area: badges; }
}
