/* ระบบจัดการการชำระเงินค่าเสื้อกีฬาสี — สไตล์คลีน อ่านง่าย ปุ่มใหญ่ ใช้งานภาษาไทยเป็นหลัก */
:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #dfe3e8;
  --color-text: #1f2933;
  --color-text-muted: #6b7280;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-success: #16a34a;
  --color-success-bg: #dcfce7;
  --color-warning: #d97706;
  --color-warning-bg: #fef3c7;
  --color-danger: #dc2626;
  --color-danger-bg: #fee2e2;
  --color-info-bg: #dbeafe;
  --sidebar-width: 220px;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Sarabun", "TH Sarabun New", "Waree", "Noto Sans Thai", "Segoe UI", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
}

a { color: var(--color-primary); text-decoration: none; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: #111827;
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  padding: 16px 0;
}

.sidebar .brand {
  font-size: 16px;
  font-weight: 700;
  padding: 0 20px 16px;
  border-bottom: 1px solid #1f2937;
  margin-bottom: 12px;
  line-height: 1.4;
}

.sidebar nav a {
  display: block;
  padding: 12px 20px;
  color: #cbd5e1;
  font-size: 15px;
  border-left: 4px solid transparent;
}

.sidebar nav a:hover { background: #1f2937; color: #fff; }
.sidebar nav a.active {
  background: #1f2937;
  color: #fff;
  border-left-color: var(--color-primary);
  font-weight: 600;
}

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

.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar .user-info { font-size: 14px; color: var(--color-text-muted); }
.topbar .user-info b { color: var(--color-text); }

.content { padding: 24px; flex: 1; }

h1.page-title { font-size: 22px; margin: 0 0 16px; }
h2.section-title { font-size: 17px; margin: 24px 0 12px; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.grid {
  display: grid;
  gap: 14px;
}
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; }
  .sidebar .brand { display: none; }
  .sidebar nav { display: flex; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
}

.stat-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-box .num { font-size: 26px; font-weight: 700; }
.stat-box .label { font-size: 13px; color: var(--color-text-muted); margin-top: 4px; }
/* PROMPT แก้ Dashboard "ภาพรวมด้านการเงิน": Subtitle เล็กๆ ใต้ label ปกติ (เช่น "ตาม Bank Statement")
   ใช้กับการ์ดที่ต้องการบอกที่มาของตัวเลขเพิ่มเติม — เพิ่มใหม่เฉยๆ ไม่กระทบ .stat-box .label เดิม */
.stat-box .sub-note { font-size: 11px; color: var(--color-text-muted); opacity: .75; margin-top: 2px; }
.stat-box.success .num { color: var(--color-success); }
.stat-box.warning .num { color: var(--color-warning); }
.stat-box.danger .num { color: var(--color-danger); }
.stat-box.primary .num { color: var(--color-primary); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
table th, table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  white-space: nowrap;
}
table th { background: #f9fafb; font-weight: 600; color: var(--color-text-muted); }
table tbody tr:hover { background: #f9fafb; }
.table-scroll { overflow-x: auto; }

/* MASTER PROMPT ข้อ 1: ตารางตรวจสอบก่อนบันทึกของหน้า Import นักเรียน (อาจมี 100+ แถว)
   - กล่องสูงจำกัด + เลื่อนได้ทั้งแนวตั้ง/แนวนอน "ในกล่องเดียวกัน" ทำให้แถบเลื่อนแนวนอนอยู่ติดขอบล่างของ
     กล่องเสมอ (มองเห็น/ใช้งานได้ตลอดเวลาที่ตรวจข้อมูล) ไม่ใช่ต้องเลื่อนหน้าเว็บลงไปสุดตารางก่อนแบบเดิม
   - หัวตาราง (thead) ตรึงด้านบน, คอลัมน์ระบุตัวตน (ชื่อ/นามสกุล) ตรึงด้านซ้าย, คอลัมน์ปุ่ม "ลบ" ตรึงด้านขวา
   - ใช้ table-layout:fixed + colgroup กำหนดความกว้างคอลัมน์ตายตัว เพื่อให้คำนวณตำแหน่ง sticky ซ้าย/ขวา
     ได้แน่นอน และคอลัมน์ไม่ถูกบีบแคบจนอ่าน/แก้ไขยาก (ความกว้างขั้นต่ำที่กำหนดไว้เพียงพอต่อการอ่าน) */
.import-preview-scroll {
  max-height: 65vh;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}
.import-preview-table {
  table-layout: fixed;
  width: auto;
}
.import-preview-table th, .import-preview-table td { white-space: nowrap; }
.import-preview-table col.c-status   { width: 110px; }
.import-preview-table col.c-code     { width: 120px; }
.import-preview-table col.c-fname    { width: 130px; }
.import-preview-table col.c-lname    { width: 130px; }
.import-preview-table col.c-grade    { width: 90px; }
.import-preview-table col.c-room     { width: 80px; }
.import-preview-table col.c-seatno   { width: 90px; }
.import-preview-table col.c-amount   { width: 120px; }
.import-preview-table col.c-color    { width: 90px; }
.import-preview-table col.c-size     { width: 90px; }
.import-preview-table col.c-sizetype { width: 110px; }
.import-preview-table col.c-qty      { width: 90px; }
.import-preview-table col.c-action   { width: 90px; }

.import-preview-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f9fafb;
}
/* คอลัมน์ระบุตัวตน (ชื่อ = คอลัมน์ที่ 3, นามสกุล = คอลัมน์ที่ 4) ตรึงซ้าย */
.import-preview-table th:nth-child(3), .import-preview-table td:nth-child(3),
.import-preview-table th:nth-child(4), .import-preview-table td:nth-child(4) {
  position: sticky;
  z-index: 1;
  background: #fff;
}
.import-preview-table th:nth-child(3), .import-preview-table td:nth-child(3) { left: 0; }
.import-preview-table th:nth-child(4), .import-preview-table td:nth-child(4) {
  left: 130px;
  box-shadow: 2px 0 4px rgba(0,0,0,0.06);
}
.import-preview-table thead th:nth-child(3), .import-preview-table thead th:nth-child(4) {
  z-index: 4;
  background: #f9fafb;
}
.import-preview-table tbody tr:hover td:nth-child(3), .import-preview-table tbody tr:hover td:nth-child(4) {
  background: #f9fafb;
}
/* คอลัมน์ปุ่ม "ลบ" (คอลัมน์สุดท้าย) ตรึงขวา ให้กดได้เสมอโดยไม่ต้องเลื่อนไปสุดขวา */
.import-preview-table th:last-child, .import-preview-table td:last-child {
  position: sticky;
  right: 0;
  z-index: 1;
  background: #fff;
  box-shadow: -2px 0 4px rgba(0,0,0,0.06);
  white-space: normal;
}
.import-preview-table thead th:last-child { z-index: 4; background: #f9fafb; }
.import-preview-table tbody tr:hover td:last-child { background: #f9fafb; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  font-size: 15px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  min-height: 42px;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #fff; color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: #f3f4f6; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 32px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-unpaid { background: #f3f4f6; color: #4b5563; }
.badge-partial { background: var(--color-warning-bg); color: #92400e; }
.badge-paid { background: var(--color-success-bg); color: #166534; }
.badge-overpaid { background: var(--color-info-bg); color: #1e40af; }
.badge-pending_review { background: #fde68a; color: #78350f; }
.badge-cancelled { background: #f3f4f6; color: #9ca3af; }
.badge-unmatched { background: #f3f4f6; color: #4b5563; }
.badge-slip_found { background: var(--color-info-bg); color: #1e40af; }
.badge-partially_allocated { background: var(--color-warning-bg); color: #92400e; }
.badge-fully_allocated { background: var(--color-success-bg); color: #166534; }
.badge-matched { background: var(--color-success-bg); color: #166534; }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
.form-inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-inline .form-row { margin-bottom: 0; min-width: 140px; flex: 1; }

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 14px;
}
.alert-error { background: var(--color-danger-bg); color: #991b1b; }
.alert-warning { background: var(--color-warning-bg); color: #92400e; }
.alert-success { background: var(--color-success-bg); color: #166534; }
.alert-info { background: var(--color-info-bg); color: #1e40af; }

.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); padding: 20px; width: 420px; max-width: 90vw;
}
.modal h3 { margin-top: 0; }

.pill-list { display: flex; gap: 8px; flex-wrap: wrap; }

.dropzone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 30px;
  text-align: center;
  color: var(--color-text-muted);
  cursor: pointer;
}
.dropzone.dragover { border-color: var(--color-primary); background: #eff6ff; }

.thumb {
  width: 90px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--color-border);
}

/* ---------- Dashboard (รอบปรับ 2026-09): Header/Branding + Gauge + Animation เบาๆ ---------- */
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 20px;
  background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
  border: none;
}
.dash-brand { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.dash-logo { max-height: 40px; max-width: 200px; object-fit: contain; display: block; }
.dash-logo-fallback {
  display: none;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #fff;
}
.dash-header-sub { font-size: 13px; color: #cbd5e1; }

/* Fade in + slide up เบาๆ ตอนโหลดหน้า (ข้อ 2.6) — ทำครั้งเดียวตอนเข้าเพจ ไม่วนซ้ำ */
.dash-card { opacity: 0; transform: translateY(10px); animation: dashFadeIn 0.55s ease forwards; }
@keyframes dashFadeIn { to { opacity: 1; transform: translateY(0); } }

.gauge-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 900px) { .gauge-row { grid-template-columns: 1fr; } }

/* FINAL STABILIZATION ข้อ 11: เครดิตผู้พัฒนา — ต้องเล็ก สีจาง ไม่เด่นกว่าข้อมูลระบบ และไม่ fixed/sticky
   (อยู่ท้ายเนื้อหาจริง เห็นเมื่อ scroll ลงสุดหน้าเท่านั้น) ใช้ทั้งใน base.html และ login.html */
.dev-footer {
  text-align: center;
  font-size: 12px;
  color: #9ca3af;
  padding: 18px 0 22px;
  margin-top: 8px;
}

/* FINAL STABILIZATION ข้อ 1.4/7.2: แถวที่ถูกเลือกใน Modal ค้นหารายการโอน / ช่องกรอกที่ผิดรูปแบบ */
.qmp-transfer-row.selected {
  background: #eff6ff;
  border-color: #3b82f6;
  box-shadow: 0 0 0 1px #3b82f6 inset;
}
.input-error {
  border-color: var(--color-danger, #dc2626) !important;
  box-shadow: 0 0 0 1px var(--color-danger, #dc2626) inset;
}

.gauge-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.gauge-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.08); transform: translateY(-2px); }
.gauge-svg { width: 100%; max-width: 200px; height: auto; overflow: visible; }
.gauge-track { fill: none; stroke: #e5e7eb; stroke-width: 10; stroke-linecap: round; }
.gauge-value {
  fill: none; stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 157.08; stroke-dashoffset: 157.08;
  transition: stroke-dashoffset 0.8s cubic-bezier(0.34, 1.2, 0.64, 1);
}
.gauge-value.gauge-primary { stroke: var(--color-primary); }
.gauge-value.gauge-success { stroke: var(--color-success); }
.gauge-value.gauge-warning { stroke: var(--color-warning); }
.gauge-percent { font-size: 26px; font-weight: 700; margin-top: -34px; }
.gauge-label { font-size: 13px; color: var(--color-text-muted); margin-top: 6px; }
.gauge-sub { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }

/* ข้อ 2.10: เคารพ prefers-reduced-motion — ปิด/ลด Animation แต่ข้อมูลยังต้องแสดงครบ */
@media (prefers-reduced-motion: reduce) {
  .dash-card { animation: none !important; opacity: 1 !important; transform: none !important; }
  .gauge-value { transition: none !important; }
  .gauge-card:hover { transform: none; }
}
