/* ========================================
   SPT AUTO GENERATOR - STYLES
   ======================================== */

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

:root {
  --primary: #1a56db;
  --primary-dark: #1e40af;
  --primary-light: #dbeafe;
  --accent: #059669;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #d1d5db;
  --border-light: #e5e7eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
  --radius: 8px;
  --font-sans: 'Segoe UI', 'Inter', system-ui, sans-serif;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---------- App Header ---------- */
.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-header .subtitle {
  font-size: 0.85rem;
  opacity: 0.85;
  font-weight: 400;
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* ---------- Layout ---------- */
.app-container {
  display: flex;
  gap: 0;
  min-height: calc(100vh - 64px);
}

/* ---------- Form Panel ---------- */
.form-panel {
  width: 480px;
  min-width: 480px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-light);
  overflow-y: auto;
  height: calc(100vh - 64px);
  position: sticky;
  top: 64px;
}

.form-section {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
}

.form-section:last-child {
  border-bottom: none;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::before {
  content: '';
  width: 3px;
  height: 16px;
  background: var(--primary);
  border-radius: 2px;
}

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

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  font-family: var(--font-sans);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fff;
}

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

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

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s;
}

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

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

.btn-success {
  background: var(--accent);
  color: white;
}

.btn-success:hover {
  background: #047857;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

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

.btn-sm {
  padding: 5px 12px;
  font-size: 0.78rem;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  font-size: 1.1rem;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ---------- Dasar Hukum List ---------- */
.dasar-item {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  align-items: flex-start;
}

.dasar-item .dasar-num {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 10px;
  min-width: 20px;
}

.dasar-item textarea {
  flex: 1;
}

.dasar-item .btn-icon {
  margin-top: 4px;
  flex-shrink: 0;
}

/* ---------- Personnel List ---------- */
.person-card {
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  position: relative;
}

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

.person-card .person-num {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 10px;
  border-radius: 12px;
}

.person-card .form-group {
  margin-bottom: 8px;
}

.person-card .form-group label {
  font-size: 0.78rem;
}

.person-card .form-group input,
.person-card .form-group select {
  padding: 7px 10px;
  font-size: 0.83rem;
}

/* ---------- Preview Panel ---------- */
.preview-panel {
  flex: 1;
  background: #e2e5ea;
  overflow-y: auto;
  height: calc(100vh - 64px);
  padding: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

/* ========================================
   A4 DOCUMENT STYLES (Preview + Print)
   ======================================== */

.a4-page {
  width: 210mm;
  min-height: 297mm;
  background: white;
  box-shadow: var(--shadow-lg);
  position: relative;
  padding: 10mm 15mm 15mm 20mm;
  /* top right bottom left — page 1 top = 10mm */
  font-family: 'Times New Roman', Times, serif;
  font-size: 12pt;
  line-height: 1.5;
  color: #000;
}

.person-entry {
  page-break-inside: avoid;
  break-inside: avoid;
}

/* --- Kop Surat --- */
.kop-surat {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 8px;
  margin-bottom: 16px;
  border-bottom: 3px double #000;
}

.kop-logo {
  width: 70px;
  height: auto;
  flex-shrink: 0;
}

.kop-text {
  text-align: center;
  flex: 1;
}

.kop-text .kop-pemerintah {
  font-size: 12pt;
  letter-spacing: 0.5px;
}

.kop-text .kop-instansi {
  font-size: 14pt;
  font-weight: bold;
  letter-spacing: 1px;
}

.kop-text .kop-alamat {
  font-size: 9pt;
  line-height: 1.3;
}

.kop-line-thin {
  display: none;
}

/* --- Judul Surat --- */
.surat-title {
  text-align: center;
  margin: 16px 0 4px 0;
}

.surat-title h2 {
  font-size: 13pt;
  font-weight: bold;
  text-decoration: underline;
  letter-spacing: 1px;
  margin: 0;
}

.surat-title .surat-nomor {
  font-size: 11pt;
  margin: 2px 0 0 0;
}

/* --- Dasar --- */
.surat-dasar {
  margin: 20px 0;
}

.dasar-table {
  width: 100%;
  border-collapse: collapse;
}

.dasar-table td {
  vertical-align: top;
  padding: 2px 0;
  font-size: 12pt;
  line-height: 1.5;
}

.dasar-table td:first-child {
  width: 70px;
  font-weight: normal;
}

.dasar-table td:nth-child(2) {
  width: 20px;
  text-align: center;
}

.dasar-table .dasar-content {
  text-align: justify;
}

/* --- Memerintahkan --- */
.memerintahkan {
  text-align: center;
  font-weight: bold;
  font-size: 12pt;
  letter-spacing: 1px;
  margin: 16px 0;
  text-decoration: underline;
}

/* --- Kepada List --- */
.kepada-section {
  margin: 8px 0;
}

.kepada-table {
  width: 100%;
  border-collapse: collapse;
}

.kepada-table>tbody>tr>td {
  vertical-align: top;
  padding: 2px 0;
  font-size: 12pt;
}

.kepada-table>tbody>tr>td:first-child {
  width: 70px;
}

.person-entry {
  margin-bottom: 8px;
}

.person-detail-table {
  width: 100%;
  border-collapse: collapse;
}

.person-detail-table td {
  padding: 1px 0;
  font-size: 12pt;
  vertical-align: top;
  line-height: 1.4;
}

.person-detail-table .person-num-cell {
  width: 30px;
  text-align: left;
}

.person-detail-table .person-label {
  width: 160px;
}

.person-detail-table .person-separator {
  width: 15px;
  text-align: center;
}

.person-detail-table .person-value {
  /* remaining width */
}

/* --- Footer Block (Untuk + Penutup + TTD grouped together) --- */
.footer-block {
  page-break-inside: avoid;
  break-inside: avoid;
}

/* --- Untuk --- */
.untuk-section {
  margin: 16px 0;
}

.untuk-table {
  width: 100%;
  border-collapse: collapse;
}

.untuk-table td {
  vertical-align: top;
  padding: 2px 0;
  font-size: 12pt;
  line-height: 1.5;
}

.untuk-table td:first-child {
  width: 70px;
}

.untuk-table .untuk-content {
  text-align: justify;
}

/* --- Penutup --- */
.penutup {
  margin: 16px 0 8px 0;
  text-indent: 60px;
  text-align: justify;
  font-size: 12pt;
  line-height: 1.5;
}

/* --- Tanda Tangan --- */
.ttd-section {
  margin-top: 24px;
  display: flex;
  justify-content: flex-end;
}

.ttd-block {
  text-align: left;
  min-width: 260px;
}

.ttd-block .ttd-tempat-tanggal {
  margin-bottom: 2px;
  font-size: 12pt;
}

.ttd-block .ttd-jabatan {
  margin-bottom: 50px;
  font-size: 12pt;
}

.ttd-block .ttd-nama {
  font-weight: bold;
  text-decoration: none;
  font-size: 12pt;
}

.ttd-block .ttd-pangkat {
  font-size: 12pt;
}

.ttd-block .ttd-nip {
  font-size: 12pt;
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {

  html,
  body {
    margin: 0;
    padding: 0;
    background: white;
  }

  .app-header,
  .form-panel,
  .no-print {
    display: none !important;
  }

  .app-container {
    display: block;
  }

  .preview-panel {
    background: white;
    padding: 0;
    overflow: visible;
    height: auto;
  }

  .a4-page {
    width: 100%;
    margin: 0;
    padding: 0;
    /* Print: margins handled by @page, NOT padding */
    box-shadow: none;
    page-break-after: always;
  }

  .lampiran-page {
    padding-top: 0 !important;
  }

  .page-break {
    page-break-before: always;
  }

  .a4-page:last-child {
    page-break-after: auto;
  }

  @page {
    size: A4;
    margin: 20mm 15mm 15mm 20mm;
    /* pages 2+ top = 20mm */
  }

  @page :first {
    margin-top: 10mm;
    /* page 1 top = 10mm */
  }
}

/* ========================================
   RESPONSIVE (screen)
   ======================================== */

@media screen and (max-width: 1200px) {
  .form-panel {
    width: 400px;
    min-width: 400px;
  }
}

@media screen and (max-width: 900px) {
  .app-container {
    flex-direction: column;
  }

  .form-panel {
    width: 100%;
    min-width: unset;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border-light);
  }

  .preview-panel {
    height: auto;
    min-height: 50vh;
  }

  .a4-page {
    width: 100%;
    min-height: auto;
    transform: none;
  }
}

/* ---------- Action Bar ---------- */
.action-bar {
  padding: 16px 24px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
}

.action-bar .btn {
  flex: 1;
}

/* ---------- Excel Actions ---------- */
.excel-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.excel-actions .btn {
  flex: 1;
}

/* ---------- Empty State ---------- */
.empty-preview {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
}

.empty-preview .icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* ---------- NIP Type Selector ---------- */
.nip-type-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nip-type-row select {
  width: 120px;
  flex-shrink: 0;
}

.nip-type-row input {
  flex: 1;
}

/* ---------- Tooltip / Help ---------- */
.help-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 3px;
}