:root {
  --dash-bg: #f4f2f8;
  --dash-panel: #ffffff;
  --dash-ink: #1f1830;
  --dash-muted: #6d647a;
  --dash-line: rgba(60, 40, 90, 0.1);
  --dash-accent: #7c3aed;
  --dash-accent-2: #6d28d9;
  --dash-soft: #efe8ff;
  --dash-gold: #eab308;
  --font: 'IBM Plex Sans Thai', 'Kanit', sans-serif;
  --display: 'Kanit', 'IBM Plex Sans Thai', sans-serif;
  --side-w: 300px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

.dash-body {
  font-family: var(--font);
  color: var(--dash-ink);
  background: var(--dash-bg);
  font-size: 14px;
}

.dash {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* Sidebar */
.dash-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--dash-line);
  padding: 0.7rem 0.65rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  background-color: #f7f1fb;
  background-image:
    linear-gradient(90deg, rgba(255, 252, 255, 0.28) 0%, rgba(255, 252, 255, 0.55) 55%, rgba(255, 252, 255, 0.72) 100%),
    url('../assets/left-bg.png');
  background-size: cover;
  background-position: left center;
  background-repeat: no-repeat;
}

.dash-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  box-sizing: border-box;
  gap: 0;
  text-decoration: none;
  color: inherit;
  padding: 0.35rem 0 0.75rem;
  line-height: 0;
}

.brand-logo-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  text-decoration: none;
  line-height: 0;
}
.brand-logo {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 140px;
  object-fit: cover;
  object-position: center;
  border-radius: 14px;
  overflow: hidden;
}
.brand-logo--sm {
  width: auto;
  height: 34px;
  max-height: 34px;
}
.brand-logo--md {
  width: 100%;
  height: auto;
  max-height: 140px;
}
.brand-logo--lg {
  width: auto;
  height: 80px;
  max-height: 80px;
  max-width: 360px;
}
.brand-logo--editor {
  width: auto;
  height: 36px;
  max-height: 36px;
  max-width: 170px;
}

.dash-sidebar .dash-logo .brand-logo,
.dash-sidebar .brand-logo {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 150px;
  object-fit: cover;
  border-radius: 16px;
  overflow: hidden;
  clip-path: inset(0 round 16px);
}

.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  box-shadow: 0 8px 18px rgba(109, 40, 217, 0.28);
}

.dash-logo strong {
  display: block;
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.1;
  color: #140c22;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.dash-logo em {
  display: block;
  font-style: normal;
  font-size: 0.72rem;
  color: #3b2f52;
  font-weight: 700;
}

.dash-nav {
  display: grid;
  gap: 0.42rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.52rem 0.72rem;
  min-height: 46px;
  border-radius: 14px;
  text-decoration: none;
  color: #2a2040;
  font-weight: 700;
  font-size: 0.88rem;
  background: rgba(255, 255, 255, 0.38);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 3px 10px rgba(40, 20, 70, 0.05);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.nav-ico {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #7c3aed;
}

.nav-ico svg {
  width: 20px;
  height: 20px;
  display: block;
}

.nav-label {
  flex: 1;
  min-width: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-trail {
  flex: 0 0 auto;
  color: #9ca3af;
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1;
  transform: translateY(-1px);
}

.nav-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(40, 20, 70, 0.1);
  background: rgba(255, 255, 255, 0.55);
  color: #1a1228;
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(139, 92, 246, 0.78) 0%, rgba(109, 40, 217, 0.72) 100%);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.28);
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(109, 40, 217, 0.28);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  text-shadow: none;
}

.nav-item.active:hover {
  background: linear-gradient(90deg, rgba(139, 92, 246, 0.88) 0%, rgba(109, 40, 217, 0.82) 100%);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(109, 40, 217, 0.34);
}

.nav-item.active .nav-ico {
  background: rgba(255, 255, 255, 0.92);
  color: #6d28d9;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.nav-item.active .nav-ico svg path,
.nav-item.active .nav-ico svg rect,
.nav-item.active .nav-ico svg circle {
  fill: #6d28d9;
}

.nav-item.active .nav-ico svg [stroke] {
  stroke: #6d28d9;
}

.nav-item.active .nav-trail {
  color: rgba(255, 255, 255, 0.95);
}

.nav-spark {
  font-size: 0.85rem;
  opacity: 0.95;
}

.side-label {
  margin: 0 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 800;
  color: #2a2040;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.team-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.4rem;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar.has-img {
  padding: 0;
  background: #efe8ff;
}
.avatar.has-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.av-a { background: linear-gradient(135deg, #a78bfa, #7c3aed); }
.av-b { background: linear-gradient(135deg, #34d399, #059669); }

.team-row strong,
.user-chip strong {
  display: block;
  font-size: 0.8rem;
  line-height: 1.15;
  color: #140c22;
}

.team-row em,
.user-chip em {
  display: block;
  font-style: normal;
  font-size: 0.68rem;
  color: #3b2f52;
  font-weight: 650;
}

.upgrade-card {
  margin-top: auto;
  border-radius: 12px;
  padding: 0.65rem 0.7rem;
  background: linear-gradient(145deg, #8b5cf6, #5b21b6);
  color: #fff;
}

.upgrade-card strong {
  display: block;
  font-family: var(--display);
  font-size: 0.95rem;
}

.upgrade-card p {
  margin: 0.2rem 0 0.45rem;
  font-size: 0.68rem;
  line-height: 1.35;
  opacity: 0.92;
}

.btn-upgrade-sm {
  border: 0;
  border-radius: 9px;
  padding: 0.4rem 0.7rem;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 750;
  background: #fff;
  color: var(--dash-accent-2);
  cursor: pointer;
  width: 100%;
}

.quota-box {
  border: 1px solid var(--dash-line);
  border-radius: 10px;
  padding: 0.5rem 0.55rem;
  background: rgba(250, 248, 255, 0.88);
  backdrop-filter: blur(6px);
}

.quota-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.quota-bar {
  height: 6px;
  border-radius: 999px;
  background: #e8e0f5;
  overflow: hidden;
}

.quota-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #8b5cf6, #22c55e);
}

.quota-box small {
  display: block;
  margin-top: 0.3rem;
  color: var(--dash-muted);
  font-size: 0.65rem;
}

/* Main */
.dash-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.dash-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem 1.35rem;
  flex-wrap: wrap;
  background: linear-gradient(
    180deg,
    rgba(237, 230, 255, 0.95) 0%,
    rgba(244, 242, 248, 0.72) 55%,
    rgba(244, 242, 248, 0) 100%
  );
  border-bottom: 0;
}

.dash-top h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.2rem;
  font-weight: 800;
}

.dash-top p {
  margin: 0.1rem 0 0;
  color: var(--dash-muted);
  font-size: 0.8rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.btn-gold {
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 750;
  background: linear-gradient(180deg, #fde047, #eab308);
  color: #422006;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(234, 179, 8, 0.3);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--dash-line);
  background: #fff;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  text-decoration: none;
  color: inherit;
}

/* Logout — pill ให้เข้ากับ top-actions */
a.btn-logout,
.btn-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  height: 36px;
  padding: 0 0.9rem;
  border-radius: 999px;
  border: 1px solid #e2e0ea;
  background: #fff;
  color: #4b4458;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 650;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(40, 30, 70, 0.04);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
a.btn-logout:hover,
.btn-logout:hover {
  background: #faf5ff;
  border-color: #c4b5fd;
  color: #6d28d9;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.25rem 0.55rem 0.25rem 0.25rem;
  border: 1px solid var(--dash-line);
  border-radius: 999px;
  background: #fff;
}

/* Profile dropdown */
.profile-menu {
  position: relative;
}
.profile-menu > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.profile-menu > summary::-webkit-details-marker { display: none; }
.profile-trigger {
  gap: 0.4rem;
  padding-right: 0.45rem;
}
.profile-trigger:hover {
  border-color: #c4b5fd;
  background: #faf5ff;
}
.profile-caret {
  font-size: 0.7rem;
  color: var(--dash-muted);
  margin-left: 0.1rem;
}
.profile-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 40;
  min-width: 240px;
  padding: 0.45rem;
  border-radius: 14px;
  border: 1px solid var(--dash-line);
  background: #fff;
  box-shadow: 0 12px 32px rgba(40, 20, 80, 0.14);
  display: grid;
  gap: 0.15rem;
}
.profile-dropdown-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.5rem 0.55rem;
  margin-bottom: 0.15rem;
  border-bottom: 1px solid var(--dash-line);
}
.profile-dropdown-head strong {
  display: block;
  font-size: 0.88rem;
  font-family: var(--display);
}
.profile-dropdown-head em {
  display: block;
  font-style: normal;
  font-size: 0.72rem;
  color: var(--dash-muted);
}
.profile-dropdown a {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.55rem;
  border-radius: 10px;
  text-decoration: none;
  color: #2a2438;
  font-size: 0.84rem;
  font-weight: 600;
}
.profile-dropdown a:hover {
  background: #f5f0ff;
  color: #6d28d9;
}
.profile-dropdown a.danger { color: #b91c1c; }
.profile-dropdown a.danger:hover { background: #fef2f2; color: #991b1b; }
.profile-dropdown hr {
  border: 0;
  border-top: 1px solid var(--dash-line);
  margin: 0.2rem 0;
}
.profile-menu[open] .profile-trigger {
  border-color: #a78bfa;
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.2);
}

.profile-card {
  background: #fff;
  border: 1px solid var(--dash-line);
  border-radius: 16px;
  padding: 1rem 1.1rem 1.15rem;
}
.profile-card-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.profile-card-head strong { display: block; font-family: var(--display); font-size: 1.1rem; }
.profile-card-head em { display: block; font-style: normal; color: var(--dash-muted); font-size: 0.8rem; margin: 0.15rem 0; }
.avatar.xl {
  width: 72px;
  height: 72px;
  font-size: 1.45rem;
}

.profile-avatar-box {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 0 0 1.15rem;
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--dash-line);
  border-radius: 14px;
  background: linear-gradient(180deg, #faf8ff 0%, #fff 100%);
}
.profile-avatar-preview {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(109, 40, 217, 0.2);
}
.profile-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.profile-avatar-fallback {
  color: #fff;
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.8rem;
}
.profile-avatar-meta {
  min-width: 0;
  flex: 1;
}
.profile-avatar-meta strong {
  display: block;
  font-size: 0.92rem;
  color: var(--dash-ink);
}
.profile-avatar-meta em {
  display: block;
  font-style: normal;
  font-size: 0.72rem;
  color: var(--dash-muted);
  margin: 0.2rem 0 0.55rem;
  line-height: 1.35;
}
.avatar-preset-form { margin: 0 0 0.55rem; }
.avatar-preset-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.4rem;
}
.avatar-preset {
  appearance: none;
  border: 2px solid transparent;
  background: #fff;
  border-radius: 999px;
  padding: 2px;
  cursor: pointer;
  line-height: 0;
  aspect-ratio: 1;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(60, 40, 90, 0.08);
}
.avatar-preset img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 999px;
}
.avatar-preset:hover {
  border-color: rgba(109, 40, 217, 0.35);
}
.avatar-preset.is-active {
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.18);
}
.profile-avatar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.profile-avatar-actions form {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  margin: 0;
}
.btn-avatar-pick,
.btn-avatar-save,
.btn-avatar-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 750;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-avatar-pick {
  background: #fff;
  border-color: rgba(109, 40, 217, 0.35);
  color: #6d28d9;
}
.btn-avatar-pick:hover { background: #f5f0ff; }
.btn-avatar-save {
  background: #7c3aed;
  color: #fff;
}
.btn-avatar-save:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-avatar-remove {
  background: #fff;
  border-color: rgba(185, 28, 28, 0.25);
  color: #b91c1c;
}
.btn-avatar-remove:hover { background: #fef2f2; }

.profile-form .field { margin-bottom: 0.7rem; }
.profile-form .field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}
.profile-form input,
.profile-form select {
  width: 100%;
  border: 1.5px solid var(--dash-line);
  border-radius: 11px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  background: #fff;
}
.profile-form input:disabled,
.profile-form select:disabled {
  opacity: 0.7;
  background: #f7f5fb;
}
@media (max-width: 520px) {
  .profile-form .field-row { grid-template-columns: 1fr; }
}
.profile-shortcuts {
  display: grid;
  gap: 0.4rem;
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--dash-line);
}
.profile-shortcuts a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.8rem;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.86rem;
  border: 1px solid var(--dash-line);
  background: #fff;
  color: #2a2438;
}
.profile-shortcuts a:first-child {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  border-color: transparent;
  color: #fff;
}
.profile-shortcuts a:hover { filter: brightness(1.03); }

.dash-content {
  padding: 0.35rem 1rem 1.5rem;
  display: grid;
  gap: 0.75rem;
}

/* Hero */
.hero-ai {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(180px, 0.65fr);
  gap: 0;
  align-items: stretch;
  border-radius: 14px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 248, 252, 0.72) 0%, rgba(255, 248, 252, 0.28) 42%, transparent 68%),
    url('../assets/search-bg.jpg') center / cover no-repeat;
  border: 1px solid var(--dash-line);
  min-height: 0;
}

.hero-ai-copy {
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hero-ai-copy h2 {
  margin: 0 0 0.55rem;
  font-family: var(--display);
  font-size: clamp(1.1rem, 1.8vw, 1.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero-prompt-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.35rem;
  align-items: center;
}

.hero-prompt-row input {
  width: 100%;
  border: 1.5px solid rgba(124, 58, 237, 0.28);
  border-radius: 11px;
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  background: #fff;
}

.hero-prompt-row input:focus {
  outline: none;
  border-color: var(--dash-accent);
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.12);
}

.btn-generate {
  border: 0;
  border-radius: 11px;
  padding: 0.55rem 0.85rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  box-shadow: 0 6px 14px rgba(109, 40, 217, 0.28);
}

.btn-generate:disabled { opacity: 0.65; cursor: wait; }

.suggest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.45rem;
}

.suggest-chips button {
  border: 1px solid var(--dash-line);
  background: #fff;
  border-radius: 999px;
  padding: 0.22rem 0.55rem;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 650;
  color: var(--dash-muted);
  cursor: pointer;
}

.suggest-chips button:hover {
  border-color: rgba(124, 58, 237, 0.35);
  color: var(--dash-accent-2);
  background: var(--dash-soft);
}

.hero-ai .status {
  margin-top: 0.3rem;
  min-height: 0.9rem;
  font-size: 0.75rem;
  color: var(--dash-muted);
}

.hero-ai-visual {
  position: relative;
  min-height: 160px;
  background: transparent;
}

/* พื้นหลัง search-bg มีวิหารด้านขวาแล้ว — ซ่อนการ์ดตัวอย่างเดิม */
.hero-ai-visual .hero-poster-card {
  display: none;
}

.hero-poster-card {
  position: absolute;
  right: 0.65rem;
  bottom: 0.65rem;
  width: 120px;
  border-radius: 10px;
  padding: 0.55rem 0.55rem;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 24px rgba(20, 12, 36, 0.25);
  display: grid;
  gap: 0.1rem;
}

.hero-poster-card span {
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--dash-accent);
  letter-spacing: 0.06em;
}

.hero-poster-card strong {
  font-family: var(--display);
  font-size: 1rem;
}

.hero-poster-card em {
  font-style: normal;
  font-size: 0.75rem;
  color: var(--dash-muted);
}

/* Sections */
.dash-section { min-width: 0; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.4rem;
}

.section-head h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 0.98rem;
  font-weight: 800;
}

.link-all {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--dash-accent-2);
  text-decoration: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 0.4rem;
}

.category-card {
  border: 1px solid var(--dash-line);
  background: #fff;
  border-radius: 11px;
  padding: 0.5rem 0.3rem;
  display: grid;
  justify-items: center;
  gap: 0.25rem;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.category-card:hover {
  transform: translateY(-2px);
  border-color: rgba(124, 58, 237, 0.35);
  box-shadow: 0 8px 18px rgba(60, 40, 90, 0.08);
}

.category-card.active {
  border-color: var(--dash-accent);
  background: var(--dash-soft);
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.12);
}

.category-card .emoji {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  background: var(--dash-soft);
}

.category-card .title {
  font-size: 0.65rem;
  font-weight: 700;
  text-align: center;
  color: var(--dash-ink);
  line-height: 1.2;
}

.category-card[data-id="food"] .emoji { background: #ede9fe; }
.category-card[data-id="cafe"] .emoji { background: #f5e6d3; }
.category-card[data-id="clinic"] .emoji { background: #dcfce7; }
.category-card[data-id="school"] .emoji { background: #dbeafe; }
.category-card[data-id="merit"] .emoji { background: #fae8ff; }
.category-card[data-id="delivery"] .emoji { background: #ffedd5; }
.category-card[data-id="run"] .emoji { background: #e0e7ff; }
.category-card[data-id="otop"] .emoji { background: #fef3c7; }

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 315px);
  gap: 0.75rem;
  justify-content: start;
}

a.tpl-card {
  display: block;
  text-decoration: none;
  color: inherit;
  width: 315px;
  max-width: 315px;
}

.tpl-card {
  width: 315px;
  max-width: 315px;
  height: 349px;
  aspect-ratio: 315 / 349;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.06);
  cursor: pointer;
  background-size: cover;
  background-position: center;
  background-color: #f3ebe3;
  box-shadow: 0 4px 14px rgba(40, 20, 70, 0.06);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tpl-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(40, 20, 70, 0.12);
}

.tpl-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(15, 10, 25, 0.72), transparent 55%);
  z-index: 1;
  pointer-events: none;
}

.tpl-thumb-mini {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #f3ebe3;
}

.tpl-thumb-mini .tpl-cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  transform: none;
  background: #f3ebe3;
}

.tpl-thumb-mini .mini-poster {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  aspect-ratio: unset !important;
  overflow: hidden;
}

.tpl-thumb-mini .mini-layer.mini-background {
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
}

.tpl-thumb-mini .mini-layer.mini-background img {
  object-fit: cover !important;
  object-position: center !important;
}

.tpl-cover,
.tpl-thumb-mini .tpl-cover {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.tpl-cover-img,
.tpl-cover-hero {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  transform: scale(1.04);
  transition: transform 0.35s ease;
}

.tpl-card:hover .tpl-cover-hero,
.tpl-card:hover .tpl-cover-img {
  transform: scale(1.1);
}

.tpl-cover-veil {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 35%, transparent 35%, rgba(20, 10, 5, 0.12) 100%),
    linear-gradient(180deg, rgba(255, 248, 240, 0.08), transparent 40%);
  pointer-events: none;
}

.tpl-cover.is-empty {
  background: linear-gradient(155deg, #efe8ff, #f8f1e8);
}

.tpl-body {
  position: absolute;
  left: 0.65rem;
  right: 0.65rem;
  bottom: 0.65rem;
  z-index: 2;
  color: #fff;
}

.tpl-body strong {
  display: block;
  font-family: var(--display);
  font-size: 0.9rem;
}

.tpl-body span {
  font-size: 0.68rem;
  opacity: 0.85;
}

.t1 { background-image: url('https://images.unsplash.com/photo-1569058242253-92a9c755a0ec?auto=format&fit=crop&w=500&q=80'); }
.t2 { background-image: url('https://images.unsplash.com/photo-1559314809-0d155014e29e?auto=format&fit=crop&w=500&q=80'); }
.t3 { background-image: url('https://images.unsplash.com/photo-1556679343-c7306c1976bc?auto=format&fit=crop&w=500&q=80'); }
.t4 { background-image: url('https://images.unsplash.com/photo-1571781926291-c477ebfd024b?auto=format&fit=crop&w=500&q=80'); }
.t5 { background-image: url('https://images.unsplash.com/photo-1560518883-ce09059eeffa?auto=format&fit=crop&w=500&q=80'); }
.t6 { background-image: url('https://images.unsplash.com/photo-1470229722913-7c0e2dbbafd3?auto=format&fit=crop&w=500&q=80'); }

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 0.85rem;
  justify-content: stretch;
  width: 100%;
  min-width: 0;
  overflow: visible;
}

.library-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--dash-line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  align-self: start;
  justify-self: stretch;
}

.library-card--actions {
  /* flex column stacks thumb / meta / actions */
}

.library-meta {
  padding: 0.65rem 0.75rem 0.35rem;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.library-thumb-link {
  position: relative;
  display: block;
  text-decoration: none;
  color: inherit;
  line-height: 0;
  min-width: 0;
  width: 100%;
  overflow: hidden;
}

.library-badge {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: #7c3aed;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  font-style: normal;
  box-shadow: 0 3px 8px rgba(91, 33, 182, 0.28);
  pointer-events: none;
}
.library-badge.is-premium {
  background: linear-gradient(90deg, #f59e0b, #fbbf24, #f59e0b);
  box-shadow: 0 3px 10px rgba(217, 119, 6, 0.35);
}
.library-badge-crown {
  width: 0.8rem;
  height: 0.8rem;
  flex-shrink: 0;
}

.library-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  padding: 0.15rem 0.75rem 0.8rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow: hidden;
}

.lib-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  flex: 0 0 auto;
  box-sizing: border-box;
  padding: 0.55rem 0.75rem;
  margin: 0;
  border-radius: 10px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 750;
  text-decoration: none;
  border: 1px solid var(--dash-line);
  background: #fff;
  color: #1f1830;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-btn.edit:hover {
  border-color: rgba(109, 40, 217, 0.35);
  color: #6d28d9;
  background: #f8f5ff;
}
.lib-btn.publish {
  background: linear-gradient(180deg, #f472b6, #db2777);
  border: 1px solid transparent;
  color: #fff;
  box-shadow: none;
}
.lib-btn.publish:hover { filter: brightness(1.05); }

.library-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 22px rgba(60, 40, 90, 0.1);
}

.library-thumb {
  position: relative;
  width: 100%;
  max-width: none;
  height: auto;
  aspect-ratio: 4 / 5;
  min-height: 0;
  background: #f3ebe3;
  overflow: hidden;
  container-type: inline-size;
}

/* Absolute fill so intrinsic image size cannot stretch/shrink the card */
.library-thumb > *,
.library-thumb > img,
.library-thumb .tpl-cover-img,
.library-thumb .tpl-cover,
.library-thumb .tpl-cover-hero,
.library-thumb .mini-poster,
.library-thumb .library-fallback {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none;
  max-height: none;
  margin: 0;
}

.library-thumb .mini-poster {
  aspect-ratio: unset !important;
  overflow: hidden;
  background: #f6f3ee;
}

.library-thumb .mini-layer {
  position: absolute;
  box-sizing: border-box;
  overflow: hidden;
  transform-origin: center center;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.library-thumb .mini-layer img {
  width: 100%;
  height: 100%;
  /* fit จริงมาจาก inline style (cover สำหรับ background) */
  object-fit: contain;
  object-position: center;
  display: block;
}

.library-thumb .mini-layer.mini-background {
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  right: auto !important;
  bottom: auto !important;
}

.library-thumb .mini-layer.mini-background img {
  object-fit: cover !important;
  object-position: center !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none;
  max-height: none;
}

.library-thumb .mini-text {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  line-height: 1.15;
  font-weight: 700;
  white-space: pre-wrap;
  word-break: break-word;
}

.library-thumb .mini-button {
  overflow: hidden;
}

.library-thumb .mini-logo-placeholder {
  background: rgba(255, 255, 255, 0.55);
  border: 1px dashed rgba(30, 20, 10, 0.35);
  border-radius: 8px;
}

.library-thumb > img,
.library-thumb .tpl-cover-img,
.library-thumb .tpl-cover-hero {
  /* Same 4:5 as Design bake — contain == cover (no edge crop / no letterbox) */
  object-fit: contain !important;
  object-position: center top;
  display: block;
  background: #f3ebe3;
  transform: none !important;
}

.library-fallback {
  height: 100%;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 800;
  color: var(--dash-accent-2);
  background: var(--dash-soft);
}

.library-meta strong {
  display: block;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-meta span {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.68rem;
  color: var(--dash-muted);
}

.library-meta em {
  display: none;
}

#libraryStatus {
  margin-top: 0.45rem;
  font-size: 0.78rem;
  color: var(--dash-muted);
}

/* Ask FAB */
.ask-fab {
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  z-index: 40;
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1.05rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 800;
  color: #fff;
  cursor: grab;
  touch-action: none;
  user-select: none;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  box-shadow: 0 14px 32px rgba(109, 40, 217, 0.35);
}

.ask-fab.is-dragging {
  cursor: grabbing;
  box-shadow: 0 18px 40px rgba(109, 40, 217, 0.45);
  opacity: 0.95;
}

.ask-panel {
  position: fixed;
  right: 1.1rem;
  bottom: 4.4rem;
  width: min(340px, calc(100vw - 1.5rem));
  background: #fff;
  border: 1px solid var(--dash-line);
  border-radius: 16px;
  box-shadow: 0 20px 48px rgba(30, 20, 50, 0.2);
  z-index: 41;
  overflow: hidden;
}

.ask-panel[hidden] { display: none !important; }

.ask-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 0.85rem;
  background: #faf7ff;
  border-bottom: 1px solid var(--dash-line);
}

.ask-panel-body {
  padding: 0.75rem;
  min-height: 120px;
  font-size: 0.85rem;
  color: var(--dash-muted);
  line-height: 1.45;
}

.ask-panel-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
  padding: 0.55rem;
  border-top: 1px solid var(--dash-line);
}

.ask-panel-form input {
  border: 1px solid var(--dash-line);
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  font: inherit;
}

.ask-panel-form button {
  border: 0;
  border-radius: 10px;
  padding: 0.5rem 0.8rem;
  font: inherit;
  font-weight: 750;
  color: #fff;
  background: var(--dash-accent);
  cursor: pointer;
}

@media (max-width: 1200px) {
  .quick-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .template-grid { grid-template-columns: repeat(auto-fill, 315px); }
  .project-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
}

@media (max-width: 900px) {
  .dash { grid-template-columns: 1fr; }
  .dash-sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--dash-line);
  }
  .hero-ai { grid-template-columns: 1fr; }
  .hero-ai-visual { min-height: 140px; }
  .quick-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .template-grid { grid-template-columns: repeat(auto-fill, 315px); }
  .project-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
  .library-card { width: 100%; max-width: none; }
  .library-thumb { width: 100%; max-width: none; height: auto; aspect-ratio: 4 / 5; }
  a.tpl-card,
  .tpl-card { width: 315px; max-width: 315px; height: 349px; aspect-ratio: 315 / 349; }
}

@media (max-width: 640px) {
  .template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
  }
  .project-grid {
    grid-template-columns: 1fr;
    justify-content: stretch;
  }
  .library-card { max-width: none; width: 100%; }
  .library-thumb {
    max-width: none;
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 5;
  }
  .library-actions { padding: 0.1rem 0.65rem 0.7rem; }
  a.tpl-card,
  .tpl-card {
    width: 100%;
    max-width: none;
    height: auto;
    aspect-ratio: 315 / 349;
  }
}
