@import url('../lib/sarabun/sarabun.css');

/* =====================================================================
   Theme tokens — switch via <html data-theme="light|dark|vivid">
   ===================================================================== */
:root,
html[data-theme="light"] {
  --sidebar-width: 270px;

  --accent-1: #4f46e5;
  --accent-2: #7c3aed;
  --accent-3: #06b6d4;
  --accent-1-rgb: 79, 70, 229;

  --bg: #f3f4fb;
  --surface: #ffffff;
  --surface-2: #f6f7fc;
  --text: #1f2330;
  --text-muted: #888da3;
  --border: #eef0f6;
  --input-border: #e2e4ee;
  --shadow: 31, 35, 48;

  --sidebar-bg: linear-gradient(195deg, #1e1b4b 0%, #312e81 55%, #4338ca 100%);
  --sidebar-text: #e5e7ff;
  --sidebar-active: linear-gradient(135deg, var(--accent-3), #818cf8);
  --topbar-bg: #ffffff;
  --auth-bg: linear-gradient(135deg, #1e1b4b 0%, #4338ca 45%, #06b6d4 100%);
  --logo-grad: linear-gradient(135deg, var(--accent-3), #a78bfa);

  --bs-primary: var(--accent-1);
  --bs-primary-rgb: var(--accent-1-rgb);
  --bs-body-bg: var(--bg);
  --bs-link-color: var(--accent-1);
}

/* ---------- DARK : luxury garage — charcoal + champagne gold ---------- */
html[data-theme="dark"] {
  --accent-1: #d4af37;
  --accent-2: #b8860b;
  --accent-3: #f1c40f;
  --accent-1-rgb: 212, 175, 55;

  --bg: #0b0e17;
  --surface: #141927;
  --surface-2: #1a2032;
  --text: #e8e6df;
  --text-muted: #8b90a0;
  --border: #232a3d;
  --input-border: #2c344a;
  --shadow: 0, 0, 0;

  --sidebar-bg: linear-gradient(195deg, #05070d 0%, #0d1220 60%, #141927 100%);
  --sidebar-text: #cfccc0;
  --sidebar-active: linear-gradient(135deg, #d4af37, #8a6d1f);
  --topbar-bg: rgba(20, 25, 39, .92);
  --auth-bg: radial-gradient(ellipse at 30% 20%, #1a2032 0%, #0b0e17 55%, #05070d 100%);
  --logo-grad: linear-gradient(135deg, #d4af37, #8a6d1f);

  --bs-primary: var(--accent-1);
  --bs-primary-rgb: var(--accent-1-rgb);
  --bs-body-bg: var(--bg);
  --bs-link-color: #e5c558;
}

/* ---------- VIVID : colorful, animated gradients ---------- */
html[data-theme="vivid"] {
  --accent-1: #ec4899;
  --accent-2: #8b5cf6;
  --accent-3: #22d3ee;
  --accent-1-rgb: 236, 72, 153;

  --bg: #0f1024;
  --surface: #191b3a;
  --surface-2: #20224a;
  --text: #eceafd;
  --text-muted: #9d9ac2;
  --border: #2c2f5e;
  --input-border: #383c74;
  --shadow: 0, 0, 0;

  --sidebar-bg: linear-gradient(195deg, #2e1065 0%, #701a75 50%, #9d174d 100%);
  --sidebar-text: #f3e8ff;
  --sidebar-active: linear-gradient(135deg, #22d3ee, #ec4899);
  --topbar-bg: rgba(25, 27, 58, .92);
  --auth-bg: linear-gradient(-45deg, #2e1065, #9d174d, #0e7490, #6d28d9);
  --logo-grad: linear-gradient(135deg, #22d3ee, #ec4899);

  --bs-primary: var(--accent-1);
  --bs-primary-rgb: var(--accent-1-rgb);
  --bs-body-bg: var(--bg);
  --bs-link-color: #f472b6;
}

* { box-sizing: border-box; }

html, body {
  font-family: 'Sarabun', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
}

body { margin: 0; min-height: 100vh; transition: background .35s ease, color .35s ease; }

a { text-decoration: none; }

/* =====================================================================
   Motion
   ===================================================================== */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes floatIn {
  from { opacity: 0; transform: translateY(30px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes shine {
  from { left: -80%; }
  to { left: 130%; }
}

@keyframes iconBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(var(--accent-1-rgb), .45); }
  50% { box-shadow: 0 0 18px 2px rgba(var(--accent-1-rgb), .35); }
}

.content-area > * { animation: fadeSlideUp .45s ease both; }
.content-area > *:nth-child(2) { animation-delay: .06s; }
.content-area > *:nth-child(3) { animation-delay: .12s; }
.content-area > *:nth-child(4) { animation-delay: .18s; }
.content-area > *:nth-child(5) { animation-delay: .24s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* =====================================================================
   Layout shell
   ===================================================================== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease, background .35s ease;
  box-shadow: 4px 0 24px rgba(var(--shadow), .25);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: 1.3rem 1.4rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand .logo-dot {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--logo-grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  box-shadow: 0 4px 14px rgba(var(--accent-1-rgb), .45);
  animation: pulseGlow 4s ease-in-out infinite;
}

.sidebar-section-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: currentColor;
  opacity: .45;
  padding: 1.1rem 1.4rem .3rem;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding-bottom: 1rem; }

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  color: var(--sidebar-text);
  opacity: .85;
  font-weight: 500;
  font-size: .95rem;
  padding: .62rem 1.1rem;
  margin: .15rem .8rem;
  border-radius: 10px;
  transition: background .18s, color .18s, transform .18s, opacity .18s;
}

.sidebar-nav .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; transition: transform .18s; }

.sidebar-nav .nav-link:hover {
  background: rgba(255,255,255,.10);
  color: #fff;
  opacity: 1;
  transform: translateX(4px);
}

.sidebar-nav .nav-link:hover i { transform: scale(1.12); }

.sidebar-nav .nav-link.active {
  background: var(--sidebar-active);
  color: #fff;
  opacity: 1;
  box-shadow: 0 4px 14px rgba(var(--accent-1-rgb), .35);
}

.sidebar-footer {
  padding: 1rem 1.4rem;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .8rem;
  color: currentColor;
  opacity: .5;
}

.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  padding: .85rem 1.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px rgba(var(--shadow), .06);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1020;
  transition: background .35s ease;
}

.topbar .page-title { font-size: 1.15rem; font-weight: 600; margin: 0; color: var(--text); }

html[data-theme="vivid"] .topbar .page-title {
  background: linear-gradient(90deg, var(--accent-3), var(--accent-1));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sidebar-toggle-btn {
  border: none;
  background: var(--surface-2);
  width: 38px; height: 38px;
  border-radius: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--accent-1);
}

.user-chip {
  display: flex; align-items: center; gap: .6rem;
  background: var(--surface-2);
  border-radius: 30px;
  padding: .35rem .9rem .35rem .4rem;
  transition: box-shadow .2s;
}

.user-chip:hover { box-shadow: 0 0 0 3px rgba(var(--accent-1-rgb), .18); }

.user-chip .avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--logo-grad);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: .85rem;
}

.user-chip .text-dark { color: var(--text) !important; }

.theme-switch {
  display: flex;
  gap: .25rem;
  background: var(--surface-2);
  border-radius: 30px;
  padding: .25rem;
}

.theme-switch button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .95rem;
  cursor: pointer;
  transition: background .2s, color .2s, transform .2s;
}

.theme-switch button:hover { transform: scale(1.15); color: var(--text); }

.theme-switch button.active {
  background: var(--logo-grad);
  color: #fff;
  box-shadow: 0 2px 8px rgba(var(--accent-1-rgb), .4);
}

.content-area {
  padding: 2rem 2.2rem 2.5rem;
  flex: 1;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
}

.content-area h2 { font-size: 1.45rem; font-weight: 700; }

/* Subtle page depth: faint tint behind content so cards stand out */
.main-wrapper {
  background:
    radial-gradient(900px 300px at 15% -5%, rgba(var(--accent-1-rgb), .06), transparent 60%),
    var(--bg);
}

footer.app-footer {
  padding: 1rem 1.6rem;
  color: var(--text-muted);
  font-size: .85rem;
  text-align: center;
}

/* =====================================================================
   Components
   ===================================================================== */
.card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(var(--shadow), .05), 0 10px 30px rgba(var(--shadow), .07);
  transition: box-shadow .25s ease, transform .25s ease, background .35s ease;
}

.card:hover { box-shadow: 0 2px 4px rgba(var(--shadow), .06), 0 16px 40px rgba(var(--shadow), .12); }

.card-header {
  background: transparent !important;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  border-radius: 16px 16px 0 0 !important;
}

.card-header.bg-white { background: transparent !important; }
.card-body { color: var(--text); }

.btn { border-radius: 10px; font-weight: 500; transition: background .2s ease, box-shadow .2s ease, transform .15s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border: none;
  color: #fff;
  box-shadow: 0 4px 14px rgba(var(--accent-1-rgb), .3);
}

.btn-primary:hover { background: linear-gradient(135deg, var(--accent-2), var(--accent-1)); color: #fff; }

.btn-success { background: linear-gradient(135deg, #059669, #10b981); border: none; }
.btn-outline-primary { border-color: var(--accent-1); color: var(--accent-1); }
.btn-outline-primary:hover { background: var(--accent-1); border-color: var(--accent-1); color: #fff; }
.btn-outline-secondary { border-color: var(--input-border); color: var(--text); }
.btn-outline-secondary:hover { background: var(--surface-2); border-color: var(--input-border); color: var(--text); }
.btn-outline-success { color: #10b981; border-color: #10b981; }
.btn-outline-danger:hover { color: #fff; }
.btn-link { color: var(--bs-link-color); }

.table { background: var(--surface); color: var(--text); border-radius: 12px; overflow: hidden; --bs-table-bg: var(--surface); --bs-table-color: var(--text); }
.table thead { background: var(--surface-2); }
.table thead th { border-bottom: none; background: var(--surface-2); color: var(--text-muted); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; }
.table td, .table th { border-color: var(--border); }
.table > :not(caption) > * > * { padding: .8rem 1rem; }
.table-sm > :not(caption) > * > * { padding: .45rem .65rem; }
.text-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-striped > tbody > tr:nth-of-type(odd) > * { background-color: var(--surface-2); color: var(--text); }
.table-hover > tbody > tr:hover > *,
.table > tbody > tr:hover > * { background-color: rgba(var(--accent-1-rgb), .07); color: var(--text); }
.table-light, .table-light > th, .table-light > td { --bs-table-bg: var(--surface-2); color: var(--text); }
.table-primary, .table-primary > th, .table-primary > td { --bs-table-bg: rgba(var(--accent-1-rgb), .16); color: var(--text); }

.badge { border-radius: 8px; font-weight: 500; padding: .42em .7em; }

.form-control, .form-select {
  border-radius: 10px;
  border-color: var(--input-border);
  background: var(--surface);
  color: var(--text);
  padding: .55rem .85rem;
  transition: border-color .2s, box-shadow .2s, background .35s;
}

.form-control:focus, .form-select:focus {
  background: var(--surface);
  color: var(--text);
  border-color: var(--accent-1);
  box-shadow: 0 0 0 .2rem rgba(var(--accent-1-rgb), .15);
}

.form-control::placeholder { color: var(--text-muted); }
.form-label, .form-check-label, dt, dd, label { color: var(--text); }
.input-group-text { background: var(--surface-2) !important; border-color: var(--input-border); color: var(--text-muted); }

.text-muted, .small.text-muted, small.text-muted { color: var(--text-muted) !important; }
h1, h2, h3, h4, h5, h6 { color: var(--text); }

.dropdown-menu { background: var(--surface); border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(var(--shadow), .18); }
.dropdown-item { color: var(--text); }
.dropdown-item:hover { background: var(--surface-2); color: var(--text); }
.dropdown-divider { border-color: var(--border); }

/* ---------- Stat cards ---------- */
.stat-card {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  padding: 1.3rem 1.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 18px rgba(var(--shadow), .06);
  border-left: 4px solid var(--accent-1);
  height: 100%;
  transition: transform .25s ease, box-shadow .25s ease;
}

.stat-card:hover { transform: translateY(-4px); box-shadow: 0 12px 28px rgba(var(--shadow), .14); }

.stat-card::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: -80%;
  width: 40%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.14), transparent);
  transform: skewX(-18deg);
  pointer-events: none;
}

.stat-card:hover::after { animation: shine .8s ease; }

.stat-card .stat-icon {
  width: 46px; height: 46px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  color: #fff;
  margin-bottom: .6rem;
}

.stat-card:hover .stat-icon { animation: iconBob 1.2s ease-in-out infinite; }

.stat-card h3 { font-size: 1.9rem; font-weight: 700; margin: 0; color: var(--text); }
.stat-card .stat-label { color: var(--text-muted); font-size: .88rem; }

.alert { border-radius: 12px; border: none; }

/* ---------- Auth ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--auth-bg);
  background-size: 300% 300%;
  animation: gradientShift 14s ease infinite;
  padding: 1.5rem;
}

.auth-card {
  background: var(--surface);
  color: var(--text);
  border-radius: 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  animation: floatIn .6s cubic-bezier(.2, .8, .3, 1.1) both;
}

.auth-card .auth-logo {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--logo-grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; color: #fff;
  margin: 0 auto 1rem;
  box-shadow: 0 8px 20px rgba(var(--accent-1-rgb), .4);
  animation: pulseGlow 3.5s ease-in-out infinite;
}

@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .sidebar-toggle-btn { display: flex; }
}

/* ---------- SweetAlert2 follows theme ---------- */
.swal2-popup { background: var(--surface) !important; color: var(--text) !important; border-radius: 18px !important; }
.swal2-title { color: var(--text) !important; }
.swal2-html-container { color: var(--text-muted) !important; }

/* ---------- DataTables ---------- */
/* Breathing room: controls and table no longer touch the card edges */
.card .dataTables_wrapper { padding: 1.1rem 1.25rem .9rem; }
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter { margin-bottom: .85rem; }
.dataTables_wrapper .dataTables_info { padding-top: .9rem; }
.dataTables_wrapper table.dataTable { margin-top: .25rem !important; border: 1px solid var(--border); border-radius: 12px; }

.dataTables_wrapper { color: var(--text); }
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter { color: var(--text-muted); }

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: var(--surface);
  color: var(--text);
  padding: .35rem .6rem;
}

.dataTables_wrapper .page-link {
  border-radius: 8px; margin: 0 .1rem;
  color: var(--accent-1);
  background: var(--surface);
  border-color: var(--border);
}
.dataTables_wrapper .page-item.disabled .page-link { background: var(--surface); border-color: var(--border); color: var(--text-muted); }
.dataTables_wrapper .page-item.active .page-link { background: var(--accent-1); border-color: var(--accent-1); color: #fff; }
