:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --line: #e5e7eb;
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  --radius: 20px;
  --font-body: 'IBM Plex Sans Thai','Segoe UI Emoji','Apple Color Emoji','Noto Color Emoji','Noto Sans Thai', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: 'Kanit','Segoe UI Emoji','Apple Color Emoji','Noto Color Emoji','IBM Plex Sans Thai', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-cute: var(--font-body); /* alias เดิม — ใช้ต่อได้ทั้งไฟล์ */
}

/* ===== SAKOOL Class wordmark ===== */
.wm { font-weight: 900; letter-spacing: .2px; }
.wm em { font-style: normal; font-weight: 600; opacity: .9; }
* { box-sizing: border-box; }
html, body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: radial-gradient(circle at top left, #dbeafe 0, transparent 35%), var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body, button, input, select, textarea { font-family: var(--font-body); }
h1, h2, h3, h4, h5, h6, .swal2-title { font-family: var(--font-display) !important; letter-spacing: .1px; }
.swal2-popup { font-family: var(--font-body) !important; }
/* ตัวเลข/รหัสที่กำหนด monospace แบบ inline ให้ใช้ฟอนต์ mono ชุดเดียวกัน */
[style*="monospace"] { font-family: var(--font-mono) !important; }
button, input, select { font: inherit; }
button { cursor: pointer; border: 0; }
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(460px, 100%);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 28px;
  padding: 34px;
  box-shadow: var(--shadow);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: white;
  font-weight: 900;
  box-shadow: 0 12px 28px rgba(37,99,235,.25);
}
.brand h1, .brand p { margin: 0; }
.brand h1 { font-size: 24px; }
.brand p { color: var(--muted); font-size: 14px; }
.field { margin-bottom: 16px; }
label { display: block; margin-bottom: 8px; color: #374151; font-weight: 700; font-size: 14px; }
input, select {
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37,99,235,.1); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 800;
  transition: .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-soft { background: #eef2ff; color: #3730a3; }
.btn-green { background: #dcfce7; color: #166534; }
.btn-red { background: #fee2e2; color: #991b1b; }
.btn-amber { background: #fef3c7; color: #92400e; }
.btn-full { width: 100%; }
.alert {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fef2f2;
  color: #991b1b;
  font-weight: 700;
  display: none;
}
.alert.show { display: block; }
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 280px;
  background: #0f172a;
  color: white;
  padding: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand { margin-bottom: 30px; }
.sidebar .brand p { color: #94a3b8; }
.nav { display: grid; gap: 8px; }
.nav button {
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border-radius: 14px;
  background: transparent;
  color: #cbd5e1;
  font-weight: 800;
}
.nav button.active, .nav button:hover { background: rgba(255,255,255,.1); color: white; }
.main { flex: 1; padding: 28px; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.topbar h2 { margin: 0; font-size: 30px; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.card {
  background: rgba(255,255,255,.92);
  border: 1px solid rgba(255,255,255,.75);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-title { color: var(--muted); font-weight: 800; }
.stat-value { font-size: 42px; font-weight: 900; margin-top: 8px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.panel-title h3 { margin: 0; font-size: 22px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 880px; }
th, td { padding: 13px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: #475569; font-size: 13px; background: #f8fafc; }
tr:hover td { background: #f9fafb; }
.badge { display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 900; }
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.active { background: #dcfce7; color: #166534; }
.badge.suspended { background: #fee2e2; color: #991b1b; }
.badge.expired { background: #e5e7eb; color: #374151; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 420px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #111827;
  color: white;
  box-shadow: var(--shadow);
  display: none;
  z-index: 10;
}
.toast.show { display: block; }
.small { color: var(--muted); font-size: 13px; }
.code { font-family: var(--font-mono); font-size: 12px; background: #f1f5f9; padding: 5px 7px; border-radius: 8px; }
@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar { width: 100%; height: auto; position: static; }
  .main { padding: 18px; }
  .grid, .form-grid { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
}
.modal {
  background: white; border-radius: 16px;
  padding: 22px 24px;
  width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 12px; }
.modal .field { margin-bottom: 12px; }


/* ===== Grouped sidebar nav ===== */
.grouped-nav {
  display: flex; flex-direction: column;
  gap: 4px;
}
.nav-group {
  display: flex; flex-direction: column;
  gap: 2px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.nav-group:last-of-type { border-bottom: 0; }
.nav-group-title {
  padding: 8px 12px 4px;
  font-size: 11px; font-weight: 800;
  letter-spacing: .5px;
  color: rgba(255,255,255,.55);
  text-transform: uppercase;
}
.grouped-nav button {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: transparent;
  color: rgba(255,255,255,.85);
  font-weight: 700; font-size: 14px;
  border: 0;
  text-align: left;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.grouped-nav button:hover {
  background: rgba(255,255,255,.08);
}
.grouped-nav button:active { transform: scale(.98); }
.grouped-nav button.active {
  background: rgba(255,255,255,.18);
  color: white;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.grouped-nav .ic {
  display: inline-flex;
  width: 24px; height: 24px;
  align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.grouped-nav .logout-btn {
  margin-top: 8px;
  background: rgba(239, 68, 68, .15);
  color: #fecaca;
}
.grouped-nav .logout-btn:hover { background: rgba(239, 68, 68, .3); color: white; }

/* ===== Recipient picker (LINE message) ===== */
.rcp-list {
  max-height: 480px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 4px;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid var(--line);
}
@media (min-width: 720px) {
  .rcp-list { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1100px) {
  .rcp-list { grid-template-columns: repeat(3, 1fr); }
}

.rcp {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  cursor: pointer;
  transition: all .12s;
  font-size: 13px;
  min-width: 0;
}
.rcp:hover { background: #f1f5f9; border-color: #cbd5e1; }
.rcp.on {
  background: #ecfdf5;
  border-color: #16a34a;
  box-shadow: 0 1px 4px rgba(22, 163, 74, .15);
}
.rcp input[type="checkbox"] { cursor: pointer; width: 16px; height: 16px; flex-shrink: 0; }

.rcp-avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}
.rcp.on .rcp-avatar { background: linear-gradient(135deg, #16a34a, #22c55e); }

.rcp-info { flex: 1; min-width: 0; overflow: hidden; }
.rcp-name {
  font-weight: 700;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  line-height: 1.3;
}
.rcp-meta {
  display: flex; gap: 6px; align-items: center;
  margin-top: 2px;
  font-size: 11px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
}
.rcp-code {
  font-family: var(--font-mono);
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  flex-shrink: 0;
}
.rcp-pkg { overflow: hidden; text-overflow: ellipsis; }

.rcp-exp {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.rcp-exp.exp-ok { background: #f1f5f9; color: #475569; }
.rcp-exp.exp-soon { background: #fef3c7; color: #92400e; }
.rcp-exp.exp-bad { background: #fee2e2; color: #991b1b; }

/* ========== Global Loader Overlay ========== */
.cc-loader-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  animation: cc-fade-in .15s ease;
}
@keyframes cc-fade-in { from { opacity: 0 } to { opacity: 1 } }
.cc-loader {
  background: white;
  border-radius: 18px;
  padding: 28px 36px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  box-shadow: var(--shadow);
  min-width: 240px;
  max-width: 90vw;
}
.cc-loader-spinner {
  width: 44px; height: 44px;
  border: 4px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: cc-spin .9s linear infinite;
}
@keyframes cc-spin { to { transform: rotate(360deg) } }
.cc-loader-text {
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  text-align: center;
}
.cc-loader-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: -6px;
}

/* ========== Tabs ========== */
.cc-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--line);
  margin-bottom: 18px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0;
}
.cc-tab {
  background: transparent;
  border: 0;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
  border-radius: 10px 10px 0 0;
}
.cc-tab:hover {
  color: var(--text);
  background: rgba(37, 99, 235, 0.05);
}
.cc-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: rgba(37, 99, 235, 0.06);
}
.cc-tab-panel { display: none; }
.cc-tab-panel.active { display: block; animation: cc-fade-in .2s ease; }

/* Button loading state */
.btn[data-loading="1"] {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}
.btn[data-loading="1"]::after {
  content: '';
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: cc-spin .8s linear infinite;
}
