:root {
  --bg: #eef2f8;
  --surface: #ffffff;
  --surface-2: #f7f9fd;
  --border: #e6eaf2;
  --text: #1f2733;
  --text-muted: #6b7588;
  --primary: #2563eb;
  --primary-700: #1d4ed8;
  --primary-soft: #eaf1ff;
  --teal: #0ea5a4;
  --teal-soft: #e2f6f5;
  --indigo: #6366f1;
  --indigo-soft: #ecedfe;
  --orange: #f59e0b;
  --orange-soft: #fef3e0;
  --green: #10b981;
  --green-soft: #e4f7ef;
  --red: #ef4444;
  --red-soft: #fdeaea;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 6px 20px rgba(16, 24, 40, 0.05);
  --radius: 16px;
  --sidebar-w: 252px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: #5779a4;
  font-family: 'Sarabun', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
.num, .mono { font-family: 'Inter', sans-serif; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #ffffff url('/side-bg.png') no-repeat bottom center;
  background-size: cover;
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar__brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 14px; border-bottom: 1px solid var(--border); }
.sidebar__title { font-weight: 700; font-size: 15px; }
.sidebar__sub { font-size: 11.5px; color: var(--text-muted); }
.brand__logo {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; color: #fff; font-weight: 700;
  font-family: 'Inter', sans-serif; letter-spacing: .5px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  box-shadow: 0 6px 14px rgba(37, 99, 235, .3);
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav__item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 11px; border: 0; background: transparent;
  font: inherit; color: var(--text-muted); cursor: pointer; text-align: left; width: 100%;
  transition: background .12s, color .12s;
}
.nav__item:hover { background: var(--surface-2); color: var(--text); }
.nav__item.is-active { background: var(--primary-soft); color: var(--primary-700); font-weight: 600; }
.nav__ico { width: 18px; text-align: center; }
.sidebar__help { margin-top: auto; }
.help-card { background: linear-gradient(135deg, #eef4ff, #e7f6f5); border-radius: 12px; padding: 14px; }
.help-card__title { font-weight: 600; font-size: 13.5px; }
.help-card__text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

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

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 15;
  background: rgba(255,255,255,.88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 12px 26px;
}
.topbar__search { position: relative; flex: 1; max-width: 560px; }
.topbar__search input {
  width: 100%; padding: 10px 14px 10px 38px; border: 1px solid var(--border);
  border-radius: 12px; font: inherit; background: var(--surface-2); outline: none;
}
.search__icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.topbar__right { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.iconbtn { position: relative; border: 1px solid var(--border); background: #fff; width: 40px; height: 40px; border-radius: 11px; cursor: pointer; font-size: 16px; }
.menu-btn { display: none; flex-shrink: 0; }
.nav-overlay { display: none; }
.iconbtn__badge { position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; font-family: 'Inter'; }
.user { display: flex; align-items: center; gap: 10px; }
.user__avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--indigo-soft); color: var(--indigo); display: grid; place-items: center; font-weight: 700; }
.user__name { font-size: 13.5px; font-weight: 600; }
.user__role { font-size: 11.5px; color: var(--text-muted); }

.content { padding: 24px 26px 40px; max-width: 1440px; width: 100%; }

/* Hero */
.hero {
  position: relative; overflow: hidden;
  border-radius: 20px; margin-bottom: 22px;
  background: linear-gradient(120deg, #eaf2ff 0%, #e4f6f6 100%);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  min-height: 280px; display: flex; align-items: center;
}
.hero__bg {
  position: absolute; inset: -10% -3%;
  background: url('/hero.png') no-repeat center top;
  background-size: cover;
  z-index: 0; will-change: transform;
}
.hero__text { position: relative; z-index: 1; padding: 28px 32px; max-width: 60%; }
.hero__title { margin: 0; font-size: 26px; font-weight: 700; color: #173a7a; }
.hero__sub { margin: 6px 0 16px; color: #3a4d76; font-size: 14.5px; }
.hero__meta { margin: -8px 0 14px; font-size: 13px; color: #5a6d96; }
.hero__meta span { font-weight: 600; color: #1e4a8c; }
.hero__chips { display: flex; gap: 10px; flex-wrap: wrap; }
.chip { background: rgba(255,255,255,.8); border: 1px solid #d7e3fb; border-radius: 999px; padding: 6px 14px; font-size: 13px; color: #2b3b5e; }
.chip b { font-family: 'Inter'; color: var(--primary-700); margin-left: 4px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; }
.stat__ico { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; font-size: 20px; flex-shrink: 0; }
.stat__ico--blue { background: var(--primary-soft); color: var(--primary); }
.stat__ico--teal { background: var(--teal-soft); color: var(--teal); }
.stat__ico--indigo { background: var(--indigo-soft); color: var(--indigo); }
.stat__ico--orange { background: var(--orange-soft); color: var(--orange); }
.stat__label { font-size: 12.5px; color: var(--text-muted); }
.stat__value { font-size: 23px; font-weight: 700; font-family: 'Inter', sans-serif; line-height: 1.2; }
.stat__sub { font-size: 11.5px; color: var(--text-muted); }

/* Panels */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 20px; }
.panel__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.panel__title { margin: 0; font-size: 15.5px; font-weight: 700; }
.panel__count { font-size: 13px; color: var(--text-muted); }
.panel__body { padding: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.chart-box { height: 280px; display: grid; place-items: center; }
.chart-box canvas { max-height: 250px; }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.search--inline { position: relative; flex: 1 1 280px; min-width: 220px; }
.search--inline input { width: 100%; padding: 9px 12px 9px 34px; border: 1px solid var(--border); border-radius: 10px; font: inherit; background: #fff; outline: none; }
.select { padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; font: inherit; background: #fff; cursor: pointer; outline: none; }
input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.check { display: inline-flex; align-items: center; gap: 7px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; font-size: 14px; color: var(--text); cursor: pointer; white-space: nowrap; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* Table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 13px 16px; text-align: left; vertical-align: top; }
.table thead th { font-size: 12px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table tbody tr { border-bottom: 1px solid var(--border); transition: background .12s; }
.table tbody tr:hover { background: var(--primary-soft); }
.table tbody tr.row-skeleton:hover { background: transparent; }
.table .num { text-align: right; white-space: nowrap; }

/* Table loading skeleton */
.table-wrap.is-loading { position: relative; }
.table-wrap.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 60%, rgba(255,255,255,.35));
  pointer-events: none;
}
.row-skeleton td { padding: 14px 16px; vertical-align: middle; }
.sk {
  display: block;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 0%, #e8edf5 45%, var(--surface-2) 90%);
  background-size: 200% 100%;
  animation: sk-shimmer 1.15s ease-in-out infinite;
}
.sk--circle { width: 22px; height: 22px; border-radius: 50%; margin: 0 auto; }
.sk--line { height: 11px; margin: 5px 0; }
.sk--lg { width: 88%; }
.sk--md { width: 72%; }
.sk--sm { width: 55%; }
.sk--xs { width: 42%; }
.sk--pill { width: 72px; height: 22px; border-radius: 999px; margin: 2px 0; }
.sk--pill.sk--sm { width: 56px; height: 20px; }
@keyframes sk-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.panel__count.is-loading {
  color: var(--text-muted);
  animation: count-pulse 1s ease-in-out infinite;
}
@keyframes count-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.pager.is-loading .pager__info { color: var(--text-muted); }
.star-col { width: 38px; }
.star { cursor: pointer; font-size: 17px; color: #cbd2de; line-height: 1; background: none; border: 0; padding: 2px; }
.star.is-on { color: #f59e0b; }
.cell-project { max-width: 430px; cursor: pointer; }
.cell-project .name { font-weight: 500; }
.cell-project .pid { font-size: 12px; color: var(--text-muted); font-family: 'Inter'; }
.cat-chip { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--teal-soft); color: #0c7d7c; font-size: 11.5px; font-family: 'Sarabun'; white-space: nowrap; }
.cell-dept { max-width: 230px; color: var(--text-muted); font-size: 13.5px; }
.cell-date { white-space: nowrap; font-size: 13.5px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge--green { background: var(--green-soft); color: var(--green); }
.badge--amber { background: var(--orange-soft); color: var(--orange); }
.badge--red { background: var(--red-soft); color: var(--red); }
.badge--gray { background: #eef0f4; color: var(--text-muted); }
.badge--blue { background: var(--primary-soft); color: var(--primary-700); }
.empty { padding: 48px; text-align: center; color: var(--text-muted); }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; gap: 12px; flex-wrap: wrap; }
.pager__left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pager__info { color: var(--text-muted); font-size: 13.5px; }
.select--sm { padding: 6px 10px; font-size: 13px; }
.pager__btns { display: flex; gap: 8px; }

/* Changes list */
.change-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.change-item:last-child { border-bottom: 0; }
.change-item--click { cursor: pointer; border-radius: 8px; margin: 0 -8px; padding: 12px 8px; transition: background .15s; }
.change-item--click:hover { background: #f4f7fc; }
.change-item--click:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
.change-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); margin-top: 7px; flex-shrink: 0; }
.change-item .c-name { font-weight: 500; }
.change-item .c-meta { font-size: 12.5px; color: var(--text-muted); }

/* Buttons */
.btn { font: inherit; cursor: pointer; border-radius: 10px; padding: 9px 14px; border: 1px solid var(--border); background: #fff; color: var(--text); transition: background .12s, border-color .12s; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--sm { padding: 7px 12px; font-size: 13.5px; }
.btn--primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn--primary:hover { background: var(--primary-700); }
.btn--block { width: 100%; padding: 12px; font-weight: 600; }
.btn--icon { padding: 6px 10px; }

/* Drawer */
.overlay { position: fixed; inset: 0; background: rgba(17,24,39,.4); z-index: 30; animation: fade .15s; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 95vw); background: var(--surface); z-index: 40; box-shadow: -8px 0 30px rgba(16,24,40,.14); display: flex; flex-direction: column; animation: slide .18s ease; }
@keyframes slide { from { transform: translateX(30px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer__head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer__title { font-size: 16px; margin: 0; }
.drawer__body { padding: 20px; overflow-y: auto; }
.detail-name { font-size: 17px; font-weight: 600; margin: 0 0 4px; line-height: 1.4; }
.detail-dept { color: var(--text-muted); margin-bottom: 16px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0 0 18px; }
.kv dt { color: var(--text-muted); font-size: 13.5px; }
.kv dd { margin: 0; font-weight: 500; }
.kv .money { font-family: 'Inter'; }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-muted); margin: 18px 0 10px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0 10px 16px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 16px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline .t-meta { font-size: 12px; color: var(--text-muted); }
.drawer__actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.nav__item--admin { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.panel__hint { margin: 0 20px 12px; font-size: 13px; color: var(--text-muted); }
.user-form-wrap { margin: 0 20px 16px; padding: 16px; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--border); }
.user-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px 16px; align-items: end; }
.user-form__actions { display: flex; gap: 8px; grid-column: 1 / -1; }
.form-error { color: var(--red); font-size: 13px; margin: 8px 0 0; grid-column: 1 / -1; }
.table--users .btn { margin-right: 6px; }
.badge--admin { background: var(--primary-soft); color: var(--primary); }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(135deg, #e7effb, #e4f6f5); padding: 20px; }
.login-card { display: grid; grid-template-columns: 1.1fr 1fr; width: min(900px, 100%); background: #fff; border-radius: 22px; overflow: hidden; box-shadow: 0 20px 60px rgba(16,24,40,.16); }
.login-art { background: url('/hero.png') center/cover, linear-gradient(135deg, #2563eb, #38bdf8); position: relative; }
.login-art__overlay { height: 100%; background: linear-gradient(160deg, rgba(37,99,235,.78), rgba(56,189,248,.55)); padding: 36px; display: flex; flex-direction: column; gap: 26px; color: #fff; }
.brand--light .brand__title { color: #fff; font-size: 17px; margin: 0; }
.brand--light .brand__subtitle { color: rgba(255,255,255,.85); font-size: 12.5px; margin: 2px 0 0; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand__title { font-size: 18px; margin: 0; }
.brand__subtitle { font-size: 12.5px; color: var(--text-muted); margin: 0; }
.login-art__points { list-style: none; padding: 0; margin: auto 0 0; display: flex; flex-direction: column; gap: 12px; }
.login-art__points li { padding-left: 26px; position: relative; font-size: 14px; }
.login-art__points li::before { content: '✓'; position: absolute; left: 0; top: 0; background: rgba(255,255,255,.25); width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; }
.login-form { padding: 40px 38px; }
.login-form__title { margin: 0; font-size: 22px; font-weight: 700; }
.login-form__subtitle { margin: 6px 0 24px; color: var(--text-muted); font-size: 14px; }
.field { display: block; margin-bottom: 16px; }
.field__label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.field input { width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 11px; font: inherit; outline: none; }
.login-error { background: var(--red-soft); color: var(--red); padding: 10px 12px; border-radius: 10px; font-size: 13.5px; margin-bottom: 14px; }
.login-hint { margin-top: 16px; font-size: 12.5px; color: var(--text-muted); text-align: center; }

@media (max-width: 900px) {
  .menu-btn { display: grid; place-items: center; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60;
    width: 270px; height: 100vh;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 8px 0 30px rgba(16,24,40,.16);
  }
  .hero__bg {
    position: absolute; inset: -2% -1%;
    background: url('/hero.png') no-repeat right top;
    background-size: cover;
    z-index: 0; will-change: transform;
  }
  .sidebar.is-open { transform: none; }
  .nav-overlay { display: block; position: fixed; inset: 0; background: rgba(17,24,39,.4); z-index: 50; }
  .nav-overlay[hidden] { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .hero__text { max-width: 100%; }
  .content { padding: 18px 16px 32px; }
  .login-card { grid-template-columns: 1fr; }
  .login-art { display: none; }
}
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; } }

.notify-form { padding: 8px 4px 20px; max-width: 720px; }
.field--row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.field--row input[type="checkbox"] { width: auto; margin-top: 3px; }
.notify-checks { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 6px; }
.notify-checks--grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px 12px; }
.notify-check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.notify-check input { width: auto; }
.notify-keywords { min-height: 120px; resize: vertical; font: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px; }
.notify-ok { color: #0d9488; font-size: 15px; font-weight: 600; margin: 12px 0 0; padding: 10px 14px; background: #ccfbf1; border-radius: 10px; }
.input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px; font: inherit; }

.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0 16px; }
.mini-table th, .mini-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.mini-table th { color: var(--text-muted); font-weight: 600; }
