/* NoteSmart V30: audit header, master-data cards, modal, dan laporan kertas responsif. */
html, body, #root {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: hidden !important;
}

/* Header mobile harus tetap terlihat dan stabil. */
@media (max-width: 768px) {
  #root header.md\:hidden,
  #root header.sticky,
  #root > div > header {
    display: block !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 60 !important;
    min-height: 64px !important;
    transform: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    backdrop-filter: blur(14px) !important;
    -webkit-backdrop-filter: blur(14px) !important;
  }
  #root header.md\:hidden > div,
  #root header.sticky > div {
    min-height: 64px !important;
  }
  #root main {
    padding-top: 16px !important;
  }
}

/* Semua halaman master data memakai layout kartu sejak render pertama di HP.
   Laporan dikecualikan karena memakai tampilan kertas. */
@media (max-width: 768px) {
  html.ns-page-kelas main table.ns-admin-card-table,
  html.ns-page-mapel main table.ns-admin-card-table,
  html.ns-page-guru main table.ns-admin-card-table,
  html.ns-page-siswa main table.ns-admin-card-table,
  html.ns-page-penugasan main table.ns-admin-card-table,
  html.ns-page-piket main table.ns-admin-card-table,
  html.ns-page-kalender main table.ns-admin-card-table,
  html.ns-page-users main table.ns-admin-card-table,
  html.ns-page-jp-master main table.ns-admin-card-table,
  html.ns-page-wa-logs main table.ns-admin-card-table,
  html.ns-page-audit main table.ns-admin-card-table {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    table-layout: auto !important;
  }

  html.ns-page-kelas main table.ns-admin-card-table thead,
  html.ns-page-mapel main table.ns-admin-card-table thead,
  html.ns-page-guru main table.ns-admin-card-table thead,
  html.ns-page-siswa main table.ns-admin-card-table thead,
  html.ns-page-penugasan main table.ns-admin-card-table thead,
  html.ns-page-piket main table.ns-admin-card-table thead,
  html.ns-page-kalender main table.ns-admin-card-table thead,
  html.ns-page-users main table.ns-admin-card-table thead,
  html.ns-page-jp-master main table.ns-admin-card-table thead,
  html.ns-page-wa-logs main table.ns-admin-card-table thead,
  html.ns-page-audit main table.ns-admin-card-table thead {
    display: none !important;
  }

  html.ns-page-kelas main table.ns-admin-card-table tbody,
  html.ns-page-mapel main table.ns-admin-card-table tbody,
  html.ns-page-guru main table.ns-admin-card-table tbody,
  html.ns-page-siswa main table.ns-admin-card-table tbody,
  html.ns-page-penugasan main table.ns-admin-card-table tbody,
  html.ns-page-piket main table.ns-admin-card-table tbody,
  html.ns-page-kalender main table.ns-admin-card-table tbody,
  html.ns-page-users main table.ns-admin-card-table tbody,
  html.ns-page-jp-master main table.ns-admin-card-table tbody,
  html.ns-page-wa-logs main table.ns-admin-card-table tbody,
  html.ns-page-audit main table.ns-admin-card-table tbody {
    display: block !important;
    width: 100% !important;
  }

  html.ns-page-kelas main table.ns-admin-card-table tr,
  html.ns-page-mapel main table.ns-admin-card-table tr,
  html.ns-page-guru main table.ns-admin-card-table tr,
  html.ns-page-siswa main table.ns-admin-card-table tr,
  html.ns-page-penugasan main table.ns-admin-card-table tr,
  html.ns-page-piket main table.ns-admin-card-table tr,
  html.ns-page-kalender main table.ns-admin-card-table tr,
  html.ns-page-users main table.ns-admin-card-table tr,
  html.ns-page-jp-master main table.ns-admin-card-table tr,
  html.ns-page-wa-logs main table.ns-admin-card-table tr,
  html.ns-page-audit main table.ns-admin-card-table tr {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 14px !important;
    padding: 16px !important;
    border-radius: 24px !important;
    border: 1px solid rgba(15, 23, 42, .08) !important;
    background: #fff !important;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .075) !important;
    transform: none !important;
    overflow: visible !important;
    contain: layout paint !important;
  }

  html.ns-page-kelas main table.ns-admin-card-table td,
  html.ns-page-mapel main table.ns-admin-card-table td,
  html.ns-page-guru main table.ns-admin-card-table td,
  html.ns-page-siswa main table.ns-admin-card-table td,
  html.ns-page-penugasan main table.ns-admin-card-table td,
  html.ns-page-piket main table.ns-admin-card-table td,
  html.ns-page-kalender main table.ns-admin-card-table td,
  html.ns-page-users main table.ns-admin-card-table td,
  html.ns-page-jp-master main table.ns-admin-card-table td,
  html.ns-page-wa-logs main table.ns-admin-card-table td,
  html.ns-page-audit main table.ns-admin-card-table td {
    display: grid !important;
    grid-template-columns: 116px minmax(0, 1fr) !important;
    gap: 10px !important;
    align-items: start !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    padding: 8px 0 !important;
    border: 0 !important;
    white-space: normal !important;
    overflow: visible !important;
    text-align: left !important;
    line-height: 1.35 !important;
    word-break: normal !important;
    overflow-wrap: anywhere !important;
  }

  html.ns-page-kelas main table.ns-admin-card-table td::before,
  html.ns-page-mapel main table.ns-admin-card-table td::before,
  html.ns-page-guru main table.ns-admin-card-table td::before,
  html.ns-page-siswa main table.ns-admin-card-table td::before,
  html.ns-page-penugasan main table.ns-admin-card-table td::before,
  html.ns-page-piket main table.ns-admin-card-table td::before,
  html.ns-page-kalender main table.ns-admin-card-table td::before,
  html.ns-page-users main table.ns-admin-card-table td::before,
  html.ns-page-jp-master main table.ns-admin-card-table td::before,
  html.ns-page-wa-logs main table.ns-admin-card-table td::before,
  html.ns-page-audit main table.ns-admin-card-table td::before {
    content: attr(data-ns-label);
    display: block !important;
    color: #6b7280 !important;
    font-size: 12px !important;
    line-height: 1.25 !important;
    font-weight: 900 !important;
    letter-spacing: .04em !important;
    text-transform: uppercase !important;
    white-space: normal !important;
  }

  /* Kolom utama menjadi judul kartu pada setiap master data. */
  html.ns-page-kelas main table.ns-admin-card-table td[data-ns-key="class_name"],
  html.ns-page-mapel main table.ns-admin-card-table td[data-ns-key="subject_name"],
  html.ns-page-guru main table.ns-admin-card-table td[data-ns-key="teacher_name"],
  html.ns-page-siswa main table.ns-admin-card-table td[data-ns-key="student_name"],
  html.ns-page-piket main table.ns-admin-card-table td[data-ns-key="teacher_name"],
  html.ns-page-kalender main table.ns-admin-card-table td[data-ns-key="title"],
  html.ns-page-users main table.ns-admin-card-table td[data-ns-key="name"],
  html.ns-page-jp-master main table.ns-admin-card-table td[data-ns-key="name"] {
    display: block !important;
    padding: 8px 0 14px !important;
    margin-bottom: 6px !important;
    font-size: 20px !important;
    line-height: 1.25 !important;
    font-weight: 900 !important;
    color: #111827 !important;
  }

  html.ns-page-kelas main table.ns-admin-card-table td[data-ns-key="class_code"],
  html.ns-page-kelas main table.ns-admin-card-table td[data-ns-key="active"],
  html.ns-page-mapel main table.ns-admin-card-table td[data-ns-key="default_duration_min"],
  html.ns-page-mapel main table.ns-admin-card-table td[data-ns-key="active"],
  html.ns-page-guru main table.ns-admin-card-table td[data-ns-key="teacher_code"],
  html.ns-page-guru main table.ns-admin-card-table td[data-ns-key="wa_number"],
  html.ns-page-guru main table.ns-admin-card-table td[data-ns-key="active"],
  html.ns-page-siswa main table.ns-admin-card-table td[data-ns-key="class_code"],
  html.ns-page-siswa main table.ns-admin-card-table td[data-ns-key="nis"],
  html.ns-page-siswa main table.ns-admin-card-table td[data-ns-key="parent_wa_number"],
  html.ns-page-siswa main table.ns-admin-card-table td[data-ns-key="active"],
  html.ns-page-users main table.ns-admin-card-table td[data-ns-key="role"],
  html.ns-page-users main table.ns-admin-card-table td[data-ns-key="active"] {
    background: #f8fafc !important;
    border-radius: 16px !important;
    padding: 10px 12px !important;
    margin: 6px 0 !important;
  }

  /* Tombol aksi selalu bisa diklik dan tidak tertutup kartu. */
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-key="actions"],
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-label="Aksi"] {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
    align-items: stretch !important;
    justify-content: stretch !important;
    padding-top: 14px !important;
    margin-top: 12px !important;
    border-top: 1px dashed #e5e7eb !important;
    position: relative !important;
    z-index: 30 !important;
    pointer-events: auto !important;
    overflow: visible !important;
    min-height: 62px !important;
  }
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-key="actions"]::before,
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-label="Aksi"]::before {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    text-align: left !important;
    pointer-events: none !important;
  }
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-key="actions"] button,
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-label="Aksi"] button,
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-key="actions"] a,
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-label="Aksi"] a {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 7px !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 46px !important;
    padding: 10px 12px !important;
    border-radius: 16px !important;
    border: 1px solid #dbe7e1 !important;
    background: #fff !important;
    color: #24523d !important;
    font-size: 13px !important;
    font-weight: 900 !important;
    line-height: 1.1 !important;
    white-space: nowrap !important;
    opacity: 1 !important;
    visibility: visible !important;
    position: relative !important;
    z-index: 35 !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
    transform: none !important;
    box-shadow: 0 4px 12px rgba(15, 23, 42, .05) !important;
  }
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-key="actions"] button svg,
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-label="Aksi"] button svg {
    width: 18px !important;
    height: 18px !important;
    pointer-events: none !important;
  }
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-key="actions"] button[data-testid*="-edit-"]::after,
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-label="Aksi"] button[data-testid*="-edit-"]::after { content: "Edit"; }
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-key="actions"] button[data-testid*="-delete-"],
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-label="Aksi"] button[data-testid*="-delete-"] {
    color: #b91c1c !important;
    background: #fff1f2 !important;
    border-color: #fecdd3 !important;
  }
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-key="actions"] button[data-testid*="-delete-"]::after,
  html:not(.ns-page-laporan) main table.ns-admin-card-table td[data-ns-label="Aksi"] button[data-testid*="-delete-"]::after { content: "Hapus"; }
}

/* Dialog harus muncul di viewport, bukan jauh di bawah posisi scroll. */
body.ns-modal-open-v30 {
  overscroll-behavior: contain !important;
}
[data-testid$="-modal"],
[data-testid="confirm-dialog"] {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  z-index: 2147483000 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)) !important;
  margin: 0 !important;
  transform: none !important;
  opacity: 1 !important;
  overflow: hidden !important;
  isolation: isolate !important;
}
[data-testid$="-modal"] > div.relative,
[data-testid="confirm-dialog"] > div.relative {
  margin: auto !important;
  width: min(100%, 42rem) !important;
  max-width: calc(100vw - 24px) !important;
  max-height: calc(100dvh - 24px) !important;
  overflow: hidden !important;
  border-radius: 24px !important;
  transform: none !important;
  animation: none !important;
}
[data-testid="confirm-dialog"] > div.relative { width: min(92vw, 28rem) !important; }
[data-testid$="-modal"] > div.relative > div:nth-child(2),
[data-testid="confirm-dialog"] > div.relative > div:nth-child(2) {
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
  max-height: calc(100dvh - 176px) !important;
  min-height: 0 !important;
}
[data-testid$="-modal"] > div.relative > div:last-child,
[data-testid="confirm-dialog"] > div.relative > div:last-child {
  position: sticky !important;
  bottom: 0 !important;
  background: #fff !important;
  flex-wrap: wrap !important;
  gap: 10px !important;
}
[data-testid$="-modal"] > div.relative > div:last-child button,
[data-testid="confirm-dialog"] > div.relative > div:last-child button {
  flex: 1 1 120px !important;
  min-height: 44px !important;
  justify-content: center !important;
}

/* Laporan: bukan kartu. Tampilkan seperti kertas laporan responsif. */
html.ns-page-laporan body {
  background: #eef2f6 !important;
}
html.ns-page-laporan #root main {
  max-width: 100% !important;
  padding-left: clamp(8px, 2.5vw, 32px) !important;
  padding-right: clamp(8px, 2.5vw, 32px) !important;
}
html.ns-page-laporan [data-testid="laporan-header"] {
  margin-bottom: 14px !important;
}
html.ns-page-laporan [data-testid="laporan-header"] + .ns-card,
html.ns-page-laporan .ns-report-control-v30 {
  border-radius: 18px !important;
  box-shadow: 0 6px 18px rgba(15, 23, 42, .06) !important;
}
html.ns-page-laporan .ns-report-paper-v30,
html.ns-page-laporan main > div.ns-animate-in > div.print\:hidden + div.ns-card {
  width: min(100%, 210mm) !important;
  min-height: min(297mm, calc(100svh - 180px)) !important;
  margin: 0 auto 24px !important;
  padding: clamp(12px, 3.5vw, 34px) !important;
  border-radius: 8px !important;
  border: 1px solid rgba(15, 23, 42, .12) !important;
  background: #fff !important;
  box-shadow: 0 18px 50px rgba(15, 23, 42, .16) !important;
  overflow: hidden !important;
}
html.ns-page-laporan .ns-report-paper-v30 > div,
html.ns-page-laporan main > div.ns-animate-in > div.print\:hidden + div.ns-card > div {
  max-width: 100% !important;
}
html.ns-page-laporan .ns-report-paper-v30 .overflow-x-auto,
html.ns-page-laporan main > div.ns-animate-in > div.print\:hidden + div.ns-card .overflow-x-auto {
  overflow-x: auto !important;
  overflow-y: visible !important;
  -webkit-overflow-scrolling: touch !important;
  width: 100% !important;
  max-width: 100% !important;
  border-radius: 0 !important;
}
html.ns-page-laporan table.report-table,
html.ns-page-laporan table[data-testid^="rpt-"] {
  display: table !important;
  table-layout: auto !important;
  width: 100% !important;
  min-width: max-content !important;
  max-width: none !important;
  border-collapse: collapse !important;
  border-spacing: 0 !important;
  background: #fff !important;
  font-size: clamp(9px, 2.2vw, 13px) !important;
  line-height: 1.25 !important;
}
html.ns-page-laporan table.report-table thead,
html.ns-page-laporan table[data-testid^="rpt-"] thead { display: table-header-group !important; }
html.ns-page-laporan table.report-table tbody,
html.ns-page-laporan table[data-testid^="rpt-"] tbody { display: table-row-group !important; }
html.ns-page-laporan table.report-table tr,
html.ns-page-laporan table[data-testid^="rpt-"] tr {
  display: table-row !important;
  width: auto !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  contain: none !important;
}
html.ns-page-laporan table.report-table th,
html.ns-page-laporan table.report-table td,
html.ns-page-laporan table[data-testid^="rpt-"] th,
html.ns-page-laporan table[data-testid^="rpt-"] td {
  display: table-cell !important;
  min-width: 0 !important;
  width: auto !important;
  max-width: none !important;
  padding: 4px 6px !important;
  border-width: 1px !important;
  white-space: normal !important;
  word-break: normal !important;
  overflow-wrap: break-word !important;
  text-align: inherit;
  vertical-align: middle !important;
}
html.ns-page-laporan table.report-table td::before,
html.ns-page-laporan table.report-table th::before,
html.ns-page-laporan table[data-testid^="rpt-"] td::before,
html.ns-page-laporan table[data-testid^="rpt-"] th::before {
  content: none !important;
  display: none !important;
}
@media (max-width: 480px) {
  html.ns-page-laporan .ns-report-paper-v30,
  html.ns-page-laporan main > div.ns-animate-in > div.print\:hidden + div.ns-card {
    width: 100% !important;
    min-height: 62svh !important;
    padding: 10px !important;
    border-radius: 6px !important;
  }
  html.ns-page-laporan table.report-table,
  html.ns-page-laporan table[data-testid^="rpt-"] {
    font-size: 9px !important;
  }
  html.ns-page-laporan table.report-table th,
  html.ns-page-laporan table.report-table td,
  html.ns-page-laporan table[data-testid^="rpt-"] th,
  html.ns-page-laporan table[data-testid^="rpt-"] td {
    padding: 3px 4px !important;
  }
}
@media print {
  html.ns-page-laporan body { background: white !important; }
  html.ns-page-laporan #root main { padding: 0 !important; }
  html.ns-page-laporan .ns-report-paper-v30,
  html.ns-page-laporan main > div.ns-animate-in > div.print\:hidden + div.ns-card {
    width: 100% !important;
    min-height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
  }
}
