:root {
  --primary: #e53e3e;
  --primary-dark: #c53030;
  --surface: #ffffff;
  --bg-app: #f7fafc;
  --border: #e2e8f0;
  --text: #2d3748;
  --accent-gold: #d69e2e;
  --grid-size: 160px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background-color: var(--bg-app);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* NAVBAR */
.navbar {
  background: var(--surface);
  height: 55px;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
}
.nav-brand img {
  height: 24px;
}
.pro-badge {
  background: var(--accent-gold);
  color: white;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-outline {
  border: 1px solid var(--primary);
  color: var(--primary);
  background: white;
  padding: 5px 12px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}

/* TOOLBAR */
.toolbar {
  background: #edf2f7;
  padding: 0.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  overflow-x: auto; /* Safety for small screens */
}
.tool-group {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.tool-btn {
  background: white;
  border: 1px solid #cbd5e0;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 5px;
  transition: 0.2s;
}
.tool-btn:hover:not(:disabled) {
  background: #e2e8f0;
  border-color: #a0aec0;
}
.tool-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.divider {
  width: 1px;
  height: 24px;
  background: #cbd5e0;
  margin: 0 5px;
}
#zoom-slider {
  width: 120px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* WORKSPACE */
.app-container {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
  background-size: 20px 20px; /* Dot pattern background */
}
.visual-workspace {
  width: 100%;
  max-width: 1400px;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.empty-state {
  text-align: center;
  color: #a0aec0;
  margin-top: 4rem;
  border: 3px dashed #cbd5e0;
  padding: 3rem;
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  cursor: pointer;
  transition: 0.2s;
  background: rgba(255, 255, 255, 0.8);
}
.empty-state:hover {
  border-color: var(--primary);
  background: #fff5f5;
}

/* GRID SYSTEM */
.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--grid-size), 1fr));
  gap: 1.5rem;
  width: 100%;
  padding-bottom: 120px; /* Extra padding for footer */
  transition: grid-template-columns 0.2s ease; /* Smooth zoom transition */
}

.page-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative; /* Penting untuk posisi absolut tombol */
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
}

.page-card:active {
  cursor: grabbing;
  transform: scale(1.02);
}
.sortable-ghost {
  opacity: 0.3;
  border: 2px dashed var(--primary);
}

/* CANVAS WRAPPER */
.canvas-wrapper {
  position: relative;
  background: #f8fafc;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-grow: 1; /* Agar mengisi ruang */
  min-height: 200px; /* Tinggi minimal agar terlihat proporsional */
}
.canvas-wrapper canvas {
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease; /* Animasi putar halus */
  max-width: 90%; /* Agar tidak terlalu mepet pinggir */
  max-height: 90%;
  object-fit: contain;
}

.card-actions-top {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  opacity: 0; /* Sembunyi default */
  transform: translateY(-10px);
  transition: all 0.3s ease;
  z-index: 10;
}

.page-card:hover .card-actions-top {
  opacity: 1;
  transform: translateY(0);
}

.action-btn-round {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(5px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  color: var(--text);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: 0.2s;
}

.action-btn-round:hover {
  background: var(--primary);
  color: white;
  transform: scale(1.1);
}

.btn-delete-page:hover {
  background: #e53e3e; /* Merah untuk hapus */
}

/* --- INFO FILE & TOMBOL HAPUS FILE (Bawah) --- */
.page-info-footer {
  padding: 12px;
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.file-name-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px; /* Batasi lebar teks nama file */
  font-weight: 500;
  color: var(--text);
}

/* Tombol Hapus File Induk (Kecil di samping nama) */
.btn-file-delete-small {
  background: none;
  border: none;
  color: #9ca3af; /* Abu-abu default */
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-file-delete-small:hover {
  color: #e53e3e; /* Merah saat hover */
  background: #fee2e2;
}

.card-actions {
  gap: 10px; /* Beri jarak antar tombol */
  justify-content: center;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.7),
    rgba(0, 0, 0, 0)
  ); /* Gradient BG */
  padding: 8px;
  display: flex;
  opacity: 0;
  transition: 0.2s;
}

.btn-file-delete {
  background: rgba(255, 255, 255, 0.9);
  color: #c53030;
  border: 1px solid #c53030;
  font-size: 0.9rem;
  font-weight: bold;
}
.btn-file-delete:hover {
  background: #c53030;
  color: white;
}
.page-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
  border-color: var(--primary-light);
}
.action-btn {
  background: rgba(255, 255, 255, 0.9);
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 6px;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: 0.2s;
}
.action-btn:hover {
  background: white;
  color: var(--primary);
  transform: scale(1.1);
}

.page-info {
  font-size: 0.8rem;
  color: #4a5568;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

/* FOOTER */
.control-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1rem 2rem;
  box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.08);
  z-index: 100;
}
.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.stats-group {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.btn-settings {
  background: #edf2f7;
  border: 1px solid #cbd5e0;
  color: var(--text);
  padding: 0.7rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: 0.2s;
}
.btn-settings:hover {
  background: #e2e8f0;
  border-color: #a0aec0;
}
.size-info {
  font-size: 0.9rem;
  color: #4a5568;
}

.btn-merge {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.8rem 2.5rem;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(229, 62, 62, 0.4);
  transition: 0.2s;
}
.btn-merge:disabled {
  background: #cbd5e0;
  cursor: not-allowed;
  box-shadow: none;
  transform: none !important;
}
.btn-merge:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(229, 62, 62, 0.6);
}

/* MODAL STYLES (Perbaikan Layout) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  backdrop-filter: blur(3px);
}
.modal-overlay.show {
  display: flex;
  animation: fadeIn 0.2s ease-out;
}
.modal-panel {
  background: white;
  width: 100%;
  max-width: 500px;
  border-radius: 12px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  animation: slideUp 0.3s ease-out;
}
.modal-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  background: #f8fafc;
  align-items: center;
}
.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
}
.btn-close {
  background: none;
  border: none;
  font-size: 1.8rem;
  color: #a0aec0;
  cursor: pointer;
  line-height: 1;
}
.btn-close:hover {
  color: var(--primary);
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  max-height: 70vh;
  overflow-y: auto;
}
.setting-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* TAMBAHKAN DI APP.CSS (Bagian MODAL STYLES) */

.modal-footer {
  padding: 1.2rem;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  /* Gunakan Flexbox untuk memisahkan teks kiri dan tombol kanan */
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.auto-save-indicator {
  font-size: 0.85rem;
  color: #059669; /* Warna Hijau Sukses */
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Responsif Mobile untuk Footer Modal */
@media (max-width: 600px) {
  .modal-footer {
    flex-direction: column-reverse; /* Tombol di atas, teks di bawah */
    gap: 1rem;
  }
  .btn-primary-outline {
    width: 100%;
    text-align: center;
  }
}

/* PERBAIKAN LAYOUT ITEM PREMIUM */
.premium-item {
  border-left: 4px solid var(--accent-gold); /* Garis lebih tebal */
  background: #fffaf0;
  padding: 12px 15px; /* Padding lebih lega */
  border-radius: 0 8px 8px 0; /* Sudut membulat */
  margin-bottom: 5px;
}
.toggle-wrapper {
  display: flex;
  align-items: center; /* FIX: Sejajarkan vertikal tengah */
  gap: 12px; /* Jarak antar checkbox dan teks */
  cursor: pointer;
  width: 100%;
}
.toggle-wrapper input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}
.toggle-text {
  display: flex;
  flex-direction: column;
}
.toggle-text strong {
  font-size: 1rem;
  color: var(--text);
}
.toggle-text small {
  color: #718096;
  font-size: 0.85rem;
}

.hidden-option {
  display: none;
  padding-left: 30px;
  margin-top: 10px;
}
.hidden-option.active {
  display: block;
  animation: fadeIn 0.3s;
}
.input-field {
  width: 100%;
  padding: 10px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.95rem;
  transition: 0.2s;
}
.input-field:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.1);
}
.row-inputs {
  display: flex;
  gap: 10px;
  align-items: center;
}
input[type="color"] {
  padding: 0;
  width: 50px;
  height: 40px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}

.modal-footer {
  padding: 1.2rem;
  border-top: 1px solid var(--border);
  text-align: right;
  background: #f8fafc;
}
.btn-primary-outline {
  background: white;
  border: 2px solid var(--primary);
  color: var(--primary);
  padding: 0.7rem 1.5rem;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s;
}
.btn-primary-outline:hover {
  background: #fff5f5;
  transform: translateY(-1px);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* TAMBAHKAN INI DI APP.CSS */
.setting-label {
  font-weight: 600;
  margin-bottom: 5px;
  display: block;
  color: var(--text);
}

/* Pastikan input field dan select konsisten */
select.input-field {
  cursor: pointer;
  background-color: #fff;
}

/* --- COPY KE BAGIAN PALING BAWAH APP.CSS --- */

/* Processing Pill (Notifikasi Minimalis) */
.processing-pill {
  position: fixed;
  bottom: 90px; /* Di atas footer */
  right: 30px;
  background: white;
  padding: 12px 20px;
  border-radius: 50px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 999;
  border: 1px solid var(--border);
  transform: translateY(100px); /* Sembunyi di bawah */
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.processing-pill.active {
  transform: translateY(0);
  opacity: 1;
}

.processing-pill span {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums; /* Agar angka tidak goyang */
}

/* Spinner Kecil */
.spinner-mini {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(229, 62, 62, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* TAMBAHKAN DI BAGIAN BAWAH APP.CSS (Processing Pill Styles) */

#cancel-processing-btn {
  background: transparent;
  border: none;
  color: #ef4444; /* Merah terang */
  font-size: 1.5rem; /* Ukuran besar agar mudah diklik */
  font-weight: 400;
  line-height: 1;
  padding: 0 4px;
  margin-left: 8px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

#cancel-processing-btn:hover {
  background: #fee2e2; /* Background merah muda saat hover */
}

/* Responsive Mobile */
@media (max-width: 600px) {
  .processing-pill {
    bottom: 140px; /* Lebih tinggi di HP biar gak ketutup tombol floating lain */
    right: 50%;
    transform: translate(50%, 100px); /* Center horizontal */
    width: max-content;
  }
  .processing-pill.active {
    transform: translate(50%, 0);
  }
}

@media (max-width: 768px) {
  .toolbar {
    flex-wrap: wrap;
    gap: 10px;
  }
  .tool-group:first-child {
    flex-grow: 1;
  }
  .footer-content {
    flex-direction: column;
    gap: 1rem;
  }
  .stats-group {
    width: 100%;
    justify-content: space-between;
  }
  .btn-merge {
    width: 100%;
  }
  .card-actions {
    opacity: 1;
    background: rgba(0, 0, 0, 0.5);
  } /* Always show actions on touch */
}
