/* ============================================================
   ระบบบริหารงานบุคคล — UI System v1 (Style 4: Sidebar + Mobile-first)
   คณะวิทยาการสารสนเทศ ม.มหาสารคาม
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root{
  /* surface */
  --bg:#f8fafc;
  --surface:#ffffff;
  --border:#e5e7eb;

  /* text */
  --text:#111827;
  --text-muted:#6b7280;
  --text-soft:#9ca3af;

  /* primary (teal) */
  --primary:#0d9488;
  --primary-dark:#0f766e;
  --primary-soft:#ccfbf1;

  /* sidebar (dark navy — fixed) */
  --sidebar-bg:#0f172a;
  --sidebar-text:#cbd5e1;
  --sidebar-active:#1e293b;

  /* status */
  --green:#16a34a;
  --amber:#d97706;
  --red:#dc2626;

  /* layout */
  --sidebar-w:240px;
}

*,*::before,*::after{box-sizing:border-box}
html,body{margin:0; padding:0; height:100%}
body{
  font-family:'Prompt', system-ui, -apple-system, sans-serif;
  background:var(--bg); color:var(--text);
  -webkit-font-smoothing:antialiased; line-height:1.5;
}
a{color:inherit; text-decoration:none}
button{font-family:inherit}

:focus-visible{outline:2px solid var(--primary); outline-offset:2px; border-radius:4px}

/* ---------- App Shell ---------- */
.app{display:grid; grid-template-columns:var(--sidebar-w) 1fr; min-height:100vh}

.sidebar{
  background:var(--sidebar-bg); color:var(--sidebar-text);
  position:sticky; top:0; height:100vh; overflow-y:auto;
  padding:20px 14px; display:flex; flex-direction:column; gap:6px;
}

.main{display:flex; flex-direction:column; min-width:0}

.scrim{
  position:fixed; inset:0; background:rgba(0,0,0,.4); z-index:30;
  opacity:0; pointer-events:none; transition:opacity .2s;
}
.scrim.show{opacity:1; pointer-events:auto}

/* ---------- Sidebar Brand ---------- */
.side-brand{
  display:flex; align-items:center; gap:10px; padding:6px 8px 18px;
  border-bottom:1px solid rgba(255,255,255,.08); margin-bottom:14px;
}
.side-mark{
  width:36px; height:36px; border-radius:10px;
  background:linear-gradient(135deg, var(--primary), var(--primary-dark));
  display:grid; place-items:center; color:#fff; font-weight:700; font-size:13px;
  box-shadow:0 4px 10px rgba(13,148,136,.4);
}
.side-name{font-weight:600; font-size:14px; color:#fff}
.side-sub{font-size:11px; color:#94a3b8}

/* ---------- Sidebar Navigation ---------- */
.nav-section-label{
  font-size:10px; text-transform:uppercase; letter-spacing:0.08em;
  color:#64748b; padding:14px 10px 6px; font-weight:600;
}
.nav-link{
  display:flex; align-items:center; gap:11px;
  padding:9px 11px; border-radius:8px; cursor:pointer;
  color:var(--sidebar-text); font-size:13px;
  transition:all .15s;
}
.nav-link:hover{background:rgba(255,255,255,.05); color:#fff}
.nav-link.active{
  background:var(--sidebar-active); color:#fff;
  box-shadow:inset 3px 0 0 var(--primary);
}
.nav-link svg{flex-shrink:0; opacity:.85}
.nav-link.active svg{opacity:1; color:var(--primary)}
.nav-badge{
  margin-left:auto; font-size:10px; padding:1px 7px;
  background:var(--primary); color:#fff; border-radius:999px; font-weight:600;
}

.side-foot{
  margin-top:auto; padding:12px 10px; border-top:1px solid rgba(255,255,255,.08);
  display:flex; align-items:center; gap:10px;
}
.side-avatar{
  width:34px; height:34px; border-radius:50%;
  background:linear-gradient(135deg, #f59e0b, #ef4444);
  display:grid; place-items:center; color:#fff; font-weight:600; font-size:12px;
}
.side-user-name{font-size:12px; color:#fff; font-weight:500}
.side-user-role{font-size:10px; color:#94a3b8}

/* ---------- Topbar ---------- */
.topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 24px; background:var(--surface);
  border-bottom:1px solid var(--border);
  position:sticky; top:0; z-index:20;
}
.hamburger{
  width:38px; height:38px; border-radius:8px; border:1px solid var(--border);
  background:var(--surface); display:none; place-items:center; cursor:pointer;
  color:var(--text);
}
.topbar-title{font-size:15px; font-weight:600}
.topbar-right{display:flex; gap:10px; align-items:center}
.icon-btn{
  width:38px; height:38px; border-radius:8px; border:1px solid var(--border);
  background:var(--surface); display:grid; place-items:center; cursor:pointer;
  color:var(--text-muted); position:relative;
}
.icon-btn:hover{color:var(--text)}
.badge-count{
  position:absolute; top:6px; right:6px; min-width:14px; height:14px;
  background:var(--red); color:#fff; font-size:9px; border-radius:999px;
  display:grid; place-items:center; padding:0 3px; font-weight:600;
}

/* ---------- Content ---------- */
.content{padding:24px; max-width:1280px; width:100%}
.page-head{margin-bottom:24px}
.page-head h1{margin:0; font-size:24px; font-weight:600; letter-spacing:-0.02em}
.page-head p{margin:4px 0 0; color:var(--text-muted); font-size:13px}

/* ---------- KPI Stat Card ---------- */
.stats{display:grid; grid-template-columns:repeat(4,1fr); gap:14px; margin-bottom:20px}
.stat{
  background:var(--surface); border:1px solid var(--border);
  border-radius:12px; padding:18px;
}
.stat-row{display:flex; align-items:center; gap:12px; margin-bottom:10px}
.stat-icon{
  width:40px; height:40px; border-radius:10px; flex-shrink:0;
  display:grid; place-items:center;
}
.si-teal{background:var(--primary-soft); color:var(--primary)}
.si-amber{background:#fef3c7; color:#92400e}
.si-violet{background:#ede9fe; color:#6d28d9}
.si-rose{background:#ffe4e6; color:#be123c}
.stat-label{font-size:12px; color:var(--text-muted); font-weight:500}
.stat-value{font-size:26px; font-weight:600; line-height:1; letter-spacing:-0.02em}
.stat-foot{
  font-size:12px; color:var(--text-muted); display:flex; align-items:center; gap:6px;
  padding-top:10px; border-top:1px solid var(--border);
}
.delta.up{color:var(--green); font-weight:600}
.delta.down{color:var(--red); font-weight:600}

/* ---------- Card ---------- */
.card{
  background:var(--surface); border:1px solid var(--border);
  border-radius:12px; padding:20px;
}
.card-head{
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom:16px; gap:10px; flex-wrap:wrap;
}
.card-title{margin:0; font-size:14px; font-weight:600}
.card-sub{font-size:12px; color:var(--text-muted); margin-top:2px}

.grid-2{display:grid; grid-template-columns:1.7fr 1fr; gap:14px; margin-bottom:14px}
.chart-wrap{height:240px; position:relative}

/* ---------- Tab Group ---------- */
.tab-group{display:flex; gap:2px; padding:3px; background:var(--bg); border-radius:8px}
.tab{
  padding:5px 12px; font-size:12px; border:none; background:transparent;
  border-radius:6px; cursor:pointer; color:var(--text-muted); font-family:inherit;
}
.tab.active{
  background:var(--surface); color:var(--text);
  box-shadow:0 1px 2px rgba(0,0,0,.06); font-weight:500;
}

/* ---------- Badge ---------- */
.badge{display:inline-block; padding:3px 9px; border-radius:6px; font-size:11px; font-weight:600}
.badge.pending  {background:#fef3c7; color:#92400e}
.badge.approved {background:#d1fae5; color:#065f46}
.badge.rejected {background:#fee2e2; color:#991b1b}
.badge.review   {background:#ede9fe; color:#5b21b6}
.badge.cancelled{background:#e5e7eb; color:#374151}
.badge.draft    {background:#f3f4f6; color:#6b7280}

/* ---------- Activity Item ---------- */
.activity{display:flex; flex-direction:column; gap:12px}
.activity-item{display:flex; gap:11px; align-items:flex-start}
.ai-icon{
  width:32px; height:32px; border-radius:50%; flex-shrink:0;
  display:grid; place-items:center; font-size:13px; color:#fff;
}
.activity-text{font-size:13px; line-height:1.45}
.activity-meta{font-size:11px; color:var(--text-soft); margin-top:1px}

/* ---------- Table ---------- */
table{width:100%; border-collapse:collapse}
th{
  text-align:left; padding:10px 12px; font-size:11px; color:var(--text-muted);
  text-transform:uppercase; letter-spacing:0.04em; font-weight:600;
  border-bottom:1px solid var(--border);
}
td{padding:13px 12px; font-size:13px; border-bottom:1px solid var(--border)}
tr:last-child td{border-bottom:none}

/* ---------- Mobile Card View (สำหรับตาราง) ---------- */
.req-cards{display:none; flex-direction:column; gap:10px}
.req-card{
  border:1px solid var(--border); border-radius:10px; padding:14px;
  display:flex; flex-direction:column; gap:8px;
}
.rc-head{display:flex; justify-content:space-between; align-items:flex-start; gap:10px}
.rc-name{font-weight:600; font-size:14px}
.rc-meta{font-size:12px; color:var(--text-muted); margin-top:2px}
.rc-grid{display:grid; grid-template-columns:1fr 1fr; gap:8px; font-size:12px}
.rc-grid > div > span{display:block; color:var(--text-soft); font-size:11px; margin-bottom:1px}

/* ---------- Form ---------- */
.form-group{margin-bottom:16px}
.form-label{
  display:block; font-size:13px; font-weight:500;
  margin-bottom:6px; color:var(--text);
}
.required{color:var(--red)}
.form-input, .form-select, .form-textarea{
  width:100%; padding:10px 12px; font-size:14px; font-family:inherit;
  border:1px solid var(--border); border-radius:8px; background:var(--surface);
  color:var(--text); transition:border-color .15s, box-shadow .15s;
  min-height:44px;
}
.form-textarea{min-height:96px; resize:vertical}
.form-input:focus, .form-select:focus, .form-textarea:focus{
  outline:none; border-color:var(--primary);
  box-shadow:0 0 0 3px rgba(13,148,136,.15);
}
.form-hint{font-size:11px; color:var(--text-muted); margin-top:4px}
.form-error{font-size:12px; color:var(--red); margin-top:4px}

.form-row{display:grid; grid-template-columns:1fr 1fr; gap:14px}

/* ---------- Buttons ---------- */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  padding:9px 16px; font-size:13px; font-weight:500; font-family:inherit;
  border-radius:8px; cursor:pointer; transition:all .15s;
  border:1px solid transparent; min-height:40px; text-decoration:none;
}
.btn-primary{background:var(--primary); color:#fff}
.btn-primary:hover{background:var(--primary-dark)}
.btn-ghost{background:var(--surface); color:var(--text); border-color:var(--border)}
.btn-ghost:hover{background:var(--bg)}
.btn-danger{background:var(--red); color:#fff}
.btn-danger:hover{background:#b91c1c}
.btn:disabled{opacity:.5; cursor:not-allowed}

.btn-block{width:100%}

/* ---------- Empty / Skeleton ---------- */
.empty{text-align:center; padding:48px 20px}
.empty-icon{font-size:48px; margin-bottom:16px; opacity:.4}
.empty-title{margin:0 0 6px; font-size:16px; font-weight:600}
.empty-text{margin:0 0 20px; color:var(--text-muted); font-size:13px}

.skeleton{
  background:linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size:200% 100%; animation:shimmer 1.5s infinite; border-radius:8px;
}
@keyframes shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}

/* ---------- Login Page (standalone — ไม่มี sidebar) ---------- */
.login-shell{
  min-height:100vh; display:grid; place-items:center; padding:20px;
  background:linear-gradient(135deg, #f8fafc 0%, #e0f2f1 100%);
}
.login-card{
  background:var(--surface); border:1px solid var(--border);
  border-radius:14px; padding:32px; width:100%; max-width:400px;
  box-shadow:0 8px 24px rgba(15,23,42,.06);
}
.login-brand{display:flex; flex-direction:column; align-items:center; gap:10px; margin-bottom:24px}
.login-brand .side-mark{width:48px; height:48px; font-size:16px}
.login-title{margin:0; font-size:18px; font-weight:600; text-align:center}
.login-sub{margin:4px 0 0; font-size:12px; color:var(--text-muted); text-align:center}

/* ---------- Notification Dropdown ---------- */
.notif-wrap{position:relative}
.notif-btn{position:relative}
.notif-dropdown{
  position:absolute; top:calc(100% + 8px); right:0; width:340px;
  background:var(--surface); border:1px solid var(--border);
  border-radius:12px; box-shadow:0 8px 24px rgba(0,0,0,.12);
  z-index:50; display:none; overflow:hidden;
}
.notif-dropdown.open{display:block}
.notif-head{
  display:flex; justify-content:space-between; align-items:center;
  padding:12px 16px; border-bottom:1px solid var(--border);
  font-size:13px; font-weight:600;
}
.notif-list{max-height:360px; overflow-y:auto}
.notif-item{
  display:flex; gap:10px; padding:12px 16px;
  border-bottom:1px solid var(--border); cursor:pointer;
  transition:background .1s;
}
.notif-item:hover{background:var(--bg)}
.notif-item:last-child{border-bottom:none}
.notif-item.unread{background:#f0fdfb}
.notif-icon{
  width:32px; height:32px; border-radius:50%; flex-shrink:0;
  display:grid; place-items:center;
}
.notif-icon.ni-leave{background:#fef3c7; color:#d97706}
.notif-icon.ni-approved{background:#d1fae5; color:#16a34a}
.ni-rejected{background:#fee2e2; color:#dc2626}
.notif-text{font-size:13px; line-height:1.4}
.notif-text strong{font-weight:600}
.notif-time{font-size:11px; color:var(--text-soft); margin-top:2px}
.notif-empty{padding:24px; text-align:center; color:var(--text-muted); font-size:13px}
.notif-see-all{
  display:block; padding:10px; text-align:center;
  border-top:1px solid var(--border); font-size:13px; color:var(--primary);
  font-weight:500;
}
.notif-see-all:hover{background:var(--bg)}

/* ============================================================
   Responsive — Mobile-first breakpoints
   ============================================================ */
@media (max-width:1100px){
  .stats{grid-template-columns:repeat(2,1fr)}
  .grid-2{grid-template-columns:1fr}
}

@media (max-width:860px){
  .app{grid-template-columns:1fr}
  .sidebar{
    position:fixed; top:0; left:0; height:100vh; width:280px;
    transform:translateX(-100%); transition:transform .25s; z-index:40;
  }
  .sidebar.open{transform:translateX(0)}
  .hamburger{display:grid}
}

@media (max-width:560px){
  .stats{grid-template-columns:1fr}
  .content{padding:16px}
  .topbar{padding:12px 16px}
  .page-head h1{font-size:20px}
  .stat-value{font-size:22px}
  .form-row{grid-template-columns:1fr}
  /* table → cards */
  table{display:none}
  .req-cards{display:flex}
}
