@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@300;400;500;600;700;800;900&family=Inter:wght@400;500;600;700;800;900&display=swap');

:root {
  --royal-950: #1b0929;
  --royal-900: #27103a;
  --royal-850: #34184c;
  --royal-800: #43205d;
  --royal-700: #613177;
  --royal-600: #7d4494;
  --orchid: #c0117c;
  --gold-600: #9f7b17;
  --gold-500: #b59e36;
  --gold-400: #d7bd58;
  --gold-300: #f1d779;
  --ivory: #fffaf0;
  --champagne: #f8edd2;
  --paper: #fffdf8;
  --gray-50: #fbfafc;
  --gray-100: #f5f0e8;
  --gray-200: #e6d9c5;
  --gray-500: #7c7284;
  --gray-800: #2e2734;
  --danger: #b42318;
  --success: #16794f;
  --shadow: 0 22px 60px rgba(27, 9, 41, .16);
  --shadow-soft: 0 14px 36px rgba(97, 49, 119, .12);
  --radius: 22px;
  --line: rgba(181, 158, 54, .22);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans Thai", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "kern", "liga";
  text-rendering: geometricPrecision;
  color: var(--gray-800);
  background:
    radial-gradient(circle at 8% 0%, rgba(215, 189, 88, .28), transparent 30%),
    radial-gradient(circle at 96% 3%, rgba(97, 49, 119, .22), transparent 28%),
    linear-gradient(135deg, #fffdf8 0%, #f7f0df 48%, #f5edf8 100%);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 16px;
  background:
    linear-gradient(160deg, rgba(255,255,255,.06), transparent 30%),
    linear-gradient(180deg, var(--royal-950), var(--royal-800) 58%, #2b123c);
  color: white;
  overflow-y: auto;
  border-right: 1px solid rgba(241, 215, 121, .22);
}
.sidebar::before {
  content: "";
  position: fixed;
  left: 0;
  top: 0;
  width: 292px;
  height: 4px;
  background: linear-gradient(90deg, var(--gold-600), var(--gold-300), var(--orchid));
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 10px 28px;
}
.brand-mark {
  width: 50px;
  height: 50px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: var(--royal-950);
  font-weight: 950;
  font-size: 24px;
  background: linear-gradient(135deg, #f8edc4, var(--gold-400) 52%, #8d6b14);
  box-shadow: 0 16px 34px rgba(181, 158, 54, .32), inset 0 1px 0 rgba(255,255,255,.65);
}
.brand h1 { margin: 0; font-size: 22px; letter-spacing: .01em; font-weight: 900; line-height: 1.05; }
.brand p { margin: 5px 0 0; opacity: .72; font-size: 11px; letter-spacing: .09em; text-transform: uppercase; }

.nav { display: grid; gap: 8px; }
.nav-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 11px 13px;
  text-align: left;
  color: rgba(255,255,255,.78);
  background: transparent;
  transition: .18s ease;
}
.nav-item:hover { background: rgba(255,255,255,.09); color: white; border-color: rgba(241,215,121,.18); }
.nav-item.active {
  color: #261031;
  background: linear-gradient(135deg, #fff3bd, var(--gold-400));
  box-shadow: 0 16px 34px rgba(181, 158, 54, .25);
  font-weight: 800;
}

.main { padding: 28px clamp(20px, 3vw, 38px); min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
  padding: 6px 2px 0;
}
.eyebrow {
  margin: 0 0 7px;
  color: var(--gold-600);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .16em;
  font-size: 12px;
}
.topbar h2 { margin: 0; font-size: clamp(30px, 4vw, 44px); letter-spacing: -.045em; color: var(--royal-950); }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 9px 15px;
  background: linear-gradient(135deg, #fff9e8, #efe0bc);
  border: 1px solid rgba(181,158,54,.26);
  color: var(--royal-900);
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(181,158,54,.12);
}

.content { display: grid; gap: 20px; }
.grid { display: grid; gap: 16px; }
.grid.cards { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  background: rgba(255,253,248,.88);
  border: 1px solid rgba(181,158,54,.22);
  border-top-color: rgba(255,255,255,.8);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}
.metric { padding: 20px; position: relative; overflow: hidden; }
.metric::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--royal-700), var(--gold-400), var(--orchid));
}
.metric::after {
  content: "";
  position: absolute;
  right: -34px;
  top: -32px;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(215,189,88,.28), transparent 65%);
}
.metric .label { color: var(--gray-500); font-size: 13px; font-weight: 750; }
.metric .value { margin-top: 10px; font-size: 34px; line-height: 1; font-weight: 950; color: var(--royal-950); letter-spacing: -.045em; }
.metric .hint { margin-top: 8px; color: var(--gray-500); font-size: 12px; }

.panel { padding: 22px; overflow: hidden; }
.panel-header { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 14px; }
.panel h3 { margin: 0; color: var(--royal-950); font-size: 18px; }
.panel p { margin: 5px 0 0; color: var(--gray-500); font-size: 13px; }

.btn {
  border: 0;
  border-radius: 14px;
  padding: 11px 15px;
  background: linear-gradient(135deg, var(--royal-700), var(--royal-950));
  color: white;
  font-weight: 800;
  box-shadow: 0 12px 26px rgba(97,49,119,.24);
}
.btn.yellow { background: linear-gradient(135deg, #fff0ad, var(--gold-400), var(--gold-600)); color: #221028; }
.btn.ghost { background: rgba(255,253,248,.86); color: var(--royal-800); border: 1px solid rgba(181,158,54,.24); box-shadow: none; }
.btn.small { padding: 8px 11px; border-radius: 12px; font-size: 13px; }
.btn.danger { background: #fff1f0; color: var(--danger); box-shadow: none; }

.form-card { padding: 20px; display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.field { display: grid; gap: 6px; }
.field label { color: var(--royal-950); font-size: 12px; font-weight: 800; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid rgba(181,158,54,.25);
  border-radius: 14px;
  padding: 11px 12px;
  background: rgba(255,255,255,.92);
  color: var(--gray-800);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--royal-600);
  box-shadow: 0 0 0 4px rgba(97,49,119,.10);
}
.form-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

.table-wrap { width: 100%; overflow-x: auto; border-radius: 18px; border: 1px solid rgba(181,158,54,.24); }
table { width: 100%; border-collapse: collapse; min-width: 760px; background: white; }
th, td { padding: 11px 13px; text-align: left; border-bottom: 1px solid #f1eadf; font-size: 13.5px; vertical-align: top; line-height: 1.55; }
th { color: var(--royal-950); background: linear-gradient(180deg, #fff8e3, #f4e6c7); font-size: 11.5px; text-transform: none; letter-spacing: .01em; font-weight: 900; position: sticky; top: 0; z-index: 1; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 800; background: #f4efe7; color: var(--royal-800); }
.badge.danger { background: #fff1f0; color: var(--danger); }
.badge.success { background: #edfdf6; color: var(--success); }
.badge.gold { background: #fff3c2; color: #695000; }

.empty { padding: 30px; text-align: center; color: var(--gray-500); }
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(440px, calc(100vw - 48px));
  border-radius: 18px;
  padding: 14px 16px;
  color: white;
  background: var(--royal-950);
  box-shadow: var(--shadow);
}
.hidden { display: none !important; }

.intro-panel {
  background: linear-gradient(135deg, rgba(255,253,248,.96), rgba(255,246,221,.82));
}
.muted { color: var(--gray-500); font-size: 12px; }
.card.panel h3 { letter-spacing: -.01em; }
.field textarea { resize: vertical; min-height: 44px; }
.table-wrap { max-height: 58vh; }
tbody tr:hover { background: #fffaf0; }
input::placeholder { color: #b4a8bc; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar::before { width: 100%; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .main { padding: 18px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .nav { grid-template-columns: 1fr; }
  .grid.cards { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .sidebar { padding: 18px; }
}

.metric .value { font-variant-numeric: tabular-nums; }
.panel .pill { white-space: nowrap; }

/* v2.4 Enterprise Controls */
.danger-soft { border-color: rgba(150, 30, 45, .35) !important; background: linear-gradient(145deg, rgba(255,255,255,.98), rgba(255,244,244,.95)) !important; }
.panel h3 { letter-spacing: -0.01em; }
.field input[type="file"] { padding: 10px; background: #fff; }
.form-actions button:disabled { opacity: .45; cursor: not-allowed; }
.table-wrap td b { font-weight: 700; }
@media (max-width: 900px) {
  .sidebar { max-height: 45vh; overflow: auto; }
  .nav { padding-bottom: 20px; }
}
