/* =====================================================================
   SIPENDUK - GLOBAL STYLES
   Palet terinspirasi lanskap desa: sawah, tanah, dan cahaya sore
   ===================================================================== */

:root {
  /* Warna utama: hijau hutan tua khas sawah & perbukitan */
  --color-primary: #1F4D3A;
  --color-primary-dark: #163829;
  --color-primary-light: #E3EDE6;

  /* Aksen: tembaga hangat, dipakai untuk highlight & CTA penting */
  --color-accent: #C97D3F;
  --color-accent-dark: #A8632D;
  --color-accent-light: #FBEBDC;

  --color-danger: #B3432B;
  --color-danger-dark: #8F3521;
  --color-danger-light: #F8E4DE;
  --color-success: #2D6A4F;
  --color-success-light: #E1EFE7;
  --color-warning: #B8842D;
  --color-warning-light: #F7EBD8;

  --color-text: #2B2620;
  --color-text-muted: #7A6F5F;
  --color-border: #E6DFD0;
  --color-bg: #F7F3E9;
  --color-surface: #FEFBF6;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-md: 0 2px 6px -1px rgba(43,38,32,0.1), 0 1px 2px -1px rgba(43,38,32,0.06);
  --shadow-lg: 0 8px 16px -4px rgba(43,38,32,0.16), 0 2px 6px -2px rgba(43,38,32,0.1);
  --shadow-xl: 0 16px 28px -6px rgba(31,77,58,0.22), 0 4px 10px -4px rgba(31,77,58,0.14);
  --transition: all 0.2s ease;
  --z-modal: 9999;
  --z-loading: 10000;
  --z-toast: 10001;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .card-header h2, .card-header h3, .stat-value {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* =====================================================================
   LAYOUT DASAR
   ===================================================================== */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 264px;
  background: var(--color-primary-dark);
  color: #E8E4D8;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  transition: width 0.22s ease, transform 0.3s ease;
}

.sidebar-brand {
  padding: 22px 20px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 19px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  /* Signature: pola garis anyaman halus khas tikar/bilik desa, sangat subtle */
  background-image: repeating-linear-gradient(135deg, rgba(201,125,63,0.08) 0px, rgba(201,125,63,0.08) 1px, transparent 1px, transparent 12px);
}
.sidebar-brand-text { white-space: nowrap; overflow: hidden; opacity: 1; transition: opacity 0.15s ease; }

.sidebar-collapse-btn {
  margin-left: auto;
  background: rgba(255,255,255,0.08);
  border: none;
  color: #E8E4D8;
  width: 26px; height: 26px;
  border-radius: 50%;
  font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.sidebar-collapse-btn:hover { background: var(--color-accent); color: #fff; }

.sidebar-nav { padding: 14px 12px; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: #C9C2AF;
  font-size: 13.5px;
  margin-bottom: 2px;
  transition: var(--transition);
  border-left: 3px solid transparent;
  position: relative;
  white-space: nowrap;
}
.sidebar-nav a .nav-label { transition: opacity 0.1s ease; }

.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active {
  background: rgba(201,125,63,0.15);
  color: #fff;
  font-weight: 600;
  border-left: 3px solid var(--color-accent);
}
.sidebar-nav .nav-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #7A7360;
  padding: 20px 14px 8px;
  font-weight: 700;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-nav .nav-section-title:first-child { border-top: none; margin-top: 0; }

/* ===== MODE SIDEBAR DICIUTKAN (hanya ikon) ===== */
html.sidebar-is-collapsed .sidebar { width: 72px; }
html.sidebar-is-collapsed .sidebar-brand-text { opacity: 0; width: 0; }
html.sidebar-is-collapsed .sidebar-collapse-btn { transform: rotate(180deg); margin-left: 6px; }
html.sidebar-is-collapsed .sidebar-nav .nav-label { opacity: 0; width: 0; display: none; }
html.sidebar-is-collapsed .sidebar-nav .nav-section-title { opacity: 0; height: 1px; padding: 8px 0 0; margin-top: 8px; overflow: hidden; }
html.sidebar-is-collapsed .sidebar-nav a { justify-content: center; padding: 11px 0; }
html.sidebar-is-collapsed .main-content { margin-left: 72px; }

/* Tooltip nama menu saat sidebar diciutkan dan salah satu item di-hover */
html.sidebar-is-collapsed .sidebar-nav a { position: relative; }
html.sidebar-is-collapsed .sidebar-nav a:hover::after {
  content: attr(title);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 10px;
  background: var(--color-primary-dark);
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  white-space: nowrap;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}

.main-content {
  margin-left: 264px;
  flex: 1;
  min-width: 0;
  width: 100%;
  transition: margin-left 0.22s ease;
}

.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--color-text);
}

.page-content { padding: 24px; max-width: 1400px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}
.sidebar-overlay.show { display: block; }

/* =====================================================================
   CARD / PANEL
   ===================================================================== */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  box-shadow: 0 1px 2px rgba(43,38,32,0.04);
  transition: border-color 0.25s ease;
}
.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-radius: var(--radius-md) 0 0 0;
}
.card-header h2, .card-header h3 { font-size: 17px; font-weight: 600; color: var(--color-primary-dark); }
.card-body { padding: 22px; }

.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  padding: 20px 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s ease, transform 0.2s ease;
}
/* Garis dekoratif tipis di kiri, khas plakat/dokumen resmi - bukan shadow mengambang generik */
.stat-card::before {
  content: '';
  position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px;
  background: var(--color-accent); border-radius: 0 3px 3px 0;
}
.stat-card:hover { transform: translateY(-1px); border-color: var(--color-accent); }
.stat-card .icon-box {
  width: 46px; height: 46px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  margin-left: 6px;
}
.stat-card .stat-value { font-family: var(--font-display); font-size: 25px; font-weight: 600; line-height: 1.2; color: var(--color-primary-dark); }
.stat-card .stat-label { font-size: 12.5px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; margin-top: 1px; }

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

/* =====================================================================
   TOMBOL
   ===================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.btn-primary:hover { background: var(--color-accent-dark); border-color: var(--color-accent-dark); }
.btn-danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger-dark); border-color: var(--color-danger-dark); }
.btn-success { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.btn-outline { background: transparent; border-color: var(--color-primary-dark); color: var(--color-primary-dark); }
.btn-outline:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-icon { padding: 8px; width: 34px; height: 34px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-block { width: 100%; }

/* =====================================================================
   FORM
   ===================================================================== */

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--color-text); }
.form-label .required { color: var(--color-danger); }
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: var(--transition);
  background: var(--color-surface);
  color: var(--color-text);
}
.form-control:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-light);
}
.form-control.error { border-color: var(--color-danger); }
.form-error-text { color: var(--color-danger); font-size: 12px; margin-top: 4px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
select.form-control { appearance: none; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 14px center; padding-right: 36px; }

/* =====================================================================
   TABEL
   ===================================================================== */

.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 600px; }
table.data-table th {
  background: var(--color-primary-light);
  text-align: left;
  padding: 12px 14px;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-primary-dark);
  white-space: nowrap;
  border-bottom: 2px solid var(--color-primary);
}
table.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
table.data-table tbody tr:hover { background: var(--color-bg); }
.table-actions { display: flex; gap: 6px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
}
.badge::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-success { background: var(--color-success-light); color: var(--color-success); border-color: rgba(45,106,79,0.15); }
.badge-danger { background: var(--color-danger-light); color: var(--color-danger); border-color: rgba(179,67,43,0.15); }
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); border-color: rgba(184,132,45,0.15); }
.badge-info { background: var(--color-primary-light); color: var(--color-primary); border-color: rgba(31,77,58,0.15); }
.badge-gray { background: #EFEAE0; color: var(--color-text-muted); border-color: rgba(122,111,95,0.15); }

/* =====================================================================
   MODAL KONFIRMASI (YA/TIDAK) - DI TENGAH LAYAR
   Dipakai untuk SEMUA aksi: tambah, edit, hapus, logout, dll
   ===================================================================== */

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  padding: 16px;
}
.confirm-overlay.show { opacity: 1; visibility: visible; }

.confirm-box {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 400px;
  padding: 28px 24px 22px;
  text-align: center;
  transform: scale(0.9) translateY(10px);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.confirm-overlay.show .confirm-box { transform: scale(1) translateY(0); }

.confirm-icon {
  width: 60px; height: 60px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  font-size: 28px;
}
.confirm-icon.type-danger { background: var(--color-danger-light); color: var(--color-danger); }
.confirm-icon.type-warning { background: var(--color-warning-light); color: var(--color-warning); }
.confirm-icon.type-info { background: var(--color-primary-light); color: var(--color-primary); }
.confirm-icon.type-success { background: var(--color-success-light); color: var(--color-success); }

.confirm-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; color: var(--color-text); }
.confirm-message { font-size: 14px; color: var(--color-text-muted); margin-bottom: 22px; line-height: 1.55; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; padding: 11px; font-size: 14px; }

/* =====================================================================
   LOADING OVERLAY (REAL - menunggu proses AJAX selesai, bukan pajangan)
   ===================================================================== */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(1px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-loading);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}
.loading-overlay.show { opacity: 1; visibility: visible; }

.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--color-surface);
  padding: 28px 36px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--color-accent-light);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text { font-size: 13.5px; font-weight: 600; color: var(--color-text); }

/* Inline button loading state (spinner kecil di dalam tombol saat submit) */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border: 2.5px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.btn-outline.is-loading::after { border-color: rgba(31,77,58,0.25); border-top-color: var(--color-primary); }

/* =====================================================================
   TOAST NOTIFIKASI
   ===================================================================== */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
  width: calc(100% - 40px);
}
.toast {
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border-left: 4px solid var(--color-primary);
  transform: translateX(120%);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-size: 13.5px;
}
.toast.show { transform: translateX(0); }
.toast.toast-success { border-left-color: var(--color-success); }
.toast.toast-error { border-left-color: var(--color-danger); }
.toast.toast-warning { border-left-color: var(--color-warning); }
.toast-icon { font-size: 18px; flex-shrink: 0; }
.toast-close { margin-left: auto; background: none; border: none; color: var(--color-text-muted); font-size: 16px; }

/* =====================================================================
   MODAL FORM (tambah/edit data)
   ===================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 9000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  overflow-y: auto;
  padding: 40px 16px;
}
.modal-overlay.show { opacity: 1; visibility: visible; }
.modal-box {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 620px;
  transform: translateY(-16px);
  transition: transform 0.25s ease;
  margin: auto;
}
.modal-overlay.show .modal-box { transform: translateY(0); }
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--color-text-muted); width: 32px; height: 32px; border-radius: 50%; }
.modal-close:hover { background: var(--color-bg); }
.modal-body { padding: 22px; max-height: 65vh; overflow-y: auto; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 10px; }

/* =====================================================================
   EMPTY STATE
   ===================================================================== */
.empty-state { text-align: center; padding: 50px 20px; color: var(--color-text-muted); }
.empty-state .empty-icon { font-size: 44px; margin-bottom: 12px; opacity: 0.5; }

/* =====================================================================
   RESPONSIVE - MOBILE
   ===================================================================== */

@media (max-width: 968px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .topbar-menu-btn { display: block; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .page-content { padding: 16px; }
  .card-header { padding: 14px 16px; }
  .card-body { padding: 16px; }
  .grid-stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; flex-direction: column; text-align: center; }
  .confirm-box { padding: 22px 18px 18px; }
  .modal-body { padding: 16px; max-height: 60vh; }
  .modal-overlay { padding: 12px; align-items: center; }
  table.data-table { font-size: 12.5px; }
  table.data-table th, table.data-table td { padding: 10px; }
  .toast-container { top: auto; bottom: 16px; right: 16px; left: 16px; max-width: none; width: auto; }

  /* Mode collapse hanya untuk desktop - di mobile sidebar sudah punya mekanisme buka/tutup sendiri (overlay) */
  .sidebar-collapse-btn { display: none; }
  html.sidebar-is-collapsed .sidebar { width: 264px; }
  html.sidebar-is-collapsed .sidebar-brand-text { opacity: 1; width: auto; }
  html.sidebar-is-collapsed .sidebar-nav .nav-label { opacity: 1; width: auto; display: inline; }
  html.sidebar-is-collapsed .sidebar-nav .nav-section-title { opacity: 1; height: auto; padding: 20px 14px 8px; }
  html.sidebar-is-collapsed .sidebar-nav a { justify-content: flex-start; padding: 11px 14px; }
  html.sidebar-is-collapsed .main-content { margin-left: 0; }
}

@media (max-width: 480px) {
  .grid-stats { grid-template-columns: 1fr; }
  .card-header { flex-direction: column; align-items: stretch; }
  .confirm-actions { flex-direction: column-reverse; }
  .btn { font-size: 13.5px; }
}

/* =====================================================================
   DROPDOWN CETAK SURAT (pilihan dengan/tanpa logo)
   ===================================================================== */
.dropdown-cetak-menu a:hover { background: var(--color-primary-light); }