:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0fe;
  --ink: #14162b;
  --muted: #6b7086;
  --border: #e7e8ee;
  --bg: #f4f5f9;
  --surface: #ffffff;
  --danger: #e0393e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20,22,31,.04), 0 6px 20px rgba(20,22,31,.05);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Inter","Noto Sans Thai",-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
}
a { color: inherit; }
header.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 28px; display: flex; align-items: center; justify-content: space-between;
}
header.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; text-decoration: none; color: var(--ink); }
header.topbar .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; }
header.topbar .who { display: flex; align-items: center; gap: 14px; font-size: .88em; color: var(--muted); }
header.topbar .who button { border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 7px 16px; font-size: .88em; cursor: pointer; color: var(--ink); font-family: inherit; }
header.topbar .who button:hover { background: var(--bg); }

main { max-width: 1120px; margin: 28px auto 80px; padding: 0 20px; }
h2 { font-size: 1.3em; margin: 0 0 4px; }
h3 { font-size: 1.05em; margin: 28px 0 12px; }
.muted { color: var(--muted); }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); opacity: .45; pointer-events: none; }
.search-box input { padding-left: 36px; width: 100%; }

input[type=text], input[type=date], select, textarea {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: .92em; background: var(--surface); color: var(--ink); font-family: inherit;
}
input[type=text]:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--primary); color: #fff; cursor: pointer;
  font-size: .88em; font-weight: 600; text-decoration: none; font-family: inherit;
}
.btn:hover { background: var(--primary-hover); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: #fdeceb; border-color: #f6c8c7; }
.btn.ghost { background: transparent; color: var(--muted); border-color: transparent; padding: 6px 10px; }
.btn.ghost:hover { background: var(--bg); color: var(--ink); }
.btn.sm { padding: 6px 11px; font-size: .82em; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 12px 14px; text-align: left; font-size: .92em; }
thead th { background: var(--bg); color: var(--muted); font-weight: 600; font-size: .78em; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #fafbfe; }
.actions { white-space: nowrap; text-align: right; }
.check { text-align: center; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .78em; font-weight: 600; }
.avatar { width: 34px; height: 34px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85em; flex-shrink: 0; }
.avatar.lg { width: 52px; height: 52px; font-size: 1.1em; }
.name-cell { display: flex; align-items: center; gap: 10px; }
.name-cell a { text-decoration: none; font-weight: 600; }
.name-cell a:hover { color: var(--primary); }

.card { background: var(--surface); padding: 22px; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); margin-bottom: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label { display: block; font-size: .8em; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field { margin-bottom: 14px; }
.field input, .field select { width: 100%; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: .9em; margin-bottom: 16px; }
.back-link:hover { color: var(--ink); }

.suggest-list { display: none; position: absolute; left: 0; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; z-index: 20; max-height: 320px; overflow-y: auto; }
.suggest-list.open { display: block; }
.suggest-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--border); cursor: pointer; background: none; width: 100%; text-align: left; border-left: none; border-right: none; border-top: none; font-family: inherit; }
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover { background: var(--bg); }
.suggest-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.suggest-name { font-weight: 600; font-size: .92em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-meta { font-size: .78em; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar.sm { width: 26px; height: 26px; font-size: .75em; }

.dp-wrap { position: relative; width: 100%; }
.dp-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: .92em; font-family: inherit; cursor: pointer; color: var(--ink);
}
.dp-trigger.placeholder { color: var(--muted); }
.dp-trigger .dp-icon { opacity: .6; }
.dp-popup {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; width: 260px;
}
.dp-popup.hidden { display: none; }
.dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-weight: 700; font-size: .92em; }
.dp-head button { border: none; background: var(--bg); width: 26px; height: 26px; border-radius: 6px; cursor: pointer; font-size: .95em; }
.dp-head button:hover { background: var(--primary-soft); color: var(--primary); }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.dp-dow { font-size: .7em; color: var(--muted); font-weight: 600; padding: 4px 0; }
.dp-day { padding: 7px 0; font-size: .82em; border-radius: 8px; cursor: pointer; background: none; border: none; font-family: inherit; }
.dp-day:hover { background: var(--bg); }
.dp-day.muted { color: #c7c9d6; }
.dp-day.today { border: 1px solid var(--primary); }
.dp-day.selected { background: var(--primary); color: #fff; font-weight: 700; }
.dp-footer { display: flex; justify-content: space-between; margin-top: 10px; }
.dp-footer button { border: none; background: none; color: var(--muted); font-size: .8em; cursor: pointer; font-family: inherit; }
.dp-footer button:hover { color: var(--primary); }

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { display: flex; align-items: center; gap: 6px; background: var(--primary-soft); color: var(--primary); padding: 5px 8px 5px 12px; border-radius: 999px; font-size: .85em; font-weight: 600; }
.chip button { border: none; background: none; color: var(--primary); cursor: pointer; font-size: 1.1em; line-height: 1; padding: 2px 4px; border-radius: 999px; }
.chip button:hover { background: rgba(79,70,229,.15); }

.add-panel { display: none; }
.add-panel.open { display: block; }
tr .edit-input { display: none; }
tr .edit-only { display: none; }
tr.editing .view-text { display: none; }
tr.editing .edit-input { display: inline-block; }
tr.editing .view-only { display: none; }
tr.editing .edit-only { display: inline-flex; }
td .edit-input[type=checkbox] { display: none; width: auto; }
tr.editing td .edit-input[type=checkbox] { display: inline-block; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 10px; font-size: .88em; box-shadow: var(--shadow); z-index: 100; display: none; }
.toast.show { display: block; }
.toast.error { background: var(--danger); }
.loading { text-align: center; padding: 60px 20px; color: var(--muted); }
