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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --max-width: 720px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
}

#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px 80px;
}

/* Header */
header {
  background: var(--gray-900);
  color: #fff;
  margin: 0 -16px 24px;
  padding: 20px 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.header-content h1 {
  font-size: 20px;
  font-weight: 700;
}

.header-badge {
  background: var(--primary);
  color: #fff;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

/* Progress Bar */
.progress-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 16px;
}

.progress-step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--gray-400);
  white-space: nowrap;
}

.progress-step.active {
  color: #fff;
}

.progress-step.active .step-num {
  background: var(--primary);
  color: #fff;
}

.progress-step.completed .step-num {
  background: var(--success);
  color: #fff;
}

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gray-600);
  color: var(--gray-400);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.step-label {
  display: none;
}

@media (min-width: 480px) {
  .step-label {
    display: inline;
  }
}

.progress-line {
  flex: 1;
  height: 3px;
  background: var(--gray-600);
  border-radius: 2px;
  overflow: hidden;
  min-width: 20px;
}

.progress-fill {
  height: 100%;
  background: var(--success);
  width: 0%;
  transition: width .3s ease;
}

/* Sections */
.step-container {
  display: none;
}

.step-container.active {
  display: block;
}

/* Card */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-200);
}

.card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 12px;
}

/* Form Grid */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
}

.form-group .required::after {
  content: " *";
  color: var(--danger);
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: inherit;
  color: var(--gray-900);
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
  width: 100%;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group textarea {
  resize: vertical;
  min-height: 70px;
}

.form-group .help-text {
  font-size: 12px;
  color: var(--gray-500);
}

/* Despesa Card */
.despesa-card {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
}

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

.despesa-header h3 {
  margin: 0;
  font-size: 14px;
}

.btn-remove {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 4px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}

.btn-remove:hover {
  background: var(--danger-light);
}

/* Upload Area */
.upload-area {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  position: relative;
  margin-bottom: 12px;
}

.upload-area:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-placeholder {
  color: var(--gray-500);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.upload-placeholder .upload-icon {
  font-size: 28px;
  margin-bottom: 4px;
}

.upload-placeholder .upload-hint {
  font-size: 12px;
  color: var(--gray-400);
}

.upload-preview {
  display: none;
}

.upload-preview.show {
  display: block;
}

.upload-preview img {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius);
  object-fit: contain;
  background: var(--gray-100);
}

.upload-preview .file-info {
  font-size: 13px;
  color: var(--gray-600);
  padding: 8px;
  background: var(--gray-100);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 8px;
}

.upload-loading {
  display: none;
  padding: 20px;
  text-align: center;
  color: var(--gray-500);
}

.upload-loading.show {
  display: block;
}

.upload-loading .spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 8px;
}

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

.upload-loaded {
  border-color: var(--success);
  background: var(--success-light);
}

/* Itens Sub-form */
.itens-section {
  margin-top: 8px;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr 120px auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.item-row input {
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
}

.item-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.btn-remove-item {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  line-height: 1;
}

.btn-remove-item:hover {
  color: var(--danger);
}

.btn-add-item {
  background: none;
  border: 1px dashed var(--gray-300);
  color: var(--gray-500);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  width: 100%;
}

.btn-add-item:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  cursor: pointer;
  transition: background .15s, transform .1s;
  width: 100%;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
}

.btn-outline {
  background: #fff;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}

.btn-outline:hover {
  background: var(--gray-50);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover {
  background: #15803d;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

@media (min-width: 480px) {
  .actions-row {
    flex-direction: row;
  }
  .actions-row .btn {
    flex: 1;
  }
}

/* Review */
.review-section {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.review-section h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-200);
}

.review-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 10px;
}

.review-field .label {
  font-size: 12px;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .3px;
}

.review-field .value {
  font-size: 15px;
  color: var(--gray-900);
  font-weight: 500;
}

.review-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
}

@media (min-width: 480px) {
  .review-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.review-despesa {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.review-despesa h4 {
  font-size: 13px;
  color: var(--gray-600);
  margin-bottom: 8px;
}

.review-despesa .review-field {
  margin-bottom: 6px;
}

.review-despesa .label {
  font-size: 11px;
}

.review-despesa .value {
  font-size: 14px;
}

.review-attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--gray-100);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
}

.review-attachment:hover {
  background: var(--primary-light);
}

/* Confirmation */
.confirmation {
  text-align: center;
  padding: 40px 20px;
}

.confirmation .icon {
  font-size: 56px;
  margin-bottom: 16px;
}

.confirmation h2 {
  font-size: 22px;
  color: var(--success);
  margin-bottom: 8px;
}

.confirmation p {
  color: var(--gray-600);
  margin-bottom: 4px;
}

.confirmation .edit-link {
  display: inline-block;
  margin-top: 24px;
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
}

.confirmation .edit-link:hover {
  text-decoration: underline;
}

/* Error / Expired */
.expired-box {
  text-align: center;
  padding: 40px 20px;
}

.expired-box h2 {
  color: var(--danger);
  margin-bottom: 8px;
}

.expired-box p {
  color: var(--gray-600);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  z-index: 1000;
  opacity: 0;
  transition: transform .3s ease, opacity .3s ease;
  pointer-events: none;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-info {
  background: var(--gray-800);
}

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

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

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 16px;
  animation: fadeIn .15s ease;
}

.modal-overlay.closing {
  animation: fadeOut .15s ease forwards;
}

.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.modal .spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 16px;
}

.modal p {
  color: var(--gray-600);
  font-size: 15px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Footer */
footer {
  text-align: center;
  padding: 32px 0 16px;
  font-size: 12px;
  color: var(--gray-400);
}

/* Responsive tweaks */
@media (max-width: 380px) {
  .header-content h1 {
    font-size: 17px;
  }
}

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