@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Colors - Light Mode / Paper Preview */
  --color-paper: #ffffff;
  --color-text: #333333;
  --color-border: #e0e0e0;
  --color-primary: #2994d1;
  --color-primary-hover: #1e7bb5;
  --color-secondary: #f0f4f8;
  --color-danger: #c13931;
  --color-success: #2e7d32;
  --color-muted: #5a5a5a;
  
  /* UI Form Dark Mode (Default) */
  --bg-ui: #1a1a2e;
  --bg-panel: rgba(255, 255, 255, 0.03);
  --border-panel: rgba(255, 255, 255, 0.08);
  --text-ui: #e2e8f0;
  
  --bg-section: rgba(0, 0, 0, 0.2);
  --text-heading: white;
  --text-label: #94a3b8;
  --bg-input: rgba(255, 255, 255, 0.05);
  --text-input: white;
  --bg-input-focus: rgba(255, 255, 255, 0.08);
  --bg-preview: #0f0f1a;
  
  --btn-secondary-bg: rgba(255, 255, 255, 0.1);
  --btn-secondary-border: rgba(255, 255, 255, 0.2);
  --btn-secondary-hover: rgba(255, 255, 255, 0.15);
  --btn-secondary-text: #ffffff;
  
  --font-body: 'Inter', system-ui, sans-serif;
}

body.light-theme {
  --bg-ui: #f1f5f9;
  --bg-panel: #ffffff;
  --border-panel: #cbd5e1;
  --text-ui: #1e293b;
  
  --bg-section: #f8fafc;
  --text-heading: #0f172a;
  --text-label: #475569;
  --bg-input: #f8fafc;
  --text-input: #0f172a;
  --bg-input-focus: #ffffff;
  --bg-preview: #e2e8f0;
  
  --btn-secondary-bg: rgba(0, 0, 0, 0.05);
  --btn-secondary-border: rgba(0, 0, 0, 0.1);
  --btn-secondary-hover: rgba(0, 0, 0, 0.08);
  --btn-secondary-text: #1e293b;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg-ui);
  color: var(--text-ui);
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}

/* Top Navbar */
.top-navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: var(--bg-section);
  border-bottom: 1px solid var(--border-panel);
  height: 60px;
}
.nav-brand {
  font-weight: bold;
  font-size: 1.2rem;
  color: var(--color-primary);
}
.nav-links {
  display: flex;
  gap: 10px;
}
.nav-link {
  background: transparent;
  border: none;
  color: var(--text-label);
  padding: 8px 16px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.3s ease;
}
.nav-link:hover {
  background: var(--bg-input);
  color: var(--text-heading);
}
.nav-link.active {
  background: var(--color-primary);
  color: white;
}

/* App Layout */
.app-container {
  display: flex;
  height: calc(100vh - 60px);
  overflow: hidden;
}

.form-panel {
  width: 35%;
  min-width: 400px;
  max-width: 500px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-panel);
  backdrop-filter: blur(10px);
  padding: 2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.preview-panel {
  flex: 1;
  background: var(--bg-preview);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem;
  overflow-y: auto;
  transition: background 0.3s ease;
}

.form-footer {
  position: sticky;
  bottom: -2rem;
  margin: 1rem -2rem -2rem -2rem;
  padding: 1.5rem 2rem;
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-panel);
  display: flex;
  gap: 1rem;
  z-index: 10;
  box-shadow: 0 -10px 30px rgba(0,0,0,0.05);
}
.form-footer .btn {
  flex: 1;
}

/* Stepper Wizard */
.stepper-container {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  position: relative;
}
.stepper-container::before {
  content: '';
  position: absolute;
  top: 18px;
  left: 30px;
  right: 30px;
  height: 2px;
  background: var(--border-panel);
  z-index: 1;
}
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 2;
  cursor: pointer;
  flex: 1;
}
.step-number {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-ui);
  border: 2px solid var(--border-panel);
  color: var(--text-label);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  transition: all 0.3s ease;
}
.step-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-label);
  text-align: center;
  transition: all 0.3s ease;
  line-height: 1.2;
}
.step:hover .step-number {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.step.active .step-number {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
  box-shadow: 0 0 0 4px rgba(41, 148, 209, 0.2);
}
.step.active .step-label {
  color: var(--text-heading);
}
.step.completed .step-number {
  background: var(--color-success);
  border-color: var(--color-success);
  color: white;
}

/* Glassmorphism Inputs */
.form-section {
  display: none;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg-section);
  padding: 1.5rem;
  border-radius: 12px;
  border: 1px solid var(--border-panel);
  transition: background 0.3s ease, border-color 0.3s ease;
}
.form-section.active {
  display: flex;
}

.form-section h3 {
  font-size: 1rem;
  color: var(--text-heading);
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-panel);
  padding-bottom: 0.5rem;
  transition: color 0.3s ease, border-color 0.3s ease;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-label);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: color 0.3s ease;
}

input, textarea, select {
  background: var(--bg-input);
  border: 1px solid var(--border-panel);
  color: var(--text-input);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(41, 148, 209, 0.2);
  background: var(--bg-input-focus);
}

.btn {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 1rem;
}

.btn:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}

.btn-icon {
  padding: 0;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  font-size: 1.1rem;
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  border: 1px solid var(--btn-secondary-border);
  color: var(--btn-secondary-text);
}
.btn-secondary:hover {
  background: var(--btn-secondary-hover);
}

.btn-danger {
  background: rgba(220, 53, 69, 0.2);
  color: #ff6b6b;
  border: 1px solid rgba(220, 53, 69, 0.3);
}
.btn-danger:hover {
  background: rgba(220, 53, 69, 0.4);
}

.btn-success {
  background: var(--color-success);
  color: white;
  border: none;
}
.btn-success:hover {
  background: #276b2a;
}


/* Invoice Preview Paper */
.invoice-paper {
  background: var(--color-paper);
  color: var(--color-text);
  width: 210mm;
  min-height: 297mm;
  padding: 2cm;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
  position: relative;
  overflow: hidden;
  z-index: 1; /* Create stacking context for watermark */
}

.watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg);
  font-size: 5rem;
  color: rgba(0, 0, 0, 0.03); /* Very faint grey */
  white-space: nowrap;
  pointer-events: none; /* Let clicks pass through */
  z-index: -1; /* Sit behind the text */
  font-weight: 800;
  user-select: none;
  text-align: center;
  width: 150%;
}

.unpaid-ribbon {
  position: absolute;
  top: 25px;
  right: -35px;
  z-index: 10;
  background: var(--color-danger) !important;
  color: white !important;
  padding: 6px 50px;
  font-weight: bold;
  font-size: 0.9rem;
  transform: rotate(45deg);
  text-align: center;
  letter-spacing: 1px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.company-logo-preview {
  max-height: 80px;
  max-width: 250px;
  object-fit: contain;
}

.company-details {
  text-align: right;
  margin-left: auto;
}
.company-details h1 {
  color: var(--color-text);
  font-size: 1.4rem;
  margin-bottom: 0.2rem;
  font-weight: 700;
}
.company-details p {
  font-size: 0.75rem; /* Ukuran font lebih kecil */
  color: var(--color-muted);
  line-height: 1.2;
  white-space: pre-wrap;
  max-width: 250px; /* Batasi lebar agar menjadi beberapa baris */
  margin-left: auto; /* Tetap rapat kanan di dalam bloknya */
}

.invoice-meta {
  background: var(--color-secondary);
  padding: 6px 10px;
  border-radius: 0;
  margin-bottom: 0.5rem;
  line-height: 1.2;
}
.invoice-meta h2 {
  font-size: 1.15rem;
  margin-bottom: 0.15rem;
}
.invoice-meta p {
  font-size: 0.95rem;
}

.bill-to {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.2;
  white-space: pre-wrap;
}
.bill-to h3 {
  margin-bottom: 0.15rem;
  font-size: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

th, td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
}

th {
  background: var(--color-secondary);
  font-weight: 600;
  border-top: 1px solid var(--color-border);
}

td.text-right, th.text-right {
  text-align: right;
}

.notes-section {
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}
.notes-section h4 {
  margin-bottom: 0.3rem;
  font-size: 1rem;
}

.payment-info {
  background: var(--color-secondary);
  padding: 6px 10px;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.2;
  white-space: pre-wrap;
}
.payment-info h4 {
  margin-bottom: 0.15rem;
  font-size: 1rem;
}

.signatures {
  display: flex;
  justify-content: space-between;
  margin-top: 0.5rem;
}
.signature-box {
  width: 45%;
  font-size: 0.9rem;
}
.signature-box.right {
  text-align: right;
}
.signature-space {
  height: 60px;
  position: relative;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.stamp-preview {
  position: absolute;
  top: -10px;
  right: 40px;
  max-height: 80px;
  opacity: 0.8;
  z-index: 1;
}
#prev-signatureImage {
  position: relative;
  z-index: 2;
  margin: 0 !important;
}
.signature-name {
  font-weight: bold;
  text-decoration: underline;
}

/* THEME: MODERN MINIMALIST */
.invoice-paper.theme-modern {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.invoice-paper.theme-modern .invoice-meta {
  background: #0ea5e9; /* Sky blue */
  color: white;
  border-radius: 8px;
  padding: 12px 15px;
}
.invoice-paper.theme-modern .invoice-meta p {
  color: #e0f2fe;
}
.invoice-paper.theme-modern .invoice-header {
  border-bottom: 2px solid #f1f5f9;
  padding-bottom: 1rem;
}
.invoice-paper.theme-modern table th {
  background: transparent;
  border-bottom: 2px solid #334155;
  color: #334155;
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
}
.invoice-paper.theme-modern table td {
  border-bottom: 1px solid #f1f5f9;
}
.invoice-paper.theme-modern .company-details h1 {
  color: #0ea5e9;
}

/* THEME: CREATIVE VIBRANT */
.invoice-paper.theme-creative {
  font-family: 'Georgia', serif;
}
.invoice-paper.theme-creative .invoice-header {
  align-items: center;
}
.invoice-paper.theme-creative .company-details h1 {
  color: #d946ef; /* Fuchsia */
}
.invoice-paper.theme-creative .invoice-meta {
  background: #fdf4ff;
  border-left: 4px solid #d946ef;
  color: #86198f;
  border-radius: 0 8px 8px 0;
}
.invoice-paper.theme-creative table {
  border-collapse: separate;
  border-spacing: 0;
}
.invoice-paper.theme-creative table th {
  background: #d946ef;
  color: white;
  border: none;
}
.invoice-paper.theme-creative table th:first-child { border-radius: 8px 0 0 8px; }
.invoice-paper.theme-creative table th:last-child { border-radius: 0 8px 8px 0; }
.invoice-paper.theme-creative table tbody tr:nth-child(even) td {
  background: #fdf4ff;
}
.invoice-paper.theme-creative table td {
  border-bottom: none;
  padding: 10px 8px;
}

/* THEME: ELEGANT MONOCHROME */
.invoice-paper.theme-elegant {
  font-family: 'Times New Roman', Times, serif;
  background: #fcfcfc;
}
.invoice-paper.theme-elegant .invoice-header {
  border-bottom: 3px solid #111;
  padding-bottom: 1rem;
}
.invoice-paper.theme-elegant .company-details h1 {
  color: #111;
  text-transform: uppercase;
  letter-spacing: 2px;
}
.invoice-paper.theme-elegant .invoice-meta {
  background: #111;
  color: #fff;
  border-radius: 0;
}
.invoice-paper.theme-elegant .invoice-meta p {
  color: #ccc;
}
.invoice-paper.theme-elegant table th {
  background: #111;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.invoice-paper.theme-elegant table td {
  border-bottom: 1px solid #ddd;
}

/* THEME: CASUAL CERIA */
.invoice-paper.theme-casual {
  font-family: 'Comic Sans MS', 'Chalkboard SE', 'Marker Felt', sans-serif;
  color: #4b5563;
  background: #fffbfa;
}
.invoice-paper.theme-casual .invoice-header {
  border-bottom: 3px dashed #fcd34d;
  padding-bottom: 1rem;
}
.invoice-paper.theme-casual .company-details h1 {
  color: #f59e0b;
}
.invoice-paper.theme-casual .invoice-meta {
  background: #fef3c7;
  color: #b45309;
  border-radius: 12px;
  border: 2px dashed #fcd34d;
}
.invoice-paper.theme-casual table {
  border-collapse: separate;
  border-spacing: 0 4px;
}
.invoice-paper.theme-casual table th {
  background: #fcd34d;
  color: #78350f;
  border: none;
}
.invoice-paper.theme-casual table th:first-child { border-radius: 12px 0 0 12px; }
.invoice-paper.theme-casual table th:last-child { border-radius: 0 12px 12px 0; }
.invoice-paper.theme-casual table td {
  border-bottom: 1px dashed #fcd34d;
  padding: 8px;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }
  
  body, html {
    background: white;
    margin: 0;
    padding: 0;
    width: 100%;
    height: auto;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .app-container {
    height: auto;
    overflow: visible;
    display: block;
  }
  
  .form-panel, .btn-print, header, footer, nav, .print-hidden {
    display: none !important;
  }
  
  .preview-panel {
    padding: 0 !important;
    background: transparent !important;
    display: block !important;
    height: auto;
    overflow: visible;
  }
  
  .invoice-paper {
    box-shadow: none !important;
    border-radius: 0 !important;
    border: none !important;
    margin: 0 !important;
    width: 210mm !important;
    height: auto !important; /* Let content dictate height so it doesn't force a 2nd page unnecessarily */
    min-height: auto !important;
    padding: 2cm !important; /* Margin 2cm di semua sisi */
    page-break-after: avoid;
  }
}
