/* ============================================
   AhiaPay — Proforma Invoice Generator
   Mobile-first, step-by-step wizard UI
   ============================================ */

/* ---- CSS Variables / Design Tokens ---- */
:root {
  --primary: #1a365d;
  --primary-light: #2b6cb0;
  --primary-dark: #0f2440;
  --accent: #d69e2e;
  --accent-light: #ecc94b;
  --accent-glow: rgba(214, 158, 46, 0.15);
  --bg: #f7f8fc;
  --card-bg: #ffffff;
  --input-bg: #f0f4f8;
  --input-border: #d2d6dc;
  --input-focus: #2b6cb0;
  --text: #1a202c;
  --text-light: #718096;
  --text-muted: #a0aec0;
  --success: #38a169;
  --error: #e53e3e;
  --danger: #e53e3e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.1);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---- App Header ---- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary);
  color: white;
  padding: 0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.3rem;
  font-weight: 300;
  letter-spacing: -0.5px;
}

.logo i {
  color: var(--accent);
  font-size: 1.4rem;
}

.logo strong {
  font-weight: 700;
}

.step-indicator {
  font-size: 0.9rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.15);
  padding: 5px 14px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

.step-current {
  font-weight: 700;
  color: var(--accent-light);
}

.progress-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.15);
  width: 100%;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 0 2px 2px 0;
}

/* ---- Wizard Container ---- */
.wizard {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* ---- Steps ---- */
.step {
  width: 100%;
  min-height: calc(100dvh - 130px);
  padding: 24px 20px 100px;
  opacity: 0;
  transition: opacity 0.3s ease;
  overflow-y: auto;
}

.step.active {
  opacity: 1;
}

.step.exit-left {
  display: none;
}

.step-content {
  max-width: 600px;
  margin: 0 auto;
}

.step-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  margin-bottom: 16px;
  box-shadow: 0 4px 16px rgba(26, 54, 93, 0.2);
}

.step h2 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}

.step-description {
  color: var(--text-light);
  font-size: 0.95rem;
  margin-bottom: 28px;
  line-height: 1.5;
}

/* ---- Form Elements ---- */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: 0.2px;
}

.required {
  color: var(--error);
}

.help-text {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.4;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
textarea,
select {
  width: 100%;
  padding: 14px 16px;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text);
  background: var(--input-bg);
  border: 2px solid var(--input-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--input-focus);
  background: white;
  box-shadow: 0 0 0 4px rgba(43, 108, 176, 0.1);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='%23718096'%3E%3Cpath d='M7 8l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ---- Upload Areas ---- */
.upload-area {
  position: relative;
  border: 2px dashed var(--input-border);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  overflow: hidden;
  background: var(--input-bg);
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--primary-light);
  background: rgba(43, 108, 176, 0.05);
}

.upload-area.has-image {
  padding: 12px;
  border-style: solid;
  border-color: var(--success);
  background: white;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-light);
}

.upload-placeholder i {
  font-size: 2rem;
  color: var(--primary-light);
  opacity: 0.6;
}

.upload-placeholder span {
  font-size: 0.95rem;
  font-weight: 500;
}

.upload-placeholder small {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.upload-preview {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  display: none;
  border-radius: 6px;
}

.upload-area.has-image .upload-placeholder {
  display: none;
}

.upload-area.has-image .upload-preview {
  display: block;
}

.upload-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  z-index: 5;
}

.upload-area.has-image .upload-remove {
  display: flex;
}

/* ---- Line Items (Step 4) ---- */
.line-item-card {
  background: var(--card-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  position: relative;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.line-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.line-item-number {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--primary);
  background: rgba(26, 54, 93, 0.08);
  padding: 4px 12px;
  border-radius: 20px;
}

.btn-remove-item {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: var(--transition);
}

.btn-remove-item:hover {
  color: var(--danger);
  background: rgba(229, 62, 62, 0.08);
}

.line-item-card .form-group {
  margin-bottom: 12px;
}

.line-item-card .form-group label {
  font-size: 0.82rem;
}

.line-item-card input {
  padding: 10px 12px;
  font-size: 0.92rem;
}

.line-item-amount {
  text-align: right;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
  padding: 8px 0 0;
  border-top: 1px solid var(--input-border);
}

.btn-add-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary-light);
  background: rgba(43, 108, 176, 0.06);
  border: 2px dashed rgba(43, 108, 176, 0.3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.btn-add-item:hover {
  background: rgba(43, 108, 176, 0.12);
  border-color: var(--primary-light);
}

/* ---- Summary Cards ---- */
.summary-card {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.summary-card.highlight {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border: none;
  color: white;
}

.summary-label {
  font-size: 0.88rem;
  font-weight: 500;
}

.summary-value {
  font-size: 1.15rem;
  font-weight: 700;
}

.summary-card.highlight .summary-label {
  opacity: 0.9;
}

.section-divider {
  border: none;
  border-top: 1px solid var(--input-border);
  margin: 24px 0;
}

/* ---- Preview Step ---- */
.preview-wrapper {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  margin-bottom: 24px;
  border: 1px solid #e2e8f0;
}

.preview-step .step-content {
  max-width: 800px;
}

/* ---- Invoice Preview Styling ---- */
.invoice-preview {
  padding: 32px 28px;
  font-family: 'Times New Roman', Times, serif;
  font-size: 11px;
  line-height: 1.5;
  color: #000;
  background: white;
}

.inv-header {
  text-align: center;
  margin-bottom: 16px;
}

.inv-header-img {
  max-width: 100%;
  max-height: 140px;
  object-fit: contain;
  margin-bottom: 8px;
}

.inv-title {
  font-size: 16px;
  font-weight: bold;
  text-align: center;
  margin: 12px 0;
  letter-spacing: 2px;
}

.inv-meta-buyer {
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 20px;
}

.inv-buyer {
  flex: 1;
  font-size: 11px;
  line-height: 1.6;
}

.inv-buyer strong {
  font-size: 11px;
}

.inv-meta {
  text-align: right;
  font-size: 11px;
  line-height: 1.8;
  white-space: nowrap;
}

.inv-meta-label {
  font-size: 9px;
  color: #555;
}

/* Items table */
.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 4px;
  font-size: 10.5px;
}

.inv-table th,
.inv-table td {
  border: 1px solid #000;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.inv-table th {
  background: #f8f8f8;
  font-weight: bold;
  font-size: 10px;
  text-transform: uppercase;
}

.inv-table .text-right {
  text-align: right;
}

.inv-table .text-center {
  text-align: center;
}

/* Totals rows inside table */
.inv-totals-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 10.5px;
}

.inv-totals-table td {
  border: 1px solid #000;
  padding: 6px 8px;
}

.inv-totals-table .label-cell {
  text-align: right;
  font-weight: bold;
}

.inv-totals-table .amount-cell {
  text-align: right;
  font-weight: bold;
  width: 140px;
}

.inv-totals-table .empty-cell {
  border: none;
}

/* Summary section */
.inv-summary {
  margin: 16px 0;
  font-size: 11px;
  line-height: 2;
}

.inv-summary p {
  margin: 0;
}

.inv-summary strong {
  display: inline-block;
  min-width: 220px;
}

/* Banking section */
.inv-banking {
  margin-top: 16px;
  font-size: 11px;
  line-height: 2;
  position: relative;
}

.inv-banking p {
  margin: 0;
}

.inv-stamp {
  position: absolute;
  bottom: 0;
  right: 0;
  max-width: 150px;
  max-height: 150px;
  object-fit: contain;
  opacity: 0.9;
}

/* ---- Send Section ---- */
.send-section {
  max-width: 600px;
  margin: 0 auto;
}

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 16px;
  font-family: var(--font);
  font-size: 1.05rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 16px rgba(26, 54, 93, 0.3);
  margin-bottom: 12px;
}

.btn-send:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(26, 54, 93, 0.4);
}

.btn-send:active {
  transform: translateY(0);
}

.btn-download {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary);
  background: transparent;
  border: 2px solid var(--primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.btn-download:hover {
  background: rgba(26, 54, 93, 0.05);
}

/* ---- Wizard Footer / Navigation ---- */
.wizard-footer {
  position: sticky;
  bottom: 0;
  z-index: 90;
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  background: white;
  border-top: 1px solid #e8ecf1;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
}

.btn-nav {
  flex: 1;
  padding: 14px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
}

.btn-back {
  background: var(--input-bg);
  color: var(--text-light);
  border: 1px solid var(--input-border);
}

.btn-back:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-back:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-next {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  box-shadow: 0 4px 12px rgba(26, 54, 93, 0.25);
}

.btn-next:hover {
  box-shadow: 0 6px 20px rgba(26, 54, 93, 0.35);
  transform: translateY(-1px);
}

.btn-next:active {
  transform: translateY(0);
}

.wizard-footer.hidden {
  display: none;
}

/* ---- Loading Overlay ---- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
}

.loading-overlay.visible {
  display: flex;
}

.loading-content {
  text-align: center;
  color: white;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

.loading-content p {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 500;
}

/* ---- Toast Notification ---- */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  z-index: 500;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  background: var(--primary-dark);
  color: white;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  transition: transform 0.3s ease;
  max-width: calc(100vw - 40px);
}

.toast.visible {
  display: flex;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--error);
}

.toast-icon {
  font-size: 1.1rem;
}

/* ---- Responsive ---- */
@media (min-width: 768px) {
  .step {
    padding: 40px 40px 100px;
  }

  .step h2 {
    font-size: 1.8rem;
  }

  .wizard-footer {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px 0;
    left: 0;
    right: 0;
  }

  .form-row {
    grid-template-columns: 1fr 1fr;
  }

  .line-item-card .form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
  }
}

@media (max-width: 480px) {
  .form-row {
    grid-template-columns: 1fr;
  }

  .invoice-preview {
    padding: 16px 12px;
    font-size: 9px;
  }

  .inv-meta-buyer {
    flex-direction: column;
  }

  .inv-table th,
  .inv-table td {
    padding: 4px 5px;
    font-size: 8.5px;
  }
}

/* ---- Print Styles ---- */
@media print {
  body * {
    visibility: hidden;
  }

  .invoice-preview,
  .invoice-preview * {
    visibility: visible;
  }

  .invoice-preview {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    padding: 20px;
    font-size: 11px;
  }

  .app-header,
  .wizard-footer,
  .toast,
  .loading-overlay {
    display: none !important;
  }
}

/* ---- PDF Page Break Rules ---- */
.inv-banking {
  page-break-inside: avoid;
  break-inside: avoid;
}

.inv-summary {
  page-break-inside: avoid;
  break-inside: avoid;
}

.inv-table {
  page-break-inside: avoid;
  break-inside: avoid;
}
