/*==============================================================
  CERDAS CERMAT - Mobile Responsive CSS
  Dibuat untuk memastikan semua halaman responsif di perangkat HP
==============================================================*/

/* ============================================================
   GLOBAL: Viewport & Box Sizing
============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

img {
  max-width: 100%;
  height: auto;
}

/* ============================================================
   AUTH PAGES: Login, Register Ketua, Register Anggota, Token
   Fix: card width hardcoded (45rem / 50rem) tidak responsif di HP
============================================================ */
.card[style*="width: 45rem"],
.card[style*="width: 50rem"],
.card[style*="width:45rem"],
.card[style*="width:50rem"] {
  width: 100% !important;
  max-width: 500px;
}

/* Pastikan container auth tidak overflow */
.section.register .container {
  padding-left: 15px;
  padding-right: 15px;
}

.section.register .col-lg-4,
.section.register .col-md-6 {
  width: 100%;
  padding: 10px 15px;
}

/* Auth card full width di mobile */
@media (max-width: 576px) {
  .section.register {
    padding: 20px 10px !important;
  }

  .section.register .card {
    width: 100% !important;
    margin: 0 !important;
  }

  .section.register .card-body {
    padding: 15px !important;
  }

  .section.register .card-title {
    font-size: 1.2rem;
  }

  /* Token page */
  .token-card,
  .card.mb-3 {
    width: 100% !important;
  }
}

/* ============================================================
   SIDEBAR: Mobile Overlay & Behavior
============================================================ */
@media (max-width: 1199px) {
  /* Sidebar tersembunyi di kiri */
  .sidebar {
    left: -300px;
    z-index: 9999;
    transition: all 0.3s ease;
  }

  /* Saat toggle-sidebar aktif, sidebar muncul */
  .toggle-sidebar .sidebar {
    left: 0 !important;
  }

  /* Overlay gelap di belakang sidebar saat terbuka */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    transition: opacity 0.3s ease;
  }

  .toggle-sidebar .sidebar-overlay {
    display: block;
  }

  /* Main content tidak bergeser saat sidebar buka */
  #main,
  #footer {
    margin-left: 0 !important;
  }
}

/* ============================================================
   HEADER: Responsif di HP kecil
============================================================ */
@media (max-width: 576px) {
  .header {
    padding-left: 10px;
    padding-right: 10px;
  }

  .header .toggle-sidebar-btn {
    font-size: 26px;
    padding-left: 5px;
  }

  .logo img {
    max-height: 34px;
    margin-right: 4px;
  }

  .logo span {
    font-size: 18px;
  }

  .header-nav .nav-profile span {
    display: none; /* Sembunyikan nama user di HP kecil */
  }

  .header-nav .nav-icon {
    margin-right: 10px;
    font-size: 18px;
  }
}

/* ============================================================
   MAIN CONTENT: Padding & Margin di Mobile
============================================================ */
@media (max-width: 767px) {
  #main {
    padding: 15px 10px;
    margin-top: 60px;
    margin-left: 0 !important;
  }

  .pagetitle h1 {
    font-size: 18px;
  }

  .breadcrumb {
    font-size: 12px;
  }

  .card {
    margin-bottom: 15px;
  }

  .card-body {
    padding: 0 12px 12px 12px;
  }

  .card-title {
    font-size: 15px;
    padding: 15px 0 10px 0;
  }
}

/* ============================================================
   HALAMAN UJIAN: Layout Soal & Panel Nomor Soal
   Fix: col-lg-9 tidak ada padding untuk mobile
============================================================ */

/* Di mobile, susun kolom soal & panel nomor secara vertikal */
@media (max-width: 991px) {
  /* Panel nomor soal pindah ke atas soal */
  .section .row.g-3 > .col-lg-9,
  .section .row > .col-lg-9 {
    order: 2;
    flex: 0 0 100%;
    max-width: 100%;
  }

  .section .row > .col-lg-3 {
    order: 1;
    flex: 0 0 100%;
    max-width: 100%;
    margin-bottom: 10px;
  }

  /* Panel nomor soal - buat lebih ringkas */
  .col-lg-3 .card {
    margin-bottom: 10px;
  }

  .col-lg-3 .card .row.mx-auto {
    max-height: 150px;
    overflow-y: auto;
  }
}

/* Timer & flag icon di header soal */
@media (max-width: 576px) {
  #timer {
    font-size: 14px;
    font-weight: bold;
  }

  #flagIcon {
    font-size: 18px;
  }

  /* Gambar soal responsif */
  .card-body img[alt="Gambar Pertanyaan"],
  .card-body img[alt="Gambar Opsi Jawaban"] {
    max-width: 100% !important;
    width: 100%;
    height: auto;
    display: block;
    margin: 8px 0;
  }

  /* Pilihan jawaban lebih mudah diklik di HP */
  .form-check {
    padding: 8px 0 8px 30px;
  }

  .form-check-input {
    width: 1.2em;
    height: 1.2em;
    margin-top: 0.15em;
  }

  .custom-control-label {
    font-size: 14px;
    line-height: 1.5;
  }

  /* Tombol prev/next ujian */
  .card-text.d-flex.justify-content-end {
    justify-content: center !important;
    gap: 8px;
  }

  .card-text .btn {
    min-width: 44px;
    min-height: 44px; /* Touch target minimal 44px */
    font-size: 14px;
  }
}

/* ============================================================
   KOTAK NOMOR SOAL: Grid responsif
============================================================ */
@media (max-width: 576px) {
  /* Kotak nomor soal lebih kecil di HP */
  .col-4.m-0.d-flex.justify-content-center .card {
    width: 90% !important;
  }

  .col-4.m-0.d-flex.justify-content-center .card-body {
    padding: 6px 4px !important;
    font-size: 11px !important;
  }
}

/* ============================================================
   TABEL: Scroll horizontal di mobile
============================================================ */
@media (max-width: 768px) {
  .table-responsive-mobile {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Buat semua tabel dalam card bisa scroll horizontal */
  .card .table-responsive,
  .card table {
    min-width: 500px;
  }

  .card .table-responsive {
    overflow-x: auto;
  }

  /* DataTable wrapper */
  .dataTables_wrapper {
    overflow-x: auto;
  }

  /* Wrap tabel otomatis supaya tidak perlu ubah semua file */
  /* Kecualikan .dash-stat-card agar tidak overflow */
  .card-body:not(.dash-stat-card .card-body) {
    overflow-x: auto;
  }

  /* Prevent card-body overflow dari merusak layout */
  .card-body > .table,
  .card-body > table {
    min-width: 480px;
  }

  /* DataTable specific */
  #myTable,
  .datatable {
    min-width: 500px;
  }
}

/* ============================================================
   FORMS: Input lebih mudah digunakan di mobile
============================================================ */
@media (max-width: 576px) {
  .form-control,
  .form-select {
    font-size: 16px; /* Mencegah auto-zoom di iOS */
    min-height: 44px; /* Touch target */
  }

  .btn {
    min-height: 44px;
    font-size: 15px;
  }

  /* Input group untuk password */
  .input-group .btn-show-password,
  .input-group .btn-show-password-konfirmasi {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ============================================================
   DASHBOARD: Cards responsif
============================================================ */
@media (max-width: 576px) {
  .dashboard .info-card {
    padding: 10px;
  }

  .dashboard .info-card h6 {
    font-size: 22px;
  }

  .dashboard .card-icon {
    width: 48px;
    height: 48px;
    font-size: 24px;
  }
}

/* ============================================================
   LANDING PAGE: Perbaikan responsif
============================================================ */
@media (max-width: 768px) {
  /* Navbar logo di landing page */
  .navbar-brand img {
    height: 32px !important;
  }

  /* Hero section */
  .hero-header {
    padding: 100px 15px 60px !important;
  }

  .hero-header h1 {
    font-size: 2rem !important;
  }

  .hero-header h2 {
    font-size: 1.2rem !important;
  }
}

/* ============================================================
   MODAL: Responsif di HP
============================================================ */
@media (max-width: 576px) {
  .modal-dialog {
    margin: 10px;
    max-width: calc(100% - 20px);
  }

  .modal-body {
    padding: 15px;
  }
}

/* ============================================================
   ALERT & BADGE
============================================================ */
@media (max-width: 576px) {
  .alert {
    font-size: 13px;
    padding: 10px 12px;
  }
}

/* ============================================================
   UTILITY: Touch-friendly spacing
============================================================ */
@media (max-width: 576px) {
  /* Dropdown items lebih mudah diklik */
  .dropdown-item {
    padding: 12px 15px !important;
    font-size: 15px !important;
  }

  /* Nav links di sidebar */
  .sidebar-nav .nav-link {
    padding: 12px 15px;
    font-size: 14px;
  }

  .sidebar-nav .nav-content a {
    padding: 12px 0 12px 35px;
  }
}

/* ============================================================
   PENJADWALAN PESERTA: Card jadwal responsif
============================================================ */
@media (max-width: 576px) {
  .card-body .btn-sm {
    width: 100%;
    margin-top: 8px;
    padding: 10px;
    font-size: 14px;
  }

  .card-body .btn.btn-danger[disabled] {
    font-size: 12px;
    white-space: normal;
    line-height: 1.4;
    height: auto;
    padding: 8px 12px;
  }
}

/* ============================================================
   PRINT: Hapus sidebar saat print
============================================================ */
@media print {
  .sidebar,
  .header,
  .back-to-top {
    display: none !important;
  }

  #main {
    margin-left: 0 !important;
    margin-top: 0 !important;
  }
}
