/* Tambahkan di bagian paling atas file css */
input,
textarea {
  user-select: text !important;
  -webkit-user-select: text !important;
  pointer-events: auto !important;
}
:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --bg: #f8fafc;
  --white: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Plus Jakarta Sans", sans-serif;
}
body {
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* Layout */
.app-container {
  display: flex;
  height: 100%;
}

/* Sidebar */
.sidebar {
  width: 250px;
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  flex-shrink: 0;
}
.brand {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.nav-menu {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.nav-item {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 500;
  transition: 0.2s;
}
.nav-item:hover,
.nav-item.active {
  background: #e0e7ff;
  color: var(--primary);
}
.user-info-mini {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.avatar {
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}
.details small {
  display: block;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
  position: relative;
  z-index: 1;
}
.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}
.tab-content.active {
  display: block;
}

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

/* Headers */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}
.page-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
}

/* Buttons */
.btn {
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  transition: 0.2s;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-secondary {
  background: var(--white);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-danger {
  background: #fee2e2;
  color: var(--danger);
}
.btn-danger:hover {
  background: #fecaca;
}
.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}
.btn-icon {
  padding: 0.5rem;
  border-radius: 6px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--white);
  padding: 1.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  gap: 1rem;
}
.icon-box {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}
.blue {
  background: #e0e7ff;
  color: var(--primary);
}
.green {
  background: #dcfce7;
  color: var(--success);
}
.orange {
  background: #ffedd5;
  color: var(--warning);
}
.stat-number {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 0.2rem;
}

/* Tables */
.table-container {
  background: var(--white);
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th,
.data-table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: #f1f5f9;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Badges */
.badge {
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.bg-draft {
  background: #f1f5f9;
  color: var(--text-muted);
}
.bg-sent {
  background: #dcfce7;
  color: var(--success);
}
.bg-interview {
  background: #e0e7ff;
  color: var(--primary);
}
.bg-rejected {
  background: #fee2e2;
  color: var(--danger);
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 1rem;
}
.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
  font-size: 0.9rem;
}
.form-input {
  width: 100%;
  padding: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: 0.2s;
}
.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.template-editor {
  background: var(--white);
  padding: 1.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

/* Chips */
.chips {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.chip {
  background: #f1f5f9;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  border: 1px solid transparent;
}
.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Settings */
.settings-card {
  background: var(--white);
  padding: 2rem;
  border-radius: 12px;
  margin-bottom: 2rem;
}
.settings-card h3 {
  margin-bottom: 0.5rem;
}
.text-muted {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}
.danger-zone {
  border: 1px solid #fee2e2;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}
.modal-content {
  background: white;
  padding: 2rem;
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  animation: slideUp 0.3s ease;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.close {
  font-size: 1.5rem;
  cursor: pointer;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 1.5rem;
}

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

/* --- FIX INPUT & NEW TEMPLATE STYLES --- */

/* Memaksa Input agar Selalu Bisa Diketik */
input,
textarea {
  position: relative;
  z-index: 10; /* Pastikan di atas elemen background */
  pointer-events: auto !important;
}

/* Styling Baru Template Editor */
.info-box {
  background: #eff6ff;
  border: 1px solid #dbeafe;
  color: #1e40af;
  padding: 1rem;
  border-radius: 8px;
  display: flex;
  gap: 12px;
  align-items: start;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}
.info-box i {
  font-size: 1.2rem;
  margin-top: 2px;
}

.variable-toolbar {
  background: #f8fafc;
  padding: 1rem;
  border-radius: 8px;
  border: 1px dashed #cbd5e1;
  margin-bottom: 1.5rem;
}

.toolbar-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: #64748b;
  margin-bottom: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  background: white;
  border: 1px solid #e2e8f0;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.chip:hover {
  background: #f1f5f9;
  border-color: #4f46e5;
  color: #4f46e5;
  transform: translateY(-1px);
}

.chip i {
  color: #4f46e5;
  opacity: 0.7;
}

/* Membuat input terlihat lebih fokus */
.subject-input {
  font-weight: 600;
  font-size: 1rem;
}
.body-input {
  line-height: 1.6;
  font-family: "Inter", sans-serif;
}

/* --- PERBAIKAN BUG TIDAK BISA MENGETIK --- */

/* 1. Paksa area konten agar punya konteks layer sendiri */
.main-content {
  isolation: isolate;
  z-index: 1;
}

/* 2. Paksa Input & Textarea agar selalu di layer paling atas & bisa diklik */
.form-input,
textarea#tpl-body,
input#tpl-subject {
  position: relative !important;
  z-index: 9999 !important; /* Layer prioritas super tinggi */
  pointer-events: auto !important; /* Paksa mouse agar bisa klik */
  background-color: #ffffff !important; /* Pastikan background putih */
}

/* 3. Pastikan tombol chip juga bisa diklik */
.chip {
  position: relative;
  z-index: 9999;
  pointer-events: auto;
}

/* 4. Pastikan tab lain benar-benar hilang saat tidak aktif */
.tab-content {
  display: none !important; /* Paksa hilang */
}
.tab-content.active {
  display: block !important; /* Paksa muncul hanya yg aktif */
  position: relative;
  z-index: 10;
}

/* --- PRESET BUTTONS STYLES --- */
.preset-container {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.preset-buttons {
  display: flex;
  gap: 10px;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.btn-preset {
  background: white;
  border: 1px solid #cbd5e1;
  color: #475569;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-preset:hover {
  background: #f8fafc;
  border-color: #4f46e5;
  color: #4f46e5;
  transform: translateY(-2px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.btn-preset i {
  color: #4f46e5;
}

/* --- SWEETALERT MOBILE FIX --- */
@media (max-width: 600px) {
  /* Kecilkan ukuran box popup */
  div:where(.swal2-container) div:where(.swal2-popup) {
    width: 85% !important; /* Lebar hanya 85% layar */
    padding: 1.2rem !important; /* Kurangi jarak dalam */
    font-size: 0.8rem !important; /* Kecilkan basis font */
  }

  /* Kecilkan judul */
  div:where(.swal2-container) h2:where(.swal2-title) {
    font-size: 1.3rem !important;
    margin-bottom: 0.5rem !important;
  }

  /* Kecilkan teks isi */
  div:where(.swal2-container) div:where(.swal2-html-container) {
    font-size: 0.95rem !important;
    margin: 0.5rem 0 !important;
  }

  /* Rapikan tombol agar tidak terlalu gemuk */
  div:where(.swal2-container) button.swal2-styled {
    padding: 0.5rem 1rem !important;
    font-size: 0.9rem !important;
    margin: 0.2rem 0.5rem !important;
  }

  /* Ikon (tanda tanya/centang) diperkecil sedikit */
  div:where(.swal2-container) .swal2-icon {
    width: 3.5rem !important;
    height: 3.5rem !important;
    margin-top: 0.5rem !important;
  }
}

/* --- DARK MODE VARIABLES --- */
body.dark-mode {
  --bg: #0f172a; /* Background Utama (Very Dark Blue) */
  --white: #1e293b; /* Card Background (Dark Blue) */
  --text: #f1f5f9; /* Teks Utama (White) */
  --text-muted: #94a3b8; /* Teks Pudar (Gray) */
  --border: #334155; /* Garis Batas */
}

/* Fix Khusus Elemen saat Dark Mode */
body.dark-mode .nav-item:hover,
body.dark-mode .nav-item.active {
  background: #334155;
  color: #818cf8;
}

body.dark-mode .brand {
  color: #818cf8;
}

/* Override Warna Input/Textarea agar tidak putih silau */
body.dark-mode input,
body.dark-mode textarea,
body.dark-mode select,
body.dark-mode .chip,
body.dark-mode .btn-secondary,
body.dark-mode .btn-preset {
  background-color: #334155 !important;
  color: #f1f5f9 !important;
  border-color: #475569 !important;
}

body.dark-mode .chip:hover,
body.dark-mode .btn-preset:hover {
  background-color: #475569 !important;
}

/* Fix Warna Tabel di Dark Mode */
body.dark-mode .data-table th {
  background: #0f172a;
  color: #cbd5e1;
}
body.dark-mode tr:hover {
  background-color: #334155; /* Efek hover baris tabel */
}

/* Fix Modal Popup */
body.dark-mode .modal-content {
  background: #1e293b;
  border: 1px solid #475569;
}

/* --- DARK MODE ULTIMATE FIXES (Tambahkan di paling bawah app.css) --- */

/* 1. Fix Popup SweetAlert (Biar tidak putih silau) */
body.dark-mode .swal2-popup {
  background: #1e293b !important; /* Warna Card Gelap */
  color: #f1f5f9 !important; /* Teks Putih */
  border: 1px solid #334155; /* Border tipis */
}
body.dark-mode .swal2-title,
body.dark-mode .swal2-html-container,
body.dark-mode .swal2-content {
  color: #f1f5f9 !important;
}

/* 2. Fix Semua Card Putih (Statistik, Settings, Template Editor) */
body.dark-mode .stat-card,
body.dark-mode .settings-card,
body.dark-mode .template-editor,
body.dark-mode .table-container,
body.dark-mode .preset-buttons .btn-preset {
  background-color: #1e293b !important;
  border-color: #334155 !important;
  color: #f1f5f9 !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3) !important;
}

/* 3. Fix List "Aktivitas Terakhir" di Dashboard */
body.dark-mode #recent-list div {
  background: #1e293b !important;
  border-color: #334155 !important;
  color: #f1f5f9 !important;
}

/* 4. Fix Info Box (Kotak Biru Petunjuk) */
body.dark-mode .info-box {
  background: rgba(59, 130, 246, 0.15) !important; /* Biru transparan gelap */
  border-color: #1e3a8a !important;
  color: #bfdbfe !important; /* Teks biru muda terang */
}

/* 5. Fix Toolbar Shortcode (Area Tombol Chip) */
body.dark-mode .variable-toolbar {
  background: #0f172a !important; /* Lebih gelap dari card */
  border-color: #334155 !important;
}
body.dark-mode .toolbar-label {
  color: #94a3b8 !important;
}

/* 6. Fix Tampilan Mobile (Card Tabel & Navigasi) */
@media (max-width: 768px) {
  /* Kartu Tabel di Mobile */
  body.dark-mode .data-table tr {
    background: #1e293b !important;
    border-color: #334155 !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
  }

  /* Garis pemisah antar data di mobile */
  body.dark-mode .data-table td {
    border-bottom-color: #334155 !important;
    color: #f1f5f9 !important;
  }

  /* Label kolom (misal: "Perusahaan:") */
  body.dark-mode .data-table td::before {
    color: #94a3b8 !important;
  }

  /* Header & Navigasi Bawah Mobile */
  body.dark-mode .sidebar,
  body.dark-mode .nav-menu {
    background: #1e293b !important;
    border-color: #334155 !important;
    border-top-color: #334155 !important;
  }

  /* Tombol Aksi (Garis putus-putus) */
  body.dark-mode .data-table td:last-child {
    border-top-color: #475569 !important;
  }
}

/* --- FIX FINAL: INPUT SUBJECT & BODY GELAP --- */

/* Kita targetkan ID secara spesifik agar lebih kuat dari aturan sebelumnya */
body.dark-mode input#tpl-subject,
body.dark-mode textarea#tpl-body,
body.dark-mode .form-input,
body.dark-mode input[type="text"],
body.dark-mode input[type="email"],
body.dark-mode input[type="url"],
body.dark-mode select {
  background-color: #1e293b !important; /* Biru Gelap (Card Color) */
  color: #f1f5f9 !important; /* Teks Putih Terang */
  border: 1px solid #475569 !important; /* Border Abu Gelap */
}

/* Ubah warna teks placeholder (teks samar contoh) */
body.dark-mode ::placeholder {
  color: #64748b !important;
  opacity: 1;
}

/* Efek saat diklik/fokus */
body.dark-mode input:focus,
body.dark-mode textarea:focus {
  border-color: #818cf8 !important; /* Indigo Terang */
  background-color: #0f172a !important; /* Lebih gelap sedikit saat ngetik */
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2) !important;
}

/* Fix List Aktivitas Dashboard yang masih putih */
body.dark-mode #recent-list,
body.dark-mode #recent-list > div {
  background-color: #1e293b !important;
  color: #f1f5f9 !important;
  border-color: #334155 !important;
}

/* --- TEMPLATE LIVE PREVIEW STYLES --- */

/* Container Controls */
.template-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 10px;
}
.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-preset-mini {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}
.btn-preset-mini:hover {
  background: #e0e7ff;
  color: #4f46e5;
  border-color: #4f46e5;
}

/* Split View Grid */
.editor-split-view {
  display: grid;
  grid-template-columns: 1fr 1fr; /* Bagi 2 kolom sama besar */
  gap: 1.5rem;
  height: calc(100vh - 250px); /* Isi sisa tinggi layar */
  min-height: 500px;
}

/* Pane Styles */
.editor-pane {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: 100%;
}

.pane-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  color: #64748b;
  font-size: 0.85rem;
  margin-bottom: 5px;
}

/* Input Area */
.input-pane textarea {
  flex: 1; /* Isi sisa ruang */
  resize: none;
  font-family: "Courier New", monospace; /* Font coding biar jelas bedanya */
  font-size: 0.9rem;
}

.mini-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap; /* Biarkan memanjang ke samping (scrollable) */
  overflow-x: auto; /* Scroll samping jika layar sempit */
  padding-bottom: 5px; /* Ruang untuk scrollbar */
  -webkit-overflow-scrolling: touch; /* Scroll halus di iPhone */
  margin-top: 5px;
  width: 100%;
}
/* Sembunyikan scrollbar tapi tetap bisa discroll */
.mini-toolbar::-webkit-scrollbar {
  height: 4px;
}
.mini-toolbar::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.mini-chip {
  background: #e0e7ff;
  color: #4338ca;
  padding: 6px 10px; /* Lebih besar sedikit agar mudah ditekan jari */
  border-radius: 20px; /* Bentuk Pill (Lonjong) */
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap; /* Teks jangan turun baris */
  display: inline-flex;
  align-items: center;
  gap: 6px; /* Jarak ikon dan teks */
  border: 1px solid transparent;
  transition: all 0.2s;
}

.mini-chip:hover {
  background: #4f46e5;
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(79, 70, 229, 0.2);
}

.mini-chip:active {
  transform: translateY(0);
}

/* Mode Gelap untuk Chip */
body.dark-mode .mini-chip {
  background: #312e81;
  color: #a5b4fc;
  border-color: #4338ca;
}
body.dark-mode .mini-chip:hover {
  background: #4f46e5;
  color: white;
  border-color: #4f46e5;
}

/* Preview Area (Gmail Lookalike) */
.gmail-preview {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1.5rem;
  height: 100%;
  overflow-y: auto;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.gmail-header {
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  font-size: 1.1rem;
}
.gmail-body {
  white-space: pre-wrap; /* Agar enter terbaca */
  line-height: 1.6;
  color: #334155;
}

/* --- DARK MODE ADJUSTMENTS --- */
body.dark-mode .template-controls,
body.dark-mode .gmail-preview {
  background: #1e293b !important;
  border-color: #334155 !important;
}
body.dark-mode .gmail-body {
  color: #f1f5f9;
}
body.dark-mode .gmail-header {
  border-bottom-color: #334155;
}
body.dark-mode .btn-preset-mini {
  background: #334155;
  color: #fff;
  border-color: #475569;
}
body.dark-mode .mini-chip {
  background: #312e81;
  color: #a5b4fc;
}

/* --- MOBILE HEADER STYLES (Default: Hidden di Desktop) --- */
.mobile-header {
  display: none; /* Sembunyikan di desktop */
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

/* --- FILTER TOOLBAR STYLES --- */
.filter-toolbar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  background: var(--white);
  padding: 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  flex-wrap: wrap; /* Agar rapi di HP */
  align-items: center;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.filter-group select,
.filter-group input {
  border: 1px solid var(--border);
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.9rem;
  outline: none;
  color: var(--text);
  background: var(--bg);
}

/* Dark Mode Support untuk Filter */
body.dark-mode .filter-toolbar {
  background: #1e293b;
  border-color: #334155;
}
body.dark-mode .filter-group select,
body.dark-mode .filter-group input {
  background: #0f172a !important;
  border-color: #334155 !important;
  color: #f1f5f9 !important;
}

/* --- COMPACT MODAL STYLES (Agar rapi di HP) --- */

/* Grid 2 Kolom */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Mengurangi Margin di dalam Modal agar tidak boros tempat */
.modal-content .form-group.compact {
  margin-bottom: 0.8rem; /* Lebih rapat dari default 1rem */
}

/* Perkecil ukuran font label dan input sedikit di modal */
.modal-content label {
  font-size: 0.85rem;
  margin-bottom: 4px;
  display: block;
}

.modal-content .form-input {
  padding: 0.6rem; /* Padding lebih kecil */
  font-size: 0.9rem;
}

/* --- FITUR CETAK / PDF GENERATOR --- */

@media print {
  /* 1. Sembunyikan Semua Elemen UI Aplikasi */
  body * {
    visibility: hidden;
  }

  .sidebar,
  .mobile-header,
  .mini-toolbar,
  .template-controls,
  .pane-header,
  .input-pane,
  .nav-menu {
    display: none !important;
  }

  /* 2. Tampilkan Hanya Konten Surat */
  #preview-body,
  #preview-body * {
    visibility: visible;
  }

  /* 3. Atur Layout Kertas A4 */
  #preview-body {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 2.5cm; /* Margin standar surat resmi */
    background: white;
    color: black;
    font-family: "Times New Roman", serif; /* Font resmi surat */
    font-size: 12pt;
    line-height: 1.5;
    border: none;
    white-space: pre-wrap; /* Jaga enter/paragraf */
  }

  /* Hilangkan background gelap jika user sedang mode gelap */
  body {
    background: white !important;
    color: black !important;
  }
}

/* Styling Modal Content di HP */
@media (max-width: 768px) {
  .modal-content {
    padding: 1.5rem; /* Kurangi padding container */
    width: 95%; /* Lebarkan dikit */
    max-height: 90vh; /* Pastikan tidak melebihi tinggi layar */
    overflow-y: auto; /* Scroll jika masih kepanjangan */
  }

  .modal-header {
    margin-bottom: 1rem;
  }

  /* Tombol simpan tetap terlihat */
  .modal-actions {
    margin-top: 1rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
  }
}

/* Mobile Adjustment */
@media (max-width: 768px) {
  .filter-toolbar {
    flex-direction: column;
    align-items: stretch; /* Tombol jadi lebar penuh */
    gap: 10px;
  }
  .filter-group {
    width: 100%;
  }
  .filter-group select,
  .filter-group input {
    width: 100%;
  }
}

/* --- PERBAIKAN FINAL MENU MOBILE (APP.CSS) --- */
@media (max-width: 768px) {
  /* 1. Header & Layout Utama */
  .app-container {
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  .mobile-header {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    height: 60px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
  }

  .main-content {
    margin-top: 60px; /* Ruang untuk Header Atas */
    margin-bottom: 80px; /* Ruang untuk Menu Bawah */
    padding: 1rem;
    height: auto;
    overflow-y: auto;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* 2. SIDEBAR MENJADI BOTTOM NAV */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px; /* Tinggi tetap */
    background: var(--white);
    border-top: 1px solid var(--border);
    border-right: none;
    padding: 0; /* Hapus padding agar full width */
    margin: 0;
    z-index: 1000;

    /* Layout Horizontal */
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between;
    align-items: center;
  }

  /* 3. SEMBUNYIKAN ELEMEN DESKTOP (SOLUSI INTI) */
  /* Kita target langsung class-nya agar pasti hilang */
  .sidebar .brand,
  .sidebar .theme-toggle-container,
  .sidebar .user-info-mini,
  .sidebar-brand,
  .sidebar-toggle {
    display: none !important; /* Paksa hilang */
  }

  /* 4. KONTAINER MENU (NAV-MENU) */
  .nav-menu {
    display: flex !important;
    flex-direction: row !important; /* Wajib baris ke samping */
    width: 100%;
    height: 100%;
    justify-content: space-around; /* Bagi jarak rata */
    align-items: center;
    padding: 0;
    margin: 0;
    gap: 0;
  }

  /* 5. ITEM MENU (TOMBOL) */
  .nav-item {
    flex: 1; /* Lebar sama rata */
    display: flex;
    flex-direction: column !important; /* Ikon atas, Teks bawah */
    justify-content: center;
    align-items: center;
    height: 100%;
    padding: 5px 0;
    margin: 0;
    border-radius: 0;
    font-size: 0.7rem; /* Teks kecil */
    color: var(--text-muted);
    background: transparent !important; /* Hapus background ungu desktop */
    text-align: center;
  }

  /* Ikon Menu */
  .nav-item i {
    font-size: 1.3rem;
    margin-bottom: 4px;
    display: block;
  }

  /* Pastikan teks muncul di bawah ikon */
  .nav-item span,
  .nav-text {
    display: block !important;
    font-size: 10px;
  }

  /* Efek Aktif Mobile (Warna Ikon Saja) */
  .nav-item.active {
    background: transparent !important; /* Pastikan transparan */
    color: var(--primary) !important;
    box-shadow: none !important;
  }
  .nav-item:hover {
    background: transparent !important;
    color: var(--primary);
  }

  /* 6. Fix Template Layout (Agar tidak melebar) */
  .editor-split-view {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem;
    height: auto !important;
  }
  .input-pane textarea,
  .input-pane input {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  .gmail-preview {
    min-height: 300px;
    max-height: 500px;
    overflow-y: auto;
  }

  /* 7. Fix Tabel & Badge */
  .data-table thead {
    display: none;
  }
  .data-table tr,
  .data-table td,
  .data-table tbody,
  .data-table {
    display: block;
    width: 100%;
  }
  .data-table tr {
    margin-bottom: 1rem;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
  }
  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* Ubah ke flex-start agar teks panjang rapi */
    text-align: right;
    padding: 0.8rem 0; /* Tambah padding sedikit */
    border-bottom: 1px solid #f1f5f9;
  }
  .data-table td:last-child {
    border-bottom: none;
    border-top: 1px dashed var(--border);
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
  }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.85rem;
  }
  .data-table td:last-child::before {
    display: none;
  }
  .badge {
    flex-shrink: 0 !important;
    white-space: nowrap;
    display: inline-block;
  }

  /* 8. Dark Mode Mobile Fix */
  body.dark-mode .mobile-header,
  body.dark-mode .sidebar {
    background: #1e293b !important;
    border-color: #334155 !important;
  }

  /* --- FIX KHUSUS BAGIAN TEMPLATE (MOBILE) --- */

  /* 1. Ubah Layout Jadi Tumpuk (Stack) */
  .editor-split-view {
    display: flex !important;
    flex-direction: column-reverse !important; /* Preview di Atas, Editor di Bawah (Opsional) atau column biasa */
    /* Kita pakai column biasa: Input Atas, Preview Bawah */
    flex-direction: column !important;
    gap: 2rem;
    height: auto !important; /* Matikan tinggi layar penuh desktop */
    min-height: auto;
  }

  /* 2. Atur Lebar Input & Preview */
  .input-pane,
  .preview-pane {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* 3. Cegah Input Melebar Keluar Layar */
  .input-pane textarea,
  .input-pane input {
    width: 100% !important;
    max-width: 100vw !important; /* PENTING: Batasi selebar layar */
    box-sizing: border-box !important; /* Hitung padding dalam lebar */
  }

  /* 4. Tinggi Area Ketik & Preview */
  .input-pane textarea {
    min-height: 250px; /* Area ketik cukup luas */
  }

  .gmail-preview {
    background: var(--bg); /* Sedikit beda warna biar kontras */
    min-height: 300px;
    max-height: 500px; /* Batasi tinggi agar tidak scroll kepanjangan */
    overflow-y: auto; /* Scroll jika konten panjang */
    border: 1px dashed var(--border); /* Garis putus-putus biar kelihatan ini preview */
  }

  /* 5. Rapikan Tombol Kontrol di Atas */
  .template-controls {
    background: transparent !important; /* Hilangkan kotak background tebal */
    border: none !important; /* Hilangkan garis pinggir */
    padding: 0 !important; /* Hilangkan padding kontainer */
    gap: 1.5rem; /* Beri jarak lega antar grup */
    margin-bottom: 1rem;
  }

  .control-group {
    display: flex;
    flex-direction: row; /* Default baris */
    flex-wrap: wrap; /* Biarkan turun ke bawah */
    gap: 10px;
    align-items: center;
  }

  .control-group label {
    width: 100%; /* Paksa label mengambil satu baris penuh */
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  #preview-selector {
    width: 100% !important;
    padding: 12px; /* Area sentuh lebih besar */
    border-radius: 8px;
    background: var(--white);
    border: 1px solid var(--border);
    font-size: 0.9rem;
  }

  .btn-preset-mini {
    flex: 1; /* Bagi rata lebar tombol */
    padding: 10px 5px; /* Padding enak */
    text-align: center;
    font-size: 0.8rem;
    border-radius: 8px;
    background: var(--white);
    border: 1px solid var(--border);
    white-space: nowrap; /* Teks jangan turun baris */
    font-weight: 500;
  }

  /* Active/Hover State untuk Preset */
  .btn-preset-mini:active {
    background: #e0e7ff;
    border-color: var(--primary);
    color: var(--primary);
    transform: scale(0.98); /* Efek tekan */
  }

  /* Dark Mode Adjustment untuk Kontrol */
  body.dark-mode #preview-selector,
  body.dark-mode .btn-preset-mini {
    background-color: #1e293b !important; /* Warna Card Gelap */
    border-color: #334155 !important;
    color: #f1f5f9 !important;
  }
}
