@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;600;700;800;900&display=swap');

:root {
  /* ── Sailom Express brand: white / blue / orange ── */
  --sidebar-w: 260px;
  --sidebar-bg: #0d1f4e;           /* navy blue */
  --sidebar-accent: #1e50a8;
  --sidebar-text: #a8bcdd;
  --sidebar-active-bg: rgba(249,115,22,.15);
  --sidebar-active-text: #fb923c;  /* orange */
  --sidebar-hover-bg: rgba(255,255,255,.07);
  --topbar-h: 60px;
  --content-bg: #f0f4f9;
  --card-bg: #ffffff;
  --primary: #1e50a8;              /* Sailom blue */
  --primary-dark: #163d86;
  --accent: #f97316;               /* Sailom orange */
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(15,23,42,.08);
  --shadow-md: 0 8px 32px rgba(15,23,42,.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Sarabun', 'TH Sarabun New', Tahoma, Arial, sans-serif;
  font-size: 15px;
  background: var(--content-bg);
  color: var(--text-main);
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 200;
  transition: transform .25s ease;
}
.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  text-decoration: none;
}
.sidebar-logo .logo-mark {
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo .logo-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, #f97316, #fb923c);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; color: #fff;
}
.sidebar-logo .logo-text { color: #fff; }
.sidebar-logo .logo-text .app-name { font-size: 1.1rem; font-weight: 900; line-height: 1.1; letter-spacing: .3px; }
.sidebar-logo .logo-text .app-sub  { font-size: .72rem; color: var(--sidebar-text); font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; }

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-section { margin-bottom: 20px; }
.nav-section-label {
  font-size: .68rem; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase;
  color: rgba(148,163,184,.5); padding: 0 10px; margin-bottom: 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px;
  color: var(--sidebar-text); font-weight: 600; font-size: .92rem;
  text-decoration: none; transition: all .18s;
  margin-bottom: 2px;
}
.nav-item i { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover-bg); color: #e2e8f0; }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
.nav-item.active i { color: var(--accent); }
.nav-badge { margin-left: auto; background: var(--primary); color: #fff; border-radius: 999px; padding: 1px 7px; font-size: .68rem; font-weight: 800; }
.nav-group{margin-top:6px}.nav-group summary{list-style:none}.nav-group summary::-webkit-details-marker{display:none}
.nav-group-title{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:10px;color:#d5e1f3;font-weight:800;cursor:pointer;transition:.18s}
.nav-group-title:hover,.nav-group-title.active{background:rgba(255,255,255,.07);color:#fff}.nav-group-title>i:first-child{width:20px;text-align:center;color:#8fb0e2}
.nav-group-arrow{margin-left:auto;font-size:.72rem;transition:transform .18s}.nav-group[open] .nav-group-arrow{transform:rotate(180deg)}
.nav-submenu{margin:3px 0 8px 18px;padding-left:9px;border-left:1px solid rgba(168,188,221,.2)}
.nav-subitem{font-size:.84rem;padding:8px 10px}.sidebar-users-link{margin-bottom:12px;border:1px solid rgba(168,188,221,.12)}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
}
.sidebar-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #f97316, #fb923c);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 900; font-size: .9rem; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { color: #e2e8f0; font-weight: 700; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { color: var(--sidebar-text); font-size: .72rem; font-weight: 600; }
.sidebar-logout { color: var(--sidebar-text); font-size: 1rem; text-decoration: none; transition: color .15s; padding: 4px; }
.sidebar-logout:hover { color: #f87171; }

/* ===== MAIN CONTENT ===== */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 4px rgba(15,23,42,.06);
}
.topbar-title { font-size: 1.15rem; font-weight: 800; color: var(--text-main); flex: 1; }
.topbar-sub { color: var(--text-muted); font-size: .82rem; font-weight: 600; }
.topbar-menu-toggle { display: none; background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text-muted); }

.page-content { padding: 28px 28px; flex: 1; }
.page-head { margin-bottom: 24px; }
.page-head h2 { font-size: 1.5rem; font-weight: 900; color: var(--text-main); }
.page-head p { color: var(--text-muted); font-size: .9rem; margin-top: 4px; }

/* ===== CARDS ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.card-header h5 { font-size: 1rem; font-weight: 800; margin: 0; }
.card-body { padding: 20px; }

/* ===== STAT CARDS ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; margin-bottom: 28px; }
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0;
  width: 4px; height: 100%;
}
.stat-card.teal::before   { background: #1e50a8; }
.stat-card.blue::before   { background: #0284c7; }
.stat-card.amber::before  { background: #f97316; }
.stat-card.rose::before   { background: #e11d48; }
.stat-card.violet::before { background: #7c3aed; }
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem; margin-bottom: 14px;
}
.stat-card.teal  .stat-icon { background: #dbeafe; color: #1e50a8; }
.stat-card.blue  .stat-icon { background: #e0f2fe; color: #0284c7; }
.stat-card.amber .stat-icon { background: #ffedd5; color: #f97316; }
.stat-card.rose  .stat-icon { background: #ffe4e6; color: #e11d48; }
.stat-card.violet .stat-icon { background: #ede9fe; color: #7c3aed; }
.stat-label { font-size: .8rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 2rem; font-weight: 900; color: var(--text-main); line-height: 1.1; margin-top: 4px; }
.stat-sub { font-size: .8rem; color: var(--text-muted); margin-top: 6px; }

/* ===== TABLES ===== */
.table-wrap { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--border); background: #fff; }
.table-wrap .table-responsive { overflow-x: auto; }
.hq-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.hq-table thead th {
  background: #f8fafc; color: var(--text-muted);
  font-weight: 800; font-size: .78rem; letter-spacing: .3px; text-transform: uppercase;
  padding: 12px 16px; border-bottom: 2px solid var(--border); white-space: nowrap;
}
.hq-table tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.hq-table tbody tr:last-child td { border-bottom: none; }
.hq-table tbody tr:hover td { background: #f8fafc; }
.hq-table tfoot td { padding: 12px 16px; background: #f1f5f9; font-weight: 800; border-top: 2px solid var(--border); }

/* ===== BADGES ===== */
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 3px 10px; font-size: .76rem; font-weight: 800; }
.badge-teal   { background: #ccfbf1; color: #065f46; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-rose   { background: #ffe4e6; color: #9f1239; }
.badge-slate  { background: #f1f5f9; color: #475569; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-violet { background: #ede9fe; color: #5b21b6; }

/* ===== FORMS ===== */
.filter-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.filter-bar label { display: flex; flex-direction: column; gap: 4px; }
.filter-bar label span { font-size: .75rem; font-weight: 700; color: var(--text-muted); }
.form-select, .form-control {
  border: 1.5px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: .9rem; color: var(--text-main);
  background: #fff; outline: none; font-family: inherit;
  transition: border-color .15s;
}
.form-select:focus, .form-control:focus { border-color: var(--primary); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; border-radius: 8px; padding: 8px 18px;
  font-weight: 700; font-size: .9rem; cursor: pointer;
  font-family: inherit; transition: all .15s; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-outline { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }
.btn-outline:hover { background: #f1f5f9; color: var(--text-main); }
.btn-danger  { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-sm { padding: 5px 12px; font-size: .82rem; }

/* ===== LOGIN PAGE ===== */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0d1f4e 0%, #1e3a8a 50%, #0d1f4e 100%);
  padding: 20px;
}
.login-card {
  background: rgba(255,255,255,.04);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 20px;
  padding: 44px 44px 36px;
  width: 100%; max-width: 420px;
  box-shadow: 0 24px 80px rgba(0,0,0,.4);
}
.login-logo {
  text-align: center; margin-bottom: 32px;
}
.login-logo .logo-circle {
  width: 68px; height: 68px; border-radius: 18px;
  background: linear-gradient(135deg, #f97316, #fb923c);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.8rem; color: #fff; margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(249,115,22,.4);
}
.login-logo h1 { color: #fff; font-size: 1.7rem; font-weight: 900; letter-spacing: .5px; }
.login-logo p  { color: rgba(148,163,184,.8); font-size: .85rem; margin-top: 4px; font-weight: 600; }
.login-field { margin-bottom: 18px; }
.login-field label { display: block; color: rgba(148,163,184,.9); font-size: .82rem; font-weight: 700; margin-bottom: 8px; letter-spacing: .3px; }
.login-field input {
  width: 100%; background: rgba(255,255,255,.06); border: 1.5px solid rgba(255,255,255,.12);
  border-radius: 10px; padding: 11px 14px; color: #fff; font-size: .95rem; font-family: inherit; outline: none;
  transition: border-color .15s;
}
.login-field input:focus { border-color: #f97316; background: rgba(255,255,255,.09); }
.login-field input::placeholder { color: rgba(148,163,184,.5); }
.login-btn {
  width: 100%; background: linear-gradient(135deg, #f97316, #fb923c);
  color: #fff; border: none; border-radius: 10px; padding: 13px;
  font-size: 1rem; font-weight: 800; cursor: pointer; font-family: inherit;
  transition: opacity .15s; margin-top: 6px;
}
.login-btn:hover { opacity: .9; }
.login-err { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; border-radius: 8px; padding: 10px 14px; font-size: .88rem; font-weight: 700; margin-bottom: 18px; }

/* ===== USER MANAGEMENT ===== */
.role-badge-admin   { background: #fef9c3; color: #854d0e; }
.role-badge-manager { background: #dbeafe; color: #1e40af; }
.role-badge-viewer  { background: #f1f5f9; color: #475569; }

/* ===== ATTENDANCE GRID ===== */
.att-grid-wrap { overflow-x: auto; }
.att-grid-tbl { border-collapse: collapse; min-width: max-content; font-size: 13px; }
.att-grid-tbl th, .att-grid-tbl td { border: 1px solid #e2e8f0; padding: 0; vertical-align: middle; }
.att-grid-tbl thead th { background: #0f172a; color: #fff; font-weight: 700; padding: 8px 6px; text-align: center; font-size: 12px; white-space: nowrap; }
.att-grid-tbl th.th-name { min-width: 160px; text-align: left; padding: 8px 12px; position: sticky; left: 0; z-index: 10; background: #0f172a; }
.att-grid-tbl th.th-dow  { font-size: 10px; font-weight: 600; color: #94a3b8; background: #1e293b; padding: 3px; }
.att-grid-tbl th.th-dow.wkend { color: #fbbf24; }
.att-grid-tbl th.th-day.wkend { background: #1e293b; }
.att-grid-tbl th.th-day.today { background: #1d4ed8; }
.att-grid-tbl td.td-name { font-weight: 700; padding: 7px 12px; white-space: nowrap; position: sticky; left: 0; background: #fff; z-index: 5; border-right: 2px solid #c7d2fe; font-size: 13.5px; }
.att-grid-tbl tr:nth-child(even) td.td-name { background: #f8fafc; }
.att-grid-tbl td.td-day { text-align: center; width: 38px; padding: 4px 2px; }
.att-grid-tbl td.td-day.wkend { background: #f8fafc; }
.att-grid-tbl tbody tr:hover td { background: #eff6ff !important; }
.att-dc {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 26px; border-radius: 6px; font-weight: 900;
  font-size: 11.5px; border: 1px solid rgba(0,0,0,.07);
}
.att-grid-tbl tfoot td { background: #f1f5f9; font-weight: 800; text-align: center; padding: 6px 4px; border-top: 2px solid #334155; font-size: 12px; }
.att-grid-tbl tfoot td.td-name { text-align: left; color: #475569; }
.att-grid-tbl th.th-sum { min-width: 40px; background: #1d4ed8; }

/* ===== FORM LABELS ===== */
.form-label {
  font-size: .78rem; font-weight: 700; color: var(--text-muted);
  display: block; margin-bottom: 5px; letter-spacing: .2px;
}

/* ===== PERSONAL HUB VISIBILITY ===== */
.hub-visibility-menu { position: relative; }
.hub-visibility-menu > summary { list-style: none; }
.hub-visibility-menu > summary::-webkit-details-marker { display: none; }
.hub-visibility-trigger {
  min-height: 34px; display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 7px;
  background: #fff; color: #334155; font-size: .78rem; font-weight: 800; cursor: pointer;
}
.hub-visibility-trigger:hover { border-color: #94a3b8; background: #f8fafc; }
.hub-visibility-trigger b {
  min-width: 19px; height: 19px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: #fee2e2; color: #b91c1c; font-size: .68rem;
}
.hub-visibility-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 80;
  width: min(340px, calc(100vw - 24px)); background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 16px 38px rgba(15,23,42,.18); overflow: hidden;
}
.hub-visibility-heading, .hub-visibility-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 13px;
}
.hub-visibility-heading { border-bottom: 1px solid var(--border); }
.hub-visibility-heading strong { font-size: .86rem; }
.hub-visibility-heading span { color: var(--text-muted); font-size: .75rem; font-weight: 800; }
.hub-visibility-list { max-height: 330px; overflow-y: auto; padding: 5px 0; }
.hub-visibility-list label {
  min-height: 38px; display: grid; grid-template-columns: 18px minmax(0,1fr) 18px;
  align-items: center; gap: 9px; padding: 7px 13px; cursor: pointer; font-size: .81rem; font-weight: 700;
}
.hub-visibility-list label:hover { background: #f8fafc; }
.hub-visibility-list label span { overflow-wrap: anywhere; }
.hub-visibility-list label i { color: #64748b; text-align: center; }
.hub-visibility-list input { width: 16px; height: 16px; accent-color: var(--primary); }
.hub-visibility-empty { padding: 18px; color: var(--text-muted); text-align: center; font-size: .8rem; }
.hub-visibility-actions { border-top: 1px solid var(--border); background: #f8fafc; }
.hub-preference-toast {
  position: fixed; top: 74px; right: 22px; z-index: 120; display: flex; align-items: center; gap: 8px;
  max-width: min(360px, calc(100vw - 32px)); padding: 10px 13px; border: 1px solid #86efac;
  border-radius: 7px; background: #f0fdf4; color: #166534; font-size: .82rem; font-weight: 800;
  box-shadow: 0 10px 24px rgba(15,23,42,.14);
}
.hub-preference-toast.is-error { border-color: #fca5a5; background: #fef2f2; color: #991b1b; }

/* ===== UTILITIES ===== */
.text-center { text-align: center !important; }
.text-right  { text-align: right !important; }
.text-left   { text-align: left !important; }
.fw-semibold { font-weight: 600 !important; }
.fw-bold     { font-weight: 700 !important; }
.fw-800      { font-weight: 800 !important; }
.text-muted  { color: var(--text-muted) !important; }
.me-1 { margin-right: 4px !important; }
.me-2 { margin-right: 8px !important; }
.mb-3 { margin-bottom: 16px !important; }
.mt-2 { margin-top: 8px !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .topbar-menu-toggle { display: block; }
  .page-content { padding: 18px 16px; }
}
@media (max-width: 600px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .hub-visibility-trigger span { display: none; }
  .hub-visibility-panel { position: fixed; top: 66px; right: 12px; }
}
