/* ════════════════════════════════════════════════════════════════
   NAN2-BASE.CSS
   Reset · Typography · Body · Links · Utility helpers
   ต้อง load หลัง nan2-variables.css
   ════════════════════════════════════════════════════════════════ */

/* ── Google Fonts: Sarabun ── */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

/* ──────────────────────────────────────────
   RESET
   ────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  line-height: var(--leading-normal);
  color: var(--text-secondary);
  background-color: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img,
video,
svg {
  display: block;
  max-width: 100%;
}

table {
  border-collapse: collapse;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

ul,
ol {
  list-style: none;
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--dur) var(--ease);
}

a:hover {
  color: var(--text-link-hover);
  text-decoration: underline;
}

/* ──────────────────────────────────────────
   TYPOGRAPHY — Headings
   ────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-main);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  line-height: var(--leading-tight);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl);  }
h4 { font-size: var(--text-lg);  }
h5 { font-size: var(--text-md);  }
h6 { font-size: var(--text-base);}

p {
  margin-bottom: var(--space-4);
  line-height: var(--leading-loose);
}

p:last-child {
  margin-bottom: 0;
}

/* ──────────────────────────────────────────
   TYPOGRAPHY — Utility classes
   ────────────────────────────────────────── */

/* Size */
.text-xs    { font-size: var(--text-xs); }
.text-sm    { font-size: var(--text-sm); }
.text-base  { font-size: var(--text-base); }
.text-md    { font-size: var(--text-md); }
.text-lg    { font-size: var(--text-lg); }
.text-xl    { font-size: var(--text-xl); }
.text-2xl   { font-size: var(--text-2xl); }
.text-3xl   { font-size: var(--text-3xl); }

/* Weight */
.font-normal   { font-weight: var(--weight-normal); }
.font-medium   { font-weight: var(--weight-medium); }
.font-semibold { font-weight: var(--weight-semibold); }
.font-bold     { font-weight: var(--weight-bold); }

/* Color */
.text-primary   { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted     { color: var(--text-muted); }
.text-hint      { color: var(--text-hint); }
.text-invert    { color: var(--text-invert); }
.text-brand     { color: var(--primary-700); }
.text-gold      { color: var(--gold-600); }
.text-success   { color: var(--success-700); }
.text-warning   { color: var(--warning-700); }
.text-danger    { color: var(--danger-700); }
.text-info      { color: var(--info-700); }

/* Alignment */
.text-left    { text-align: left; }
.text-center  { text-align: center; }
.text-right   { text-align: right; }

/* Truncate */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ──────────────────────────────────────────
   DIVIDERS
   ────────────────────────────────────────── */
hr,
.divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: var(--space-6) 0;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-hint);
  margin: var(--space-5) 0;
}

.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

/* ──────────────────────────────────────────
   BREADCRUMB
   ────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

.breadcrumb a {
  color: var(--text-muted);
}

.breadcrumb a:hover {
  color: var(--primary-600);
  text-decoration: none;
}

.breadcrumb-sep {
  color: var(--gray-300);
  user-select: none;
}

.breadcrumb-current {
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
}

/* ──────────────────────────────────────────
   PAGE HEADER
   ────────────────────────────────────────── */
.page-header {
  margin-bottom: var(--space-8);
}

.page-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
  line-height: var(--leading-tight);
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* ──────────────────────────────────────────
   SECTION HEADING (ภายใน page)
   ────────────────────────────────────────── */
.section-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

/* ──────────────────────────────────────────
   DISPLAY / FLEXBOX / GRID UTILITIES
   ────────────────────────────────────────── */

/* Display */
.d-block  { display: block; }
.d-flex   { display: flex; }
.d-grid   { display: grid; }
.d-none   { display: none; }
.d-inline { display: inline; }
.d-inline-flex { display: inline-flex; }

/* Flex */
.flex-col    { flex-direction: column; }
.flex-wrap   { flex-wrap: wrap; }
.items-start  { align-items: flex-start; }
.items-center { align-items: center; }
.items-end    { align-items: flex-end; }
.justify-start   { justify-content: flex-start; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }
.justify-between { justify-content: space-between; }
.flex-1  { flex: 1; }
.flex-none { flex: none; }
.flex-shrink-0 { flex-shrink: 0; }

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .grid-2,
  .grid-3,
  .grid-4 { grid-template-columns: 1fr; }
}

/* Gap */
.gap-1  { gap: var(--space-1); }
.gap-2  { gap: var(--space-2); }
.gap-3  { gap: var(--space-3); }
.gap-4  { gap: var(--space-4); }
.gap-6  { gap: var(--space-6); }
.gap-8  { gap: var(--space-8); }

/* ──────────────────────────────────────────
   SPACING UTILITIES
   ────────────────────────────────────────── */

/* Margin */
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }

/* Padding */
.p-2  { padding: var(--space-2); }
.p-3  { padding: var(--space-3); }
.p-4  { padding: var(--space-4); }
.p-5  { padding: var(--space-5); }
.p-6  { padding: var(--space-6); }
.px-3 { padding-left: var(--space-3); padding-right: var(--space-3); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

/* ──────────────────────────────────────────
   BORDER UTILITIES
   ────────────────────────────────────────── */
.rounded-sm   { border-radius: var(--radius-sm); }
.rounded-md   { border-radius: var(--radius-md); }
.rounded-lg   { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }

.border       { border: 1px solid var(--border-color); }
.border-top   { border-top: 1px solid var(--border-color); }
.border-bottom { border-bottom: 1px solid var(--border-color); }

/* ──────────────────────────────────────────
   WIDTH / HEIGHT UTILITIES
   ────────────────────────────────────────── */
.w-full  { width: 100%; }
.h-full  { height: 100%; }
.min-h-screen { min-height: 100vh; }
.overflow-hidden { overflow: hidden; }
.overflow-auto   { overflow: auto; }
.overflow-x-auto { overflow-x: auto; }

/* ──────────────────────────────────────────
   POSITION UTILITIES
   ────────────────────────────────────────── */
.relative { position: relative; }
.absolute { position: absolute; }
.sticky   { position: sticky; }

/* ──────────────────────────────────────────
   VISIBILITY
   ────────────────────────────────────────── */
.invisible  { visibility: hidden; }
.opacity-0  { opacity: 0; }
.opacity-50 { opacity: .5; }

/* Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

/* ──────────────────────────────────────────
   AVATAR / USER INITIALS
   ────────────────────────────────────────── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  font-weight: var(--weight-semibold);
  color: var(--text-invert);
  background-color: var(--primary-600);
  flex-shrink: 0;
  line-height: 1;
}

.avatar-sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar-md { width: 36px; height: 36px; font-size: var(--text-sm); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-base); }
.avatar-xl { width: 64px; height: 64px; font-size: var(--text-md); }

.avatar-gold   { background-color: var(--gold-500); color: var(--primary-950); }
.avatar-school { background-color: var(--primary-100); color: var(--primary-800); }

/* ──────────────────────────────────────────
   EMPTY STATE
   ────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-6);
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: var(--space-4);
  opacity: .5;
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.empty-state-desc {
  font-size: var(--text-sm);
  max-width: 360px;
}

/* ──────────────────────────────────────────
   LOADING SPINNER
   ────────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.spinner-sm { width: 14px; height: 14px; border-width: 2px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

/* ──────────────────────────────────────────
   PRINT RESET
   ────────────────────────────────────────── */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  a { color: inherit; text-decoration: none; }
}

/* ──────────────────────────────────────────
   MODULE GRID (dashboard quick access tiles)
   ────────────────────────────────────────── */
.module-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.module-tile {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  transition: box-shadow var(--dur), border-color var(--dur), transform var(--dur);
  text-align: center;
  cursor: pointer;
}
.module-tile:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary-200);
  transform: translateY(-2px);
  text-decoration: none;
}
.module-tile-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.module-tile-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.3;
}
.module-tile-sub {
  font-size: 10px;
  color: var(--text-hint);
}
.mod-school  { background: var(--primary-50); }
.mod-onet    { background: var(--gold-50); }
.mod-nt      { background: #eef2ff; }
.mod-pisa    { background: #f0fdf4; }
.mod-cert    { background: #fff7ed; }
.mod-setting { background: var(--gray-100); }
@media (max-width: 768px) {
  .module-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
  .module-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .module-tile { padding: 12px 8px; }
  .module-tile-icon { width: 40px; height: 40px; font-size: 20px; }
}
