/* ============================================================
   style.css — Design System
   วิทยาลัยเทคนิครัตนบุรี | Deep Navy + Gold
   ============================================================ */

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

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --navy:        #0f2044;
  --navy-mid:    #1a3260;
  --navy-light:  #2a4a8a;
  --gold:        #c9a227;
  --gold-light:  #f0c84a;
  --gold-pale:   #fdf3d0;
  --white:       #ffffff;
  --gray-50:     #f8f9fc;
  --gray-100:    #eef0f5;
  --gray-200:    #dce0ea;
  --gray-400:    #8892aa;
  --gray-600:    #4a5568;
  --gray-800:    #1e2433;
  --green:       #16a34a;
  --green-light: #dcfce7;
  --red:         #dc2626;
  --red-light:   #fee2e2;
  --amber:       #d97706;
  --amber-light: #fef3c7;
  --blue:        #2563eb;
  --blue-light:  #dbeafe;
  --radius:      10px;
  --radius-lg:   16px;
  --shadow:      0 2px 8px  rgba(15,32,68,0.08);
  --shadow-md:   0 4px 20px rgba(15,32,68,0.12);
  --shadow-lg:   0 8px 40px rgba(15,32,68,0.18);
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html   {
  scroll-behavior: smooth;
  height: 100%;
}
body   {
  font-family: 'Sarabun', 'Noto Sans Thai', sans-serif;
  background: var(--gray-50); color: var(--gray-800);
  font-size: 15px; line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  /* ห้าม body overflow เพื่อให้ scroll อยู่ใน .main แทน */
  overflow-x: hidden;
}

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ── Loading overlay ───────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.85);
  z-index: 9999;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  backdrop-filter: blur(2px);
}
.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────────── */
#toast { position: fixed; bottom: 24px; right: 24px; z-index: 9998; display: none; }
#toast-inner {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 8px;
  max-width: 340px; color: white;
}

/* ============================================================
   AUTH SCREEN
   ============================================================ */
#auth-screen {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 65%, #1e4080 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  position: relative; overflow: hidden;
}
#auth-screen::before {
  content: '';
  position: absolute; top: -120px; right: -120px;
  width: 420px; height: 420px; border-radius: 50%;
  background: radial-gradient(circle, rgba(201,162,39,.18) 0%, transparent 70%);
  pointer-events: none;
}
#auth-screen::after {
  content: '';
  position: absolute; bottom: -90px; left: -90px;
  width: 320px; height: 320px; border-radius: 50%;
  background: radial-gradient(circle, rgba(201,162,39,.12) 0%, transparent 70%);
  pointer-events: none;
}

.auth-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 44px 40px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
  position: relative; z-index: 1;
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo .logo-wrap { display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.auth-logo .school-logo {
  width: 76px; height: 76px;
  object-fit: contain;
  border-radius: 18px;
}
.auth-logo .logo-icon {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--navy), var(--navy-light));
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(15,32,68,.3);
}
.auth-logo .logo-icon svg { width: 38px; height: 38px; }
.auth-logo h1 { font-size: 18px; font-weight: 700; color: var(--navy); line-height: 1.3; }
.auth-logo p  { font-size: 13px; color: var(--gray-400); margin-top: 4px; }
.gold-line { width: 48px; height: 3px; background: var(--gold); border-radius: 2px; margin: 10px auto 0; }

/* Login name autocomplete suggestion box */
.suggest-box {
  display: none;
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-height: 220px; overflow-y: auto;
  z-index: 50; margin-top: 4px;
}
.suggest-item {
  padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; cursor: pointer; font-size: 13.5px;
  border-bottom: 1px solid var(--gray-100);
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover,
.suggest-item.active { background: var(--gray-50); }
.suggest-name { font-weight: 600; color: var(--gray-800); }
.suggest-dept { font-size: 11.5px; color: var(--gray-400); }

.auth-card h2   { font-size: 22px; font-weight: 700; color: var(--navy); margin-bottom: 4px; }
.auth-card .sub { font-size: 14px; color: var(--gray-400); margin-bottom: 22px; }

/* ============================================================
   LAYOUT
   ============================================================ */
#app { display: none; min-height: 100vh; }

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: 260px;
  height: 100vh;
  height: 100dvh; /* dynamic viewport height — รองรับ taskbar มือถือ */
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-mid) 100%);
  display: flex; flex-direction: column;
  z-index: 100;
  overflow-x: hidden;
  overflow-y: auto;
}
.sidebar-header { padding: 22px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-logo   { display: flex; align-items: center; gap: 12px; }
.sidebar-logo .icon {
  width: 42px; height: 42px;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar-logo .icon svg { width: 22px; height: 22px; color: var(--navy); }
.sidebar-logo h2 { font-size: 13px; font-weight: 700; color: var(--white); line-height: 1.3; }
.sidebar-logo p  { font-size: 11px; color: rgba(255,255,255,.5); margin-top: 1px; }

.user-badge {
  margin: 14px 16px;
  background: rgba(255,255,255,.07);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: var(--navy); flex-shrink: 0;
}
.user-info .name      { font-size: 12px; font-weight: 600; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .role-badge { font-size: 10px; color: var(--gold-light); margin-top: 1px; }

.nav-section       { padding: 8px 12px 4px; }
.nav-section-label {
  font-size: 10px; font-weight: 700;
  color: rgba(255,255,255,.35);
  letter-spacing: .1em; text-transform: uppercase;
  padding: 8px 8px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 8px; cursor: pointer;
  transition: background .15s;
  margin-bottom: 2px;
  color: rgba(255,255,255,.7);
  font-size: 13.5px; font-weight: 500;
  border: none; background: none;
  width: 100%; text-align: left; font-family: inherit;
}
.nav-item svg   { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.08); color: var(--white); }
.nav-item.active{ background: rgba(201,162,39,.2);  color: var(--gold-light); }
.nav-item .badge {
  margin-left: auto;
  background: var(--red); color: var(--white);
  font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 10px;
  min-width: 18px; text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 16px;
  padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
  border-top: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0; /* ป้องกันไม่ให้ถูกบีบ */
  position: sticky;
  bottom: 0;
  background: var(--navy-mid); /* ให้มีพื้นหลังเมื่อ scroll */
  z-index: 1;
}
.btn-logout {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  background: rgba(220,38,38,.15);
  border: none; border-radius: 8px;
  color: #fca5a5;
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.btn-logout:hover { background: rgba(220,38,38,.25); }
.btn-logout svg   { width: 16px; height: 16px; }

/* ── Main content ──────────────────────────────────────── */
.main {
  margin-left: 260px;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-y: auto;
  /* safe area สำหรับ iPhone notch / home indicator */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-100);
  padding: 16px 28px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.topbar h1        { font-size: 18px; font-weight: 700; color: var(--navy); }
.topbar .breadcrumb { font-size: 12px; color: var(--gray-400); margin-top: 1px; }
.topbar-actions   { display: flex; gap: 10px; align-items: center; }

.content { padding: 24px 28px; }

/* ── Page visibility ───────────────────────────────────── */
.page-hidden { display: none !important; }

/* ============================================================
   COMPONENTS
   ============================================================ */

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  cursor: pointer; border: none;
  transition: all .15s; text-decoration: none; white-space: nowrap;
}
.btn svg  { width: 15px; height: 15px; }
.btn-navy { background: var(--navy);  color: var(--white); }
.btn-navy:hover { background: var(--navy-light); }
.btn-gold { background: var(--gold);  color: var(--navy); }
.btn-gold:hover { background: var(--gold-light); }
.btn-outline {
  background: var(--white); color: var(--navy);
  border: 1.5px solid var(--gray-200);
}
.btn-outline:hover { border-color: var(--navy-light); background: var(--gray-50); }
.btn-green { background: var(--green); color: var(--white); }
.btn-green:hover { opacity: .9; }
.btn-red   { background: var(--red);   color: var(--white); }
.btn-red:hover   { opacity: .9; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-xs { padding: 4px 10px; font-size: 12px; border-radius: 6px; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-100);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 700; color: var(--navy); }
.card-body { padding: 20px 22px; }

/* ── Stat grid ─────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--gray-100);
  box-shadow: var(--shadow);
  display: flex; align-items: flex-start; gap: 14px;
}
.stat-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 22px; height: 22px; }
.stat-val   { font-size: 26px; font-weight: 800; color: var(--navy); line-height: 1; }
.stat-label { font-size: 12px; color: var(--gray-400); margin-top: 3px; }

/* ── Status badges ─────────────────────────────────────── */
.status {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.status-draft                { background: var(--gray-100);   color: var(--gray-600); }
.status-draft::before        { background: var(--gray-400); }
.status-submitted            { background: var(--blue-light);  color: var(--blue); }
.status-submitted::before    { background: var(--blue); }
.status-dept_approved        { background: #ede9fe; color: #7c3aed; }
.status-dept_approved::before{ background: #7c3aed; }
.status-curriculum_approved        { background: var(--amber-light); color: var(--amber); }
.status-curriculum_approved::before{ background: var(--amber); }
.status-vice_approved        { background: #fce7f3; color: #be185d; }
.status-vice_approved::before{ background: #be185d; }
.status-director_approved        { background: var(--green-light); color: var(--green); }
.status-director_approved::before{ background: var(--green); }
.status-rejected        { background: var(--red-light); color: var(--red); }
.status-rejected::before{ background: var(--red); }

/* ── Table ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  background: var(--gray-50);
  padding: 10px 14px;
  text-align: left;
  font-size: 11.5px; font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--gray-100);
  white-space: nowrap;
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-600);
  vertical-align: middle;
}
tbody tr:hover { background: var(--gray-50); }
tbody tr:last-child td { border-bottom: none; }

/* ── Form fields ───────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label,
.field label {
  display: block;
  font-size: 13px; font-weight: 600; color: var(--gray-600);
  margin-bottom: 6px;
}
.field label .req { color: var(--red); margin-left: 3px; }

.form-group select,
.form-group input,
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-family: inherit; font-size: 14px; color: var(--gray-800);
  background: var(--white);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}
.form-group select:focus,
.form-group input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--navy-light);
  box-shadow: 0 0 0 3px rgba(42,74,138,.08);
}
.field textarea { resize: vertical; min-height: 80px; line-height: 1.6; }

.form-grid         { display: grid; gap: 16px; }
.form-grid.cols-2  { grid-template-columns: 1fr 1fr; }
.form-grid.cols-3  { grid-template-columns: 1fr 1fr 1fr; }

/* ── Checkbox grid (media) ─────────────────────────────── */
.checkbox-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.checkbox-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px; cursor: pointer;
  transition: all .15s;
  font-size: 13px; color: var(--gray-600);
}
.checkbox-item input { width: 15px; height: 15px; accent-color: var(--navy); cursor: pointer; }
.checkbox-item:has(input:checked) {
  border-color: var(--navy-light);
  background: #eef2fb; color: var(--navy); font-weight: 600;
}

/* ── Counter row ───────────────────────────────────────── */
.counter-row  { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; }
.counter-field{ text-align: center; }
.counter-field label { font-size: 12px; color: var(--gray-400); font-weight: 600; display: block; margin-bottom: 6px; }
.counter-field input {
  width: 100%; padding: 8px; text-align: center;
  border: 1.5px solid var(--gray-200); border-radius: var(--radius);
  font-size: 18px; font-weight: 700; color: var(--navy); font-family: inherit;
  outline: none;
}
.counter-field input:focus { border-color: var(--navy-light); }

/* ── แถวจำนวนนักเรียนแบบ 6 ช่องในบรรทัดเดียว (ย่อขนาด) ─── */
.counter-row-6 { grid-template-columns: repeat(6,1fr); gap: 8px; }
.counter-row-6 .counter-field label { font-size: 10.5px; margin-bottom: 4px; white-space: nowrap; }
.counter-row-6 .counter-field input { padding: 6px 4px; font-size: 14px; }

/* ── Section title ─────────────────────────────────────── */
.section-title {
  font-size: 12.5px; font-weight: 700;
  color: var(--navy-light);
  text-transform: uppercase; letter-spacing: .07em;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--gold);
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.section-title svg { width: 14px; height: 14px; }

/* ── Alert ─────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13.5px; margin-bottom: 14px; }
.alert-warning { background: var(--amber-light); color: #92400e; border-left: 4px solid var(--amber); }
.alert-success { background: var(--green-light); color: #14532d; border-left: 4px solid var(--green); }
.alert-info    { background: var(--blue-light);  color: #1e3a8a; border-left: 4px solid var(--blue); }

/* ── Approval steps ────────────────────────────────────── */
.approval-steps { display: flex; gap: 0; margin: 16px 0; overflow-x: auto; }
.step {
  flex: 1; min-width: 90px;
  display: flex; flex-direction: column; align-items: center;
  position: relative;
}
.step:not(:last-child)::after {
  content: ''; position: absolute;
  top: 14px; left: 50%;
  width: 100%; height: 2px;
  background: var(--gray-200);
}
.step:not(:last-child).done::after { background: var(--green); }
.step-dot {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--gray-200);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--gray-400);
  position: relative; z-index: 1;
  border: 2px solid var(--gray-200);
  transition: all .3s;
}
.step.done    .step-dot    { background: var(--green); border-color: var(--green); color: white; }
.step.current .step-dot    { background: var(--navy);  border-color: var(--navy);  color: white; }
.step-label { font-size: 10px; color: var(--gray-400); margin-top: 6px; text-align: center; line-height: 1.3; }
.step.done    .step-label  { color: var(--green); font-weight: 600; }
.step.current .step-label  { color: var(--navy);  font-weight: 700; }

/* ── Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,32,68,.5);
  z-index: 200;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 700px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--white); z-index: 1;
}
.modal-header h3 { font-size: 16px; font-weight: 700; color: var(--navy); }
.btn-close {
  width: 30px; height: 30px; border-radius: 8px;
  border: none; background: var(--gray-100);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--gray-600);
  transition: background .15s;
}
.btn-close:hover { background: var(--gray-200); }
.modal-body   { padding: 22px 24px; }
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--gray-100);
  display: flex; justify-content: flex-end; gap: 10px;
  flex-wrap: wrap;
}

/* ── Tabs ──────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 0;
  border-bottom: 2px solid var(--gray-100);
  margin-bottom: 20px;
}
.tab-btn {
  padding: 10px 20px;
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  color: var(--gray-400);
  background: none; border: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .15s;
}
.tab-btn.active           { color: var(--navy); border-bottom-color: var(--navy); }
.tab-btn:hover:not(.active) { color: var(--gray-600); }
.tab-panel       { display: none; }
.tab-panel.active{ display: block; }

/* ── Filter bar ────────────────────────────────────────── */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.filter-bar select,
.filter-bar input {
  padding: 8px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-family: inherit; font-size: 13px;
  background: var(--white); outline: none;
  min-width: 140px;
}
.filter-bar select:focus,
.filter-bar input:focus { border-color: var(--navy-light); }

/* ── Config notice ─────────────────────────────────────── */
.config-notice {
  display: none;
  background: linear-gradient(135deg, #fff7ed, #fef3c7);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  margin-bottom: 20px;
}
.config-notice h4 { color: #92400e; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.config-notice p  { font-size: 13px; color: #78350f; line-height: 1.6; }
.config-notice code {
  background: rgba(0,0,0,.08); padding: 1px 6px;
  border-radius: 4px; font-family: monospace; font-size: 12px;
}

/* ── Empty state ───────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--gray-400); }
.empty-state svg  { width: 48px; height: 48px; margin: 0 auto 12px; display: block; opacity: .4; }
.empty-state h4   { font-size: 15px; font-weight: 600; color: var(--gray-600); }
.empty-state p    { font-size: 13px; margin-top: 4px; }

/* ── Primary button (auth) ─────────────────────────────── */
.btn-primary {
  width: 100%; padding: 12px;
  background: linear-gradient(135deg, var(--navy), var(--navy-light));
  color: var(--white); border: none; border-radius: var(--radius);
  font-family: inherit; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: opacity .2s, transform .1s; margin-top: 6px;
}
.btn-primary:hover  { opacity: .92; }
.btn-primary:active { transform: scale(.99); }

.error-msg {
  color: var(--red); font-size: 13px;
  margin-top: 10px; text-align: center; display: none;
}

/* ── Print ─────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .no-print, .btn, .tabs, .filter-bar { display: none !important; }
  .main    { margin-left: 0 !important; }
  .content { padding: 0 !important; }
  body     { background: white; font-size: 12pt; }
  .card    { box-shadow: none; border: 1px solid #ccc; }
  table    { font-size: 10pt; }
}

/* ============================================================
   RESPONSIVE + COLLAPSIBLE SIDEBAR
   ============================================================ */

/* ── CSS variables สำหรับ sidebar width ─────────────────── */
:root {
  --sidebar-w:         260px;  /* ขยาย */
  --sidebar-collapsed: 64px;   /* ยุบ */
  --topbar-h:          65px;
}

/* ── Toggle button (ปุ่มยุบ/ขยาย sidebar) ───────────────── */
.sidebar-toggle {
  position: fixed;
  top: 16px; left: 16px;
  z-index: 300;
  width: 34px; height: 34px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.12);
  color: var(--white);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.22); }
.sidebar-toggle svg   { width: 18px; height: 18px; }

/* ── Sidebar collapsed state ────────────────────────────── */
.sidebar {
  transition: width .25s cubic-bezier(.4,0,.2,1);
  overflow-x: hidden;  /* ซ่อนแนวนอนเพื่อ animation */
  overflow-y: auto;    /* scroll แนวตั้งได้เมื่อเมนูเยอะ */
  width: var(--sidebar-w);
}
.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

/* ซ่อนข้อความโดยไม่ใช้ font-size:0 (เพราะ cascade ไปทำ input/text เสีย) */
.sidebar.collapsed .sidebar-logo h2,
.sidebar.collapsed .sidebar-logo p,
.sidebar.collapsed .user-info,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .nav-item span:not(.badge),
.sidebar.collapsed .btn-logout span {
  display: none;
}
.sidebar.collapsed .nav-item .badge        { display: none; }
.sidebar.collapsed .sidebar-footer .btn-logout { width: 100%; }
.sidebar.collapsed .sidebar-logo  { justify-content: center; }
.sidebar.collapsed .sidebar-header{ padding: 18px 11px; }
.sidebar.collapsed .user-badge    { justify-content: center; padding: 10px 8px; }
.sidebar.collapsed .user-avatar   { margin: 0; }
.sidebar.collapsed .nav-section   { padding: 4px 8px; }
.sidebar.collapsed .nav-item      {
  justify-content: center;
  padding: 10px 0;
  border-radius: 8px;
}
.sidebar.collapsed .nav-item svg  { margin: 0; }
.sidebar.collapsed .sidebar-footer{ padding: 10px 8px; }
.sidebar.collapsed .btn-logout    { justify-content: center; padding: 10px 0; min-width: 0; }

/* tooltip เมื่อ hover ตอน collapsed */
.sidebar.collapsed .nav-item      { position: relative; }
.sidebar.collapsed .nav-item::after {
  content: attr(data-label);
  position: absolute;
  left: calc(var(--sidebar-collapsed) + 8px);
  top: 50%; transform: translateY(-50%);
  background: var(--navy);
  color: var(--white);
  font-size: 12px; font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s .05s;
  z-index: 200;
}
.sidebar.collapsed .nav-item:hover::after { opacity: 1; }

/* ── Main content ขยับตาม sidebar ──────────────────────── */
.main {
  transition: margin-left .25s cubic-bezier(.4,0,.2,1);
  margin-left: var(--sidebar-w);
}
.sidebar.collapsed ~ .main,
body.sidebar-collapsed .main {
  margin-left: var(--sidebar-collapsed);
}

/* ── Mobile overlay ─────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15,32,68,.45);
  z-index: 99;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* ── Tablet (≤ 1024px) ──────────────────────────────────── */
@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(2,1fr); }
  .form-grid.cols-3 { grid-template-columns: 1fr 1fr; }
  .content { padding: 18px 20px; }
}

/* ── Mobile (≤ 768px) ───────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar เด้งออกมาจากซ้ายแบบ overlay */
  :root { --sidebar-w: 260px; }

  .sidebar {
    position: fixed;
    left: calc(-1 * var(--sidebar-w));
    transition: left .25s cubic-bezier(.4,0,.2,1), width .25s;
    width: var(--sidebar-w) !important;
    height: 100vh;
    height: 100dvh;
    z-index: 200;
  }
  .sidebar.mobile-open {
    left: 0;
    box-shadow: 4px 0 24px rgba(15,32,68,.3);
  }
  .main {
    margin-left: 0 !important;
  }

  /* topbar hamburger */
  .topbar {
    padding: 12px 16px;
    gap: 10px;
  }
  .topbar h1    { font-size: 15px; }
  .topbar .breadcrumb { display: none; }

  /* hamburger button บน mobile */
  .mobile-menu-btn {
    display: flex !important;
    align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border: none; border-radius: 8px;
    background: var(--gray-100);
    cursor: pointer; flex-shrink: 0;
    color: var(--navy);
  }
  .mobile-menu-btn svg { width: 20px; height: 20px; }

  /* content */
  .content { padding: 14px 14px; }
  .stat-grid { grid-template-columns: repeat(2,1fr); gap: 10px; }
  .stat-card { padding: 14px 12px; gap: 10px; }
  .stat-val  { font-size: 22px; }

  /* form */
  .form-grid.cols-2  { grid-template-columns: 1fr; }
  .form-grid.cols-3  { grid-template-columns: 1fr; }
  .counter-row       { grid-template-columns: repeat(3,1fr); gap: 8px; }
  .counter-row-6     { grid-template-columns: repeat(6,1fr); gap: 5px; }
  .counter-row-6 .counter-field label { font-size: 9.5px; }
  .counter-row-6 .counter-field input { padding: 5px 2px; font-size: 12.5px; }
  .checkbox-grid     { grid-template-columns: repeat(2,1fr); }

  /* table */
  .table-wrap { border-radius: 0; }
  table       { font-size: 12.5px; }
  thead th    { padding: 8px 10px; font-size: 11px; }
  tbody td    { padding: 10px 10px; }

  /* modal */
  .modal        { max-width: 100% !important; margin: 8px; border-radius: 12px; }
  .modal-body   { padding: 16px; }
  .modal-footer { padding: 12px 16px; gap: 8px; }
  .modal-footer .btn { flex: 1; justify-content: center; }

  /* tabs */
  .tabs { overflow-x: auto; gap: 0; }
  .tab-btn { padding: 9px 14px; font-size: 13px; white-space: nowrap; }

  /* filter bar */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar select,
  .filter-bar input   { min-width: 0; width: 100%; }

  /* profile */
  .form-grid.cols-2 { grid-template-columns: 1fr; }

  /* admin backup */
  #admin-tab-backup .form-grid.cols-2 { grid-template-columns: 1fr; }

  /* approval steps */
  .approval-steps { flex-wrap: wrap; gap: 4px; }
  .step           { min-width: 80px; }
  .step::after    { display: none; }

  /* signature modal */
  #sig-canvas { height: 160px !important; }

  /* report summary */
  #report-summary { justify-content: flex-start; }
  #report-summary > div { min-width: 80px; }

  /* topbar actions ไม่ wrap */
  .topbar-actions { flex-shrink: 0; }
  .topbar-actions .btn { font-size: 12px; padding: 7px 10px; }
}

/* ── Small mobile (≤ 480px) ────────────────────────────── */
@media (max-width: 480px) {
  .stat-grid         { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card         { padding: 12px 10px; flex-direction: column; gap: 6px; }
  .stat-icon         { width: 36px; height: 36px; }
  .checkbox-grid     { grid-template-columns: 1fr 1fr; }
  .counter-row       { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .counter-field input { font-size: 15px; }
  .counter-row-6     { grid-template-columns: repeat(6,1fr); gap: 3px; }
  .counter-row-6 .counter-field label { font-size: 8.5px; }
  .counter-row-6 .counter-field input { padding: 4px 1px; font-size: 11px; }
  .content           { padding: 10px 10px; }

  /* form sections */
  .section-title { font-size: 11.5px; }
  .field input,
  .field select,
  .field textarea { font-size: 13.5px; }
}

/* ── ซ่อน mobile-menu-btn บน desktop ──────────────────── */
.mobile-menu-btn { display: none; }

/* ── Sidebar toggle ตำแหน่งใน header ───────────────────── */
.sidebar-header-row {
  display: flex; align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* ── Form action bar (ปุ่มล่างฟอร์มบันทึก) ─────────────── */
.form-action-bar {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  border-top: 1px solid var(--gray-100);
  padding-top: 20px;
  margin-top: 4px;
}
.btn-action-draft {
  border-color: var(--gold);
  color: var(--amber);
}

@media (max-width: 600px) {
  .form-action-bar {
    flex-direction: column-reverse; /* ปุ่มหลักอยู่บนสุด */
    gap: 8px;
  }
  .form-action-bar .btn {
    width: 100%;
    justify-content: center;
    padding: 13px 16px;
    font-size: 15px;
  }
  /* ให้ card body เลื่อนได้เมื่อเนื้อหาล้น */
  #page-log-form .content {
    padding-bottom: 24px;
  }
  #page-log-form .card-body {
    overflow-y: auto;
  }
}

/* ── Table vertical alignment ────────────────────────────── */
tbody td { vertical-align: middle; }

/* ── Signature mode tabs ─────────────────────────────────── */
.sig-mode-tabs {
  display: flex; gap: 0;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.sig-mode-btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 12px;
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  color: var(--gray-400);
  background: var(--white);
  border: none; cursor: pointer;
  transition: all .15s;
}
.sig-mode-btn svg { width: 15px; height: 15px; }
.sig-mode-btn:first-child { border-right: 1.5px solid var(--gray-200); }
.sig-mode-btn.active {
  background: var(--navy);
  color: var(--white);
}
.sig-mode-btn:hover:not(.active) { background: var(--gray-50); color: var(--gray-600); }

#sig-upload-dropzone:hover {
  border-color: var(--navy-light) !important;
  background: var(--gray-100) !important;
}

/* ── Page size selector ──────────────────────────────────── */
.pagesize-bar {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--gray-600);
}
.pagesize-bar select {
  padding: 5px 10px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-family: inherit; font-size: 13px;
  background: var(--white); outline: none;
  cursor: pointer;
}
.pagesize-bar select:focus { border-color: var(--navy-light); }

/* ── Pagination bar ──────────────────────────────────────── */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid var(--gray-100);
  flex-wrap: wrap; gap: 10px;
}
.pager-info {
  font-size: 13px; color: var(--gray-400);
}
.pager-btns {
  display: flex; gap: 4px;
}
.pager-btn {
  min-width: 32px; height: 32px;
  padding: 0 6px;
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  background: var(--white);
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--gray-600);
  cursor: pointer; transition: all .15s;
}
.pager-btn:hover:not(:disabled):not(.active) {
  border-color: var(--navy-light);
  color: var(--navy);
  background: var(--gray-50);
}
.pager-btn.active {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--white);
}
.pager-btn:disabled {
  opacity: .35; cursor: not-allowed;
}

/* ── Media checkbox grid ─────────────────────────────────── */
.checkbox-grid { grid-template-columns: repeat(3,1fr); }
