/* CenTer City — โหมดมืดเป็นค่าเริ่มต้น · สลับโหมดสว่างด้วย data-theme="light" */
:root {
  color-scheme: dark;
  --bg: #0f1419;
  --bg-elevated: #161d26;
  --bg-card: #1a222d;
  --border: #2d3a4a;
  --text: #e8eef2;
  --text-muted: #94a3b8;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-soft: rgba(45, 212, 191, 0.14);
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
  --font: "IBM Plex Sans Thai", "Sarabun", "Segoe UI", system-ui, sans-serif;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.4);
  --input-bg: #121a22;
  --input-border: var(--border);
  --btn-default-bg: #1e2630;
  --btn-secondary-bg: #1e2630;
  --nav-hover-bg: #252f3d;
  --nav-active-bg: #1e2835;
  --table-header-bg: #151c24;
  --table-row-hover: rgba(255, 255, 255, 0.05);
  --logo-surface: #1a222d;
  --stat-box-bg: var(--bg-card);
  --chart-legend: #a1b0c4;
  --chart-grid: rgba(148, 163, 184, 0.12);
  --flash-success-bg: rgba(52, 211, 153, 0.12);
  --flash-success-border: rgba(52, 211, 153, 0.35);
  --flash-success-text: #6ee7b7;
  --flash-error-bg: rgba(248, 113, 113, 0.1);
  --flash-error-border: rgba(248, 113, 113, 0.35);
  --flash-error-text: #fca5a5;
  --flash-warn-bg: rgba(251, 191, 36, 0.1);
  --flash-warn-border: rgba(251, 191, 36, 0.35);
  --flash-warn-text: #fcd34d;
  --badge-in-bg: rgba(52, 211, 153, 0.16);
  --badge-in-fg: #6ee7b7;
  --badge-out-bg: rgba(129, 140, 248, 0.18);
  --badge-out-fg: #a5b4fc;
  --badge-ot-bg: rgba(251, 146, 60, 0.16);
  --badge-ot-fg: #fdba74;
  --badge-muted-bg: rgba(148, 163, 184, 0.12);
  --badge-warn-bg: rgba(251, 191, 36, 0.14);
  --badge-warn-fg: #fcd34d;
  --staff-pos-boss-fg: #fbbf24;
  --staff-pos-boss-bg: rgba(251, 191, 36, 0.12);
  --staff-pos-dev-fg: #38bdf8;
  --staff-pos-dev-bg: rgba(56, 189, 248, 0.12);
  --staff-pos-admin-fg: #c084fc;
  --staff-pos-admin-bg: rgba(192, 132, 252, 0.12);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f8;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --accent: #0f766e;
  --accent-hover: #0d9488;
  --accent-soft: rgba(15, 118, 110, 0.1);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --input-bg: #ffffff;
  --btn-default-bg: #ffffff;
  --btn-secondary-bg: #ffffff;
  --nav-hover-bg: #ffffff;
  --nav-active-bg: #ffffff;
  --table-header-bg: #f8fafc;
  --table-row-hover: #fafafa;
  --logo-surface: #ffffff;
  --chart-legend: #64748b;
  --chart-grid: rgba(148, 163, 184, 0.2);
  --flash-success-bg: #ecfdf5;
  --flash-success-border: #a7f3d0;
  --flash-success-text: #047857;
  --flash-error-bg: #fef2f2;
  --flash-error-border: #fecaca;
  --flash-error-text: #b91c1c;
  --flash-warn-bg: #fffbeb;
  --flash-warn-border: #fde68a;
  --flash-warn-text: #b45309;
  --badge-in-bg: #d1fae5;
  --badge-in-fg: #047857;
  --badge-out-bg: #e0e7ff;
  --badge-out-fg: #4338ca;
  --badge-ot-bg: #ffedd5;
  --badge-ot-fg: #c2410c;
  --badge-muted-bg: #f1f5f9;
  --badge-warn-bg: #fef3c7;
  --badge-warn-fg: #b45309;
  --staff-pos-boss-fg: #b45309;
  --staff-pos-boss-bg: rgba(251, 191, 36, 0.28);
  --staff-pos-dev-fg: #0369a1;
  --staff-pos-dev-bg: rgba(14, 165, 233, 0.16);
  --staff-pos-admin-fg: #6d28d9;
  --staff-pos-admin-bg: rgba(167, 139, 250, 0.22);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

html:has(body.layout-page--app-fill) {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  overflow-x: clip;
}

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

a:hover {
  text-decoration: underline;
}

/* หน้าแรก — จัดกึ่งกลางแนวตั้ง */
.page-landing {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: max(4.5rem, calc(env(safe-area-inset-top) + 3rem));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  box-sizing: border-box;
}

.landing-inner {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.session-logout-fab {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  right: calc(max(1rem, env(safe-area-inset-right)) + 2.75rem + 0.45rem);
  z-index: 199;
  box-sizing: border-box;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--btn-secondary-bg);
  color: var(--text-muted);
  font-family: inherit;
  line-height: 0;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.session-logout-fab:hover {
  background: var(--nav-hover-bg);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.45);
}

.session-logout-fab::-moz-focus-inner {
  border: 0;
  padding: 0;
}

.session-logout-fab__icon {
  display: block;
  width: 1.375rem;
  height: 1.375rem;
  flex: 0 0 auto;
  overflow: visible;
  pointer-events: none;
}

.theme-fab {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  z-index: 200;
  box-sizing: border-box;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  background: var(--btn-secondary-bg);
  color: var(--text);
  border: 1px solid var(--border);
  font-family: inherit;
  line-height: 0;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.theme-fab:hover {
  background: var(--nav-hover-bg);
  color: var(--accent);
}

.theme-fab::-moz-focus-inner {
  border: 0;
  padding: 0;
}

.theme-fab__icon {
  display: block;
  width: 1.375rem;
  height: 1.375rem;
  flex: 0 0 auto;
  overflow: visible;
  pointer-events: none;
}

.app-shell {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
}

.app-shell--narrow {
  max-width: 520px;
}

.app-shell--home {
  max-width: 560px;
  margin: 0 auto;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.app-header--minimal {
  align-items: center;
}

.app-header--no-border {
  border-bottom: none;
  margin-bottom: 0.5rem;
  padding-bottom: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand--compact .brand-text h1 {
  font-size: 1.15rem;
}

/* หน้าเข้าสู่ระบบ / สมัคร — โลโก้ด้านบนกึ่งกลาง เหนือหัวข้อ */
.brand--stacked-logo {
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.75rem;
}

.brand--stacked-logo .brand-text {
  width: 100%;
  text-align: center;
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 10px;
  background: var(--logo-surface);
  padding: 6px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand-logo--auth-top {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}

.brand-logo--sm {
  width: 40px;
  height: 40px;
}

.brand-logo--hero {
  width: clamp(16rem, 82vw, 26rem);
  height: auto;
  max-width: 100%;
  object-fit: contain;
  padding: 1.35rem 1.6rem;
  border-radius: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  background: var(--logo-surface);
}

.brand-text h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}

.brand-text .tagline {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.nav-link {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 6.25rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  font-size: 0.88rem;
  color: var(--text-muted);
  border: 1px solid transparent;
  text-align: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.nav-link:hover {
  color: var(--text);
  background: var(--nav-hover-bg);
  border-color: var(--border);
  text-decoration: none;
}

.nav-link.is-active {
  color: var(--accent);
  border-color: var(--border);
  background: var(--nav-active-bg);
  font-weight: 500;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
}

.card--flat {
  box-shadow: var(--shadow-md);
}

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

/* กริดสองคอลัมน์: ช่องว่างใช้ gap อย่างเดียว — อย่าใส่ margin-top ให้การ์ดคอลัมน์ที่สอง (ทำให้ความสูง/ขอบบนไม่เท่ากัน) */
.grid-2 > .card + .card,
.staff-fill-grid > .card + .card,
.leave-split-grid > .card + .card {
  margin-top: 0;
}

.card-title {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 800px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 720px) {
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.field {
  margin-bottom: 0.9rem;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.textarea {
  min-height: 72px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.input--readonly,
.input[readonly] {
  cursor: default;
  opacity: 0.92;
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.35rem;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  background: var(--btn-default-bg);
  color: var(--text);
}

.btn:active {
  transform: scale(0.99);
}

.btn-primary {
  background: var(--accent);
  color: #0f172a;
  border-color: var(--accent);
}

[data-theme="light"] .btn-primary {
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
  text-decoration: none;
}

.btn-ghost:hover {
  color: var(--text);
  text-decoration: none;
}

.btn-in {
  background: var(--success);
  color: #0f172a;
  border-color: var(--success);
}

.btn-out {
  background: #6366f1;
  color: #fff;
  border-color: #6366f1;
}

.btn-ot {
  background: #ea580c;
  color: #fff;
  border-color: #ea580c;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.45);
}

[data-theme="light"] .btn-danger {
  background: #fff;
}

.ot-assign-inline {
  margin: 0.5rem 0 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius);
  border: 1px solid var(--flash-warn-border);
  background: var(--flash-warn-bg);
  color: var(--flash-warn-text);
}

.ot-assign-inline__text {
  margin: 0 0 0.45rem;
  font-size: 0.82rem;
  line-height: 1.45;
}

.ot-assign-inline__actions {
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  padding: 0.55rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--table-header-bg);
}

tr:hover td {
  background: var(--table-row-hover);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-in {
  background: var(--badge-in-bg);
  color: var(--badge-in-fg);
}

.badge-out {
  background: var(--badge-out-bg);
  color: var(--badge-out-fg);
}

.badge-ot {
  background: var(--badge-ot-bg);
  color: var(--badge-ot-fg);
}

.badge-muted {
  background: var(--badge-muted-bg);
  color: var(--text-muted);
}

.badge-warn {
  background: var(--badge-warn-bg);
  color: var(--badge-warn-fg);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-box {
  background: var(--stat-box-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
}

.stat-box .value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-box .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.chart-box {
  position: relative;
  min-height: 240px;
}

.muted {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.small-print {
  font-size: 0.8rem;
  margin: 0.5rem 0 0;
}

.footer-note {
  margin-top: 2rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

.empty-state {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
}

.status-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 800px) {
  .status-columns {
    grid-template-columns: 1fr 1fr;
  }
}

.status-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.88rem;
}

.status-list li {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}

.status-list li:last-child {
  border-bottom: none;
}

.session-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.session-bar strong {
  color: var(--text);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 1rem 0;
}

.hidden {
  display: none !important;
}

/* จัดคอนเทนต์กึ่งกลางแนวนอน */
.layout-page {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.layout-page > .app-shell:not(.layout-form-centered) {
  width: 100%;
  max-width: 1040px;
}

.layout-form-centered {
  width: 100%;
  max-width: 28rem;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.layout-form-centered .card {
  width: 100%;
}

.app-header--brand-center {
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: 100%;
}

.app-header--brand-center .brand {
  justify-content: center;
  width: 100%;
}

.app-header--brand-center .nav {
  justify-content: center;
}

.nav--center {
  justify-content: center;
  width: 100%;
}

.btn-row--center {
  justify-content: center;
}

/* หน้าเข้าสู่ระบบ / สมัคร — กึ่งกลางแนวตั้งและแนวนอน */
.layout-page--viewport-center {
  min-height: 100vh;
  min-height: 100dvh;
  justify-content: center;
  padding-top: max(3.25rem, calc(env(safe-area-inset-top) + 2rem));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
  box-sizing: border-box;
}

.layout-page--viewport-center > .app-shell {
  flex-shrink: 0;
  width: 100%;
}

/* ไม่ใส่ overflow ภายใน .layout-form-centered — กันสองแถบเลื่อน (เอกสาร vs กล่องใน) */

/* เข้าสู่ระบบ / สมัคร — UI ใหญ่ขึ้น (ใช้ร่วม .auth-page) */
body.auth-page .layout-form-centered {
  max-width: min(32rem, 94vw);
}

body.auth-page .brand--stacked-logo {
  gap: 0.55rem;
}

body.auth-page .brand-logo--auth-top {
  width: 56px;
  height: 56px;
}

body.auth-page .brand-text h1 {
  font-size: 1.28rem;
}

body.auth-page .brand-text .tagline {
  font-size: 0.84rem;
  margin: 0.15rem 0 0;
  line-height: 1.45;
}

body.auth-page .app-header {
  margin-bottom: 0.75rem;
  padding-bottom: 0.55rem;
}

body.auth-page .nav-link {
  min-width: 5.75rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
}

body.auth-page .card {
  padding: 1.1rem 1.2rem;
}

body.auth-page .card-title {
  font-size: 1.02rem;
  margin: 0 0 0.75rem;
}

body.auth-page .field {
  margin-bottom: 0.58rem;
}

body.auth-page .field label {
  font-size: 0.82rem;
  margin-bottom: 0.28rem;
}

body.auth-page .input,
body.auth-page .select {
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
}

body.auth-page .btn-row {
  margin-top: 0.45rem;
  gap: 0.55rem;
}

body.auth-page .btn {
  padding: 0.55rem 1.05rem;
  font-size: 0.93rem;
  min-height: 46px;
}

body.auth-page .footer-note {
  font-size: 0.74rem;
  margin: 0.55rem 0 0;
  line-height: 1.45;
}

body.login-page.layout-page--viewport-center {
  min-height: 100dvh;
  min-height: 100vh;
  justify-content: center;
  align-items: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  box-sizing: border-box;
}

/* หน้าสมัคร — กึ่งกลางจอ ให้พอดีหนึ่งหน้าจอ (จอสูงปกติ) */
html:has(body.register-page) {
  height: 100%;
  overflow: hidden;
}

body.register-page.layout-page--viewport-center {
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  justify-content: center;
  align-items: center;
  padding: max(0.5rem, env(safe-area-inset-top)) max(0.85rem, env(safe-area-inset-right)) max(0.5rem, env(safe-area-inset-bottom)) max(0.85rem, env(safe-area-inset-left));
  overflow: hidden;
  box-sizing: border-box;
}

body.register-page .layout-form-centered {
  flex-shrink: 1;
  min-height: 0;
  max-height: 100%;
}

body.register-page .app-header {
  flex-shrink: 0;
}

body.register-page .register-times-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  align-items: end;
}

body.register-page .register-times-row .field {
  margin-bottom: 0.58rem;
}

@media (max-height: 620px) {
  html:has(body.register-page) {
    overflow: auto;
  }

  body.register-page.layout-page--viewport-center {
    height: auto;
    max-height: none;
    min-height: 100dvh;
    overflow: visible;
    padding-top: max(0.75rem, env(safe-area-inset-top));
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}

@media (max-width: 380px) {
  body.register-page .register-times-row {
    grid-template-columns: 1fr;
  }
}

/* หน้าแอป — จัดกึ่งกลางแนวนอน + พื้นที่ปลอดภัย (มือถือ / แท็บเล็ต) */
.layout-page--app {
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: max(0.5rem, env(safe-area-inset-top));
  padding-left: max(0.75rem, env(safe-area-inset-left));
  padding-right: max(0.75rem, env(safe-area-inset-right));
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  box-sizing: border-box;
}

.layout-page--app > .app-shell {
  width: 100%;
}

/* หน้าแอปแบบเต็ม viewport — ไม่เลื่อนทั้ง body; เลื่อนเฉพาะแผงภายใน */
.layout-page--app-fill {
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding-top: max(0.35rem, env(safe-area-inset-top));
  padding-left: max(0.65rem, env(safe-area-inset-left));
  padding-right: max(0.65rem, env(safe-area-inset-right));
  padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
}

.layout-page--app-fill > .app-shell--fill {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0.5rem 0.85rem 0.35rem;
}

.app-shell--fill .app-header {
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  flex-shrink: 0;
}

/* แถบหัวแอป — ติดด้านบนขณะเลื่อน (ไม่เลื่อนหายไปกับเนื้อหา) + ความสูงสม่ำเสมอระหว่างหน้า */
.layout-page--app-fill > .app-shell--fill > .app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  margin-bottom: 0.5rem;
  padding-top: 0.2rem;
  padding-bottom: 0.5rem;
  background-color: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

@media (min-width: 801px) {
  .layout-page--app-fill > .app-shell--fill > .app-header {
    min-height: 3.75rem;
    align-items: center;
  }
}

.app-shell--fill .footer-note {
  margin-top: 0.35rem;
  flex-shrink: 0;
  font-size: 0.72rem;
}

.app-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: hidden;
}

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel-scroll--max {
  max-height: min(42vh, 22rem);
}

.clock-split {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: hidden;
}

.clock-split__top {
  flex: 1 1 52%;
  min-height: 0;
  align-items: stretch;
}

.clock-split__top.grid-2 {
  align-items: stretch;
}

.clock-split__top > .card {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  align-self: stretch;
}

/* การ์ดลงเวลา — ไม่ยืดเต็มความสูงคู่กับคอลัมน์สถานะ (กันช่องว่างว่างแล้วเนื้อหาดูติดขอบล่าง) */
.clock-split__top > .card.clock-card-today {
  height: auto;
  align-self: start;
  justify-content: flex-start;
  width: 100%;
  max-height: 100%;
  box-sizing: border-box;
}

.clock-split__top .status-columns {
  flex: 1;
  min-height: 0;
}

.clock-split__top .status-columns > div {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.clock-split__top .status-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.clock-recent-block {
  flex: 1 1 46%;
  min-height: 8rem;
  max-height: 46%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.clock-recent-block .card-title {
  flex-shrink: 0;
}

.staff-fill-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
  overflow: hidden;
}

.staff-fill-grid > .card {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.staff-fill-grid .table-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* หน้าบุคลากร — header แถวเดียวเหมือนหน้าขอลา; สองคอลัมน์เนื้อหา 1fr 1fr */

.staff-page .staff-fill-grid {
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: stretch;
}

@media (min-width: 800px) {
  .staff-page .staff-fill-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }
}

.staff-page .staff-fill-grid > .card {
  height: 100%;
  align-self: stretch;
}

.staff-page .staff-form-card {
  min-height: 0;
}

.staff-form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
  align-items: stretch;
}

.staff-form-grid .field {
  margin-bottom: 0;
}

.staff-form-grid .field--full {
  grid-column: 1 / -1;
}

.staff-form-grid .field--span-2 {
  grid-column: 1 / -1;
}

.staff-form-actions {
  margin-top: 0.2rem;
  padding-top: 0.15rem;
}

.staff-page .staff-form-grid .input,
.staff-page .staff-form-grid .select,
.staff-page .staff-form-grid .textarea {
  padding: 0.38rem 0.5rem;
  font-size: 0.84rem;
}

.staff-page .staff-form-grid label {
  font-size: 0.74rem;
  margin-bottom: 0.22rem;
}

.staff-weekly-off-label {
  font-size: 0.74rem;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
}

.staff-weekly-off {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--input-bg);
}

.staff-weekly-off__item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
  color: var(--text);
}

.staff-weekly-off__cb {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}


.staff-page .staff-list-card {
  min-height: 0;
}

.staff-page .staff-table-wrap {
  flex: 1;
  min-height: 0;
}

.staff-data-table {
  font-size: 0.8rem;
}

.staff-data-table th,
.staff-data-table td {
  padding: 0.32rem 0.4rem;
  white-space: nowrap;
}

.staff-data-table td:nth-child(2) {
  white-space: normal;
  max-width: 12rem;
}

.staff-data-table__group-cell {
  padding: 0.42rem 0.45rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  white-space: normal;
}

.staff-data-table__group-cell--boss {
  color: var(--staff-pos-boss-fg);
  background: var(--staff-pos-boss-bg);
}

.staff-data-table__group-cell--dev {
  color: var(--staff-pos-dev-fg);
  background: var(--staff-pos-dev-bg);
}

.staff-data-table__group-cell--admin {
  color: var(--staff-pos-admin-fg);
  background: var(--staff-pos-admin-bg);
}

.staff-data-table__group-cell--other {
  color: var(--text-muted);
  background: rgba(148, 163, 184, 0.08);
}

[data-theme="light"] .staff-data-table__group-cell--other {
  background: rgba(148, 163, 184, 0.14);
}

.staff-pos {
  font-weight: 600;
}

.staff-pos--boss {
  color: var(--staff-pos-boss-fg);
}

.staff-pos--dev {
  color: var(--staff-pos-dev-fg);
}

.staff-pos--admin {
  color: var(--staff-pos-admin-fg);
}

.staff-pos--other {
  color: var(--text-muted);
  font-weight: 500;
}

.staff-page .staff-fill-grid .table-wrap {
  overflow-x: auto;
}

/* หน้าขอลา — ใช้ความกว้าง/padding เดียวกับหน้าลงเวลา (.layout-page--app-fill > .app-shell--fill) */

body.leave-page #needLogin {
  padding: 0.4rem 0.5rem;
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
}

.leave-fill-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.leave-split-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: stretch;
}

@media (min-width: 800px) {
  .leave-split-grid.leave-split-grid--session {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }
}

.leave-split-grid > .card {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.leave-split-grid .card-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.leave-split-grid .muted {
  font-size: 0.85rem;
}

.leave-split-grid .grid-2 {
  gap: 1rem;
}

.leave-split-grid .btn-row {
  margin-top: 0.35rem;
}

.leave-form-card .leave-note-textarea {
  min-height: 3rem;
  resize: vertical;
  max-height: 7rem;
}

.leave-requests-card .leave-my-requests-table,
.leave-split-grid .table-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.leave-split-grid table {
  font-size: 0.88rem;
}

.leave-split-grid th,
.leave-split-grid td {
  padding: 0.45rem 0.55rem;
}

.leave-split-grid .empty-state {
  font-size: 0.85rem;
  padding: 0.5rem 0;
}

/* โมดัลยืนยัน (หน้ารายงาน ฯลฯ) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 220;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(7, 11, 18, 0.72);
  backdrop-filter: blur(3px);
}

.modal-backdrop[hidden] {
  display: none !important;
}

[data-theme="light"] .modal-backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.modal--confirm {
  width: 100%;
  max-width: 22rem;
  padding: 1.1rem 1.2rem;
  margin: 0;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  outline: none;
}

.modal__title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  color: var(--text);
  line-height: 1.35;
}

.modal__text {
  font-size: 0.84rem;
  line-height: 1.55;
  margin: 0 0 0.5rem;
  color: var(--text-muted);
}

.modal__text:last-of-type {
  margin-bottom: 0;
}

.modal__text--warn {
  color: var(--flash-warn-text);
  font-weight: 500;
}

.modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.1rem;
}

/* แท็บหน้ารายงาน */
.app-main--dashboard {
  gap: 0.35rem;
}

.app-main--dashboard .dash-tab-toolbar {
  margin-bottom: 0.35rem;
}

.dash-tab-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.dash-tab-toolbar__end {
  flex-shrink: 0;
  margin-left: auto;
}

.btn--dash-clear-history {
  padding: 0.38rem 0.85rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

.dash-tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0;
  flex-shrink: 0;
  flex: 1;
  min-width: 0;
}

.dash-tab {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.dash-tab:hover {
  color: var(--text);
  border-color: var(--accent);
}

.dash-tab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.dash-tab-panels {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dash-tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 0.5rem;
  overflow: hidden;
}

.dash-tab-panel.is-active {
  display: flex;
}

.dash-tab-panel__scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-right: 0.15rem;
}

.dash-report-date-field {
  max-width: none;
  flex-shrink: 1;
  min-width: 0;
}

/* แถบตัวกรอกรายงานรายวัน — วันที่เริ่ม · วันที่สิ้น · บุคคล ในแถวเดียว */
.dash-daily-toolbar--row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(10.5rem, 1.25fr);
  gap: 0.4rem 0.65rem;
  align-items: end;
  flex-shrink: 0;
}

.dash-daily-toolbar--row .dash-daily-scope-field {
  min-width: 0;
}

.dash-daily-toolbar,
.dash-month-toolbar {
  align-items: end;
}

.dash-daily-toolbar .field,
.dash-month-toolbar .field {
  margin-bottom: 0;
}

.dash-scope-hint {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
}

.dash-scope-hint--inline {
  margin: 0;
  flex-shrink: 0;
  line-height: 1.35;
}

/* แท็บรายงานรายวัน — จัดให้พอดี viewport เลื่อนเฉพาะในตารางถ้าจำเป็น */
#dash-panel-daily.dash-tab-panel {
  min-height: 0;
}

.dash-tab-panel__scroll--daily {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-right: 0;
  min-height: 0;
}

.dash-tab-panel__scroll--daily .stats-row--daily-bar {
  flex-shrink: 0;
  margin-bottom: 0;
  gap: 0.45rem;
  margin-top: 0;
}

.stats-row--daily-bar {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.dash-absent-hint {
  margin: -0.25rem 0 0.45rem;
  font-size: 0.72rem;
  line-height: 1.4;
}

.stats-row--daily-bar .stat-box {
  padding: 0.4rem 0.5rem;
}

.stats-row--daily-bar .stat-box .value {
  font-size: 1.05rem;
}

.stats-row--daily-bar .stat-box .label {
  font-size: 0.68rem;
  line-height: 1.25;
}

.dash-daily-tables {
  flex: 1;
  min-height: 0;
  align-items: stretch;
  gap: 0.75rem;
}

.dash-daily-tables > .card--dash-daily {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0.65rem 0.85rem;
}

.card-title--dash-daily {
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
  flex-shrink: 0;
  line-height: 1.35;
}

.table-wrap--dash-daily {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

#dash-panel-daily .table--compact {
  table-layout: auto;
}

#dash-panel-daily .table--compact th,
#dash-panel-daily .table--compact td {
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  line-height: 1.5;
  vertical-align: middle;
}

#dash-panel-daily .table--compact td {
  word-break: break-word;
}

#dash-panel-daily .table--compact th {
  font-size: 0.72rem;
}

#dash-panel-daily .dash-report-table--late th:nth-child(4),
#dash-panel-daily .dash-report-table--late td:nth-child(4) {
  text-align: right;
  padding-left: 1.25rem;
  min-width: 12rem;
}

.empty-state--dash-daily {
  padding: 0.65rem 0.5rem;
  font-size: 0.78rem;
  flex-shrink: 0;
}

.app-shell--fill .footer-note--dash {
  margin-top: 0.25rem;
  padding-top: 0.35rem;
  margin-bottom: 0;
  border-top: none;
  font-size: 0.7rem;
}

@media (max-width: 640px) {
  .dash-daily-toolbar--row {
    grid-template-columns: 1fr;
  }

  .dash-month-toolbar.grid-2 {
    grid-template-columns: 1fr;
  }

  .stats-row--daily-bar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .dash-daily-toolbar--row {
    grid-template-columns: 1fr 1fr;
  }

  .dash-daily-toolbar--row .dash-daily-scope-field {
    grid-column: 1 / -1;
  }

  .stats-row--daily-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.chart-box--compact {
  min-height: 0;
  height: 170px;
  max-height: 22vh;
}

.stats-row--tight {
  margin-bottom: 0.5rem;
}

.stats-row--tight .stat-box {
  padding: 0.55rem 0.65rem;
}

.stats-row--tight .stat-box .value {
  font-size: 1.15rem;
}

@media (max-width: 799px) {
  html:has(body.layout-page--app-fill) {
    height: auto;
    overflow: auto;
  }

  .layout-page--app-fill {
    height: auto;
    max-height: none;
    min-height: 100dvh;
    overflow: auto;
  }

  .layout-page--app-fill > .app-shell--fill {
    overflow: visible;
    min-height: min-content;
  }

  .clock-split {
    overflow: visible;
  }

  .clock-recent-block {
    max-height: none;
  }
}

/* แท็บเล็ตและมือถือ */
@media (max-width: 900px) {
  .app-shell {
    padding-left: clamp(0.65rem, 3vw, 1rem);
    padding-right: clamp(0.65rem, 3vw, 1rem);
    padding-bottom: 1.75rem;
  }

  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
  }

  .app-header .brand {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .app-header .nav {
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .nav-link {
    min-width: 5.5rem;
    font-size: 0.82rem;
    padding: 0.4rem 0.45rem;
  }

  .brand-text h1 {
    font-size: clamp(1rem, 4vw, 1.2rem);
  }
}

@media (max-width: 480px) {
  .card {
    padding: 1rem 0.85rem;
  }

  .btn {
    min-height: 44px;
    touch-action: manipulation;
  }

  .theme-fab {
    width: 2.5rem;
    height: 2.5rem;
  }

  .session-logout-fab {
    width: 2.5rem;
    height: 2.5rem;
    right: calc(max(1rem, env(safe-area-inset-right)) + 2.5rem + 0.45rem);
  }
}
