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

:root {
  --blue:       #2563eb;
  --blue-light: #eff6ff;
  --blue-dark:  #1d4ed8;
  --green:      #16a34a;
  --green-light:#f0fdf4;
  --red:        #dc2626;
  --red-light:  #fef2f2;
  --amber:      #d97706;
  --amber-light:#fffbeb;
  --gray-50:    #f8fafc;
  --gray-100:   #f1f5f9;
  --gray-200:   #e2e8f0;
  --gray-400:   #94a3b8;
  --gray-500:   #64748b;
  --gray-700:   #334155;
  --gray-900:   #0f172a;
  --white:      #ffffff;
  --radius:     12px;
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg:  0 4px 6px rgba(0,0,0,.05), 0 10px 40px rgba(0,0,0,.1);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.6;
  min-height: 100vh;
}

/* ─── Layout ────────────────────────────────────────────────────────────── */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 1.5rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--gray-200);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--gray-900);
  text-decoration: none;
}

.logo-icon {
  width: 34px; height: 34px;
  background: var(--blue);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}

.privacy-badge {
  font-size: 0.78rem;
  color: var(--gray-500);
  display: flex;
  align-items: center;
  gap: 5px;
}

main {
  flex: 1;
  padding: 2.5rem 1.5rem 4rem;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

/* ─── Screens ───────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ─── Upload screen ─────────────────────────────────────────────────────── */
.hero {
  text-align: center;
  margin-bottom: 2.5rem;
}

.hero h1 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 800;
  color: var(--gray-900);
  line-height: 1.2;
  margin-bottom: 1rem;
}

.hero h1 span { color: var(--blue); }

.hero p {
  font-size: 1.05rem;
  color: var(--gray-500);
  max-width: 540px;
  margin: 0 auto;
}

.trust-row {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

.trust-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  color: var(--gray-500);
}

.upload-card {
  background: var(--white);
  border: 2px dashed var(--gray-200);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  position: relative;
}

.upload-card:hover,
.upload-card.drag-over {
  border-color: var(--blue);
  background: var(--blue-light);
}

.upload-card input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.upload-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  display: block;
}

.upload-card h2 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.4rem;
}

.upload-card p {
  font-size: 0.88rem;
  color: var(--gray-400);
}

.upload-card .browse-link {
  color: var(--blue);
  text-decoration: underline;
  font-weight: 500;
}

/* File preview */
.file-preview {
  display: none;
  align-items: center;
  gap: 1rem;
  background: var(--green-light);
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 0.9rem 1.2rem;
  margin-top: 1rem;
}

.file-preview.visible { display: flex; }

.preview-thumb {
  width: 52px; height: 52px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.preview-thumb.pdf-icon {
  background: var(--red-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
}

.preview-info { flex: 1; text-align: left; }
.preview-name { font-weight: 600; font-size: 0.9rem; color: var(--gray-900); word-break: break-all; }
.preview-size { font-size: 0.8rem; color: var(--gray-500); }

.remove-file {
  background: none; border: none; cursor: pointer;
  color: var(--gray-400); font-size: 1.2rem; padding: 4px;
  flex-shrink: 0;
}
.remove-file:hover { color: var(--red); }

/* Form controls */
.form-row {
  margin-top: 1.25rem;
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.form-group { flex: 1; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.4rem;
}

select, input[type="text"] {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 0.95rem;
  color: var(--gray-900);
  background: var(--white);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='%2394a3b8' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 2.2rem;
  transition: border-color .15s;
}

select:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--blue);
  color: var(--white);
  box-shadow: 0 2px 8px rgba(37,99,235,.25);
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { background: var(--gray-400); cursor: not-allowed; box-shadow: none; }

.btn-success {
  background: var(--green);
  color: var(--white);
  box-shadow: 0 2px 8px rgba(22,163,74,.2);
}
.btn-success:hover { background: #15803d; }

.btn-outline {
  background: var(--white);
  color: var(--gray-700);
  border: 1.5px solid var(--gray-200);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); }

.btn-email {
  background: #7c3aed;
  color: var(--white);
  box-shadow: 0 2px 8px rgba(124,58,237,.25);
}
.btn-email:hover    { background: #6d28d9; }
.btn-email:disabled { background: var(--gray-400); cursor: not-allowed; box-shadow: none; }

.btn-lg { padding: 0.9rem 2rem; font-size: 1.05rem; width: 100%; margin-top: 1.25rem; }

/* ─── Loading screen ────────────────────────────────────────────────────── */
.loading-wrap {
  text-align: center;
  padding: 3rem 1rem;
}

.loading-wrap h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.loading-wrap p {
  color: var(--gray-500);
  margin-bottom: 2.5rem;
}

.spinner {
  width: 56px; height: 56px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 2.5rem;
}

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

.steps-list {
  list-style: none;
  max-width: 340px;
  margin: 0 auto;
  text-align: left;
}

.steps-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.7rem 0;
  font-size: 0.95rem;
  color: var(--gray-400);
  border-bottom: 1px solid var(--gray-100);
  transition: color .3s;
}

.steps-list li:last-child { border-bottom: none; }

.step-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--gray-200);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
  transition: all .3s;
}

.steps-list li.active { color: var(--blue); }
.steps-list li.active .step-icon {
  border-color: var(--blue);
  background: var(--blue-light);
  color: var(--blue);
}

.steps-list li.done { color: var(--green); }
.steps-list li.done .step-icon {
  border-color: var(--green);
  background: var(--green-light);
  color: var(--green);
}

/* ─── Results screen ────────────────────────────────────────────────────── */
.results-header {
  text-align: center;
  margin-bottom: 2rem;
}

.result-icon { font-size: 3.5rem; margin-bottom: 0.75rem; }

.results-header h2 {
  font-size: 1.7rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
}

.results-header p {
  color: var(--gray-500);
  font-size: 1rem;
}

/* Summary card */
.summary-card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.summary-card.has-errors {
  border-color: #fca5a5;
  background: linear-gradient(135deg, #fff 60%, var(--red-light));
}

.summary-card.no-errors {
  border-color: #86efac;
  background: linear-gradient(135deg, #fff 60%, var(--green-light));
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.summary-stat { text-align: center; }
.summary-stat .value {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  color: var(--red);
}
.summary-stat .value.green { color: var(--green); }
.summary-stat .label {
  font-size: 0.78rem;
  color: var(--gray-500);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.provider-row {
  font-size: 0.88rem;
  color: var(--gray-500);
  margin-top: 0.5rem;
}
.provider-row strong { color: var(--gray-700); }

/* Error cards */
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-700);
  margin: 1.5rem 0 0.75rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.error-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-left: 4px solid var(--red);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  margin-bottom: 0.9rem;
  box-shadow: var(--shadow);
}

.error-card.confidence-medium { border-left-color: var(--amber); }
.error-card.confidence-low    { border-left-color: var(--gray-400); }

.error-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.error-type {
  font-weight: 700;
  font-size: 0.97rem;
  color: var(--gray-900);
}

.error-cpt {
  font-size: 0.78rem;
  color: var(--gray-500);
  margin-top: 2px;
}

.confidence-badge {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 3px 10px;
  border-radius: 20px;
}

.confidence-badge.high   { background: #fee2e2; color: var(--red); }
.confidence-badge.medium { background: #fef3c7; color: #92400e; }
.confidence-badge.low    { background: var(--gray-100); color: var(--gray-500); }

.error-amounts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-bottom: 0.75rem;
}

.amount-item { font-size: 0.88rem; color: var(--gray-600); }
.amount-item .amount-label { color: var(--gray-400); font-size: 0.78rem; display: block; }
.amount-item .amount-value { font-weight: 600; }
.amount-item.overcharge .amount-value { color: var(--red); }
.amount-item.fair        .amount-value { color: var(--green); }

.error-explanation {
  font-size: 0.88rem;
  color: var(--gray-600);
  background: var(--gray-50);
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  line-height: 1.5;
}

/* Actions */
.action-section {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.what-next {
  background: var(--blue-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  margin-top: 1.5rem;
}

.what-next h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--blue-dark);
  margin-bottom: 0.75rem;
}

.what-next ol {
  padding-left: 1.25rem;
  font-size: 0.88rem;
  color: var(--gray-700);
  line-height: 1.8;
}

/* ─── Letter preview ────────────────────────────────────────────────────── */
#letter-preview {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 2rem;
  margin-top: 1.5rem;
  font-family: 'Georgia', serif;
  font-size: 0.95rem;
  line-height: 1.7;
  color: #222;
  display: none;
}

#letter-preview.visible { display: block; }

.letter-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* ─── Header right cluster ──────────────────────────────────────────────── */
.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ─── Error / alert ─────────────────────────────────────────────────────── */
.alert {
  padding: 1rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.5;
  margin-top: 1rem;
}

.alert-error {
  background: var(--red-light);
  border: 1px solid #fca5a5;
  color: #7f1d1d;
}

.alert-info {
  background: var(--blue-light);
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.alert-warning {
  background: var(--amber-light);
  border: 1px solid #fcd34d;
  color: #78350f;
}


/* ─── Letter modal ──────────────────────────────────────────────────────── */

.letter-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(3px);
  z-index: 300;
}
.letter-backdrop.visible { display: block; }

.letter-modal {
  position: fixed;
  top: 50%;  left: 50%;
  transform: translate(-50%, -50%) scale(.96);
  width: min(860px, 96vw);
  height: min(88vh, 820px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 24px 64px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  z-index: 301;
  opacity: 0;
  pointer-events: none;
  transition: transform .25s ease, opacity .25s ease;
}
.letter-modal.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.letter-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.letter-modal-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--gray-900);
}
.letter-modal-actions {
  display: flex;
  gap: .5rem;
  align-items: center;
}
.letter-btn-print {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: .45rem .9rem;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.letter-btn-print:hover { background: var(--blue-dark); }
.letter-btn-close {
  background: none;
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  width: 32px; height: 32px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--gray-500);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.letter-btn-close:hover { background: var(--gray-100); }

.letter-frame {
  flex: 1;
  border: none;
  border-radius: 0 0 12px 12px;
  background: #fff;
}


/* ─── Email modal ────────────────────────────────────────────────────────── */

.email-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(3px);
  z-index: 300;
}
.email-backdrop.visible { display: block; }

.email-modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.96);
  width: min(520px, 96vw);
  background: var(--white);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  z-index: 301;
  opacity: 0;
  pointer-events: none;
  transition: transform .25s ease, opacity .25s ease;
}
.email-modal.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.email-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.email-modal-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--gray-900);
}
.email-modal-close {
  background: none;
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  width: 32px; height: 32px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--gray-500);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.email-modal-close:hover { background: var(--gray-100); }

.email-modal-body {
  padding: 1.25rem 1.5rem 1.5rem;
  overflow-y: auto;
}

.email-modal-footer {
  margin-top: 1.25rem;
}
.email-modal-footer .btn { margin-top: 0; }

.email-field-group {
  margin-bottom: 1.1rem;
}
.email-field-group label {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .9rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: .4rem;
}
.email-field-group small {
  font-weight: 400;
  color: var(--gray-400);
}

.email-input-wrap {
  display: flex;
  gap: .4rem;
  align-items: center;
}
.email-input-wrap input,
.email-field-group > input {
  flex: 1;
  width: 100%;
  padding: .6rem .85rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: .95rem;
  color: var(--gray-900);
  background: var(--white);
  transition: border-color .15s;
}
.email-input-wrap input:focus,
.email-field-group > input:focus {
  outline: none;
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124,58,237,.1);
}
.email-input-wrap input:disabled {
  background: var(--gray-50);
  color: var(--gray-400);
}

.email-search-btn {
  padding: .55rem .65rem;
  background: var(--gray-100);
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  cursor: pointer;
  font-size: .95rem;
  flex-shrink: 0;
  transition: background .15s;
}
.email-search-btn:hover    { background: var(--gray-200); }
.email-search-btn:disabled { opacity: .5; cursor: not-allowed; }

.email-field-hint {
  font-size: .78rem;
  color: var(--gray-400);
  margin-top: .35rem;
  line-height: 1.5;
}

.email-lookup-badge {
  font-size: .72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-high   { background: #dcfce7; color: #15803d; }
.badge-medium { background: #fef9c3; color: #92400e; }
.badge-low    { background: var(--gray-100); color: var(--gray-500); }


/* ─── Provider name prompt ──────────────────────────────────────────────── */

.provider-prompt {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 8px rgba(217,119,6,.1);
}

.provider-prompt-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
  line-height: 1;
  margin-top: .1rem;
}

.provider-prompt-body { flex: 1; }

.provider-prompt-title {
  font-size: 1rem;
  font-weight: 700;
  color: #92400e;
  margin-bottom: .25rem;
}

.provider-prompt-sub {
  font-size: .88rem;
  color: #b45309;
  margin-bottom: .85rem;
  line-height: 1.5;
}

.provider-prompt-row {
  display: flex;
  gap: .6rem;
  align-items: center;
  flex-wrap: wrap;
}

.provider-name-input {
  flex: 1;
  min-width: 200px;
  padding: .6rem .9rem;
  border: 1.5px solid #fcd34d;
  border-radius: 8px;
  font-size: .95rem;
  color: var(--gray-900);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.provider-name-input:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(217,119,6,.12);
}

.provider-prompt-btn {
  background: #b45309;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: .6rem 1.3rem;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
  flex-shrink: 0;
}
.provider-prompt-btn:hover { background: #92400e; }


/* ─── Auth header ───────────────────────────────────────────────────────── */
#auth-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.btn-login-header {
  display: inline-flex;
  align-items: center;
  padding: 0.42rem 0.85rem;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-login-header:hover { background: var(--blue-dark); }

.user-name-chip {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gray-700);
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-plan-chip {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--blue-light);
  color: var(--blue-dark);
  white-space: nowrap;
}

.user-usage-chip {
  font-size: 0.78rem;
  color: var(--gray-400);
  white-space: nowrap;
}

.btn-logout-header {
  padding: 0.38rem 0.7rem;
  background: var(--white);
  color: var(--gray-500);
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all .15s;
}
.btn-logout-header:hover { border-color: var(--red); color: var(--red); }

/* Auth wall / upgrade prompt (inline in upload screen) */
.auth-wall-banner {
  background: var(--blue-light);
  border: 1.5px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  margin-top: 1rem;
}
.auth-wall-banner h3 {
  font-size: 1.1rem; font-weight: 700;
  color: var(--blue-dark); margin-bottom: 0.4rem;
}
.auth-wall-banner p {
  font-size: 0.9rem; color: var(--gray-600); margin-bottom: 1rem;
}
.auth-wall-banner .btn { margin-top: 0; width: auto; display: inline-flex; }

.upgrade-wall-banner {
  background: #fff7ed;
  border: 1.5px solid #fdba74;
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  margin-top: 1rem;
}
.upgrade-wall-banner h3 {
  font-size: 1.1rem; font-weight: 700;
  color: #9a3412; margin-bottom: 0.4rem;
}
.upgrade-wall-banner p {
  font-size: 0.9rem; color: #78350f; margin-bottom: 1rem;
}
.btn-upgrade {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.75rem 1.5rem;
  background: #ea580c;
  color: var(--white);
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
}
.btn-upgrade:hover { background: #c2410c; }


/* ─── Preview / locked error cards ─────────────────────────────────────── */
.error-card-locked {
  position: relative;
  border-left-color: var(--gray-200);
  overflow: hidden;
  user-select: none;
}

.locked-blur {
  filter: blur(4px);
  pointer-events: none;
}

.locked-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248,250,252,.75);
  backdrop-filter: blur(2px);
  z-index: 2;
}

.locked-badge {
  background: var(--gray-900);
  color: var(--white);
  border-radius: 20px;
  padding: .4rem 1rem;
  font-size: .82rem;
  font-weight: 700;
}

.locked-icon {
  font-size: .7em;
  vertical-align: middle;
  margin-left: .2rem;
}

/* ─── Preview CTA banner ─────────────────────────────────────────────── */
.preview-cta-banner {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  margin-top: 1rem;
  color: var(--white);
}

.preview-cta-icon { font-size: 2rem; flex-shrink: 0; }

.preview-cta-body h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: .4rem;
  color: var(--white);
}

.preview-cta-body p {
  font-size: .88rem;
  color: rgba(255,255,255,.8);
  margin-bottom: .75rem;
}

/* ─── Pending analysis toast ─────────────────────────────────────────── */
.pending-analysis-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--white);
  border: 1.5px solid var(--blue);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: .875rem 1.25rem;
  display: flex;
  align-items: center;
  gap: .875rem;
  font-size: .9rem;
  font-weight: 600;
  color: var(--gray-900);
  z-index: 9999;
  max-width: 94vw;
  animation: slideUp .3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .form-row   { flex-direction: column; }
  .error-top  { flex-direction: column; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  header      { padding: 0 1rem; }
  main        { padding: 1.5rem 1rem 3rem; }
  .privacy-badge { display: none; }
  .provider-prompt { flex-direction: column; gap: .75rem; }
  .provider-prompt-row { flex-direction: column; align-items: stretch; }
  .provider-name-input { min-width: 0; }
  .provider-prompt-btn { width: 100%; justify-content: center; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   HISTORY SIDE PANEL
═══════════════════════════════════════════════════════════════════════════ */

/* "My Bills" header button */
.btn-history-header {
  background: transparent;
  border: 1.5px solid var(--blue);
  color: var(--blue);
  border-radius: 8px;
  padding: .35rem .85rem;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.btn-history-header:hover {
  background: var(--blue);
  color: #fff;
}

/* Overlay (dim background) */
.history-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1100;
}
.history-overlay.visible { display: block; }

/* The panel itself */
.history-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  max-width: 100vw;
  height: 100vh;
  background: var(--surface, #fff);
  border-left: 1px solid var(--border, #e5e7eb);
  box-shadow: -4px 0 32px rgba(0,0,0,.18);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}
.history-panel.open { transform: translateX(0); }

/* Panel header */
.history-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
  flex-shrink: 0;
}
.history-panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-900, #111);
}
.history-panel-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.15rem;
  color: var(--gray-400, #9ca3af);
  padding: .25rem .4rem;
  border-radius: 6px;
  line-height: 1;
  transition: background .15s, color .15s;
}
.history-panel-close:hover { background: var(--gray-100, #f3f4f6); color: var(--gray-900, #111); }

/* Stats row */
.history-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border-bottom: 1px solid var(--border, #e5e7eb);
  flex-shrink: 0;
}
.hstat {
  padding: .85rem .5rem;
  text-align: center;
  border-right: 1px solid var(--border, #e5e7eb);
}
.hstat:last-child { border-right: none; }
.hstat-val {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--blue, #3b82f6);
  line-height: 1.2;
}
.hstat-lbl {
  font-size: .68rem;
  color: var(--gray-400, #9ca3af);
  margin-top: .2rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Tabs */
.history-tabs {
  display: flex;
  border-bottom: 1px solid var(--border, #e5e7eb);
  flex-shrink: 0;
}
.history-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2.5px solid transparent;
  padding: .75rem 0;
  font-size: .88rem;
  font-weight: 600;
  color: var(--gray-400, #9ca3af);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.history-tab.active {
  color: var(--blue, #3b82f6);
  border-bottom-color: var(--blue, #3b82f6);
}
.history-tab:hover:not(.active) { color: var(--gray-600, #4b5563); }

/* Scrollable list area */
.history-list {
  flex: 1;
  overflow-y: auto;
  padding: .75rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

/* Empty state */
.history-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--gray-400, #9ca3af);
  font-size: .88rem;
}
.history-empty p { margin: .25rem 0; }

/* Loading */
.history-loading {
  padding: 2rem;
  text-align: center;
  color: var(--gray-400, #9ca3af);
  font-size: .88rem;
}

/* Individual bill/letter card */
.hcard {
  background: var(--gray-50, #f9fafb);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px;
  padding: .75rem .9rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  transition: box-shadow .15s;
}
.hcard:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }

.hcard-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .5rem;
}
.hcard-provider {
  font-weight: 600;
  font-size: .88rem;
  color: var(--gray-900, #111);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70%;
}
.hcard-date {
  font-size: .75rem;
  color: var(--gray-400, #9ca3af);
  white-space: nowrap;
  flex-shrink: 0;
}

.hcard-bottom {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.hcard-errors {
  font-size: .75rem;
  font-weight: 700;
  background: #fef2f2;
  color: #dc2626;
  border-radius: 5px;
  padding: .15rem .45rem;
}
.hcard-savings {
  font-size: .75rem;
  font-weight: 700;
  background: #f0fdf4;
  color: #16a34a;
  border-radius: 5px;
  padding: .15rem .45rem;
}
.hcard-clean {
  font-size: .75rem;
  font-weight: 700;
  background: #f0fdf4;
  color: #16a34a;
  border-radius: 5px;
  padding: .15rem .45rem;
}
.hcard-meta {
  font-size: .73rem;
  color: var(--gray-400, #9ca3af);
}

/* Mobile: full-width panel */
@media (max-width: 500px) {
  .history-panel { width: 100vw; }
  .history-stats { grid-template-columns: repeat(2, 1fr); }
  .hstat:nth-child(2) { border-right: none; }
}
