@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap');

:root {
  --navy: #10275f;
  --navy-light: #1c3d8a;
  --blue: #2563eb;
  --cyan: #20a9df;
  --pink: #ec168c;
  --gray: #6b7280;
  --line: #d7d9df;
  --soft: #f3f4f6;
  --panel-w: 380px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #eef1f7;
  font-family: 'Roboto', sans-serif;
  color: #202124;
  -webkit-font-smoothing: antialiased;
}

input,
select,
textarea,
button {
  font-family: inherit;
  font-size: 14px;
}

/* ----------------- MOBILE HEADER (Hidden on Desktop) ----------------- */
.mobile-header {
  display: none;
}

/* ----------------- APP LAYOUT (Desktop Side-by-Side) ----------------- */
.app {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  min-height: 100vh;
}

/* ----------------- EDITOR PANEL ----------------- */
.panel {
  background: #fff;
  padding: 24px;
  border-right: 1px solid #e5e7eb;
  overflow-y: auto;
  height: 100vh;
  position: sticky;
  top: 0;
}

.panel-brand {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.panel-logo {
  height: 36px;
  width: auto;
  display: block;
}

.panel-tagline {
  margin: 0 0 18px;
  color: #6b7280;
  font-size: 12.5px;
  line-height: 1.4;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin: 13px 0 6px;
  color: #374151;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  outline: none;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

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

.grid2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease, transform 0.08s ease;
}

button:active {
  transform: translateY(1px);
}

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

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

.secondary {
  background: #e9eefb;
  color: var(--navy);
}

.secondary:hover {
  background: #dbe4f9;
}

.danger {
  background: #fee2e2;
  color: #b91c1c;
}

.danger:hover {
  background: #fecaca;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 18px;
}

.item-editor {
  border: 1px solid #e5e7eb;
  border-radius: 9px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fafafa;
}

.item-editor .remove {
  float: right;
  font-size: 11px;
  padding: 5px 8px;
}

.btn-jump-preview {
  display: none; /* Only on mobile */
  width: 100%;
  padding: 12px;
  font-size: 14px;
  margin-top: 14px;
  background: var(--navy);
}

/* ----------------- STAGE (Desktop Preview Area) ----------------- */
.stage {
  padding: 34px 20px;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  width: 100%;
}

/* Toolbar preview: HANYA untuk mobile, tersembunyi di desktop & cetak */
.preview-toolbar {
  display: none !important;
}

.stage-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.scaler-wrapper {
  position: relative;
  width: 794px;
  margin: 0 auto;
  transition: width 0.15s ease-out, height 0.15s ease-out;
}

.invoice-scaler {
  transform-origin: top left;
  transition: transform 0.15s ease-out;
  width: 794px;
}

/* ----------------- INVOICE SHEET (A4 Standard) ----------------- */
.invoice {
  width: 794px;
  min-height: 1123px;
  background: #fff;
  padding: 50px 55px;
  box-shadow: 0 5px 30px rgba(0, 0, 0, 0.08);
  box-sizing: border-box;
}

.topline {
  height: 6px;
  background: linear-gradient(90deg, var(--navy) 0%, var(--cyan) 100%);
  margin: -38px 0 25px;
  border-radius: 3px;
}

.brand {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 18px;
  border-bottom: 1px solid #eef0f5;
}

.logo {
  height: 54px;
  width: auto;
  object-fit: contain;
}

.company-info {
  text-align: right;
}

.company-address {
  font-size: 12px;
  color: #6b7280;
  line-height: 1.6;
}

.company-services {
  color: var(--cyan);
  font-weight: 600;
  font-size: 11.5px;
}

.invoice-title {
  font-size: 38px;
  color: var(--navy);
  font-weight: 800;
  margin: 28px 0 4px;
  letter-spacing: -0.5px;
}

.submitted {
  color: var(--pink);
  font-weight: 700;
  font-size: 13px;
}

.info {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 26px;
  margin-top: 24px;
}

.info h4 {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #6b7280;
  font-weight: 700;
}

.info p {
  margin: 0;
  color: #1e293b;
  font-size: 12.5px;
  line-height: 1.6;
}

.info .block2 {
  margin-top: 20px;
}

.rule {
  border-top: 1px solid #e2e8f0;
  margin: 24px 0 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 12px;
  table-layout: fixed;
}

th {
  text-align: left;
  color: var(--navy);
  font-size: 12px;
  padding: 10px 8px;
  border-bottom: 2px solid #e2e8f0;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #f8fafc;
}

td {
  padding: 9px 8px;
  border-bottom: 1px solid #f1f5f9;
  word-break: break-word;
}

tbody tr:nth-child(odd) {
  background: #fafbfc;
}

.num {
  text-align: right;
}

table th:nth-child(1), table td:nth-child(1) { width: 48%; }
table th:nth-child(2), table td:nth-child(2) { width: 14%; }
table th:nth-child(3), table td:nth-child(3) { width: 19%; }
table th:nth-child(4), table td:nth-child(4) { width: 19%; }

.summary {
  margin-top: 2px;
  margin-left: auto;
  width: 48%;
  font-size: 12px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  color: #555;
}

.summary-row.total {
  font-size: 27px;
  color: var(--pink);
  font-weight: 800;
  padding-top: 7px;
}

.notes {
  color: #888;
  font-size: 12px;
  margin-top: 10px;
}

/* ----------------- RESPONSIVE (Tablet & Mobile <= 950px) ----------------- */
@media (max-width: 950px) {
  .mobile-header {
    display: block;
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  }

  .mobile-bar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid #f1f5f9;
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .mobile-brand-logo {
    height: 26px;
    width: auto;
  }

  .mobile-brand-name {
    font-size: 14px;
    font-weight: 800;
    color: var(--navy);
    line-height: 1.2;
  }

  .mobile-brand-sub {
    font-size: 11px;
    color: var(--gray);
  }

  .mobile-tab-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 6px 12px;
    gap: 8px;
    background: #f8fafc;
  }

  .tab-btn {
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 700;
    border-radius: 6px;
    background: transparent;
    color: #4b5563;
    border: 1px solid transparent;
  }

  .tab-btn.active {
    background: #fff;
    color: var(--navy);
    border-color: #d1d5db;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  }

  .preview-badge {
    font-size: 11px;
    background: #e0e7ff;
    color: #3730a3;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 700;
    margin-left: 4px;
  }

  .app {
    display: block;
    min-height: auto;
  }

  .panel {
    height: auto;
    position: static;
    border-right: 0;
    padding: 20px 16px 40px;
  }

  .panel-brand {
    display: none;
  }

  .btn-jump-preview {
    display: block;
  }

  /* Dual view switching on mobile */
  .app.view-edit .stage {
    display: none !important;
  }

  .app.view-preview .panel {
    display: none !important;
  }

  .app.view-preview .stage {
    display: flex !important;
    padding: 14px 12px 60px;
    align-items: center;
  }

  /* Mobile preview toolbar */
  .app.view-preview .preview-toolbar {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 14px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .toolbar-btn {
    font-size: 12px;
    padding: 7px 11px;
    background: #fff;
    border: 1px solid #d1d5db;
    color: #374151;
    border-radius: 6px;
  }

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

@media (max-width: 480px) {
  .panel {
    padding: 14px 12px 30px;
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .toolbar-group {
    width: 100%;
    justify-content: space-between;
  }
}

/* ----------------- PRINT STYLES (Clean A4 without browser headers/footers) ----------------- */
@page {
  size: A4 portrait;
  margin: 0 !important;
}

@media print {
  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 210mm !important;
    height: 297mm !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Sembunyikan SEMUA tombol, header navigasi, toolbar preview, dan panel formulir */
  header,
  aside,
  .mobile-header,
  .panel,
  .preview-toolbar,
  .app.view-preview .preview-toolbar,
  .btn-jump-preview,
  button {
    display: none !important;
    visibility: hidden !important;
  }

  .app {
    display: block !important;
    min-height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .stage {
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
    overflow: visible !important;
    width: 210mm !important;
  }

  .stage-container,
  .scaler-wrapper {
    display: block !important;
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    position: static !important;
    overflow: visible !important;
  }

  .invoice-scaler {
    transform: none !important;
    position: static !important;
    width: 210mm !important;
    display: block !important;
  }

  .invoice {
    box-shadow: none !important;
    border: none !important;
    width: 210mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    padding: 18mm 20mm !important;
    margin: 0 auto !important;
    border-radius: 0 !important;
    box-sizing: border-box !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .topline {
    margin: -10px 0 20px !important;
  }
}