/**
 * SekolahLMS - Lapisan responsif (tablet & HP).
 * Dimuat setelah ui-system.css dan classroom.css.
 * Hanya berisi override; token & komponen dasar tetap di ui-system.css.
 */

/* =====================================================================
   1. PENJAGA LEBAR: item flex/grid tidak boleh selebar min-content-nya
   ===================================================================== */
main,
.sekolahlms-page-wrapper,
.lms-main-content,
.lms-dashboard-layout,
.lms-dashboard-content,
.g-reader-shell,
.g-reader-main,
.g-reader-aside {
  min-width: 0;
}

.g-container,
.lms-container {
  min-width: 0;
  width: 100%;
}

img,
svg,
video,
canvas {
  max-width: 100%;
  height: auto;
}

/* =====================================================================
   2. UTILITAS SPLIT: satu kolom dulu, dua kolom saat ada ruang
   ===================================================================== */
.g-split,
.g-split-wide,
.g-import-grid,
.g-cols-2,
.g-cols-narrow {
  display: grid;
  gap: 20px;
  align-items: start;
  grid-template-columns: minmax(0, 1fr);
}

.g-import-grid {
  align-items: stretch;
}

@media (min-width: 641px) {
  .g-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .g-cols-narrow {
    grid-template-columns: 140px minmax(0, 1fr);
  }
}

@media (min-width: 1025px) {
  .g-split {
    gap: 28px;
    grid-template-columns: minmax(0, 1.8fr) minmax(0, 1.2fr);
  }
  .g-split-wide {
    gap: 24px;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  }
  .g-import-grid {
    gap: 24px;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  }
}

/* =====================================================================
   3. HEADER & NAVIGASI
   ===================================================================== */
.lms-appbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 58px;
}

.lms-brand-block {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.lms-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

body.lms-drawer-open {
  overflow: hidden;
}

:root {
  --lms-header-h: 58px;
}

.lms-sidebar {
  width: min(280px, 86vw);
  top: calc(var(--lms-header-h) + 16px);
}

.g-timer-chip {
  top: calc(var(--lms-header-h) + 12px);
}

@media (max-width: 900px) {
  :root {
    --lms-header-h: 104px;
  }

  .lms-appbar-inner {
    flex-wrap: wrap;
    min-height: 0;
    padding-top: 8px;
    padding-bottom: 6px;
  }

  .lms-header-actions {
    order: 2;
  }

  .lms-top-nav {
    order: 3;
    flex: 0 0 100%;
    display: flex;
    gap: 4px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-light);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .lms-top-nav::-webkit-scrollbar {
    display: none;
  }

  .lms-top-nav .btn {
    flex: 0 0 auto;
    min-height: 40px;
  }

  .lms-avatar-btn span:nth-child(2) {
    display: none;
  }
}

/* Drawer & overlay mulai di bawah app bar agar header tetap terang. */
@media (max-width: 768px) {
  .lms-sidebar {
    top: var(--lms-header-h);
    bottom: 0;
    height: auto;
    max-height: none;
    border-radius: 0;
  }

  .lms-sidebar-backdrop {
    top: var(--lms-header-h);
    bottom: 0;
  }

  body.lms-drawer-open .g-appbar {
    z-index: 9999;
  }

  .lms-mobile-hamburger-btn[aria-expanded="true"] {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
  }
}

/* =====================================================================
   4. BERANDA: hero & statistik
   ===================================================================== */
.g-hero {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 20px;
}

.g-hero-main {
  min-width: 0;
}

.g-hero-stats {
  min-width: 0;
  width: 100%;
}

@media (min-width: 901px) {
  .g-hero {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 36px 40px;
  }
  .g-hero-stats {
    width: auto;
  }
}

/* =====================================================================
   5. HALAMAN MATERI (READER)
   ===================================================================== */
@media (max-width: 900px) {
  .g-reader-shell {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .g-reader-main {
    order: 1;
    padding: 20px 16px 40px;
  }

  .g-reader-article {
    padding: 24px 18px;
  }

  .g-reader-aside {
    order: 2;
    border-right: 0;
    border-top: 1px solid var(--g-border);
    max-height: none;
    overflow: visible;
  }

  .g-reader-aside a,
  .g-reader-aside a > span {
    min-width: 0;
  }

  .g-course-grid,
  .courses-list-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* =====================================================================
   6. HP: tipografi, spacing, target sentuh
   ===================================================================== */
@media (max-width: 640px) {
  .lms-container {
    padding-left: 16px;
    padding-right: 16px;
  }

  .g-container {
    padding: 20px 16px 44px;
  }

  .g-form-body {
    padding: 20px 16px;
  }

  .g-form-title {
    font-size: 22px;
  }

  .g-classroom-header {
    padding: 24px 20px;
  }

  .g-classroom-title {
    font-size: 24px;
  }

  .card {
    padding: 16px;
  }

  .lms-page-head > h1,
  .lms-page-head > h2 {
    font-size: 17px;
  }

  .lms-page-actions {
    gap: 8px;
  }

  .lms-page-actions > input[type="text"],
  .lms-page-actions > input[type="search"] {
    flex: 1 1 100%;
  }

  /* 16px agar iOS tidak melakukan zoom otomatis saat fokus. */
  .g-input,
  .g-select,
  .g-textarea,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="search"],
  input[type="url"],
  input[type="datetime-local"],
  select,
  textarea {
    font-size: 16px;
  }

  .btn-sm,
  .g-btn-sm {
    min-height: 40px;
  }

  .g-btn {
    white-space: normal;
    text-align: center;
  }

  .g-scroll-tabs .g-btn,
  .lms-top-nav .btn {
    white-space: nowrap;
  }

  .lms-att-rows > div {
    flex-wrap: wrap;
  }

  .g-topic-heading {
    flex-wrap: wrap;
    gap: 8px;
    font-size: 17px;
  }

  .g-material-row {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .g-material-row .g-material-title {
    flex: 1 0 calc(100% - 62px);
  }

  .lms-breadcrumb {
    min-width: 0;
    flex-wrap: nowrap;
    overflow: hidden;
  }

  .lms-breadcrumb > a {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .lms-breadcrumb-current {
    flex: 0 0 auto;
  }

  .att-name strong {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  #wpadminbar .display-name {
    display: none;
  }

  .kebab-btn {
    width: 40px;
    height: 40px;
  }

  .lms-sidebar-item {
    min-height: 44px;
  }

  .g-q-head {
    flex-wrap: wrap;
    gap: 8px;
  }

  .g-q-head > div {
    flex-wrap: wrap;
    min-width: 0;
  }

  .studio-question-card .g-radio-option {
    flex-wrap: wrap;
  }

  .studio-question-card .g-radio-option .g-chip {
    margin-left: 0;
  }
}

/* Toolbar WordPress (superadmin) tidak melebar di tablet & HP. */
@media (max-width: 782px) {
  #wpadminbar .display-name {
    display: none;
  }
}

.g-q-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.g-actions-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.g-actions-row .g-btn {
  white-space: nowrap;
}

.g-material-title {
  flex: 1;
  min-width: 0;
}

.g-scroll-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.g-scroll-tabs::-webkit-scrollbar {
  display: none;
}

.g-scroll-tabs > * {
  flex: 0 0 auto;
}

@media (max-width: 640px) {
  .g-hide-sm {
    display: none;
  }
}

/* =====================================================================
   7. TABEL: kartu bertumpuk di HP (butuh data-label per td)
   ===================================================================== */
@media (max-width: 640px) {
  .g-table-wrapper--stack {
    overflow: visible;
    border: 0;
  }

  .g-table-stack,
  .g-table-stack tbody,
  .g-table-stack tr,
  .g-table-stack td {
    display: block;
    width: 100%;
  }

  .g-table-stack thead {
    display: none;
  }

  .g-table-stack tr {
    background: var(--g-surface);
    border: 1px solid var(--g-border);
    border-radius: 10px;
    padding: 4px 14px;
    margin-bottom: 12px;
  }

  .g-table-stack td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 9px 0;
    border: 0;
    border-bottom: 1px dashed var(--g-border-subtle);
    height: auto;
    text-align: right;
  }

  .g-table-stack td:last-child {
    border-bottom: 0;
  }

  .g-table-stack td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 12px;
    font-weight: 600;
    color: var(--g-text-secondary);
    text-align: left;
  }

  .g-table-stack td[colspan] {
    justify-content: center;
    text-align: center;
  }

  .g-table-stack td[colspan]::before {
    content: none;
  }
}