/* K-PASS Cloud — tối ưu điện thoại & máy tính bảng */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  -webkit-tap-highlight-color: transparent;
}

/* Thanh user Cloud — chỉ trang thường, không áp dụng màn thi */
body:has(.kpass-user-bar):not(:has(.app-layout-exam)) .app-layout {
  padding-top: calc(2.65rem + env(safe-area-inset-top, 0px));
}

/* Desktop: thanh user góc phải, không full width */
@media (min-width: 769px) {
  .kpass-user-bar {
    left: auto;
    border-bottom-left-radius: 10px;
  }
}

body:has(.kpass-user-bar) .mobile-nav-wrap.is-open .app-nav {
  top: calc(6.9rem + env(safe-area-inset-top, 0px));
}

/* ===== Điện thoại ===== */
@media (max-width: 768px) {
  .kpass-user-bar {
    top: env(safe-area-inset-top, 0px);
    left: 0;
    right: 0;
    padding: 0.4rem max(0.75rem, env(safe-area-inset-left, 0px)) 0.4rem max(0.75rem, env(safe-area-inset-right, 0px));
    border-radius: 0;
    font-size: 0.8rem;
  }

  .kpass-user-bar-name {
    max-width: 42vw;
    font-size: 0.82rem;
  }

  .kpass-user-bar-link,
  .kpass-user-bar-logout {
    min-height: 36px;
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
    touch-action: manipulation;
  }

  /* Trang chủ — thẻ bộ đề */
  .set-grid,
  .home-set-grid {
    grid-template-columns: 1fr !important;
  }

  .set-card,
  .home-set-card {
    padding: 1rem !important;
  }

  .page-header .page-title {
    font-size: 1.35rem !important;
    line-height: 1.25;
  }

  .card {
    padding: 1rem !important;
  }

  /* Màn thi: xem exam-mobile-cloud.css (load sau file này) */

  /* Form thêm/sửa đề */
  .review-page,
  .import-page {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  .question-editor-card {
    padding: 0.85rem !important;
  }

  .answer-picker-block {
    padding: 0.75rem !important;
  }
}

/* ===== Máy tính bảng (dọc & ngang nhỏ) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
  .app-main {
    padding-left: max(1.25rem, env(safe-area-inset-left, 0px));
    padding-right: max(1.25rem, env(safe-area-inset-right, 0px));
  }

  .set-grid,
  .home-set-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .app-main-exam:has(.exam-screen) {
    padding: 0.75rem 1rem 1.25rem !important;
  }

  .exam-body {
    gap: 1rem !important;
  }

  .exam-sidebar {
    max-height: calc(100vh - 9rem) !important;
  }

  .page-header .page-title {
    font-size: 1.5rem !important;
  }
}

/* ===== Đăng nhập ===== */
@media (max-width: 768px) {
  .login-main {
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
  }
}

/* ===== Trang quản trị ===== */
@media (max-width: 1024px) {
  .admin-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem max(1rem, env(safe-area-inset-left, 0px)) 1rem max(1rem, env(safe-area-inset-right, 0px));
    padding-top: max(1rem, env(safe-area-inset-top, 0px));
  }

  .admin-header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .admin-header-actions .btn-secondary,
  .admin-header-actions button {
    flex: 1;
    min-height: 44px;
  }

  .admin-main {
    padding: 0.85rem max(0.85rem, env(safe-area-inset-left, 0px))
      calc(1rem + env(safe-area-inset-bottom, 0px)) max(0.85rem, env(safe-area-inset-right, 0px));
  }

  .admin-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding-left: max(0.85rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.85rem, env(safe-area-inset-right, 0px));
  }

  .admin-tab {
    flex: 0 0 auto;
    min-height: 44px;
    white-space: nowrap;
  }

  .admin-form-grid {
    grid-template-columns: 1fr;
  }

  .admin-card-head {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-card-head .btn-primary {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .perm-grid {
    grid-template-columns: 1fr;
  }

  .row-actions {
    flex-direction: column;
  }

  .row-actions button,
  .row-actions a {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .perm-dialog {
    width: calc(100vw - 1.5rem);
    max-width: none;
    margin: auto;
  }
}

@media (max-width: 768px) {
  .admin-card table {
    border: 0;
  }

  .admin-card table thead {
    display: none;
  }

  .admin-card table tbody tr {
    display: block;
    margin-bottom: 0.85rem;
    padding: 0.85rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
  }

  .admin-card table td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    border: 0;
    padding: 0.4rem 0;
    font-size: 0.9rem;
  }

  .admin-card table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #64748b;
    flex: 0 0 38%;
    font-size: 0.82rem;
  }

  .admin-card table td:last-child {
    flex-direction: column;
    padding-top: 0.65rem;
    margin-top: 0.35rem;
    border-top: 1px dashed #cbd5e1;
  }

  .admin-card table td:last-child::before {
    margin-bottom: 0.35rem;
  }

  .perm-summary {
    max-width: none;
    text-align: right;
  }
}
