/* ============================================================
   ระบบบันทึกการทำเวรสีประจำวัน — Design System
   แนวคิด: "เช้าวันใหม่ + เวรสี" — โทนฟ้าเข้ม (เข้าชุดกับ BVL System)
   จุดเด่น: วงแหวน "พระอาทิตย์ขึ้น" แสดงความคืบหน้าการเช็คชื่อ
   และแบนเนอร์ที่ปรับสีตามกลุ่มสีจริงของผู้ใช้แบบไดนามิก
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@500;600;700&family=IBM+Plex+Sans+Thai:wght@400;500;600&display=swap');

:root {
  /* --- โทนสีหลัก: ฟ้าเข้ม สไตล์เดียวกับ BVL System --- */
  --bg: #EFF4FA;
  --bg-alt: #E3ECF7;
  --surface: #FFFFFF;
  --ink: #1A2B3C;
  --ink-soft: #5A6B7D;
  --ink-faint: #8FA0B3;
  --border: #DCE6F2;

  --brand: #1D6FE0;
  --brand-dark: #0F3D91;
  --brand-tint: #E6EFFC;

  --accent: #F5A524;      /* สีเสริม: เหลืองอำพัน ใช้เท่าที่จำเป็น */
  --accent-tint: #FDF1DC;

  --success: #40916C;
  --success-tint: #E4F5EC;
  --danger: #D9534F;
  --danger-tint: #FBEAE9;
  --info: #6366F1;
  --info-tint: #ECEBFE;
  --warning: #F5A524;
  --warning-tint: #FDF1DC;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --shadow-sm: 0 1px 2px rgba(15, 61, 145, 0.07);
  --shadow-md: 0 6px 20px rgba(15, 61, 145, 0.12);
  --shadow-lg: 0 16px 40px rgba(15, 61, 145, 0.16);

  --font-display: 'Kanit', 'IBM Plex Sans Thai', sans-serif;
  --font-body: 'IBM Plex Sans Thai', 'Kanit', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 12% -10%, rgba(245, 165, 36, 0.13), transparent 45%),
    radial-gradient(circle at 100% 0%, rgba(29, 111, 224, 0.12), transparent 40%);
  background-attachment: fixed;
}

h1, h2, h3, .display {
  font-family: var(--font-display);
  color: var(--brand-dark);
  margin: 0;
  line-height: 1.25;
}

p { margin: 0 0 0.5rem; color: var(--ink-soft); }
a { color: var(--brand); }

/* ---------- Layout shells ---------- */
.shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.shell--narrow { max-width: 460px; }

/* ============================================================
   App shell: sidebar (desktop) + off-canvas drawer (mobile)
   ============================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 268px;
  flex-shrink: 0;
  position: fixed;
  inset-block: 0;
  left: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: linear-gradient(165deg, var(--brand-dark) 0%, #0A2C6B 100%);
  color: #fff;
  box-shadow: var(--shadow-lg);
  transition: transform .25s ease;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: 1.25rem 1.15rem;
  text-decoration: none;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  flex-shrink: 0;
}
.sidebar__logo {
  width: 40px; height: 40px;
  border-radius: 11px;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.26);
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}
.sidebar__title { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.sidebar__title strong { font-family: var(--font-display); font-size: .96rem; font-weight: 600; }
.sidebar__title small { font-size: .7rem; color: rgba(255,255,255,0.68); font-weight: 400; }

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: .9rem .8rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}

.sidebar__link, .sidebar__group-toggle {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .7rem .8rem;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.82);
  text-decoration: none;
  font-size: .89rem;
  font-weight: 500;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: var(--font-body);
}
.sidebar__link i:first-child, .sidebar__group-toggle i:first-child { width: 18px; text-align: center; opacity: .9; }
.sidebar__link:hover, .sidebar__group-toggle:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar__link.is-active { background: rgba(255,255,255,0.16); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }

.sidebar__group-toggle { justify-content: space-between; }
.sidebar__group-toggle .chevron { margin-inline-start: auto; transition: transform .2s ease; font-size: .75rem; opacity: .75; }
.sidebar__group-toggle.is-open .chevron { transform: rotate(180deg); }

.sidebar__submenu {
  overflow: hidden;
  max-height: 0;
  transition: max-height .22s ease;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding-inline-start: .6rem;
}
.sidebar__submenu.is-open { max-height: 320px; }
.sidebar__submenu .sidebar__link {
  font-size: .83rem;
  padding: .55rem .8rem .55rem 1.6rem;
  color: rgba(255,255,255,0.68);
  position: relative;
}
.sidebar__submenu .sidebar__link::before {
  content: '';
  position: absolute;
  left: .95rem;
  top: 50%;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  transform: translateY(-50%);
  opacity: .6;
}
.sidebar__submenu .sidebar__link.is-active { box-shadow: none; background: rgba(255,255,255,0.1); color: #fff; }

.sidebar__footer {
  flex-shrink: 0;
  padding: 1rem 1.15rem 1.15rem;
  border-top: 1px solid rgba(255,255,255,0.12);
}
.sidebar__user { display: flex; align-items: center; gap: .6rem; margin-bottom: .7rem; }
.sidebar__avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.16);
  display: grid; place-items: center;
  font-size: .85rem;
  flex-shrink: 0;
}
.sidebar__username { font-size: .85rem; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__signout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  width: 100%;
  border: 1px solid rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.06);
  color: #fff;
  padding: .6rem;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: .82rem;
  cursor: pointer;
}
.sidebar__signout:hover { background: rgba(255,255,255,0.18); }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(10, 20, 40, 0.5);
  display: none;
}
.sidebar-overlay.is-open { display: block; }

/* ---------- Mobile top bar (hamburger) ---------- */
.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  align-items: center;
  gap: .8rem;
  padding: .8rem 1rem;
  background: linear-gradient(120deg, var(--brand-dark) 0%, var(--brand) 100%);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.mobile-topbar__toggle {
  border: none;
  background: rgba(255,255,255,0.14);
  color: #fff;
  width: 38px; height: 38px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}
.mobile-topbar__title { font-family: var(--font-display); font-weight: 600; font-size: .95rem; }

/* ---------- Main content area ---------- */
.app-main {
  flex: 1;
  min-width: 0;
  margin-left: 268px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.app-main > .shell { flex: 1 0 auto; }

/* ---------- Footer: dark, pinned to viewport bottom ---------- */
.site-footer {
  flex-shrink: 0;
  background: var(--brand-dark);
  color: rgba(255,255,255,0.85);
}
.site-footer__inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .4rem;
  font-size: .78rem;
  color: rgba(255,255,255,0.75);
}
.site-footer__inner strong { color: #fff; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.is-open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .mobile-topbar { display: flex; }
}

@media (max-width: 640px) {
  .site-footer__inner { flex-direction: column; text-align: center; gap: .3rem; }
}

/* ---------- Cards & surfaces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

.card + .card { margin-top: 1.25rem; }

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.15rem;
  flex-wrap: wrap;
}

.card__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: .55rem;
}
.card__title i { color: var(--brand); }

.eyebrow {
  font-family: var(--font-display);
  font-size: .72rem;
  letter-spacing: .08em;
  color: var(--brand);
  text-transform: uppercase;
  font-weight: 600;
}

.page-head { margin-bottom: 1.5rem; }
.page-head h1 { font-size: 1.55rem; margin-top: .3rem; }

/* ---------- Stat cards (vivid icon badges) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.1rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.3rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform .15s ease, box-shadow .15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card__icon {
  width: 48px; height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  color: #fff;
  box-shadow: 0 6px 14px -4px rgba(0,0,0,0.25);
}
.stat-card__body { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.stat-card__value { font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; color: var(--ink); line-height: 1.15; }
.stat-card__label { font-size: .8rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stat-card--brand .stat-card__icon { background: linear-gradient(145deg, var(--brand), var(--brand-dark)); }
.stat-card--success .stat-card__icon { background: linear-gradient(145deg, #52B788, var(--success)); }
.stat-card--danger .stat-card__icon { background: linear-gradient(145deg, #E57373, var(--danger)); }
.stat-card--warning .stat-card__icon { background: linear-gradient(145deg, #FFC24B, var(--warning)); }
.stat-card--info .stat-card__icon { background: linear-gradient(145deg, #818CF8, var(--info)); }

/* ---------- Dynamic color-group banner (signature element) ---------- */
.group-banner {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.4rem;
  color: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  background: linear-gradient(135deg, var(--gc, var(--brand)) 0%, color-mix(in srgb, var(--gc, var(--brand)) 70%, #0a0a0a 20%) 100%);
}
.group-banner::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at 85% -20%, rgba(255,255,255,.35), transparent 55%);
  pointer-events: none;
}
.group-banner h1 { color: #fff; font-size: 1.35rem; }
.group-banner p { color: rgba(255,255,255,0.85); }
.group-banner__meta {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-top: .6rem;
  font-size: .82rem;
  color: rgba(255,255,255,0.9);
}

/* ---------- Sunrise ring progress (signature element) ---------- */
.ring {
  --pct: 0;
  --size: 92px;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  position: relative;
  display: grid;
  place-items: center;
  background:
    radial-gradient(closest-side, var(--surface) 68%, transparent 69% 100%),
    conic-gradient(var(--rc, var(--accent)) calc(var(--pct) * 1%), rgba(255,255,255,0.35) 0);
  box-shadow: 0 4px 14px -6px rgba(0,0,0,0.3);
  flex-shrink: 0;
}
.ring--onlight {
  background:
    radial-gradient(closest-side, var(--surface) 68%, transparent 69% 100%),
    conic-gradient(var(--rc, var(--brand)) calc(var(--pct) * 1%), var(--bg-alt) 0);
  box-shadow: none;
}
.ring__label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  text-align: center;
  line-height: 1.1;
}
.ring__label small { display: block; font-family: var(--font-body); font-weight: 500; font-size: .62rem; color: var(--ink-faint); }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: .92rem;
  border-radius: 999px;
  padding: .75rem 1.4rem;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  transition: transform .12s ease, box-shadow .12s ease, background .15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; color: var(--brand); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--brand); }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: .45rem .75rem; font-size: .8rem; }

/* ---------- Forms ---------- */
label { font-size: .84rem; font-weight: 500; color: var(--ink-soft); display: block; margin-bottom: .35rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="file"], select, textarea {
  width: 100%;
  font-family: var(--font-body);
  font-size: .92rem;
  padding: .7rem .85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}
.field { margin-bottom: 1rem; }
.field--row { display: flex; gap: .75rem; }
.field--row > * { flex: 1; }

/* ---------- Roster / attendance rows ---------- */
.roster-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  transition: border-color .15s ease, background .15s ease;
}
.roster-item:hover { border-color: var(--brand); background: var(--brand-tint); }
.roster-item + .roster-item { margin-top: .6rem; }
.roster-item__name { font-weight: 600; font-size: .93rem; color: var(--ink); }
.roster-item__meta { font-size: .76rem; color: var(--ink-faint); }

.status-toggle { display: inline-flex; border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.status-toggle input { display: none; }
.status-toggle label {
  margin: 0;
  padding: .5rem .9rem;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink-faint);
  background: var(--surface);
  transition: background .15s, color .15s;
}
.status-toggle input[value="helped"]:checked + label { background: var(--success); color: #fff; }
.status-toggle input[value="not_helped"]:checked + label { background: var(--danger); color: #fff; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .74rem;
  font-weight: 600;
  padding: .28rem .65rem;
  border-radius: 999px;
}
.badge--success { background: var(--success-tint); color: var(--success); }
.badge--danger { background: var(--danger-tint); color: var(--danger); }
.badge--warning { background: var(--warning-tint); color: var(--warning); }
.badge--info { background: var(--info-tint); color: var(--info); }
.badge--brand { background: var(--brand-tint); color: var(--brand-dark); }
.badge--dot::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Nav menu (dashboard) ---------- */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.1rem;
}
.menu-card {
  display: flex;
  flex-direction: column;
  gap: .7rem;
  text-decoration: none;
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.menu-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--brand); }
.menu-card .glyph {
  width: 46px; height: 46px;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--brand), var(--brand-dark));
  color: #fff;
  display: grid; place-items: center;
  font-size: 1.2rem;
  box-shadow: 0 6px 14px -4px rgba(0,0,0,0.25);
}
.menu-card.glyph--success .glyph { background: linear-gradient(145deg, #52B788, var(--success)); }
.menu-card.glyph--info .glyph { background: linear-gradient(145deg, #818CF8, var(--info)); }
.menu-card.glyph--warning .glyph { background: linear-gradient(145deg, #FFC24B, var(--warning)); }
.menu-card h3 { font-size: 1.02rem; }
.menu-card p { font-size: .83rem; margin: 0; }

/* ---------- Auth screen ---------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 2.2rem 1.9rem;
}
.auth-card .glyph {
  width: 52px; height: 52px;
  border-radius: 16px;
  background: linear-gradient(145deg, var(--brand), var(--brand-dark));
  display: grid; place-items: center;
  color: #fff; font-size: 1.4rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-md);
}

/* ---------- Utility ---------- */
.stack { display: flex; flex-direction: column; gap: .75rem; }
.row { display: flex; align-items: center; gap: .75rem; }
.row--between { justify-content: space-between; }
.muted { color: var(--ink-faint); font-size: .82rem; }
.empty-state { text-align: center; padding: 2.4rem 1rem; color: var(--ink-faint); }
.empty-state i { font-size: 1.6rem; margin-bottom: .6rem; display: block; }

.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: .5rem; }
.week-strip__day { text-align: center; }
.week-strip__date { font-size: .72rem; color: var(--ink-faint); margin-bottom: .3rem; }
.week-strip__bar {
  border-radius: var(--radius-sm);
  padding: .55rem .3rem;
  background: var(--success-tint);
  border: 1px solid var(--border);
}
.week-strip__bar span { font-family: var(--font-display); font-weight: 700; font-size: .82rem; color: var(--success); }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.photo-grid img {
  width: 100%; height: 92px; object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

table.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data-table th { text-align: right; color: var(--ink-soft); font-weight: 600; font-size: .78rem; padding: .7rem .5rem; border-bottom: 2px solid var(--border); background: var(--bg); }
table.data-table th:first-child, table.data-table td:first-child { text-align: right; border-radius: var(--radius-sm) 0 0 0; }
table.data-table td { padding: .7rem .5rem; border-bottom: 1px solid var(--border); }
table.data-table tbody tr:hover { background: var(--brand-tint); }

.toast-region { position: fixed; top: 1rem; right: 1rem; z-index: 999; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--brand-dark); color: #fff;
  padding: .7rem 1.1rem; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: .86rem;
  animation: toast-in .2s ease;
}
.toast--error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 640px) {
  .shell { padding: 1rem .9rem 2.4rem; }
  .card { padding: 1.1rem; }
  .field--row { flex-direction: column; }
  table.data-table { font-size: .8rem; }
}

@media (max-width: 880px) {
  .two-col { grid-template-columns: 1fr !important; }
}
