/* ═══════════════════════════════════════════════════════
   DESIGN SYSTEM — Gerador de Recibos
   Poliana Damasceno Consultoria em Viagens
   ═══════════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
  --primary: #ff91a4;
  --primary-dark: #e8758a;
  --primary-darker: #c25570;
  --primary-light: #ffb8c6;
  --primary-lightest: #fff0f3;
  --primary-gradient: linear-gradient(135deg, #ff91a4 0%, #e8758a 50%, #c25570 100%);
  --primary-gradient-soft: linear-gradient(135deg, #ffc1cc 0%, #ff91a4 100%);

  --bg: #f3f4f8;
  --bg-subtle: #ecedf2;
  --surface: #ffffff;
  --surface-elevated: #ffffff;

  --text: #1a1b2e;
  --text-secondary: #6b7194;
  --text-muted: #9ca3bf;
  --text-on-primary: #ffffff;

  --border: #e4e6ef;
  --border-light: #f0f1f6;
  --divider: #e8e9f0;

  --shadow-xs: 0 1px 2px rgba(26, 27, 46, 0.04);
  --shadow-sm: 0 1px 3px rgba(26, 27, 46, 0.06), 0 1px 2px rgba(26, 27, 46, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(26, 27, 46, 0.07), 0 2px 4px -1px rgba(26, 27, 46, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(26, 27, 46, 0.08), 0 4px 6px -2px rgba(26, 27, 46, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(26, 27, 46, 0.1), 0 10px 10px -5px rgba(26, 27, 46, 0.03);
  --shadow-paper: 0 2px 8px rgba(26, 27, 46, 0.08), 0 12px 40px rgba(26, 27, 46, 0.12);
  --shadow-glow: 0 0 20px rgba(255, 145, 164, 0.25);

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-receipt: Arial, Helvetica, sans-serif;

  --appbar-height: 64px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

/* ═══════════════════════════════════════════════════════
   LOGIN OVERLAY
   ═══════════════════════════════════════════════════════ */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.5s ease;
}

.login-backdrop {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #fce4ec 0%, #f8bbd0 30%, #ff91a4 60%, #e8758a 100%);
}

.login-backdrop::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 50%, rgba(255, 255, 255, 0.3) 0%, transparent 60%),
              radial-gradient(circle at 70% 80%, rgba(255, 145, 164, 0.4) 0%, transparent 50%);
}

.login-card {
  position: relative;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 420px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 25px 50px rgba(194, 85, 112, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.3);
  animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-icon-wrap {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  box-shadow: var(--shadow-glow);
  animation: pulse 2s ease-in-out infinite;
}

.login-icon-wrap svg {
  width: 36px;
  height: 36px;
  color: white;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 32px;
  letter-spacing: -0.02em;
}

.login-field {
  text-align: left;
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

.login-field input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.7);
  transition: var(--transition);
  outline: none;
}

.login-field input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(255, 145, 164, 0.15);
}

.login-field input::placeholder {
  color: var(--text-muted);
}

.login-error {
  color: #dc2626;
  font-size: 0.8125rem;
  font-weight: 500;
  margin: 4px 0 12px;
  opacity: 0;
  transform: translateY(-4px);
  transition: var(--transition-fast);
  pointer-events: none;
}

.login-error.visible {
  opacity: 1;
  transform: translateY(0);
}

.login-btn {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary-gradient);
  color: var(--text-on-primary);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  margin-top: 8px;
  letter-spacing: 0.01em;
}

.login-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(255, 145, 164, 0.4);
}

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

/* ═══════════════════════════════════════════════════════
   APP SHELL
   ═══════════════════════════════════════════════════════ */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  opacity: 1;
  transition: opacity 0.4s ease;
}

.app.hidden {
  display: none;
}

.login-overlay.hidden {
  display: none;
}

/* ── App Bar ── */
.app-bar {
  height: var(--appbar-height);
  background: var(--primary-gradient-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  z-index: 10;
}

.app-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-bar-left svg {
  width: 28px;
  height: 28px;
  color: var(--primary-darker);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-bar h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.app-bar-subtitle {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-style: italic;
  font-weight: 400;
}

/* ── Main Layout ── */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Form Panel ── */
.form-panel {
  width: 420px;
  min-width: 380px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border-light);
}

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

.panel-header h2 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.panel-divider {
  height: 1px;
  background: var(--divider);
  margin: 12px 24px;
}

.form-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 4px 24px 16px;
}

.form-scroll::-webkit-scrollbar {
  width: 6px;
}

.form-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.form-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.form-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Form Groups ── */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
  letter-spacing: 0.01em;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  transition: var(--transition);
  outline: none;
}

.form-group input:hover,
.form-group textarea:hover {
  border-color: var(--primary-light);
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 145, 164, 0.12);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-muted);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.6;
}

/* ── Input with Prefix ── */
.input-with-prefix {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: var(--transition);
  background: var(--surface);
}

.input-with-prefix:hover {
  border-color: var(--primary-light);
}

.input-with-prefix:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 145, 164, 0.12);
}

.input-prefix {
  padding: 10px 0 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary-dark);
  user-select: none;
  white-space: nowrap;
}

.input-with-prefix input {
  border: none !important;
  box-shadow: none !important;
  padding-left: 6px;
  flex: 1;
}

.input-with-prefix input:focus {
  box-shadow: none !important;
}

/* ── Action Buttons ── */
.action-buttons {
  display: flex;
  gap: 10px;
  padding: 8px 24px 20px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
}

.btn-outline:hover {
  background: var(--bg);
  border-color: var(--text-muted);
  color: var(--text);
}

.btn-primary {
  background: var(--primary-gradient);
  color: var(--text-on-primary);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(255, 145, 164, 0.35);
}

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

.btn-secondary {
  background: var(--primary-darker);
  color: var(--text-on-primary);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: #b04a63;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(194, 85, 112, 0.3);
}

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

/* ── Vertical Divider ── */
.vertical-divider {
  width: 1px;
  background: var(--border-light);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════
   PREVIEW PANEL
   ═══════════════════════════════════════════════════════ */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-subtle);
  min-width: 0;
}

.preview-container {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.preview-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.preview-container::-webkit-scrollbar-track {
  background: transparent;
}

.preview-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.a4-wrapper {
  flex-shrink: 0;
}

/* ── Loading ── */
.loading {
  display: flex;
  align-items: center;
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ═══════════════════════════════════════════════════════
   A4 PAGE — RECEIPT
   ═══════════════════════════════════════════════════════ */
.a4-page {
  width: 794px;
  height: 1123px;
  background: white;
  position: relative;
  font-family: var(--font-receipt);
  color: #1a1a1a;
  box-shadow: var(--shadow-paper);
  border-radius: 2px;
  overflow: hidden;
}

.receipt-header {
  width: 100%;
  height: 170px;
  overflow: hidden;
}

.receipt-header img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.receipt-content {
  padding: 30px 94px 0;
}

.receipt-title {
  text-align: center;
  font-size: 40px;
  font-weight: bold;
  letter-spacing: 6px;
  margin-bottom: 36px;
  color: #000;
}

.receipt-body {
  text-align: justify;
  font-size: 15px;
  line-height: 1.8;
  color: #1a1a1a;
}

.receipt-body .destaque {
  font-weight: bold;
  color: #000;
}

.receipt-descricao {
  text-align: justify;
  font-size: 15px;
  line-height: 1.8;
  font-style: italic;
  margin-top: 16px;
  color: #1a1a1a;
}

.receipt-signature {
  text-align: center;
  margin-top: 50px;
  position: relative;
}

.receipt-signature img {
  width: 260px;
  height: auto;
  display: block;
  margin: 0 auto -20px auto;
  position: relative;
  z-index: 1;
}

.receipt-signature-line {
  border-bottom: 1px solid #000;
  width: 280px;
  margin: 0 auto;
  position: relative;
  z-index: 0;
}

.receipt-signature-label {
  font-size: 11px;
  letter-spacing: 2px;
  margin-top: 6px;
  text-align: center;
  color: #1a1a1a;
}



.receipt-footer {
  position: absolute;
  bottom: 40px;
  left: 94px;
  right: 94px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.receipt-footer-info {
  font-size: 13px;
  line-height: 1.6;
  color: #1a1a1a;
}

.receipt-footer-info strong {
  display: block;
  margin-bottom: 2px;
}

.receipt-footer-logo img {
  width: 180px;
  height: auto;
}

/* ═══════════════════════════════════════════════════════
   TOAST NOTIFICATION
   ═══════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #166534;
  color: white;
  padding: 14px 28px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-xl);
  z-index: 2000;
  opacity: 0;
  transition: var(--transition);
  pointer-events: none;
  white-space: nowrap;
}

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

.toast.hidden {
  display: block;
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
}

/* ═══════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(255, 145, 164, 0.25); }
  50% { box-shadow: 0 0 30px rgba(255, 145, 164, 0.45); }
}

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

/* ═══════════════════════════════════════════════════════
   PRINT STYLES
   ═══════════════════════════════════════════════════════ */
@media print {
  body * {
    visibility: hidden;
  }
  .a4-page,
  .a4-page * {
    visibility: visible;
  }
  .a4-page {
    position: absolute;
    left: 0;
    top: 0;
    width: 210mm;
    height: 297mm;
    box-shadow: none;
    margin: 0;
    border-radius: 0;
  }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .main-layout {
    flex-direction: column;
  }

  .form-panel {
    width: 100%;
    min-width: 0;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border-light);
  }

  .vertical-divider {
    display: none;
  }

  .preview-panel {
    min-height: 55vh;
  }

  /* Removido o scale e transform-origin fixos do CSS, pois o JS já calcula o scale exato */
}

@media (max-width: 768px) {
  body {
    height: auto;
    overflow: auto;
  }
  
  .app {
    height: auto;
    min-height: 100vh;
  }

  .main-layout {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  .form-panel {
    max-height: none;
    overflow: visible;
  }

  .form-scroll {
    overflow: visible;
  }

  .preview-panel {
    min-height: auto;
    overflow: visible;
    padding-bottom: 40px;
  }

  .preview-container {
    overflow: visible;
    padding: 10px;
  }
}

@media (max-width: 600px) {
  .app-bar {
    padding: 0 16px;
    height: 56px;
  }

  .app-bar h1 {
    font-size: 1rem;
  }

  .app-bar-subtitle {
    display: none;
  }

  .action-buttons {
    padding: 8px 16px 16px;
    flex-direction: column;
    gap: 12px;
  }

  .btn {
    width: 100%;
    justify-content: center;
    padding: 12px 14px;
    font-size: 0.95rem;
  }

  .form-scroll {
    padding: 4px 16px 16px;
  }

  .panel-header {
    padding: 16px 16px 0;
  }

  .panel-divider {
    margin: 10px 16px;
  }

  .login-card {
    padding: 36px 28px;
  }
}
