:root {
  --primary: #73bff2;
  --primary-dark: #2f7eb3;
  --primary-soft: #eaf6ff;
  --sidebar: #80caff;
  --sidebar-dark: #459bd2;
  --bg: #f5f9fc;
  --surface: #ffffff;
  --surface-2: #f8fbfd;
  --text: #203044;
  --muted: #6f8096;
  --line: #dce7ef;
  --success: #1f9d68;
  --warning: #d48a12;
  --danger: #de4b5f;
  --info: #3b82f6;
  --shadow: 0 18px 50px rgba(45, 89, 122, .12);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Sarabun", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.boot-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: radial-gradient(circle at top left, #e3f5ff, #f9fbfd 52%, #eef6fb);
}
.brand-mark {
  width: 76px;
  height: 76px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #71c5fa, #bfe8ff);
  color: #17466a;
  font-weight: 800;
  box-shadow: var(--shadow);
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(460px, 620px);
  background: radial-gradient(circle at 10% 20%, #e3f6ff, #f9fcff 55%, #eef5fa);
}
.login-visual {
  padding: 64px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
}
.login-visual h1 { font-size: clamp(36px, 5vw, 66px); margin: 0; line-height: 1.05; }
.login-visual p { max-width: 720px; font-size: 20px; color: var(--muted); }
.login-card-wrap { display: flex; align-items: center; padding: 40px; }
.login-card {
  width: 100%;
  background: rgba(255, 255, 255, .96);
  border: 1px solid rgba(210, 228, 240, .9);
  border-radius: 28px;
  padding: 38px;
  box-shadow: var(--shadow);
}
.login-card h2 { margin: 18px 0 8px; font-size: 32px; }
.login-card .brand-mark { width: 94px; height: 94px; }

.form-grid { display: grid; gap: 16px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 7px; }
.field label { font-weight: 700; }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  transition: .18s ease;
}
.textarea { min-height: 110px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(115, 191, 242, .16);
}
.input[disabled], .select[disabled], .textarea[disabled] { background: #f1f5f8; color: #8b99a9; }
.help { font-size: 13px; color: var(--muted); }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { cursor: not-allowed; opacity: .48; transform: none; }
.btn-primary { background: var(--primary); color: #143c58; }
.btn-primary:hover { background: #63b6ec; }
.btn-secondary { background: #edf3f7; color: var(--text); }
.btn-success { background: #dff6ec; color: #13754d; }
.btn-warning { background: #fff2d7; color: #9a650b; }
.btn-danger { background: #ffe6ea; color: #b62b3d; }
.btn-outline { border: 1px solid var(--line); background: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 11px; font-size: 13px; border-radius: 10px; }

.notice {
  border-radius: 14px;
  padding: 13px 15px;
  background: #edf6ff;
  border: 1px solid #c8e4f9;
  color: #24577a;
}
.notice.warning { background: #fff7e7; border-color: #f4dca9; color: #84560b; }
.notice.danger { background: #fff0f2; border-color: #ffcfd6; color: #a52d3d; }
.notice.success { background: #eaf9f2; border-color: #bee9d5; color: #176b49; }

.app-shell { min-height: 100vh; display: block; }
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 280px;
  z-index: 30;
  background: linear-gradient(180deg, var(--sidebar), #6bb9eb);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-shadow: 10px 0 30px rgba(58, 122, 165, .12);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,.3);
  border: 1px solid rgba(255,255,255,.45);
  padding: 13px;
  border-radius: 18px;
  margin-bottom: 16px;
}
.sidebar-brand .brand-mark { width: 50px; height: 50px; border-radius: 15px; box-shadow: none; font-size: 14px; }
.nav-section { margin: 12px 10px 7px; font-size: 12px; font-weight: 800; color: rgba(20,58,84,.65); text-transform: uppercase; letter-spacing: .08em; }
.nav-btn {
  width: 100%;
  border: 0;
  background: transparent;
  color: rgba(21, 55, 80, .86);
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  border-radius: 14px;
  font-weight: 700;
  text-align: left;
  margin-bottom: 4px;
}
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,.72); color: #173f5d; }
.nav-btn .nav-icon { width: 28px; text-align: center; }
.sidebar-footer { margin-top: auto; padding-top: 14px; }
.user-mini {
  padding: 13px;
  border-radius: 18px;
  background: rgba(255,255,255,.58);
  border: 1px solid rgba(255,255,255,.58);
  display: grid;
  gap: 8px;
}
.user-name-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.user-role-list { display: flex; flex-wrap: wrap; gap: 5px; }
.role-switcher { display: grid; gap: 6px; }
.role-switcher label { font-size: 12px; font-weight: 800; color: #315a76; }
.role-select {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(49, 101, 137, .22);
  border-radius: 12px;
  background: rgba(255,255,255,.92);
  color: var(--text);
  padding: 9px 34px 9px 11px;
  font-weight: 700;
  outline: none;
}
.role-select:focus { border-color: var(--primary-dark); box-shadow: 0 0 0 3px rgba(47,126,179,.13); }
.role-hint { font-size: 11px; line-height: 1.35; color: #53738a; }
.active-role-badge { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 999px; background: #e6f4ff; color: #245f88; font-size: 12px; font-weight: 800; white-space: nowrap; }
.topbar-user { display: flex; align-items: center; justify-content: flex-end; gap: 10px; min-width: 0; }
.topbar-username { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.sidebar-backdrop { display: none; }

.main { margin-left: 280px; width: calc(100% - 280px); min-width: 0; min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 0 28px;
  background: rgba(245, 249, 252, .9);
  backdrop-filter: blur(15px);
  border-bottom: 1px solid rgba(220, 231, 239, .85);
}
.mobile-menu { display: none; }
.page { width: 100%; padding: 28px; max-width: 1600px; margin: 0 auto; min-width: 0; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; min-width: 0; }
.page-header h1 { margin: 0; font-size: clamp(25px, 2.2vw, 32px); line-height: 1.2; overflow-wrap: anywhere; }
.page-header p { margin: 5px 0 0; color: var(--muted); line-height: 1.5; }
.header-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  min-width: 0;
  overflow-wrap: anywhere;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 8px 28px rgba(50, 87, 116, .06);
}
.card h2, .card h3 { margin-top: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.stat-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stat-value { font-size: 32px; font-weight: 800; }
.stat-label { color: var(--muted); }
.stat-icon { width: 50px; height: 50px; border-radius: 16px; display: grid; place-items: center; background: var(--primary-soft); font-size: 24px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #edf3f7;
  color: #52667b;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.success { background: #ddf7eb; color: #13754d; }
.badge.warning { background: #fff0ce; color: #96620a; }
.badge.danger { background: #ffe3e8; color: #ad2d3d; }
.badge.info { background: #e2f1ff; color: #246494; }

.role-choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.role-choice {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.role-choice:hover { border-color: #a9d3ee; background: #f8fcff; }
.role-choice input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--primary-dark); }
.role-choice strong { display: block; }
.role-choice span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.role-badges { display: flex; flex-wrap: wrap; gap: 5px; }
.account-status-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }

.table-wrap { width: 100%; max-width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: 15px; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 780px; background: #fff; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f0f7fb; color: #4d6479; font-size: 13px; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; gap: 7px; flex-wrap: wrap; }

.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 18px; }
.tab-btn {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 9px 13px;
  font-weight: 700;
  color: #5f7184;
}
.tab-btn.active { background: var(--primary); color: #17466a; border-color: var(--primary); }

.stepper { display: grid; grid-template-columns: repeat(10, minmax(80px, 1fr)); gap: 7px; overflow-x: auto; padding-bottom: 7px; }
.step {
  min-width: 90px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 10px;
  background: #fff;
  text-align: center;
  font-size: 12px;
}
.step.current { border-color: var(--primary); background: var(--primary-soft); }
.step.done { background: #e8f7f0; border-color: #bee6d2; }
.step-number { font-weight: 800; font-size: 15px; }

.result-grid { display: grid; gap: 12px; }
.result-row { display: grid; grid-template-columns: 110px repeat(5, minmax(130px, 1fr)); gap: 8px; align-items: end; border-bottom: 1px dashed var(--line); padding-bottom: 12px; }
.result-row:last-child { border-bottom: 0; }

.timeline { display: grid; gap: 12px; }
.timeline-item { display: grid; grid-template-columns: 12px 1fr; gap: 12px; }
.timeline-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); margin-top: 6px; }
.timeline-content { padding-bottom: 14px; border-bottom: 1px solid var(--line); }

.empty-state { text-align: center; padding: 40px 18px; color: var(--muted); }
.empty-icon { font-size: 48px; margin-bottom: 10px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(14, 31, 46, .42);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal {
  width: min(760px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 30px 90px rgba(13, 42, 64, .28);
  padding: 22px;
}
.modal-lg { width: min(1100px, 100%); }
.modal-header { display: flex; justify-content: space-between; gap: 15px; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 17px; }
.modal-header h2 { margin: 0; }
.close-btn { border: 0; background: #eef3f7; width: 38px; height: 38px; border-radius: 12px; font-size: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

.toast-stack { position: fixed; right: 20px; top: 90px; z-index: 200; display: grid; gap: 10px; width: min(380px, calc(100vw - 40px)); }
.toast { background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--info); border-radius: 13px; padding: 13px 15px; box-shadow: var(--shadow); }
.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.danger { border-left-color: var(--danger); }

.loader { width: 22px; height: 22px; border: 3px solid #cfe3f0; border-top-color: var(--primary-dark); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.print-only { display: none; }
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .no-print, .btn, .tabs { display: none !important; }
  .main { margin: 0; width: 100%; }
  .page { max-width: none; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
  .print-only { display: block; }
}

@media (max-width: 1150px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .result-row > strong { grid-column: 1 / -1; }
}


@media (min-width: 901px) and (max-width: 1180px) {
  .sidebar { width: 250px; }
  .main { margin-left: 250px; width: calc(100% - 250px); }
  .page { padding: 22px; }
  .topbar { padding: 0 22px; }
}

@media (max-width: 900px) {
  .login-page { grid-template-columns: 1fr; }
  .login-visual { display: none; }
  .login-card-wrap { min-height: 100vh; padding: 18px; }
  .login-card { padding: 26px 20px; }
  .sidebar { width: min(310px, 88vw); transform: translateX(-105%); transition: .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 25; background: rgba(15,35,50,.34); backdrop-filter: blur(2px); }
  .sidebar-backdrop.show { display: block; }
  .main { margin-left: 0; width: 100%; }
  .mobile-menu { display: inline-flex; flex: 0 0 auto; }
  .topbar { height: 66px; padding: 0 14px; }
  .topbar-user { gap: 7px; }
  .topbar-username { display: none; }
  .page { padding: 18px 14px 28px; }
  .page-header { flex-direction: column; align-items: stretch; }
  .header-actions { width: 100%; }
  .form-grid.cols-2, .form-grid.cols-3, .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .role-choice-grid { grid-template-columns: 1fr; }
  .account-status-row { grid-template-columns: 1fr; }
}

@media (max-width: 580px) {
  .grid.cols-4 { grid-template-columns: 1fr; }
  .login-card h2 { font-size: 26px; }
  .card { padding: 15px; border-radius: 15px; }
  .result-row { grid-template-columns: 1fr; }
  .header-actions { display: grid; grid-template-columns: 1fr; }
  .header-actions .btn { width: 100%; }
  .topbar { align-items: center; }
  .topbar > div:first-child { min-width: 0; }
  .topbar > div:first-child > div { min-width: 0; }
  .topbar > div:first-child strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56vw; }
  .active-role-badge { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; }
  .modal-backdrop { padding: 10px; align-items: end; }
  .modal { width: 100%; max-height: 92vh; padding: 18px 15px; border-radius: 20px 20px 0 0; }
  .modal-footer { display: grid; grid-template-columns: 1fr; }
  .modal-footer .btn { width: 100%; }
  table { min-width: 700px; }
  th, td { padding: 10px 11px; }
}
