/* ระบบเยี่ยมบ้านออนไลน์ — ธีมหลัก (ใช้ร่วมกับ Bootstrap 5) */
:root {
  --hv-primary: #1e3a8a;
  --hv-primary-2: #2563eb;
  --hv-accent: #db2777;
  --hv-bg: #f3f5fb;
  --hv-card: #ffffff;
  --hv-muted: #64748b;
  --bs-primary: #1e40af;
  --bs-primary-rgb: 30, 64, 175;
  --bs-body-font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Tahoma", system-ui, sans-serif;
  --bs-body-font-size: 1rem;
  --bs-border-radius: .6rem;
}
body { background: var(--hv-bg); color: #0f172a; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1 0 auto; }
.ico { width: 1.1em; height: 1.1em; vertical-align: -0.18em; }
.btn .ico { margin-right: .15rem; }

/* แถบเมนู */
.app-nav { background: linear-gradient(90deg, var(--hv-primary), var(--hv-primary-2)); box-shadow: 0 2px 12px rgba(30, 58, 138, .25); }
.app-nav .navbar-brand small { font-size: .72rem; }
.app-nav .nav-link { border-radius: .5rem; padding: .45rem .75rem !important; }
.app-nav .nav-link.active, .app-nav .nav-link:hover { background: rgba(255, 255, 255, .16); }
.year-select { min-width: 12rem; background-color: rgba(255, 255, 255, .95); }
.year-badge { font-size: .85rem; padding: .45rem .6rem; }

/* การ์ด / สถิติ */
.card { border: 0; border-radius: 1rem; box-shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 6px 18px rgba(15, 23, 42, .05); }
.card-header { background: transparent; border-bottom: 1px solid #eef1f7; font-weight: 600; padding: .9rem 1.1rem; }
.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-ico { position: absolute; right: .8rem; top: .8rem; width: 2.6rem; height: 2.6rem; border-radius: .8rem;
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem; }
.stat-card .stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-card .stat-label { color: var(--hv-muted); font-size: .9rem; }
.bg-soft-primary { background: #e0e7ff; color: #3730a3; }
.bg-soft-success { background: #dcfce7; color: #166534; }
.bg-soft-warning { background: #fef3c7; color: #92400e; }
.bg-soft-danger  { background: #fee2e2; color: #991b1b; }
.bg-soft-info    { background: #e0f2fe; color: #075985; }
.bg-soft-pink    { background: #fce7f3; color: #9d174d; }
.page-title { font-weight: 700; font-size: 1.45rem; margin: 0; }
.page-sub { color: var(--hv-muted); }

/* กราฟแท่งรายระดับชั้น */
.grade-bars { display: flex; align-items: flex-end; gap: .75rem; height: 220px; padding: .5rem .25rem 0; }
.grade-bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; text-decoration: none; color: inherit; }
.grade-bar .bar-track { width: 100%; max-width: 64px; flex: 1; background: #eef2ff; border-radius: .6rem .6rem .25rem .25rem; position: relative; overflow: hidden; }
.grade-bar .bar-fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(180deg, #60a5fa, #1d4ed8); border-radius: .6rem .6rem .25rem .25rem; transition: height .6s ease; }
.grade-bar .bar-fill.done { background: linear-gradient(180deg, #4ade80, #15803d); }
.grade-bar .bar-pct { font-weight: 700; font-size: .9rem; margin-bottom: .25rem; }
.grade-bar .bar-label { font-weight: 600; margin-top: .35rem; }
.grade-bar:hover .bar-track { outline: 2px solid #93c5fd; }

/* ตารางรายชื่อ */
.table-app { --bs-table-bg: transparent; margin: 0; }
.table-app thead th { background: #f1f5f9; color: #334155; font-weight: 600; white-space: nowrap; border-bottom: 0; }
.table-app td { vertical-align: middle; }
.table-app tr.visited td { background: #dcfce7; }
.table-app.table-hover tr.visited:hover td { background: #bbf7d0; }
.vtype-sel .btn { min-width: 4.4rem; }
.btn-visited { min-width: 7rem; }
.photo-dots { display: inline-flex; gap: 3px; }
.photo-dots span { width: .65rem; height: .65rem; border-radius: 50%; background: #e2e8f0; display: inline-block; }
.photo-dots span.on { background: #22c55e; }
.btn-mark { min-width: 7.2rem; }

/* รายการนักเรียนแบบการ์ดบนมือถือ */
@media (max-width: 767.98px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { background: #fff; border-radius: .9rem; margin-bottom: .75rem; padding: .6rem .8rem; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
  .table-cards tr { border-left: 5px solid #cbd5e1; }
  .table-cards tr.visited { border-left-color: #16a34a; background: #f0fdf4; }
  .table-cards td.td-visit .btn-visited { width: 100%; }
  .table-cards .vtype-sel { width: calc(100% - 4.5rem); }
  .table-cards .vtype-sel .btn { flex: 1; }
  .table-cards td { border: 0; padding: .2rem 0; }
  .table-cards td[data-label]::before { content: attr(data-label) " : "; color: var(--hv-muted); font-size: .85rem; }
  .table-cards td.td-actions { padding-top: .5rem; display: flex; flex-wrap: wrap; gap: .4rem; }
  .table-cards td.td-actions .btn { flex: 1 1 auto; }
  .table-cards tr.visited td { background: transparent; }
}

/* ฟอร์มนักเรียน */
.section-head { font-weight: 700; color: var(--hv-primary); border-left: 4px solid var(--hv-accent); padding-left: .6rem; margin: 1.2rem 0 .6rem; }
.form-label { font-weight: 600; font-size: .92rem; margin-bottom: .25rem; color: #334155; }
.nav-tabs-app { gap: .35rem; border: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.nav-tabs-app .nav-link { border: 0; border-radius: 2rem; background: #e2e8f0; color: #334155; white-space: nowrap; }
.nav-tabs-app .nav-link.active { background: var(--hv-primary); color: #fff; }
.sticky-save { position: sticky; bottom: 0; z-index: 5; background: rgba(243, 245, 251, .92); backdrop-filter: blur(6px); padding: .75rem 0; border-top: 1px solid #e2e8f0; }

/* ช่องรูปภาพ */
.photo-slot { border: 2px dashed #cbd5e1; border-radius: 1rem; background: #f8fafc; overflow: hidden; position: relative; aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: border-color .2s; }
.photo-slot:hover { border-color: var(--hv-primary-2); }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; }
.photo-slot .ph-empty { text-align: center; color: var(--hv-muted); padding: 1rem; }
.photo-slot .ph-empty .ico { width: 2.4rem; height: 2.4rem; display: block; margin: 0 auto .4rem; }
.photo-slot .ph-busy { position: absolute; inset: 0; background: rgba(255,255,255,.8); display: none; align-items: center; justify-content: center; flex-direction: column; }
.photo-slot.busy .ph-busy { display: flex; }
.photo-slot.has-photo { border-style: solid; border-color: #86efac; }

/* หน้าเข้าสู่ระบบ */
body.guest { background: radial-gradient(1200px 600px at 10% -10%, #3b82f6 0, transparent 60%), radial-gradient(900px 500px at 110% 110%, #db2777 0, transparent 55%), #1e3a8a; }
body.guest .app-footer { display: none; }
.login-wrap { max-width: 440px; margin: 4vh auto; }
.login-card { border-radius: 1.4rem; }
.login-logo { width: 96px; height: auto; }
.login-tabs .nav-link { border-radius: .8rem; }
.login-tabs .nav-link:not(.active) { background: #f1f5f9; color: #334155; }

.app-footer { color: #64748b; border-top: 1px solid #e2e8f0; background: #fff; }
.toast { border-radius: .8rem; }
.min-w-0 { min-width: 0; }
.cursor-pointer { cursor: pointer; }
@media (max-width: 575.98px) {
  .page-title { font-size: 1.2rem; }
  .stat-card .stat-value { font-size: 1.5rem; }
  .grade-bars { height: 180px; gap: .4rem; }
}
.app-nav .nav-link { white-space: nowrap; }
@media (min-width: 992px) and (max-width: 1399.98px) { .app-nav .navbar-brand small { display: none; } .app-nav .nav-link { padding: .45rem .55rem !important; } }
