/* ===== ระบบ HR - Stylesheet หลัก ===== */
:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #e2e6ea;
  --color-text: #202733;
  --color-text-muted: #6b7280;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-danger: #dc2626;
  --color-sidebar-bg: #111827;
  --color-sidebar-text: #d1d5db;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

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

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

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-sidebar-bg);
  color: var(--color-sidebar-text);
  padding: 20px 0;
  overflow-x: hidden;
  transition: width .15s ease, transform .2s ease;
}

/* ปุ่มเปิด-ปิดแถบด้านข้าง (แสดงทุกขนาดหน้าจอ) */
.sidebar-toggle-btn {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--color-text);
  flex-shrink: 0;
}
.sidebar-toggle-btn:hover { background: var(--color-bg); }
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-left .topbar-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-backdrop { display: none; }

/* พับ/ยุบแถบด้านข้างบนจอกว้าง (desktop) - สถานะจำไว้ด้วย localStorage */
@media (min-width: 769px) {
  .app-shell.sidebar-collapsed .sidebar { width: 0; padding: 0; }
}
.sidebar-brand {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  padding: 0 20px 20px;
  border-bottom: 1px solid #1f2937;
  margin-bottom: 10px;
}
.sidebar-nav { display: flex; flex-direction: column; }
.sidebar-nav a {
  color: var(--color-sidebar-text);
  padding: 11px 20px;
  font-size: 16px;
}
.sidebar-nav a:hover { background: #1f2937; text-decoration: none; color: #fff; }
.nav-group { display: flex; flex-direction: column; }
.nav-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  margin: 0;
  font-family: inherit;
  text-align: left;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  padding: 18px 20px 6px;
  cursor: pointer;
}
.nav-section-toggle:hover { color: #fff; }
.nav-section-toggle .chevron {
  font-size: 11px;
  color: #9ca3af;
  transition: transform .15s ease;
  margin-left: 8px;
}
.nav-section-toggle.collapsed .chevron { transform: rotate(-90deg); }
.nav-group-links { display: flex; flex-direction: column; }
.nav-group-links.collapsed { display: none; }

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

.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-title { font-size: 20px; font-weight: 600; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--color-text-muted); }

.content { padding: 28px; }
.content-plain { max-width: 420px; margin: 60px auto; padding: 0 16px; }

/* ---------- card ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card-title { font-size: 16px; font-weight: 600; margin: 0 0 16px; }

/* ---------- form ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 200px; }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=time], input[type=file], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--color-text);
}
textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }

/* ---------- ช่องกรอกวันที่ วว/ดด/ปปปป (date_input_th() ใน includes/functions.php) ---------- */
.date-th-wrap { position: relative; display: block; width: 100%; }
.date-th-input { padding-right: 34px !important; }
.date-th-icon-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 5px 6px;
  border-radius: 4px;
}
.date-th-icon-btn:hover { background: var(--color-bg); }
.date-th-popup {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  width: 240px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
  padding: 10px;
}
.date-th-popup-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 600; font-size: 14px; }
.date-th-popup-header button {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  padding: 3px 9px;
  border-radius: 4px;
  color: var(--color-text);
}
.date-th-popup-header button:hover { background: var(--color-bg); }
.date-th-popup-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.date-th-popup-grid .dow { font-weight: 600; color: var(--color-text-muted); font-size: 11px; padding: 4px 0; }
.date-th-popup-day {
  padding: 6px 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  border: 1px solid transparent;
}
.date-th-popup-day:hover { background: var(--color-bg); }
.date-th-popup-day.is-today { border-color: var(--color-primary); }
.date-th-popup-day.is-selected { background: var(--color-primary); color: #fff; }
.date-th-popup-day.is-empty { visibility: hidden; cursor: default; }
.date-th-popup-today-btn { display: block; width: 100%; text-align: center; margin-top: 8px; padding: 6px; font-size: 12px; border: 1px solid var(--color-border); border-radius: 4px; background: transparent; cursor: pointer; color: var(--color-text); }
.date-th-popup-today-btn:hover { background: var(--color-bg); }

.btn {
  display: inline-block;
  padding: 9px 18px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--color-primary);
  color: #fff;
}
.btn:hover { background: var(--color-primary-dark); text-decoration: none; }
.btn-secondary { background: #e5e7eb; color: var(--color-text); }
.btn-secondary:hover { background: #d1d5db; }
.btn-success { background: var(--color-success); }
.btn-danger { background: var(--color-danger); }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ---------- table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--color-border); text-align: left; }
th { background: #f9fafb; font-weight: 600; color: var(--color-text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: #fafbfc; }
.table-wrap { overflow-x: auto; }

/* ---------- badge / alert ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-muted   { background: #e5e7eb; color: #374151; }

.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error   { background: #fee2e2; color: #991b1b; }
.alert-info    { background: #dbeafe; color: #1e40af; }

/* ---------- login ---------- */
.login-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 32px;
}
.login-box h1 { font-size: 20px; margin: 0 0 4px; text-align: center; }
.login-box .sub { text-align: center; color: var(--color-text-muted); font-size: 13px; margin-bottom: 24px; }

/* ---------- stat grid ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 18px; }
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card .label { font-size: 13px; color: var(--color-text-muted); margin-top: 2px; }

.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.mb-0 { margin-bottom: 0; }

/* ---------- responsive (มือถือ/แท็บเล็ตแนวตั้ง) ---------- */
@media (max-width: 768px) {
  body { font-size: 14px; }

  /* แถบด้านข้างกลายเป็นเมนูแบบเลื่อนออกมาทับหน้าจอ (off-canvas) ซ่อนไว้เป็นค่าเริ่มต้น */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
    box-shadow: 2px 0 16px rgba(0, 0, 0, .3);
  }
  .app-shell.sidebar-mobile-open .sidebar { transform: translateX(0); }
  .app-shell.sidebar-mobile-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, .5);
    z-index: 999;
  }

  .main-area { width: 100%; min-width: 0; }

  .topbar { padding: 10px 14px; gap: 8px; }
  .topbar-title { font-size: 17px; }
  .topbar-user span:not(.badge) { display: none; } /* ซ่อนชื่อผู้ใช้บนจอแคบ เหลือแค่ตำแหน่ง */

  .content, .content-plain { padding: 14px; }
  .content-plain { margin: 24px auto; }

  .card { padding: 14px; }

  .form-row { gap: 10px; }
  .form-row .form-group { min-width: 0; flex-basis: 100%; }

  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 12px; }
  .stat-card .value { font-size: 20px; }

  th, td { padding: 8px 10px; font-size: 13px; }
}

@media (min-width: 769px) {
  /* บนจอกว้างไม่ใช้เมนูแบบทับหน้าจอ ปิดผลของคลาสฝั่งมือถือกันเผลอค้าง */
  .sidebar-backdrop { display: none !important; }
}
