/* app.css LENGKAP */
:root {
  --sidebar-bg: #111827;
  --sidebar-text: #e5e7eb;
  --sidebar-border: #374151;
  --input-bg: #1f2937;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --canvas-bg: #f3f4f6;
  --card-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Inter", sans-serif;
}

body,
html {
  height: 100%;
  overflow: hidden;
  background: var(--canvas-bg);
}

.app-container {
  display: flex;
  height: 100vh;
}

/* --- SIDEBAR --- */
aside {
  width: 320px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  transition: transform 0.3s ease;
  z-index: 50;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--sidebar-border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 1.1rem;
  color: white;
}

/* FIX LOGO ICON STYLE */
.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.logo-icon img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  /* Membuat SVG jadi putih total */
  filter: brightness(0) invert(1);
  display: block;
}

.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
.scroll-area::-webkit-scrollbar {
  width: 5px;
}
.scroll-area::-webkit-scrollbar-thumb {
  background: #374151;
  border-radius: 4px;
}

/* Input Styles */
.control-group {
  margin-bottom: 25px;
  border-bottom: 1px solid #374151;
  padding-bottom: 20px;
}
.control-group:last-child {
  border-bottom: none;
}
.group-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: #9ca3af;
  margin-bottom: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.input-wrapper {
  position: relative;
  margin-bottom: 12px;
}
.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  font-size: 1rem;
}
input[type="text"] {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--sidebar-border);
  color: white;
  padding: 10px 10px 10px 38px;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: all 0.2s;
}
input[type="text"]:focus {
  border-color: var(--primary);
  outline: none;
}

/* Layout Buttons */
.layout-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.layout-btn {
  background: var(--input-bg);
  border: 1px solid var(--sidebar-border);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  text-align: center;
  transition: 0.2s;
}
.layout-btn:hover {
  background: #374151;
}
.layout-btn.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}
.layout-btn small {
  color: #9ca3af;
  font-size: 0.7rem;
  display: block;
  margin-top: 5px;
}

/* Visual Preview Box */
.preview-box {
  height: 30px;
  background: #374151;
  border-radius: 2px;
  position: relative;
}
.p-center span {
  position: absolute;
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  background: #6b7280;
  border-radius: 50%;
}
.p-left span {
  position: absolute;
  top: 8px;
  left: 5px;
  width: 10px;
  height: 10px;
  background: #6b7280;
  border-radius: 50%;
}
.p-modern {
  background: linear-gradient(90deg, #374151 30%, #4b5563 30%);
}

/* Color & File */
.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--input-bg);
  padding: 5px;
  border-radius: 6px;
  border: 1px solid var(--sidebar-border);
}
input[type="color"] {
  border: none;
  width: 30px;
  height: 30px;
  cursor: pointer;
  background: none;
}
#color-code {
  font-size: 0.8rem;
  color: #9ca3af;
  font-family: monospace;
}
input[type="file"] {
  display: none;
}
.custom-file-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px dashed #4b5563;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px;
  width: 100%;
  cursor: pointer;
  border-radius: 6px;
  color: #d1d5db;
  font-size: 0.9rem;
  transition: 0.2s;
}
.custom-file-upload:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Footer */
.sidebar-footer {
  padding: 20px;
  border-top: 1px solid var(--sidebar-border);
  text-align: center;
  margin-top: auto;
}
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 12px;
  width: 100%;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
  transition: 0.2s;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.back-link {
  font-size: 0.8rem;
  color: #6b7280;
  text-decoration: none;
}

/* --- MAIN CANVAS --- */
main {
  flex: 1;
  position: relative;
  background-image: radial-gradient(#d1d5db 1px, transparent 1px);
  background-size: 24px 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}
.canvas-toolbar {
  position: absolute;
  top: 20px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.toolbar-label {
  font-size: 0.9rem;
  color: #4b5563;
  font-weight: 600;
}
.badge {
  background: #def7ec;
  color: #03543f;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
}

/* --- ID CARD --- */
#id-card {
  width: 580px;
  height: 366px;
  background: white;
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  position: relative;
  overflow: hidden;
  display: flex;
  transition: all 0.3s ease;
  color: #1f2937;
}

/* Card Elements */
.bg-shape {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  clip-path: polygon(0 0, 100% 0, 100% 35%, 0 55%);
  background: var(--primary);
  transition: background 0.3s;
}
.card-content {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: flex;
  padding: 25px;
}
.profile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.info-name {
  font-weight: 800;
  font-size: 1.8rem;
  line-height: 1.2;
  margin-bottom: 5px;
}
.info-role {
  font-weight: 600;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.8;
  margin-bottom: 5px;
}

/* FIX ID TEXT COLOR (Lebih Gelap) */
.info-id {
  font-family: "Courier New", monospace;
  font-size: 0.95rem;
  color: #374151 !important; /* Warna Abu Gelap */
  font-weight: 600;
  opacity: 0.9;
}

.qr-section {
  background: white;
  padding: 5px;
  border-radius: 8px;
  display: inline-block;
}
.qr-section img {
  display: block;
}

/* Layout Variations */
/* Center */
#id-card.layout-center .card-content {
  flex-direction: column;
  align-items: center;
  text-align: center;
  justify-content: center;
}
#id-card.layout-center .bg-shape {
  clip-path: circle(70% at 50% -40%);
}
#id-card.layout-center .profile-img-container {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  border: 6px solid white;
  overflow: hidden;
  margin-bottom: 15px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
#id-card.layout-center .qr-section {
  position: absolute;
  bottom: 25px;
  right: 25px;
  transform: scale(0.9);
}

/* --- PERBAIKAN LAYOUT LEFT (FINAL CENTER FIX) --- */

/* 1. Container Utama: Hapus padding agar elemen bisa menempel ke ujung */
#id-card.layout-left .card-content {
  flex-direction: row;
  align-items: center;
  gap: 0;
  padding: 0; /* <--- KUNCI PERBAIKAN: Reset padding jadi 0 */
}

/* 2. Background Shape (Area Warna Biru) */
#id-card.layout-left .bg-shape {
  width: 35%;
  height: 100%;
  clip-path: none;
  right: auto;
  left: 0;
  border-radius: 16px 0 0 16px; /* Agar sudut kiri melengkung sesuai kartu */
}

/* 3. Area Foto (Sekarang lebarnya sinkron 100% dengan background) */
#id-card.layout-left .profile-section {
  flex: 0 0 35%; /* Lebar sama persis dengan bg-shape */
  height: 100%; /* Tinggi penuh agar centering vertikal sempurna */
  display: flex;
  justify-content: center; /* Center Horizontal */
  align-items: center; /* Center Vertikal */
  z-index: 2;
}

/* 4. Lingkaran Foto */
#id-card.layout-left .profile-img-container {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  border: 5px solid white;
  overflow: hidden;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

/* 5. Area Teks (Kita beri padding manual karena padding container dihapus) */
#id-card.layout-left .info-section {
  flex: 1;
  text-align: left;
  padding: 30px 30px 30px 50px; /* Atas Kanan Bawah Kiri(Jarak dr warna) */
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
}

/* Styling Teks Layout Left */
#id-card.layout-left .info-name {
  font-size: 2.2rem;
}
#id-card.layout-left .info-role {
  font-size: 1.1rem;
  margin-bottom: 10px;
}

/* 6. QR Code Position */
#id-card.layout-left .qr-section {
  position: absolute;
  bottom: 20px;
  right: 20px;
  border: 1px solid #eee;
  background: white;
}

/* Modern */
#id-card.layout-modern .bg-shape {
  display: none;
}
#id-card.layout-modern {
  border-left: 20px solid var(--primary);
}
#id-card.layout-modern .card-content {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
#id-card.layout-modern .profile-img-container {
  width: 100px;
  height: 100px;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 0;
  box-shadow: none;
  border: 1px solid #eee;
}
#id-card.layout-modern .profile-section {
  order: 2;
}
#id-card.layout-modern .info-section {
  order: 1;
  text-align: left;
}
#id-card.layout-modern .qr-section {
  position: absolute;
  bottom: 25px;
  left: 30px;
}
#id-card.layout-modern .info-name {
  color: var(--primary);
}

/* TAMBAHAN DI app.css */

/* --- 1. Texture Selector Buttons --- */
.texture-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.texture-btn {
  background: var(--input-bg);
  border: 1px solid var(--sidebar-border);
  border-radius: 6px;
  height: 40px;
  cursor: pointer;
  padding: 4px;
  transition: 0.2s;
}
.texture-btn:hover {
  border-color: #9ca3af;
}
.texture-btn.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

/* Preview Box di tombol */
.pat-preview {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  opacity: 0.7;
}
.pat-none {
  background: #374151;
}
/* CSS Patterns Murni */
.pat-dots {
  background-image: radial-gradient(#9ca3af 1px, transparent 1px);
  background-size: 6px 6px;
  background-color: #374151;
}
.pat-grid {
  background-image: linear-gradient(#9ca3af 1px, transparent 1px),
    linear-gradient(90deg, #9ca3af 1px, transparent 1px);
  background-size: 8px 8px;
  background-color: #374151;
}
.pat-lines {
  background: repeating-linear-gradient(
    45deg,
    #374151,
    #374151 5px,
    #9ca3af 5px,
    #9ca3af 6px
  );
}

/* Tombol Reset (Secondary) */
.btn-secondary {
  background: transparent;
  color: #9ca3af;
  border: 1px solid var(--sidebar-border);
  padding: 10px;
  width: 100%;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 0.85rem;
  transition: 0.2s;
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  color: white;
  border-color: #6b7280;
}

/* --- 2. Aplikasi Pattern pada KARTU PREVIEW --- */

/* Pattern DOTS pada Kartu (Warna abu sangat muda agar elegan) */
#id-card.pat-dots {
  background-image: radial-gradient(#d1d5db 1.5px, transparent 1.5px);
  background-size: 12px 12px;
  background-color: white;
}

/* Pattern GRID pada Kartu */
#id-card.pat-grid {
  background-size: 20px 20px;
  background-image: linear-gradient(to right, #f3f4f6 1px, transparent 1px),
    linear-gradient(to bottom, #f3f4f6 1px, transparent 1px);
  background-color: white;
}

/* Pattern LINES pada Kartu */
#id-card.pat-lines {
  background-color: white;
  background-image: repeating-linear-gradient(
    135deg,
    transparent,
    transparent 10px,
    #f3f4f6 10px,
    #f3f4f6 12px
  );
}

/* Pattern NONE (Default) */
#id-card.pat-none {
  background: white;
  background-image: none;
}

/* TAMBAHAN DI app.css */

/* Style Umum Logo Perusahaan */
.company-logo {
  position: absolute;
  max-width: 120px; /* Batas lebar logo */
  max-height: 50px; /* Batas tinggi logo */
  object-fit: contain;
  z-index: 10; /* Pastikan di atas background */
  display: none; /* Sembunyi kalau kosong */
}

/* POSISI LOGO BERDASARKAN LAYOUT */

/* 1. Layout Center: Logo di Pojok Kiri Atas */
#id-card.layout-center .company-logo {
  top: 25px;
  left: 25px;
}

/* 2. Layout Left: Logo di Pojok Kanan Atas (Area Putih) */
#id-card.layout-left .company-logo {
  top: 25px;
  right: 30px; /* Sejajar vertikal dengan konten */
}

/* 3. Layout Modern: Logo di Pojok Kanan Atas */
#id-card.layout-modern .company-logo {
  top: 25px;
  right: 25px;
}

/* --- APP.CSS TAMBAHAN --- */

/* 1. TYPOGRAPHY SELECTOR */
.font-grid {
  display: flex;
  gap: 10px;
}
.font-btn {
  flex: 1;
  height: 40px;
  border: 1px solid var(--sidebar-border);
  background: var(--input-bg);
  color: white;
  border-radius: 6px;
  font-size: 1.2rem;
  cursor: pointer;
  transition: 0.2s;
}
.font-btn:hover {
  border-color: #9ca3af;
}
.font-btn.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary);
}

/* Class Font untuk Kartu */
.font-sans {
  font-family: "Inter", sans-serif !important;
}
.font-serif {
  font-family: "Playfair Display", serif !important;
}
.font-mono {
  font-family: "Space Mono", monospace !important;
  letter-spacing: -0.5px;
}

/* 2. TEXTAREA INPUT */
textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--sidebar-border);
  color: white;
  padding: 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  resize: none;
}
textarea:focus {
  border-color: var(--primary);
  outline: none;
}

/* 3. VIEW SWITCHER (Depan/Belakang) */
.view-switcher {
  background: white;
  padding: 4px;
  border-radius: 8px;
  display: flex;
  gap: 5px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}
.view-btn {
  padding: 6px 15px;
  border: none;
  background: transparent;
  color: #6b7280;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 6px;
}
.view-btn.active {
  background: var(--primary);
  color: white;
}

/* 4. CARD BACK SIDE STYLE */
.card-base {
  /* Base style yang sama untuk depan & belakang */
  width: 580px;
  height: 366px;
  background: white;
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  position: relative;
  overflow: hidden;
  color: #1f2937;
  transition: all 0.3s ease;
}

#id-card-back {
  display: flex;
  flex-direction: column;
  text-align: center;
  background-image: radial-gradient(#e5e7eb 1px, transparent 1px);
  background-size: 20px 20px;
}

.back-header {
  width: 100%;
  height: 15px;
  background: var(--primary);
}
.back-content {
  flex: 1;
  padding: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#card-terms {
  font-size: 0.9rem;
  line-height: 1.6;
  color: #4b5563;
  white-space: pre-wrap; /* Agar enter di textarea terbaca */
}
.back-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* TAMBAHAN DI app.css */

/* Barcode Container */
.barcode-section {
  position: absolute;
  bottom: 15px;
  right: 20px;
  background: white;
  padding: 5px 10px; /* Padding kanan kiri lebih lebar */
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

/* Khusus Layout Modern (Barcode di kiri) */
#id-card.layout-modern .barcode-section {
  left: 25px;
  right: auto;
}

/* Adjust SVG size agar responsif di dalam kotak */
#barcode-svg {
  max-height: 40px; /* Tinggi maksimal barcode */
  width: auto;
}
/* --- MOBILE RESPONSIVE (UPDATE FINAL) --- */
.mobile-nav {
  display: none;
}

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

  .mobile-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--sidebar-bg);
    color: white;
    border-bottom: 1px solid #374151;
    position: relative;
    z-index: 60; /* Pastikan di atas sidebar */
  }

  .brand-mobile {
    font-weight: bold;
    font-size: 1.2rem;
    display: flex;
    gap: 8px;
    align-items: center;
  }
  #toggle-sidebar {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
  }

  aside {
    position: fixed;
    top: 60px;
    left: 0;
    width: 100%;
    height: calc(100% - 60px);
    transform: translateX(-100%); /* Hidden by default */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  aside.open {
    transform: translateX(0);
  }

  main {
    padding: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Mulai dari atas agar tidak tertutup keyboard */
    padding-top: 40px;
  }

  /* FIX: Terapkan scaling ke KEDUA sisi kartu */
  #id-card,
  #id-card-back {
    transform: scale(0.55); /* Perkecil ke 55% */
    transform-origin: center top; /* Titik tengah atas */
    margin-bottom: -150px; /* Hilangkan whitespace sisa scaling */
  }

  /* Sesuaikan posisi view switcher di HP */
  .canvas-toolbar {
    position: relative;
    top: 0;
    left: 0;
    margin-bottom: 20px;
    justify-content: center;
    width: 100%;
  }
}
