:root {
  --g9: #14532d; --g8: #166534; --g7: #166534; --g6: #15803d; --g5: #16a34a; --g1: #dcfce7; --g0: #f0fdf4;
  --gold: #d97706; --ink: #111827; --ink2: #374151; --muted: #6b7280; --line: #e5e7eb; --bg: #f9fafb;
  --red: #dc2626; --r: 14px;
  --sh: 0 1px 2px rgba(17,24,39,.04);
  --font: "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); font-size: 15.5px; line-height: 1.55; color: var(--ink); background: var(--bg); }
h1, h2, h3, .btn, .kpi b { font-family: var(--font); }
a { color: var(--g6); text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Layout ---------- */
.side {
  position: fixed; inset: 0 auto 0 0; width: 258px; z-index: 50;
  display: flex; flex-direction: column;
  background: #fff; border-right: 1px solid var(--line);
  color: var(--ink); padding: 18px 14px;
}
.side-brand { display: flex; align-items: center; gap: 12px; color: var(--ink); padding: 6px 8px 18px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.side-brand .brand-logo { width: 42px; height: 42px; display: grid; place-items: center; background: var(--g6); border-radius: 12px; }
.side-brand svg, .side-brand img { width: 36px; height: 36px; object-fit: contain; }
.side-brand span:last-child { display: flex; flex-direction: column; line-height: 1.2; }
.side-brand strong { font-size: 19px; }
.side-brand small { color: var(--muted); font-size: 12.5px; }
.side-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; overflow: auto; }
.side-nav a { display: flex; align-items: center; gap: 12px; color: var(--ink2); font-weight: 500; padding: 10px 12px; border-radius: 11px; transition: .15s; }
.side-nav a:hover { color: var(--ink); background: var(--bg); }
.side-nav a.active { color: var(--g7); background: var(--g0); font-weight: 600; }
.side-nav a.active .i { color: var(--g6); }
.side-sep { height: 1px; background: var(--line); margin: 10px 6px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 12px 8px 4px; border-top: 1px solid var(--line); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--g1); color: var(--g7); font-weight: 700; }
.who { display: flex; flex-direction: column; line-height: 1.2; flex: 1; min-width: 0; }
.who small { color: var(--muted); font-size: 12px; }
.side-user .icon-btn { color: var(--muted); background: var(--bg); }
.side-user .icon-btn:hover { color: var(--red); background: #fef2f2; }

.main { margin-left: 258px; min-height: 100vh; }
.main-top { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; padding: 16px 32px; background: rgba(255,255,255,.85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.main-top h1 { margin: 0; font-size: 21px; font-weight: 700; }
.menu-btn { display: none; }
.content { padding: 26px 32px 60px; max-width: 1320px; }
.side-overlay { display: none; }

/* ---------- Components ---------- */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 20px; box-shadow: var(--sh); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-head h3, .form-title { margin: 0 0 14px; font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-head h3 { margin: 0; }
.link { font-size: 14px; font-weight: 500; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
.stack { display: grid; gap: 20px; }
.intro { margin: -4px 0 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 16px; border-radius: 11px; font-size: 14.5px; font-weight: 500; cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: #c7d6cd; background: #fafcfb; }
.btn-primary { border: 0; color: #fff; background: var(--g6); }
.btn-primary:hover { background: var(--g7); }
.btn-ghost { background: transparent; }
.btn-danger { border-color: #fecaca; color: var(--red); background: #fff; }
.btn-danger:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13.5px; }
.btn-block { width: 100%; padding: 12px; font-size: 16px; }
.danger-text { color: var(--red); }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--g0); color: var(--ink2); cursor: pointer; transition: .15s; font-size: 18px; }
.icon-btn:hover { background: var(--g1); color: var(--g7); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.danger:hover { background: #fee2e2; color: var(--red); }
.push { margin-left: auto; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--g0); color: var(--g7); font-size: 13px; font-weight: 500; white-space: nowrap; }
.gdot { --gc: var(--g5); display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 6px; border-radius: 9px; background: color-mix(in srgb, var(--gc) 10%, white); color: var(--gc); border: 1px solid color-mix(in srgb, var(--gc) 28%, white); font-weight: 700; font-size: 13.5px; }

.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; border: 1px solid; font-size: 15px; }
.alert-success { background: #ecfdf3; border-color: #bbf7d0; color: #166534; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi { display: flex; align-items: center; gap: 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--sh); }
.kpi-ico { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; color: var(--c); background: color-mix(in srgb, var(--c) 12%, white); }
.kpi-ico .i { width: 24px; height: 24px; }
.kpi b { display: block; font-size: 26px; font-weight: 600; line-height: 1.1; }
.kpi small { color: var(--muted); font-size: 13.5px; }
.hero-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; background: #fff; border-color: var(--g1); border-left: 4px solid var(--g6); }
.hero-card h2 { margin: 0 0 4px; }
.hero-card p { margin: 0; color: var(--ink2); }

/* bars */
.bars { display: grid; gap: 4px; }
.bar-row { display: grid; grid-template-columns: 190px 1fr 34px; align-items: center; gap: 12px; padding: 6px 8px; border-radius: 10px; color: var(--ink); }
.bar-row:hover { background: var(--g0); }
.bar-label { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bar-area { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14.5px; }
.bar-track { height: 10px; border-radius: 99px; background: #f3f4f6; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 99px; background: var(--gc); transition: width .6s; }
.bar-row b { text-align: right; font-weight: 700; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.list-plain li:last-child { border-bottom: 0; }

/* ---------- Toolbar / Table ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px; margin-bottom: 16px; }
.toolbar select, .form input, .form select, .toolbar input {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 11px; padding: 9px 12px; outline: 0; transition: .15s;
}
.toolbar select:focus, .form input:focus, .form select:focus, .toolbar input:focus { border-color: var(--g5); box-shadow: 0 0 0 4px rgba(22,163,74,.12); }
.input-ico { position: relative; flex: 1 1 260px; }
.input-ico .i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-ico input { width: 100%; padding-left: 38px; }
.toolbar label.inline { display: flex; align-items: center; gap: 8px; }
.file-name { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }

.table-card { padding: 0; overflow: hidden; }
.table-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 13px; background: var(--bg); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 12px; border-bottom: 1px solid #f1f3f5; vertical-align: middle; }
.table tbody tr:hover { background: #fafafa; }
.table .strong { font-weight: 600; white-space: nowrap; }
.table.compact td { padding: 7px 12px; }
.w-chk { width: 36px; }
.t-right { text-align: right; }
.nowrap { white-space: nowrap; }
.table td form { display: inline; }
.empty-row { text-align: center; color: var(--muted); padding: 40px !important; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--g6); }

/* ---------- Forms ---------- */
.form { display: grid; gap: 14px; }
.form label { display: block; font-size: 14px; font-weight: 500; color: var(--ink2); }
.form input, .form select { display: block; width: 100%; font-size: 15px; margin-top: 6px; }
.form .radio-card input { margin-top: 4px; }
.form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; align-items: end; }
.form .row .col-2 { grid-column: span 2; }
.req { color: var(--red); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 6px; flex-wrap: wrap; }
.grid-form { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.group-preview dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 14px 0; font-size: 14.5px; }
.group-preview dt { color: var(--muted); }
.group-preview dd { margin: 0; font-weight: 500; }
.gp-badge { --gc: var(--g5); width: 76px; height: 76px; border-radius: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--gc); font-size: 32px; font-weight: 700; line-height: 1; background: color-mix(in srgb, var(--gc) 9%, white); border: 1.5px solid color-mix(in srgb, var(--gc) 28%, white); }
.gp-badge small { font-size: 11px; font-weight: 400; margin-bottom: 3px; }
.gp-badge.sm { width: 54px; height: 54px; border-radius: 15px; font-size: 22px; }
.gp-badge.sm small { font-size: 9.5px; }

/* groups */
.group-edit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.g-edit { --gc: var(--g5); display: grid; gap: 10px; position: relative; overflow: hidden; border-top: 4px solid var(--gc); }
.g-edit label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
.g-edit input:not([type=color]) { font: inherit; font-size: 14.5px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px; outline: 0; }
.g-edit input:focus { border-color: var(--gc); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gc) 15%, transparent); }
.g-edit-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.g-edit-head > div { flex: 1; }

.color-pick input { width: 42px; height: 42px; border: 0; padding: 0; background: none; cursor: pointer; border-radius: 12px; }
.color-pick input::-webkit-color-swatch-wrapper { padding: 3px; }
.color-pick input::-webkit-color-swatch { border-radius: 10px; border: 1px solid rgba(0,0,0,.08); }
.sticky-save { position: sticky; bottom: 0; z-index: 10; display: flex; justify-content: flex-end; padding: 16px 0; margin-top: 4px; background: linear-gradient(to top, var(--bg) 60%, transparent); }
.add-group { margin-top: 20px; }

/* ---------- Import ---------- */
.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 20px; flex-wrap: wrap; }
.steps li { display: flex; align-items: center; gap: 10px; padding: 8px 16px 8px 8px; border-radius: 999px; background: #fff; border: 1px solid var(--line); color: var(--muted); font-weight: 500; }
.steps li span { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: #f3f4f6; font-size: 13px; }
.steps li.on { color: var(--g7); border-color: #bbe5c8; background: var(--g0); }
.steps li.on span { background: var(--g6); color: #fff; }
.steps li.done span { background: var(--g1); color: var(--g7); }
.dropzone { display: flex !important; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 34px 20px; border: 2px dashed #c9dccf; border-radius: 16px; background: #fafdfb; cursor: pointer; transition: .2s; position: relative; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone:hover, .dropzone.over { border-color: var(--g5); background: var(--g0); }
.dropzone.has { border-style: solid; border-color: var(--g5); background: var(--g0); }
.dz-ico { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: #fff; color: var(--g6); box-shadow: var(--sh); }
.dz-ico .i { width: 28px; height: 28px; }
.dropzone b { color: var(--ink); font-size: 15.5px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13.5px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.radio-card { display: flex !important; grid-template-columns: none; align-items: flex-start; gap: 12px !important; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; transition: .15s; }
.radio-card:hover { border-color: #bfd8c7; }
.radio-card:has(input:checked) { border-color: var(--g5); background: var(--g0); box-shadow: 0 0 0 3px rgba(22,163,74,.1); }
.radio-card input { width: auto !important; margin-top: 4px; accent-color: var(--g6); }
.radio-card span { display: flex; align-items: center; gap: 8px; color: var(--ink); word-break: break-all; }
.radio-card.big span { flex-direction: column; align-items: flex-start; gap: 2px; word-break: normal; }
.radio-card.big small { color: var(--muted); font-weight: 400; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.import-confirm { margin-bottom: 22px; }
.help p { margin: 0 0 12px; color: var(--ink2); }
.cols-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.cols-chips span { font-size: 13px; padding: 4px 10px; border-radius: 8px; background: #f1f5f3; color: var(--ink2); }
.cols-chips .req-chip { background: var(--g1); color: var(--g7); font-weight: 600; }
.sub-title { font-size: 17px; margin: 0 0 12px; }
.preview-groups { display: grid; gap: 10px; }
.pg { padding: 0; overflow: hidden; border-left: 4px solid var(--gc); }
.pg summary { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; list-style: none; flex-wrap: wrap; }
.pg summary::-webkit-details-marker { display: none; }
.pg[open] summary { border-bottom: 1px solid var(--line); }

/* ---------- Auth ---------- */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(700px 300px at 50% 0%, rgba(22,163,74,.08), transparent 70%), var(--bg); }
.auth-wrap { width: 100%; max-width: 420px; }
.auth-card { background: #fff; border-radius: 24px; padding: 36px 32px 28px; border: 1px solid var(--line); box-shadow: 0 24px 48px -16px rgba(17,24,39,.15); text-align: center; }
.auth-card .form { text-align: left; margin-top: 20px; }
.auth-card h2 { margin: 14px 0 4px; font-size: 24px; }
.auth-card p { margin: 0; }
.auth-logo { width: 72px; height: 72px; margin: 0 auto; border-radius: 22px; display: grid; place-items: center; background: var(--g6); }
.auth-logo svg, .auth-logo img { width: 52px; height: 52px; object-fit: contain; }
.back-link { display: inline-block; margin-top: 18px; font-size: 14px; color: var(--muted); }
.auth .alert { margin-top: 16px; text-align: left; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-form { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .side { transform: translateX(-100%); transition: transform .25s; }
  body.nav-open .side { transform: none; }
  body.nav-open .side-overlay { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(17,24,39,.3); }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid; }
  .main-top { padding: 12px 16px; }
  .main-top h1 { font-size: 19px; }
  .content { padding: 18px 16px 50px; }
  .mode-grid { grid-template-columns: 1fr; }
  .form .row .col-2 { grid-column: auto; }
  .bar-row { grid-template-columns: 130px 1fr 30px; }
}
@media (max-width: 520px) {
  .kpis { gap: 10px; }
  .kpi { padding: 14px; gap: 10px; }
  .kpi-ico { width: 40px; height: 40px; }
  .kpi b { font-size: 21px; }
  .toolbar > * { flex: 1 1 100%; }
  .toolbar .push { margin-left: 0; }
  .group-edit-grid { grid-template-columns: 1fr; }
  .hero-card { flex-direction: column; align-items: flex-start; }
}
