:root {
  --ink: #223044;
  --muted: #6d7686;
  --line: #e6edf2;
  --paper: #fffdf8;
  --panel: rgba(255, 255, 255, 0.86);
  --mint: #b8f1dc;
  --coral: #ff9f8f;
  --blue: #8fc8ff;
  --sun: #ffd76d;
  --plum: #6657a8;
  --good: #1d9a72;
  --bad: #cc4b5d;
  --shadow-sm: 0 4px 14px rgba(43, 64, 90, 0.06);
  --shadow: 0 20px 52px rgba(43, 64, 90, 0.1);
  --shadow-lg: 0 32px 72px rgba(43, 64, 90, 0.14);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  font-family: "Inter", "Noto Sans Thai", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(184, 241, 220, 0.38), transparent 60%),
    radial-gradient(ellipse 60% 70% at 90% 30%, rgba(255, 159, 143, 0.22), transparent 55%),
    radial-gradient(ellipse 50% 50% at 50% 70%, rgba(143, 200, 255, 0.18), transparent 50%),
    linear-gradient(175deg, #f9fcfb 0%, #f4f8f7 40%, #faf7f5 100%);
  background-attachment: fixed;
}

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

button {
  border: 0;
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

button:active {
  transform: scale(0.97);
}

.shell {
  min-height: 100vh;
}

/* ─── Boot / Login ─── */

.boot,
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 24px;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--line);
  border-top-color: var(--plum);
  border-radius: 999px;
  animation: spin 0.7s linear infinite;
  margin: auto;
  box-shadow: 0 0 28px rgba(102, 87, 168, 0.14);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Login Card ─── */

.login-card {
  width: min(1120px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(380px, 0.92fr);
  gap: 0;
  align-items: stretch;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-lg);
  overflow: hidden;
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
}

.login-visual {
  min-height: clamp(380px, 52vh, 520px);
  background: url("/assets/registry-chibi-hero.png") center / cover no-repeat;
}

.login-form {
  align-self: center;
  padding: 44px 38px;
}

.eyebrow {
  color: var(--plum);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.08em;
  margin: 0 0 10px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(34px, 4.8vw, 58px);
  line-height: 1.06;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--plum) 0%, #8b75d6 60%, var(--coral) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  font-size: clamp(24px, 3.2vw, 38px);
  letter-spacing: -0.01em;
}

h3 {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 10px;
}

.muted {
  color: var(--muted);
  line-height: 1.65;
}

/* ─── Fields ─── */

.field {
  display: grid;
  gap: 6px;
  margin: 12px 0;
}

.field span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color 0.22s ease, box-shadow 0.22s ease;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

input::placeholder {
  color: #bcc3cf;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--plum);
  box-shadow: 0 0 0 5px rgba(102, 87, 168, 0.08);
}

/* ─── Buttons ─── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #2a3c56 0%, var(--ink) 100%);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 18px rgba(34, 48, 68, 0.14);
  transition: all 0.26s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(34, 48, 68, 0.22);
  filter: brightness(1.08);
}

.btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(34, 48, 68, 0.18);
}

.btn.secondary {
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.btn.secondary:hover {
  border-color: var(--plum);
  background: #faf8ff;
  box-shadow: 0 8px 24px rgba(102, 87, 168, 0.1);
}

.btn.soft {
  background: linear-gradient(135deg, var(--mint) 0%, #d4f7e8 100%);
  color: #1a5e46;
  box-shadow: 0 4px 18px rgba(29, 154, 114, 0.13);
}

.btn.soft:hover {
  box-shadow: 0 12px 28px rgba(29, 154, 114, 0.2);
}

.btn.danger {
  background: #fff0f2;
  color: var(--bad);
  border: 2px solid #ffd4da;
  box-shadow: none;
}

.btn.danger:hover {
  background: #ffe8eb;
}

/* ─── App Layout ─── */

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 22px;
  background: rgba(255, 253, 248, 0.82);
  border-right: 1px solid rgba(230, 237, 242, 0.8);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.mark {
  width: 50px;
  height: 50px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--mint) 0%, var(--sun) 100%);
  box-shadow: 0 10px 28px rgba(29, 154, 114, 0.22);
  font-weight: 900;
  font-size: 18px;
  color: #1a5e46;
  transition: transform 0.22s ease;
}

.mark:hover {
  transform: rotate(-6deg) scale(1.06);
}

.brand strong {
  display: block;
  font-size: 16px;
  font-weight: 800;
}

.brand .muted {
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 6px;
  flex: 1;
}

.nav button {
  width: 100%;
  text-align: left;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  transition: all 0.2s ease;
  position: relative;
}

.nav button:hover {
  background: rgba(184, 241, 220, 0.28);
  color: var(--ink);
}

.nav button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 6px 22px rgba(43, 64, 90, 0.08);
}

.nav button.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 4px;
  border-radius: 99px;
  background: linear-gradient(180deg, var(--plum), var(--coral));
}

.content {
  padding: 32px 36px;
}

/* ─── Topbar ─── */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 28px;
}

.topbar .eyebrow {
  margin-bottom: 4px;
}

/* ─── Hero ─── */

.hero {
  min-height: 240px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 460px);
  gap: 28px;
  align-items: center;
  margin-bottom: 28px;
  padding: 0;
  border-radius: var(--radius-lg);
}

.hero-copy h1 {
  max-width: 780px;
  margin-bottom: 10px;
}

.hero img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.35s ease;
}

.hero img:hover {
  transform: scale(1.02);
}

/* ─── Grid & Stats ─── */

.grid {
  display: grid;
  gap: 16px;
}

.stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.card {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.84);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.mt {
  margin-top: 16px;
}

.stat-value {
  font-size: 40px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--ink), var(--plum));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ─── Toolbar ─── */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: 20px 0;
}

.search {
  flex: 1 1 280px;
}

/* ─── Table ─── */

.table-wrap {
  overflow-x: auto;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.84);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  padding: 15px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
  background: rgba(248, 250, 252, 0.6);
  position: sticky;
  top: 0;
}

tbody tr {
  transition: background 0.18s ease;
}

tbody tr:hover {
  background: rgba(184, 241, 220, 0.12);
}

/* ─── Pills ─── */

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 12px;
  border-radius: 999px;
  background: #eef8ff;
  color: #27608d;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.pill.active {
  background: linear-gradient(135deg, #e8fbf3, #d2f5e4);
  color: var(--good);
}

.pill.moved {
  background: linear-gradient(135deg, #fff7df, #fff2ca);
  color: #8a6414;
}

.pill.deceased,
.pill.inactive {
  background: linear-gradient(135deg, #fff0f2, #ffe4e7);
  color: var(--bad);
}

/* ─── Actions ─── */

.actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: #fff;
  border: 2px solid var(--line);
  color: var(--ink);
  font-size: 18px;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  border-color: var(--plum);
  background: #faf8ff;
  box-shadow: 0 4px 14px rgba(102, 87, 168, 0.1);
}

/* ─── Modal ─── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(34, 48, 68, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.22s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-panel {
  width: min(1020px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px 32px;
  animation: slideUp 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 16px;
}

.wide {
  grid-column: 1 / -1;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
}

.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--plum);
}

/* ─── Empty ─── */

.empty {
  padding: 48px 28px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

.empty::before {
  content: "🌸";
  display: block;
  font-size: 40px;
  margin-bottom: 12px;
}

/* ─── Toast ─── */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #2a3c56, var(--ink));
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes toastIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.hidden {
  display: none !important;
}

/* ─── Scrollbar ─── */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
  background: #ccd4dd;
}

/* ─── Responsive: Tablet ─── */

@media (max-width: 920px) {
  .login-card,
  .app,
  .hero {
    grid-template-columns: 1fr;
  }

  .login-visual {
    min-height: 240px;
    background: url("/assets/registry-chibi-hero.png") center / cover no-repeat;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    padding: 20px;
  }

  .brand {
    margin-bottom: 0;
  }

  .nav {
    flex-direction: row;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    flex: 0;
  }

  .nav button {
    text-align: center;
    padding: 12px 10px;
    font-size: 13px;
  }

  .nav button.active::before {
    display: none;
  }

  .content {
    padding: 24px 20px;
  }

  .hero {
    padding: 24px;
  }

  .hero img {
    aspect-ratio: 16 / 9;
  }

  .stats,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ─── Responsive: Mobile ─── */

@media (max-width: 560px) {
  .content,
  .login,
  .login-form {
    padding: 18px;
  }

  .login-form {
    padding: 28px 20px;
  }

  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .stats,
  .form-grid,
  .nav {
    grid-template-columns: 1fr;
  }

  .hero {
    padding: 20px;
    gap: 18px;
  }

  .hero img {
    aspect-ratio: 16 / 9;
  }

  h1 {
    font-size: 30px;
  }

  h2 {
    font-size: 22px;
  }

  .modal-panel {
    padding: 20px 16px;
    border-radius: var(--radius);
  }

  .sidebar {
    padding: 14px 12px;
    gap: 10px;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}