:root {
  --brand: #6d28d9;
  --brand-dark: #2e1065;
  --brand-mid: #4c1d95;
  --brand-soft: #ede9fe;
  --brand-softer: #f5f3ff;
  --ink: #1f1b2e;
  --muted: #6b6880;
  --line: #e7e4f0;
  --bg: #f7f6fb;
  --card: #ffffff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 20, 60, .06), 0 4px 16px rgba(30, 20, 60, .05);
  font-family: "Noto Sans Thai", "Sarabun", "Thonburi", "Leelawadee UI", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 15px; line-height: 1.55; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--brand-dark), var(--brand-mid));
  color: #ede9fe; padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; color: #fff; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; background: #a78bfa; color: var(--brand-dark);
  display: grid; place-items: center; font-weight: 800;
}
.brand strong { display: block; font-size: 1.05rem; }
.brand span { font-size: .75rem; opacity: .75; }
.nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav a, .nav .soon {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: #ddd6fe; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.nav a.active { background: #fff; color: var(--brand-dark); }
.nav .soon { opacity: .5; cursor: default; justify-content: space-between; }
.nav .soon em { font-style: normal; font-size: .7rem; background: rgba(255,255,255,.15); padding: 1px 6px; border-radius: 6px; }
.nav-section { margin: 16px 12px 6px; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; opacity: .6; }
.nav-icon { width: 20px; text-align: center; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 14px 28px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.search { flex: 1; max-width: 460px; }
.search input { width: 100%; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.avatar.lg { width: 88px; height: 88px; font-size: 1.8rem; }
.content { padding: 24px 28px 48px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.breadcrumb { font-size: .82rem; color: var(--muted); margin-bottom: 6px; }

/* Cards & grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-title { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-title .icon { width: 32px; height: 32px; border-radius: 9px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.9rem; font-weight: 700; color: var(--brand-dark); }
.stat.highlight { background: var(--brand-softer); border-color: #ddd6fe; }

.kv { display: grid; grid-template-columns: minmax(120px, 42%) 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; text-align: right; overflow-wrap: anywhere; }

.profile-head {
  display: flex; align-items: center; gap: 20px; padding: 22px; border-radius: var(--radius);
  background: linear-gradient(90deg, var(--brand-soft), var(--brand-softer)); margin-bottom: 16px; flex-wrap: wrap;
}
.profile-head .meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: .9rem; }
.profile-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .82rem; color: var(--muted); font-weight: 600; background: var(--brand-softer); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: #faf9ff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 28px; }

/* Badges & buttons */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.grey { background: #eceaf2; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { text-decoration: none; border-color: #c4b5fd; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #5b21b6; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.link-btn { background: none; border: 0; color: #ddd6fe; font: inherit; cursor: pointer; padding: 0; }

/* Forms */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); }
input, select, textarea {
  font: inherit; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c4b5fd; border-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.field { display: grid; gap: 5px; }
.field label { font-size: .85rem; font-weight: 600; }
.field.full { grid-column: 1 / -1; }
.field input, .field select, .field textarea { width: 100%; }
.field .err { color: var(--bad); font-size: .82rem; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.notice { padding: 12px 16px; border-radius: 10px; background: var(--brand-softer); border: 1px solid #ddd6fe; }
.notice.warn { background: var(--warn-soft); border-color: #fde68a; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.timeline .when { color: var(--muted); font-size: .85rem; }

/* Landing */
.landing { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand-dark), var(--brand)); }
.landing .card { width: min(420px, 92vw); text-align: center; padding: 36px; }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
  .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dd { text-align: left; }
}
.center-mark { margin: 0 auto 14px; }
.grid > .card + .card { margin-top: 0; }
