/* pvec_mis/css/main.css
   Mobile-First — base style = mobile, ขยายด้วย min-width breakpoints
*/

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@300;400;500;600;700&display=swap');
@import url('https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@3.4.0/dist/tabler-icons.min.css');

/* ─── Design Tokens ──────────────────────────────── */
:root {
  --navy:     #0f3460;
  --navy2:    #164080;
  --navy3:    #1a4f9c;
  --gold:     #c9973a;
  --gold2:    #e8b84b;
  --sky:      #2d7dd2;
  --teal:     #0f7c6e;
  --teal2:    #14a896;

  --bg:       #f7f8fc;
  --bg2:      #eef1f7;
  --white:    #ffffff;
  --border:   #dde3ef;
  --border2:  #c8d0e0;

  --text:     #1a2340;
  --text2:    #3a4a6b;
  --text3:    #6b7a99;

  --green-bg: #e8f5ef;
  --green-fg: #1a7a4a;
  --red-bg:   #fce8e8;
  --red-fg:   #8a1a1a;
  --amber-bg: #fff8e6;
  --amber-fg: #8a5a00;

  --font:     'IBM Plex Sans Thai', 'Sarabun', sans-serif;
  --r:        8px;
  --r-lg:     12px;
  --shadow:   0 1px 4px rgba(15,52,96,.08), 0 4px 16px rgba(15,52,96,.06);
  --shadow-md:0 4px 20px rgba(15,52,96,.13);

  /* Touch targets ≥ 44px ทุกจุด */
  --tap:      44px;
}

/* ─── Reset / Base ───────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 15px;
  /* ป้องกัน font inflation บน Android */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;          /* dynamic viewport height — กันแถบ address bar */
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: none; /* กัน pull-to-refresh เมื่อ scroll ใน app */
}

a { color: var(--navy3); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }

/* ─── Layout Shell ───────────────────────────────── */
.page-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.main-content {
  flex: 1;
  padding: 14px 14px 80px; /* bottom padding กัน iOS home bar */
  width: 100%;
}

/* desktop: จำกัดความกว้าง + center */
@media (min-width: 768px) {
  .main-content {
    padding: 24px 24px 40px;
    max-width: 1200px;
    margin: 0 auto;
  }
}

/* ─── HEADER ─────────────────────────────────────── */
.site-header {
  background: var(--navy);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: 54px;
  border-bottom: 3px solid var(--gold);
}

/* Mobile: hamburger + logo + avatar */
.header-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  min-width: 0;
}

.header-shield {
  width: 36px; height: 36px;
  background: var(--white);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.header-shield svg { width: 24px; height: 24px; }

.header-brand-text { min-width: 0; }
.header-brand-text .l1 {
  font-size: 13px; font-weight: 700;
  color: var(--white); line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-brand-text .l2 {
  font-size: 9px;
  color: rgba(255,255,255,.5);
  letter-spacing: .3px;
  display: none; /* ซ่อนบน mobile เล็ก */
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Hamburger — mobile only */
.btn-hamburger {
  width: var(--tap); height: var(--tap);
  background: transparent;
  border: none;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 5px;
  cursor: pointer;
  padding: 10px;
  border-radius: 6px;
  transition: background .15s;
  flex-shrink: 0;
}
.btn-hamburger:hover { background: rgba(255,255,255,.1); }
.btn-hamburger span {
  display: block;
  width: 20px; height: 2px;
  background: rgba(255,255,255,.85);
  border-radius: 1px;
  transition: all .3s;
}

/* Header avatar (mobile: ไม่แสดงชื่อ) */
.header-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  border: 1.5px solid rgba(255,255,255,.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--white);
  flex-shrink: 0;
}

.header-user-name  { display: none; } /* ซ่อนบน mobile */
.header-user-role  { display: none; }
.btn-logout-header { display: none; } /* ซ่อนบน mobile — ใช้ drawer แทน */

/* ─── Inline Nav (tablet/desktop เท่านั้น) ───────── */
.header-nav {
  display: none; /* ซ่อนบน mobile */
}

/* ─── Tablet breakpoint: ≥ 600px ─────────────────── */
@media (min-width: 600px) {
  .header-top { padding: 0 20px; height: 58px; }
  .header-shield { width: 40px; height: 40px; }
  .header-shield svg { width: 28px; height: 28px; }
  .header-brand-text .l1 { font-size: 14px; }
  .header-brand-text .l2 { display: block; }
  .header-avatar { width: 34px; height: 34px; font-size: 12px; }
}

/* ─── Desktop breakpoint: ≥ 768px ────────────────── */
@media (min-width: 768px) {
  /* ซ่อน hamburger, แสดง inline nav */
  .btn-hamburger { display: none; }

  .header-nav {
    display: flex;
    padding: 0 24px;
    background: var(--navy2);
    border-top: 1px solid rgba(255,255,255,.07);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .header-nav::-webkit-scrollbar { display: none; }

  .nav-item {
    display: flex; align-items: center; gap: 6px;
    padding: 10px 14px;
    font-size: 12px; font-weight: 500;
    color: rgba(255,255,255,.5);
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    min-height: var(--tap);
    transition: all .2s;
  }
  .nav-item i { font-size: 15px; }
  .nav-item:hover { color: rgba(255,255,255,.9); text-decoration: none; }
  .nav-item.active { color: var(--white); border-bottom-color: var(--gold2); }

  .header-user-name {
    display: block;
    font-size: 13px; font-weight: 600; color: var(--white);
  }
  .btn-logout-header {
    display: flex; align-items: center; gap: 5px;
    padding: 6px 14px; min-height: var(--tap);
    background: transparent;
    border: 1.5px solid rgba(255,255,255,.25);
    border-radius: 5px;
    color: rgba(255,255,255,.7);
    font-family: var(--font); font-size: 12px; font-weight: 500;
    cursor: pointer; text-decoration: none;
    transition: all .2s;
  }
  .btn-logout-header:hover {
    border-color: var(--gold2); color: var(--gold2);
    text-decoration: none;
  }
}

/* ─── DRAWER (mobile nav) ─────────────────────────── */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.drawer-overlay.is-open { opacity: 1; pointer-events: all; }

.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(300px, 85vw);
  background: var(--navy);
  z-index: 201;
  transform: translateX(-100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
  box-shadow: 4px 0 24px rgba(0,0,0,.3);
  overscroll-behavior: contain;
}
.drawer.is-open { transform: translateX(0); }

/* ซ่อน drawer บน desktop */
@media (min-width: 768px) {
  .drawer, .drawer-overlay { display: none !important; }
}

.drawer-header {
  padding: 14px 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; gap: 10px;
}

.drawer-shield {
  width: 34px; height: 34px;
  background: var(--white);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.drawer-shield svg { width: 22px; height: 22px; }

.drawer-brand-text { flex: 1; min-width: 0; }
.drawer-brand-text .l1 { font-size: 13px; font-weight: 700; color: var(--white); }
.drawer-brand-text .l2 { font-size: 9px; color: rgba(255,255,255,.45); }

.btn-drawer-close {
  width: var(--tap); height: var(--tap);
  background: rgba(255,255,255,.1);
  border: none; border-radius: 6px;
  color: rgba(255,255,255,.7);
  font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.btn-drawer-close:hover { background: rgba(255,255,255,.2); }

.drawer-user {
  padding: 12px 14px;
  background: rgba(255,255,255,.05);
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
}

.drawer-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  border: 2px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: var(--white);
  flex-shrink: 0;
}

.drawer-user-name { font-size: 13px; font-weight: 600; color: var(--white); line-height: 1.2; }
.drawer-user-role { font-size: 10px; color: rgba(255,255,255,.5); margin-top: 2px; }

.drawer-nav {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  overscroll-behavior: contain;
}

.drawer-nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  height: var(--tap);           /* tap target 44px */
  font-size: 13px; font-weight: 500;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all .15s;
}
.drawer-nav-item i { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }
.drawer-nav-item:hover, .drawer-nav-item.active {
  background: rgba(255,255,255,.08);
  color: var(--white);
  border-left-color: var(--gold2);
  text-decoration: none;
}

.drawer-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.btn-drawer-logout {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: var(--tap);
  background: rgba(220,38,38,.15);
  border: 1px solid rgba(220,38,38,.3);
  border-radius: 6px;
  color: #f87171;
  font-family: var(--font); font-size: 13px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: background .15s;
}
.btn-drawer-logout:hover {
  background: rgba(220,38,38,.25);
  text-decoration: none;
}

/* ─── FOOTER ──────────────────────────────────────── */
.site-footer {
  background: var(--navy);
  padding: 10px 14px;
  margin-top: auto;
}

.footer-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: center;
}

.footer-left  { font-size: 10px; color: rgba(255,255,255,.4); }
.footer-right { font-size: 10px; color: rgba(255,255,255,.35); }

@media (min-width: 600px) {
  .site-footer { padding: 10px 24px; }
  .footer-inner {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    text-align: left;
  }
  .footer-right { text-align: right; }
  .footer-left  { font-size: 11px; }
  .footer-right { font-size: 11px; }
}

/* ─── Card ────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 13px; font-weight: 600; color: var(--text2);
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 7px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.card-title i { color: var(--navy3); font-size: 16px; }

/* ─── Section Label ───────────────────────────────── */
.section-label {
  font-size: 10px; font-weight: 600;
  color: var(--text3); letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 7px;
}
.section-label::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.section-label i { font-size: 13px; }

/* ─── User Card ───────────────────────────────────── */
.user-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px;
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.user-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--navy), var(--navy3), var(--gold));
}

.user-card-inner {
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-avatar-lg {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--bg2);
  border: 2px solid var(--border2);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: var(--navy3);
  flex-shrink: 0;
}

.user-card-body { flex: 1; min-width: 0; }
.user-card-name {
  font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-card-college { font-size: 11px; color: var(--text3); margin-top: 2px; }

.user-card-badges {
  display: flex; flex-wrap: wrap; gap: 5px;
  margin-top: 8px;
}

@media (min-width: 600px) {
  .user-avatar-lg { width: 58px; height: 58px; font-size: 20px; }
  .user-card-name { font-size: 18px; white-space: normal; }
}

/* ─── Badge ───────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 600;
  padding: 3px 9px; border-radius: 4px;
  white-space: nowrap;
}
.badge i { font-size: 11px; }

.badge-navy  { background: #e8edfb; color: #1a3a8f; }
.badge-teal  { background: #e8f5f3; color: #0f5e54; }
.badge-gold  { background: var(--amber-bg); color: var(--amber-fg); }
.badge-green { background: var(--green-bg); color: var(--green-fg); }
.badge-gray  { background: var(--bg2); color: var(--text3); }

/* ─── Menu Grid ───────────────────────────────────── */
.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr; /* mobile: 2 คอลัมน์ */
  gap: 10px;
}

/* เมนูสุดท้ายถ้าเป็นคี่ — ขยายเต็มแถว */
.menu-card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}
/* เมื่อ full-width แสดงแนวนอน */
.menu-card:last-child:nth-child(odd) .menu-card-inner {
  flex-direction: row;
  align-items: center;
  gap: 14px;
}
.menu-card:last-child:nth-child(odd) .menu-card-arrow {
  margin-left: auto;
}

@media (min-width: 480px) {
  .menu-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .menu-card:last-child:nth-child(odd) { grid-column: auto; }
  .menu-card:last-child:nth-child(odd) .menu-card-inner { flex-direction: column; }
  .menu-card:last-child:nth-child(odd) .menu-card-arrow { margin-left: 0; }
}

@media (min-width: 900px) {
  .menu-grid { grid-template-columns: repeat(5, 1fr); gap: 14px; }
}

.menu-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r);
  text-decoration: none;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
  transition: border-color .2s, box-shadow .2s, transform .15s;
  /* active state สำหรับ touch */
  -webkit-tap-highlight-color: rgba(26,79,156,.08);
}

.menu-card::after {
  content: '';
  position: absolute; bottom: 0; left: 0; right: 0; height: 2.5px;
  background: var(--navy3);
  transform: scaleX(0);
  transition: transform .2s;
}

.menu-card:hover,
.menu-card:focus-visible {
  border-color: var(--navy3);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}

.menu-card:active { transform: scale(.97); }
.menu-card:hover::after { transform: scaleX(1); }

.menu-card-inner {
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100px; /* เพียงพอสำหรับ touch */
}

.menu-card-icon {
  width: 40px; height: 40px;
  background: var(--bg2);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--navy3);
  transition: background .2s;
  flex-shrink: 0;
}
.menu-card:hover .menu-card-icon { background: #e8edfb; }

.menu-card-label {
  font-size: 12px; font-weight: 600;
  color: var(--text); line-height: 1.35;
  flex: 1;
}

.menu-card-arrow {
  font-size: 14px; color: var(--text3);
  align-self: flex-end;
  transition: color .2s, transform .2s;
}
.menu-card:hover .menu-card-arrow {
  color: var(--navy3);
  transform: translateX(3px);
}

/* ─── Login Page ──────────────────────────────────── */
.login-page {
  min-height: 100dvh;
  background: var(--navy);
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 44px 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 16px 32px;
}

.login-box {
  width: 100%;
  max-width: 400px;
}

.login-header {
  text-align: center;
  margin-bottom: 22px;
}

/* ── Login Shield / Logo ───────────────────────────────── */
.login-shield {
  /* เปลี่ยนจาก navy background เป็น transparent
     เพื่อให้ logo แสดงได้ชัดบน navy background ของ login page */
  width: 68px;
  height: 68px;
  border: 0px solid var(--gold);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  overflow: hidden;
  background: rgba(15, 52, 96, 1);
  padding: 4px;
}
.login-shield svg { width: 36px; height: 36px; }

.login-header h1 {
  font-size: 17px; font-weight: 700;
  color: var(--white); margin-bottom: 4px;
}
.login-header p { font-size: 11px; color: rgba(255,255,255,.5); }

.login-card {
  background: var(--white);
  border-radius: var(--r-lg);
  padding: 22px 20px 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-card-title {
  font-size: 14px; font-weight: 700; color: var(--text);
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 7px;
}
.login-card-title i { color: var(--navy3); font-size: 17px; }

.form-group { margin-bottom: 14px; }
.form-group:last-of-type { margin-bottom: 18px; }

.form-group label {
  display: block;
  font-size: 12px; font-weight: 600;
  color: var(--text2); margin-bottom: 5px;
}

.form-control {
  width: 100%;
  /* height ≥ 44px สำหรับ touch */
  height: 44px;
  padding: 0 12px;
  border: 1.5px solid var(--border2);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 15px; /* ป้องกัน zoom บน iOS (<16px จะ zoom) */
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  -webkit-appearance: none;
  appearance: none;
}
.form-control:focus {
  border-color: var(--navy3);
  box-shadow: 0 0 0 3px rgba(26,79,156,.1);
}

.btn-primary {
  width: 100%;
  height: 48px;
  background: var(--navy);
  border: none; border-radius: 6px;
  color: var(--white);
  font-family: var(--font); font-size: 15px; font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .2s;
  -webkit-appearance: none;
}
.btn-primary:hover { background: var(--navy2); }
.btn-primary:active { transform: scale(.98); }

.alert-error {
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--red-bg);
  border: 1px solid #f5c6cb;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px; color: var(--red-fg);
  margin-bottom: 14px;
  line-height: 1.5;
}
.alert-error i { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

.login-footer-note {
  text-align: center;
  margin-top: 16px;
  font-size: 10px;
  color: rgba(255,255,255,.3);
}

/* ─── Utilities ───────────────────────────────────── */
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-16 { margin-top: 16px; }
.text-muted { color: var(--text3); }
.text-sm    { font-size: 12px; }

/* ─── Focus visible (accessibility) ─────────────────*/
:focus-visible {
  outline: 2px solid var(--navy3);
  outline-offset: 2px;
}

/* ── Header / Drawer Logo ──────────────────────────────── */
.header-logo-wrap,
.drawer-logo-wrap {
  background: var(--white);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

/* header: ขนาดเดียวกับ header-shield เดิม */
.header-logo-wrap {
  width: 36px;
  height: 36px;
  padding: 2px;
}

.header-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* drawer: ขนาดเดียวกับ drawer-shield เดิม */
.drawer-logo-wrap {
  width: 34px;
  height: 34px;
  padding: 2px;
}

.drawer-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@media (min-width: 600px) {
  .header-logo-wrap { width: 40px; height: 40px; }
}