:root {
  --py-primary: #12343f;
  --py-primary-2: #1e5d63;
  --py-accent: #e46f44;
  --py-accent-2: #f4b24b;
  --py-mint: #2a9d8f;
  --py-soft: #f2f6f5;
  --py-line: #dce7e3;
  --py-text: #18252b;
  --py-muted: #667780;
}

body {
  background: #f6f8f7;
  color: var(--py-text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-right: 8px;
  border-radius: 8px;
  background: var(--py-accent-2);
  color: #19323a;
  font-weight: 800;
}

.app-frame {
  min-height: 100vh;
}

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  width: 286px;
  display: flex;
  flex-direction: column;
  padding: 16px;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(18, 52, 63, 0.98), rgba(22, 70, 74, 0.98)),
    radial-gradient(circle at top left, rgba(244, 178, 75, 0.28), transparent 32%);
  box-shadow: 18px 0 40px rgba(18, 52, 63, 0.18);
  transform: translateX(0);
  transition: transform 0.22s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 50px;
}

.sidebar-brand-link {
  min-width: 0;
  display: flex;
  align-items: center;
  color: #fff;
  text-decoration: none;
}

.brand-text {
  min-width: 0;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 850;
}

.sidebar-close {
  display: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
}

.sidebar-context {
  margin: 18px 0 14px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
}

.sidebar-context span {
  display: block;
  color: #ffe2a1;
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.sidebar-context strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-nav {
  display: grid;
  gap: 5px;
  overflow-y: auto;
  padding-right: 2px;
}

.sidebar-nav a {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  font-weight: 650;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.nav-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.3);
}

.sidebar-nav a.active .nav-dot {
  background: var(--py-accent-2);
}

.sidebar-footer {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: 14px;
}

.sidebar-user {
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-user strong,
.sidebar-user span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user span {
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.84rem;
}

.app-main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin-left: 286px;
  transition: margin-left 0.22s ease;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--py-line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 26px rgba(24, 37, 43, 0.06);
}

.topbar-left {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title {
  max-width: 62vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 850;
  font-size: 1.05rem;
}

.topbar-subtitle {
  max-width: 62vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--py-muted);
  font-size: 0.84rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hamburger-btn {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--py-line);
  border-radius: 8px;
  background: #fff;
}

.hamburger-btn span {
  width: 19px;
  height: 2px;
  display: block;
  border-radius: 999px;
  background: var(--py-primary);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1030;
  display: none;
  background: rgba(12, 24, 30, 0.52);
}

.sidebar-collapsed .app-sidebar {
  transform: translateX(-100%);
}

.sidebar-collapsed .app-main {
  margin-left: 0;
}

.app-shell {
  max-width: 1440px;
  flex: 1 0 auto;
}

.app-footer {
  background: #fff;
}

.app-card,
.surface-card {
  border: 1px solid var(--py-line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(24, 37, 43, 0.06);
}

.surface-card {
  padding: 20px;
}

.stat-tile {
  border-left: 4px solid var(--py-mint);
}

.table th {
  background: var(--py-soft);
  white-space: nowrap;
}

.badge-soft {
  background: var(--py-soft);
  color: var(--py-primary);
}

.btn-primary {
  background: var(--py-primary-2);
  border-color: var(--py-primary-2);
}

.btn-primary:hover {
  background: var(--py-primary);
  border-color: var(--py-primary);
}

.btn-accent {
  background: var(--py-accent);
  border-color: var(--py-accent);
  color: #fff;
}

.btn-accent:hover {
  background: #c85d37;
  border-color: #c85d37;
  color: #fff;
}

.public-home {
  background:
    linear-gradient(180deg, #edf5f1 0%, #f8faf9 34%, #f6f8f7 100%);
}

.login-page {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(18, 52, 63, 0.92), rgba(42, 157, 143, 0.76)),
    radial-gradient(circle at top right, rgba(244, 178, 75, 0.35), transparent 28%);
}

.public-hero {
  min-height: 430px;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.6fr);
  align-items: stretch;
  gap: 20px;
  padding: 26px;
  margin-bottom: 18px;
  border-radius: 8px;
  color: #fff;
  background:
    linear-gradient(120deg, rgba(18, 52, 63, 0.94), rgba(30, 93, 99, 0.9)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='640' viewBox='0 0 1200 640'%3E%3Crect width='1200' height='640' fill='%2312343f'/%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.16' stroke-width='6'%3E%3Cpath d='M120 80h960v480H120z'/%3E%3Cpath d='M600 80v480M120 320h960'/%3E%3Ccircle cx='600' cy='320' r='92'/%3E%3Cpath d='M120 190h170v260H120M1080 190H910v260h170'/%3E%3C/g%3E%3Cg fill='%23f4b24b' fill-opacity='.9'%3E%3Ccircle cx='1010' cy='118' r='34'/%3E%3Ccircle cx='170' cy='514' r='22'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
  overflow: hidden;
}

.public-hero__content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 840px;
}

.hero-kicker {
  width: fit-content;
  margin-bottom: 14px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(244, 178, 75, 0.18);
  color: #ffe2a1;
  font-weight: 700;
  font-size: 0.9rem;
}

.public-hero h1 {
  max-width: 760px;
  margin: 0 0 12px;
  font-size: clamp(2.1rem, 5vw, 4.8rem);
  line-height: 1.02;
  font-weight: 850;
}

.public-hero p {
  max-width: 760px;
  margin-bottom: 20px;
  color: rgba(255, 255, 255, 0.86);
  font-size: 1.08rem;
}

.hero-search {
  display: flex;
  gap: 8px;
  max-width: 620px;
  margin-bottom: 14px;
}

.hero-search .form-control {
  min-height: 48px;
  border: 0;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.public-hero__panel {
  align-self: center;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
}

.scoreboard-label {
  color: #ffe2a1;
  font-weight: 800;
  margin-bottom: 12px;
}

.scoreboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.scoreboard-item {
  min-height: 104px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
}

.scoreboard-item span {
  display: block;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.88rem;
}

.scoreboard-item strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
}

.quick-links {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.quick-links a {
  padding: 16px 18px;
  border: 1px solid var(--py-line);
  border-radius: 8px;
  background: #fff;
  color: var(--py-primary);
  font-weight: 750;
  text-decoration: none;
  box-shadow: 0 10px 22px rgba(24, 37, 43, 0.05);
}

.quick-links a:hover {
  color: var(--py-accent);
  transform: translateY(-1px);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading span {
  color: var(--py-accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.section-heading h2 {
  margin: 2px 0 0;
  font-size: 1.25rem;
  font-weight: 800;
}

.section-heading a {
  color: var(--py-primary-2);
  font-weight: 700;
  text-decoration: none;
}

.timeline-list,
.result-list,
.compact-schedule,
.medal-list {
  display: grid;
  gap: 10px;
}

.timeline-item,
.result-item,
.medal-row,
.compact-schedule > div {
  display: grid;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--py-soft);
}

.timeline-item {
  grid-template-columns: 70px minmax(0, 1fr) auto;
}

.timeline-time {
  color: var(--py-primary);
  font-weight: 850;
  font-size: 1.08rem;
}

.timeline-item strong,
.result-item strong {
  display: block;
}

.timeline-item span,
.result-item span,
.compact-schedule small {
  color: var(--py-muted);
}

.status-pill,
.medal-badge {
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.8rem;
  background: #fff;
  color: var(--py-primary);
}

.medal-row {
  grid-template-columns: 38px minmax(0, 1fr) 44px 44px 44px;
}

.rank-no {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #fff;
  font-weight: 800;
}

.team-name {
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.medal-count {
  min-width: 36px;
  padding: 6px 8px;
  border-radius: 8px;
  text-align: center;
  font-weight: 850;
}

.gold { background: #ffe8a6; color: #7a5300; }
.silver { background: #e9edf1; color: #47515a; }
.bronze { background: #f1d2b5; color: #77451c; }

.result-item {
  grid-template-columns: minmax(0, 1fr) auto;
}

.medal-badge.none { background: #eef2f4; color: #58666d; }
.medal-badge.gold { background: #ffe8a6; color: #7a5300; }
.medal-badge.silver { background: #e9edf1; color: #47515a; }
.medal-badge.bronze { background: #f1d2b5; color: #77451c; }

.compact-schedule > div {
  grid-template-columns: 86px minmax(0, 1fr);
}

.compact-schedule time {
  font-weight: 800;
  color: var(--py-primary-2);
}

.compact-schedule span {
  font-weight: 700;
}

.compact-schedule small {
  grid-column: 2;
}

.announcement-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.announcement-grid article {
  padding: 14px;
  border-radius: 8px;
  background: var(--py-soft);
}

.announcement-grid strong {
  display: block;
  margin-bottom: 6px;
}

.announcement-grid p {
  margin: 0;
  color: var(--py-muted);
}

.empty-state {
  padding: 28px 16px;
  border-radius: 8px;
  background: var(--py-soft);
  color: var(--py-muted);
  text-align: center;
}

.certificate-layout-editor {
  display: grid;
  gap: 10px;
}

.certificate-field-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) 80px 80px 84px 70px 110px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--py-line);
  border-radius: 8px;
  background: var(--py-soft);
}

.certificate-field-row .field-name {
  align-self: center;
}

.certificate-print-page {
  margin: 0;
  background: #e9eef0;
}

.certificate-print-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: #fff;
  border-bottom: 1px solid var(--py-line);
}

.certificate-sheet {
  position: relative;
  margin: 18px auto;
  background: #fff center/cover no-repeat;
  box-shadow: 0 14px 40px rgba(24, 37, 43, 0.18);
  overflow: hidden;
}

.certificate-sheet.landscape {
  width: 297mm;
  height: 210mm;
}

.certificate-sheet.portrait {
  width: 210mm;
  height: 297mm;
}

.certificate-text {
  position: absolute;
  width: 90%;
  font-family: "TH Sarabun New", "Sarabun", "Tahoma", sans-serif;
  line-height: 1.15;
  white-space: pre-wrap;
}

@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .sidebar-open .app-sidebar {
    transform: translateX(0);
  }
  .sidebar-open .sidebar-backdrop {
    display: block;
  }
  .sidebar-close {
    display: inline-grid;
    place-items: center;
  }
  .app-main {
    margin-left: 0;
  }
  .app-topbar {
    padding: 10px 14px;
  }
  .topbar-actions {
    display: none;
  }
  .public-hero {
    grid-template-columns: 1fr;
    padding: 20px;
  }
  .quick-links,
  .announcement-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .certificate-field-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .certificate-field-row .field-name {
    grid-column: 1 / -1;
  }
}

@media (max-width: 575.98px) {
  .app-sidebar {
    width: min(88vw, 320px);
  }
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }
  .public-hero {
    min-height: auto;
    padding: 18px;
  }
  .hero-search {
    flex-direction: column;
  }
  .scoreboard-grid,
  .quick-links,
  .announcement-grid {
    grid-template-columns: 1fr;
  }
  .timeline-item {
    grid-template-columns: 1fr;
  }
  .medal-row {
    grid-template-columns: 32px minmax(0, 1fr) 38px 38px 38px;
  }
  .certificate-field-row {
    grid-template-columns: 1fr;
  }
}

@media print {
  .app-sidebar, .app-topbar, .sidebar-backdrop, footer, .btn, .no-print {
    display: none !important;
  }
  .app-main {
    margin-left: 0;
  }
  body {
    background: #fff;
  }
  .app-card,
  .surface-card {
    box-shadow: none;
    border: 0;
  }
  @page {
    size: A4 landscape;
    margin: 0;
  }
  .certificate-print-page {
    background: #fff;
  }
  .certificate-sheet {
    margin: 0;
    box-shadow: none;
    page-break-after: always;
  }
  .certificate-sheet.landscape {
    width: 297mm;
    height: 210mm;
  }
  .certificate-sheet.portrait {
    width: 210mm;
    height: 297mm;
  }
}

/* Certificate manager - simplified workflow */
.cert-step-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--py-line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(16, 36, 40, .06);
  height: 100%;
}
.cert-step-card span {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--py-primary);
  color: #fff;
  font-weight: 800;
}
.cert-step-card small {
  display: block;
  color: var(--py-muted);
  margin-top: 2px;
}
.cert-card-preview {
  position: relative;
  height: 190px;
  background: var(--py-soft);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.cert-card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cert-no-bg {
  color: var(--py-muted);
  font-size: .95rem;
}
.cert-status-badge {
  position: absolute;
  top: 10px;
  right: 10px;
}
.cert-editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(340px, .75fr);
  gap: 16px;
  align-items: start;
}
.cert-preview-panel {
  position: sticky;
  top: 12px;
  padding: 12px;
  border: 1px solid var(--py-line);
  border-radius: 14px;
  background: #fff;
}
.cert-preview-wrap {
  overflow: auto;
  max-height: 72vh;
  border: 1px dashed var(--py-line);
  border-radius: 12px;
  background: #eef3f4;
  padding: 10px;
}
.certificate-sheet.preview {
  transform: scale(.34);
  transform-origin: top left;
  margin: 0;
  box-shadow: 0 8px 24px rgba(24, 37, 43, .18);
}
.cert-preview-wrap:has(.certificate-sheet.preview.landscape) {
  height: calc(210mm * .34 + 22px);
}
.cert-preview-wrap:has(.certificate-sheet.preview.portrait) {
  height: calc(297mm * .34 + 22px);
}
.cert-field-group {
  border: 1px solid var(--py-line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}
.cert-field-group + .cert-field-group {
  margin-top: 12px;
}
.cert-field-group-title {
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--py-primary);
}
.cert-position-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.cert-position-buttons .btn {
  padding: 2px 7px;
  font-size: .75rem;
}

@media (max-width: 1199.98px) {
  .cert-editor-grid {
    grid-template-columns: 1fr;
  }
  .cert-preview-panel {
    position: static;
  }
}
@media (max-width: 575.98px) {
  .cert-card-preview {
    height: 150px;
  }
  .cert-preview-wrap {
    max-height: 50vh;
  }
}

/* Certificate editor full-page preview (admin add/edit no modal) */
.certificate-sheet.cert-editor-preview {
  transform: scale(.52);
  transform-origin: top left;
  margin: 0;
  box-shadow: 0 10px 30px rgba(24, 37, 43, .20);
}
.cert-preview-wrap:has(.certificate-sheet.cert-editor-preview.landscape) {
  min-height: calc(210mm * .52 + 24px);
}
.cert-preview-wrap:has(.certificate-sheet.cert-editor-preview.portrait) {
  min-height: calc(297mm * .52 + 24px);
}
@media (max-width: 1199.98px) {
  .certificate-sheet.cert-editor-preview { transform: scale(.42); }
  .cert-preview-wrap:has(.certificate-sheet.cert-editor-preview.landscape) { min-height: calc(210mm * .42 + 24px); }
  .cert-preview-wrap:has(.certificate-sheet.cert-editor-preview.portrait) { min-height: calc(297mm * .42 + 24px); }
}


/* Drag and resize certificate fields directly in preview */
[data-cert-editor-form] .certificate-sheet {
  user-select: none;
}
[data-cert-editor-form] .certificate-text {
  cursor: move;
  min-width: 24px;
  min-height: 14px;
  padding: 2px 5px;
  border: 1px dashed transparent;
  border-radius: 4px;
}
[data-cert-editor-form] .certificate-text:hover,
[data-cert-editor-form] .certificate-text.cert-field-selected {
  border-color: rgba(13, 110, 253, .85);
  background: rgba(13, 110, 253, .06);
}
.cert-resize-handle {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #0d6efd;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  cursor: nwse-resize;
  display: none;
  z-index: 5;
}
.certificate-text.cert-field-selected .cert-resize-handle,
.certificate-text:hover .cert-resize-handle {
  display: block;
}
.cert-dragging-active {
  cursor: grabbing !important;
}

/* Homepage management and public slideshow */
.home-event-logo {
  max-width: 128px;
  max-height: 128px;
  object-fit: contain;
  margin-bottom: 14px;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.18));
}

.home-banner-section {
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(18, 52, 63, 0.12);
  background: #fff;
}

.home-banner-carousel .carousel-item {
  position: relative;
  background: #102f3a;
}

.home-banner-carousel .carousel-item img {
  width: 100%;
  height: clamp(220px, 34vw, 460px);
  object-fit: cover;
}

.home-banner-caption {
  position: absolute;
  left: clamp(18px, 5vw, 64px);
  right: clamp(18px, 5vw, 64px);
  bottom: clamp(16px, 4vw, 54px);
  display: grid;
  gap: 6px;
  max-width: 780px;
  padding: 18px 20px;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(135deg, rgba(18, 52, 63, 0.9), rgba(30, 93, 99, 0.72));
  backdrop-filter: blur(7px);
}

.home-banner-caption strong {
  font-size: clamp(1.35rem, 3vw, 2.6rem);
  line-height: 1.15;
}

.home-banner-caption span {
  color: rgba(255, 255, 255, 0.88);
  font-size: clamp(0.95rem, 1.5vw, 1.2rem);
}

.homepage-admin-logo {
  max-width: 140px;
  max-height: 140px;
  object-fit: contain;
  border: 1px solid var(--py-line);
  border-radius: 16px;
  padding: 10px;
  background: #fff;
}

.homepage-banner-admin-card {
  overflow: hidden;
  height: 100%;
  border: 1px solid var(--py-line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(18, 52, 63, 0.08);
}

.homepage-banner-admin-card img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
}

.homepage-banner-modal-preview {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--py-line);
}

/* ใบเรียกรายงานตัว */
.report-call-sheet { break-inside: avoid; page-break-inside: avoid; }
.report-call-sheet table th, .report-call-sheet table td { vertical-align: middle; }
@media print {
  .no-print, .app-sidebar, .app-topbar, .sidebar-backdrop, .btn, form.no-print { display: none !important; }
  body.has-sidebar, .app-main { padding: 0 !important; margin: 0 !important; background: #fff !important; }
  .app-shell { padding: 0 !important; margin: 0 !important; max-width: none !important; width: 100% !important; }
  .print-card, .report-call-sheet { border: 0 !important; box-shadow: none !important; margin: 0 !important; page-break-after: always; }
  .print-card .card-body { padding: 12mm !important; }
  .report-call-sheet table { font-size: 13px; }
  .report-call-sheet .table > :not(caption) > * > * { padding: .38rem .45rem; }
}

/* สดใสแบบแยกธีมตามบทบาท: ทั่วไป / โรงเรียน / เจ้าหน้าที่ / แอดมิน */
:root,
.theme-public {
  --py-primary: #0f766e;
  --py-primary-2: #14b8a6;
  --py-accent: #f97316;
  --py-accent-2: #facc15;
  --py-mint: #22c55e;
  --py-soft: #ecfeff;
  --py-line: #bae6fd;
  --py-text: #134e4a;
  --py-muted: #64748b;
  --py-bg: #f0fdfa;
  --py-bg-2: #ecfeff;
  --py-sidebar-start: #0f766e;
  --py-sidebar-end: #0891b2;
  --py-sidebar-glow: rgba(250, 204, 21, .35);
  --py-hero-start: rgba(15, 118, 110, .94);
  --py-hero-end: rgba(8, 145, 178, .88);
  --py-card-shadow: rgba(14, 116, 144, .13);
}

.theme-unit {
  --py-primary: #166534;
  --py-primary-2: #22c55e;
  --py-accent: #0ea5e9;
  --py-accent-2: #bef264;
  --py-mint: #14b8a6;
  --py-soft: #f0fdf4;
  --py-line: #bbf7d0;
  --py-text: #14532d;
  --py-muted: #64748b;
  --py-bg: #f0fdf4;
  --py-bg-2: #ecfdf5;
  --py-sidebar-start: #166534;
  --py-sidebar-end: #16a34a;
  --py-sidebar-glow: rgba(190, 242, 100, .38);
  --py-hero-start: rgba(22, 101, 52, .94);
  --py-hero-end: rgba(20, 184, 166, .84);
  --py-card-shadow: rgba(22, 163, 74, .14);
}

.theme-staff {
  --py-primary: #1d4ed8;
  --py-primary-2: #3b82f6;
  --py-accent: #06b6d4;
  --py-accent-2: #a5f3fc;
  --py-mint: #0ea5e9;
  --py-soft: #eff6ff;
  --py-line: #bfdbfe;
  --py-text: #1e3a8a;
  --py-muted: #64748b;
  --py-bg: #eff6ff;
  --py-bg-2: #f0f9ff;
  --py-sidebar-start: #1e40af;
  --py-sidebar-end: #0284c7;
  --py-sidebar-glow: rgba(165, 243, 252, .34);
  --py-hero-start: rgba(30, 64, 175, .94);
  --py-hero-end: rgba(2, 132, 199, .84);
  --py-card-shadow: rgba(37, 99, 235, .14);
}

.theme-admin {
  --py-primary: #7e22ce;
  --py-primary-2: #a855f7;
  --py-accent: #ec4899;
  --py-accent-2: #fde047;
  --py-mint: #8b5cf6;
  --py-soft: #faf5ff;
  --py-line: #e9d5ff;
  --py-text: #581c87;
  --py-muted: #64748b;
  --py-bg: #faf5ff;
  --py-bg-2: #fdf2f8;
  --py-sidebar-start: #6b21a8;
  --py-sidebar-end: #be185d;
  --py-sidebar-glow: rgba(253, 224, 71, .35);
  --py-hero-start: rgba(107, 33, 168, .94);
  --py-hero-end: rgba(190, 24, 93, .84);
  --py-card-shadow: rgba(168, 85, 247, .15);
}

body {
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--py-accent-2) 18%, transparent), transparent 32%),
    linear-gradient(180deg, var(--py-bg) 0%, #ffffff 46%, var(--py-bg-2) 100%);
}

.app-sidebar {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--py-sidebar-start) 98%, #000 2%), color-mix(in srgb, var(--py-sidebar-end) 95%, #000 5%)),
    radial-gradient(circle at top left, var(--py-sidebar-glow), transparent 34%);
  box-shadow: 18px 0 42px color-mix(in srgb, var(--py-primary) 22%, transparent);
}

.brand-mark {
  background: var(--py-accent-2);
  color: color-mix(in srgb, var(--py-primary) 78%, #000 22%);
}

.sidebar-context span,
.scoreboard-label,
.hero-kicker {
  color: var(--py-accent-2);
}

.sidebar-nav a.active .nav-dot {
  background: var(--py-accent-2);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--py-accent-2) 22%, transparent);
}

.app-topbar {
  border-bottom-color: var(--py-line);
  background: color-mix(in srgb, #fff 88%, var(--py-soft));
}

.app-card,
.surface-card,
.quick-links a,
.cert-step-card,
.cert-preview-panel,
.cert-field-group,
.homepage-banner-admin-card {
  border-color: var(--py-line);
  box-shadow: 0 14px 32px var(--py-card-shadow);
}

.btn-primary {
  background: linear-gradient(135deg, var(--py-primary), var(--py-primary-2));
  border-color: var(--py-primary-2);
}

.btn-primary:hover {
  background: linear-gradient(135deg, color-mix(in srgb, var(--py-primary) 86%, #000), var(--py-primary));
  border-color: var(--py-primary);
}

.btn-outline-primary {
  color: var(--py-primary);
  border-color: var(--py-primary-2);
}

.btn-outline-primary:hover {
  background: var(--py-primary);
  border-color: var(--py-primary);
  color: #fff;
}

.btn-accent {
  background: linear-gradient(135deg, var(--py-accent), color-mix(in srgb, var(--py-accent) 78%, var(--py-accent-2)));
  border-color: var(--py-accent);
}

.btn-accent:hover {
  background: color-mix(in srgb, var(--py-accent) 86%, #000);
  border-color: color-mix(in srgb, var(--py-accent) 86%, #000);
}

.table th,
.empty-state,
.timeline-item,
.result-item,
.medal-row,
.compact-schedule > div,
.announcement-grid article,
.certificate-field-row {
  background: var(--py-soft);
}

.public-home {
  background:
    radial-gradient(circle at top right, color-mix(in srgb, var(--py-accent-2) 22%, transparent), transparent 28%),
    linear-gradient(180deg, var(--py-bg) 0%, #fff 42%, var(--py-bg-2) 100%);
}

.public-hero {
  background:
    linear-gradient(120deg, var(--py-hero-start), var(--py-hero-end)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='640' viewBox='0 0 1200 640'%3E%3Crect width='1200' height='640' fill='%230f766e'/%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.18' stroke-width='6'%3E%3Cpath d='M120 80h960v480H120z'/%3E%3Cpath d='M600 80v480M120 320h960'/%3E%3Ccircle cx='600' cy='320' r='92'/%3E%3Cpath d='M120 190h170v260H120M1080 190H910v260h170'/%3E%3C/g%3E%3Cg fill='%23facc15' fill-opacity='.9'%3E%3Ccircle cx='1010' cy='118' r='34'/%3E%3Ccircle cx='170' cy='514' r='22'/%3E%3C/g%3E%3C/svg%3E");
}

.home-banner-caption {
  background: linear-gradient(135deg, var(--py-hero-start), var(--py-hero-end));
}

.theme-public .sidebar-context span::after { content: ' / ทั่วไป'; }
.theme-unit .sidebar-context span::after { content: ' / โรงเรียน'; }
.theme-staff .sidebar-context span::after { content: ' / เจ้าหน้าที่'; }
.theme-admin .sidebar-context span::after { content: ' / แอดมิน'; }


/* บังคับใช้สีตามบทบาทจริง ป้องกัน CSS เก่าหรือ Bootstrap ทับ */
body.theme-public,
body.theme-unit,
body.theme-staff,
body.theme-admin {
  background:
    radial-gradient(circle at 8% 0%, color-mix(in srgb, var(--py-accent-2) 24%, transparent), transparent 32%),
    radial-gradient(circle at 100% 12%, color-mix(in srgb, var(--py-primary-2) 18%, transparent), transparent 30%),
    linear-gradient(180deg, var(--py-bg) 0%, #ffffff 46%, var(--py-bg-2) 100%) !important;
  color: var(--py-text) !important;
}

.theme-public .app-sidebar,
.theme-unit .app-sidebar,
.theme-staff .app-sidebar,
.theme-admin .app-sidebar {
  background:
    radial-gradient(circle at top left, var(--py-sidebar-glow), transparent 36%),
    linear-gradient(180deg, var(--py-sidebar-start), var(--py-sidebar-end)) !important;
  box-shadow: 18px 0 42px var(--py-card-shadow) !important;
}

.theme-public .brand-mark,
.theme-unit .brand-mark,
.theme-staff .brand-mark,
.theme-admin .brand-mark,
.theme-public .cert-step-card span,
.theme-unit .cert-step-card span,
.theme-staff .cert-step-card span,
.theme-admin .cert-step-card span {
  background: var(--py-accent-2) !important;
  color: color-mix(in srgb, var(--py-primary) 78%, #000 22%) !important;
}

.theme-public .app-topbar,
.theme-unit .app-topbar,
.theme-staff .app-topbar,
.theme-admin .app-topbar {
  border-bottom-color: var(--py-line) !important;
  background: color-mix(in srgb, #fff 88%, var(--py-soft)) !important;
}

.theme-public .app-card,
.theme-unit .app-card,
.theme-staff .app-card,
.theme-admin .app-card,
.theme-public .surface-card,
.theme-unit .surface-card,
.theme-staff .surface-card,
.theme-admin .surface-card,
.theme-public .quick-links a,
.theme-unit .quick-links a,
.theme-staff .quick-links a,
.theme-admin .quick-links a,
.theme-public .cert-step-card,
.theme-unit .cert-step-card,
.theme-staff .cert-step-card,
.theme-admin .cert-step-card,
.theme-public .cert-preview-panel,
.theme-unit .cert-preview-panel,
.theme-staff .cert-preview-panel,
.theme-admin .cert-preview-panel,
.theme-public .cert-field-group,
.theme-unit .cert-field-group,
.theme-staff .cert-field-group,
.theme-admin .cert-field-group,
.theme-public .homepage-banner-admin-card,
.theme-unit .homepage-banner-admin-card,
.theme-staff .homepage-banner-admin-card,
.theme-admin .homepage-banner-admin-card {
  border-color: var(--py-line) !important;
  box-shadow: 0 14px 32px var(--py-card-shadow) !important;
}

.theme-public .btn-primary,
.theme-unit .btn-primary,
.theme-staff .btn-primary,
.theme-admin .btn-primary,
.theme-public .btn-success,
.theme-unit .btn-success,
.theme-staff .btn-success,
.theme-admin .btn-success,
.theme-public .btn-info,
.theme-unit .btn-info,
.theme-staff .btn-info,
.theme-admin .btn-info {
  background: linear-gradient(135deg, var(--py-primary), var(--py-primary-2)) !important;
  border-color: var(--py-primary-2) !important;
  color: #fff !important;
}

.theme-public .btn-warning,
.theme-unit .btn-warning,
.theme-staff .btn-warning,
.theme-admin .btn-warning,
.theme-public .btn-accent,
.theme-unit .btn-accent,
.theme-staff .btn-accent,
.theme-admin .btn-accent {
  background: linear-gradient(135deg, var(--py-accent), color-mix(in srgb, var(--py-accent) 68%, var(--py-accent-2))) !important;
  border-color: var(--py-accent) !important;
  color: #fff !important;
}

.theme-public .btn-outline-primary,
.theme-unit .btn-outline-primary,
.theme-staff .btn-outline-primary,
.theme-admin .btn-outline-primary,
.theme-public .btn-outline-success,
.theme-unit .btn-outline-success,
.theme-staff .btn-outline-success,
.theme-admin .btn-outline-success,
.theme-public .btn-outline-info,
.theme-unit .btn-outline-info,
.theme-staff .btn-outline-info,
.theme-admin .btn-outline-info {
  border-color: var(--py-primary-2) !important;
  color: var(--py-primary) !important;
}

.theme-public .btn-outline-primary:hover,
.theme-unit .btn-outline-primary:hover,
.theme-staff .btn-outline-primary:hover,
.theme-admin .btn-outline-primary:hover,
.theme-public .btn-outline-success:hover,
.theme-unit .btn-outline-success:hover,
.theme-staff .btn-outline-success:hover,
.theme-admin .btn-outline-success:hover,
.theme-public .btn-outline-info:hover,
.theme-unit .btn-outline-info:hover,
.theme-staff .btn-outline-info:hover,
.theme-admin .btn-outline-info:hover {
  background: var(--py-primary) !important;
  border-color: var(--py-primary) !important;
  color: #fff !important;
}

.theme-public .bg-primary,
.theme-unit .bg-primary,
.theme-staff .bg-primary,
.theme-admin .bg-primary,
.theme-public .text-bg-primary,
.theme-unit .text-bg-primary,
.theme-staff .text-bg-primary,
.theme-admin .text-bg-primary {
  background-color: var(--py-primary) !important;
  color: #fff !important;
}

.theme-public .text-primary,
.theme-unit .text-primary,
.theme-staff .text-primary,
.theme-admin .text-primary,
.theme-public .section-heading span,
.theme-unit .section-heading span,
.theme-staff .section-heading span,
.theme-admin .section-heading span,
.theme-public .quick-links a:hover,
.theme-unit .quick-links a:hover,
.theme-staff .quick-links a:hover,
.theme-admin .quick-links a:hover {
  color: var(--py-primary) !important;
}

.theme-public .table th,
.theme-unit .table th,
.theme-staff .table th,
.theme-admin .table th,
.theme-public .empty-state,
.theme-unit .empty-state,
.theme-staff .empty-state,
.theme-admin .empty-state,
.theme-public .timeline-item,
.theme-unit .timeline-item,
.theme-staff .timeline-item,
.theme-admin .timeline-item,
.theme-public .result-item,
.theme-unit .result-item,
.theme-staff .result-item,
.theme-admin .result-item,
.theme-public .medal-row,
.theme-unit .medal-row,
.theme-staff .medal-row,
.theme-admin .medal-row,
.theme-public .compact-schedule > div,
.theme-unit .compact-schedule > div,
.theme-staff .compact-schedule > div,
.theme-admin .compact-schedule > div,
.theme-public .announcement-grid article,
.theme-unit .announcement-grid article,
.theme-staff .announcement-grid article,
.theme-admin .announcement-grid article,
.theme-public .certificate-field-row,
.theme-unit .certificate-field-row,
.theme-staff .certificate-field-row,
.theme-admin .certificate-field-row {
  background: var(--py-soft) !important;
}

.theme-public .public-home,
.theme-unit .public-home,
.theme-staff .public-home,
.theme-admin .public-home,
.theme-public .login-page,
.theme-unit .login-page,
.theme-staff .login-page,
.theme-admin .login-page {
  background:
    radial-gradient(circle at top right, color-mix(in srgb, var(--py-accent-2) 24%, transparent), transparent 30%),
    linear-gradient(180deg, var(--py-bg) 0%, #fff 42%, var(--py-bg-2) 100%) !important;
}

.theme-public .public-hero,
.theme-unit .public-hero,
.theme-staff .public-hero,
.theme-admin .public-hero {
  background:
    linear-gradient(120deg, var(--py-hero-start), var(--py-hero-end)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='640' viewBox='0 0 1200 640'%3E%3Crect width='1200' height='640' fill='%230f766e'/%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.18' stroke-width='6'%3E%3Cpath d='M120 80h960v480H120z'/%3E%3Cpath d='M600 80v480M120 320h960'/%3E%3Ccircle cx='600' cy='320' r='92'/%3E%3Cpath d='M120 190h170v260H120M1080 190H910v260h170'/%3E%3C/g%3E%3Cg fill='%23facc15' fill-opacity='.9'%3E%3Ccircle cx='1010' cy='118' r='34'/%3E%3Ccircle cx='170' cy='514' r='22'/%3E%3C/g%3E%3C/svg%3E") !important;
  color: #fff !important;
}

.theme-public .home-banner-caption,
.theme-unit .home-banner-caption,
.theme-staff .home-banner-caption,
.theme-admin .home-banner-caption {
  background: linear-gradient(135deg, var(--py-hero-start), var(--py-hero-end)) !important;
}

.theme-public .cert-resize-handle,
.theme-unit .cert-resize-handle,
.theme-staff .cert-resize-handle,
.theme-admin .cert-resize-handle {
  background: var(--py-primary) !important;
}

.theme-public [data-cert-editor-form] .certificate-text:hover,
.theme-public [data-cert-editor-form] .certificate-text.cert-field-selected,
.theme-unit [data-cert-editor-form] .certificate-text:hover,
.theme-unit [data-cert-editor-form] .certificate-text.cert-field-selected,
.theme-staff [data-cert-editor-form] .certificate-text:hover,
.theme-staff [data-cert-editor-form] .certificate-text.cert-field-selected,
.theme-admin [data-cert-editor-form] .certificate-text:hover,
.theme-admin [data-cert-editor-form] .certificate-text.cert-field-selected {
  border-color: color-mix(in srgb, var(--py-primary) 80%, transparent) !important;
  background: color-mix(in srgb, var(--py-primary) 8%, transparent) !important;
}

/* Mobile friendly improvements */
html {
  -webkit-text-size-adjust: 100%;
}
body {
  overflow-x: hidden;
}
img, svg, video, canvas {
  max-width: 100%;
  height: auto;
}
.form-control,
.form-select,
.btn,
.input-group-text {
  min-height: 42px;
}
.form-control,
.form-select,
textarea.form-control {
  font-size: 16px; /* prevent iOS zoom */
}
.btn-sm,
.input-group-sm > .form-control,
.input-group-sm > .form-select,
.input-group-sm > .btn,
.input-group-sm > .input-group-text {
  min-height: 36px;
}
.table-responsive,
.table-responsive-mobile {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-responsive-mobile > .table,
.table-responsive > .table {
  margin-bottom: 0;
}
.mobile-scroll-hint {
  display: none;
  color: var(--py-muted);
  font-size: .82rem;
  padding: .25rem .75rem .5rem;
}
.action-buttons,
.btn-toolbar,
.card-actions,
.page-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.card-header,
.app-card .card-header {
  gap: .75rem;
}
.app-card .card-header .btn,
.surface-card .btn {
  white-space: normal;
}
.modal-content {
  border-radius: 14px;
}
.modal-body {
  overflow-x: hidden;
}
.cert-preview-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.cert-preview-panel {
  min-width: 0;
}
.certificate-field-row input,
.certificate-field-row select {
  min-width: 0;
}

@media (max-width: 991.98px) {
  .app-topbar {
    min-height: 60px;
  }
  .topbar-title {
    max-width: calc(100vw - 86px);
    font-size: 1rem;
  }
  .topbar-subtitle {
    max-width: calc(100vw - 86px);
  }
  .sidebar-nav a {
    min-height: 44px;
    font-size: .98rem;
  }
  .app-shell {
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
  }
  .surface-card {
    padding: 16px;
  }
  .section-heading {
    flex-direction: column;
    align-items: stretch;
  }
  .section-heading a,
  .section-heading .btn {
    width: 100%;
  }
  .hero-actions .btn,
  .quick-links a {
    min-height: 46px;
  }
  .public-hero__panel {
    align-self: stretch;
  }
  .app-table-search {
    padding-left: .75rem !important;
    padding-right: .75rem !important;
  }
  .table-responsive-mobile + .mobile-scroll-hint,
  .table-responsive + .mobile-scroll-hint {
    display: block;
  }
}

@media (max-width: 767.98px) {
  .container-fluid.app-shell {
    padding-left: .75rem;
    padding-right: .75rem;
  }
  .app-card,
  .surface-card,
  .public-hero,
  .public-hero__panel,
  .quick-links a,
  .announcement-card,
  .homepage-banner-modal-preview {
    border-radius: 14px;
  }
  .row {
    --bs-gutter-x: .75rem;
    --bs-gutter-y: .75rem;
  }
  .card-body,
  .card-header,
  .card-footer {
    padding: .85rem;
  }
  .card-header {
    flex-direction: column;
    align-items: stretch !important;
  }
  .card-header > .d-flex,
  .surface-card > .d-flex,
  .app-card > .d-flex {
    flex-wrap: wrap;
  }
  .btn-group,
  .btn-group-sm {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
  }
  .btn-group > .btn,
  .btn-group-sm > .btn {
    border-radius: .5rem !important;
  }
  .table {
    min-width: 720px;
    font-size: .92rem;
  }
  .table th,
  .table td {
    padding: .55rem .65rem;
    vertical-align: middle;
  }
  .table .btn,
  td .btn {
    margin-bottom: .25rem;
  }
  .input-group {
    flex-wrap: nowrap;
  }
  .input-group > .form-control,
  .input-group > .form-select {
    min-width: 0;
  }
  .modal-dialog {
    margin: .5rem;
  }
  .modal-header,
  .modal-body,
  .modal-footer {
    padding: .85rem;
  }
  .modal-footer {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .modal-footer .btn {
    width: 100%;
  }
  .nav-tabs,
  .nav-pills {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .nav-tabs .nav-link,
  .nav-pills .nav-link {
    white-space: nowrap;
  }
  .certificate-layout-editor,
  .cert-editor-grid {
    grid-template-columns: 1fr !important;
  }
  .certificate-sheet.cert-editor-preview {
    transform: scale(.34);
  }
  .cert-preview-wrap:has(.certificate-sheet.cert-editor-preview.landscape) {
    min-height: calc(210mm * .34 + 24px);
    min-width: 100%;
  }
  .cert-preview-wrap:has(.certificate-sheet.cert-editor-preview.portrait) {
    min-height: calc(297mm * .34 + 24px);
    min-width: 100%;
  }
}

@media (max-width: 575.98px) {
  body {
    font-size: .95rem;
  }
  .app-sidebar {
    width: min(92vw, 340px);
    padding: 14px;
  }
  .sidebar-context {
    margin: 12px 0;
    padding: 12px;
  }
  .app-topbar {
    padding: 8px 10px;
  }
  .hamburger-btn {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
  }
  .topbar-subtitle {
    display: none;
  }
  .public-hero h1 {
    font-size: clamp(1.8rem, 10vw, 2.7rem);
  }
  .public-hero p {
    font-size: .98rem;
  }
  .scoreboard-item {
    min-height: auto;
  }
  .scoreboard-item strong {
    font-size: 1.55rem;
  }
  .hero-search .btn,
  .hero-actions .btn,
  .topbar-actions .btn,
  .surface-card > .btn,
  .app-card .btn.w-100-mobile {
    width: 100%;
  }
  .d-flex.gap-2,
  .d-flex.gap-3 {
    row-gap: .5rem !important;
  }
  .form-label {
    margin-bottom: .3rem;
  }
  .form-text,
  .small {
    font-size: .82rem;
  }
  .alert {
    padding: .75rem .9rem;
  }
  .pagination {
    flex-wrap: wrap;
    gap: .25rem;
  }
  .certificate-sheet.cert-editor-preview {
    transform: scale(.27);
  }
  .cert-preview-wrap:has(.certificate-sheet.cert-editor-preview.landscape) {
    min-height: calc(210mm * .27 + 24px);
  }
  .cert-preview-wrap:has(.certificate-sheet.cert-editor-preview.portrait) {
    min-height: calc(297mm * .27 + 24px);
  }
  .certificate-text {
    touch-action: none;
  }
  .app-footer .container-fluid {
    justify-content: center !important;
    text-align: center;
  }
}

/* Athlete image crop box */
.athlete-crop-box{width:230px;max-width:100%;padding:5px;border:1px dashed var(--bs-border-color);border-radius:12px;background:#fff;touch-action:none}
.athlete-crop-box canvas{width:220px;height:220px;max-width:100%;display:block;border-radius:10px;cursor:move;background:#f8fafc}
@media print{.application-print-card{page-break-after:always}.application-print-card:last-child{page-break-after:auto}}

/* PY-Competition: single solid color theme (no gradients) */
:root,
body.theme-public,
body.theme-unit,
body.theme-staff,
body.theme-admin {
  --py-primary: #2563eb !important;
  --py-primary-2: #1d4ed8 !important;
  --py-accent: #f59e0b !important;
  --py-accent-2: #fbbf24 !important;
  --py-mint: #2563eb !important;
  --py-soft: #eff6ff !important;
  --py-line: #c7d2fe !important;
  --py-text: #172033 !important;
  --py-muted: #64748b !important;
  --py-bg: #f8fafc !important;
  --py-bg-2: #f1f5f9 !important;
  --py-sidebar-start: #1d4ed8 !important;
  --py-sidebar-end: #1d4ed8 !important;
  --py-hero-start: #2563eb !important;
  --py-hero-end: #2563eb !important;
}
body,
body.theme-public,
body.theme-unit,
body.theme-staff,
body.theme-admin,
.public-home,
.login-page {
  background: #f8fafc !important;
}
.app-sidebar,
.theme-public .app-sidebar,
.theme-unit .app-sidebar,
.theme-staff .app-sidebar,
.theme-admin .app-sidebar,
.public-hero,
.theme-public .public-hero,
.theme-unit .public-hero,
.theme-staff .public-hero,
.theme-admin .public-hero,
.hero-stat,
.theme-public .hero-stat,
.theme-unit .hero-stat,
.theme-staff .hero-stat,
.theme-admin .hero-stat {
  background: #2563eb !important;
  background-image: none !important;
}
.btn-primary,
.theme-public .btn-primary,
.theme-unit .btn-primary,
.theme-staff .btn-primary,
.theme-admin .btn-primary {
  background: #2563eb !important;
  background-image: none !important;
  border-color: #2563eb !important;
}
.btn-primary:hover,
.theme-public .btn-primary:hover,
.theme-unit .btn-primary:hover,
.theme-staff .btn-primary:hover,
.theme-admin .btn-primary:hover {
  background: #1d4ed8 !important;
  border-color: #1d4ed8 !important;
}
.btn-accent,
.theme-public .btn-accent,
.theme-unit .btn-accent,
.theme-staff .btn-accent,
.theme-admin .btn-accent,
.brand-mark,
.theme-public .brand-mark,
.theme-unit .brand-mark,
.theme-staff .brand-mark,
.theme-admin .brand-mark {
  background: #f59e0b !important;
  background-image: none !important;
  border-color: #f59e0b !important;
}
.app-topbar,
.app-card,
.surface-card,
.quick-links a,
.theme-public .app-card,
.theme-unit .app-card,
.theme-staff .app-card,
.theme-admin .app-card {
  background: #ffffff !important;
  background-image: none !important;
}

/* PY-Competition: บังคับหน้ารายงาน/หน้าพิมพ์ทั่วไปเป็น A4 แนวตั้ง */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  body:not(.certificate-print-page) {
    background: #ffffff !important;
    color: #111827 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body:not(.certificate-print-page).has-sidebar,
  body:not(.certificate-print-page) .app-main,
  body:not(.certificate-print-page) .app-shell {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: none !important;
  }

  body:not(.certificate-print-page) .app-sidebar,
  body:not(.certificate-print-page) .app-topbar,
  body:not(.certificate-print-page) .sidebar-backdrop,
  body:not(.certificate-print-page) footer,
  body:not(.certificate-print-page) .btn,
  body:not(.certificate-print-page) .no-print,
  body:not(.certificate-print-page) form.no-print {
    display: none !important;
  }

  body:not(.certificate-print-page) .print-card,
  body:not(.certificate-print-page) .report-call-sheet,
  body:not(.certificate-print-page) .application-print-card,
  body:not(.certificate-print-page) .app-card,
  body:not(.certificate-print-page) .surface-card {
    box-shadow: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: #ffffff !important;
  }

  body:not(.certificate-print-page) .print-card,
  body:not(.certificate-print-page) .report-call-sheet,
  body:not(.certificate-print-page) .application-print-card {
    width: 190mm !important;
    max-width: 190mm !important;
    margin: 0 auto !important;
    page-break-after: always;
    break-after: page;
  }

  body:not(.certificate-print-page) .print-card:last-child,
  body:not(.certificate-print-page) .report-call-sheet:last-child,
  body:not(.certificate-print-page) .application-print-card:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  body:not(.certificate-print-page) .print-card .card-body,
  body:not(.certificate-print-page) .report-call-sheet .card-body,
  body:not(.certificate-print-page) .application-print-card .card-body {
    padding: 0 !important;
  }

  body:not(.certificate-print-page) .table-responsive {
    overflow: visible !important;
  }

  body:not(.certificate-print-page) table,
  body:not(.certificate-print-page) .table {
    width: 100% !important;
    max-width: 100% !important;
    font-size: 10.5pt !important;
    line-height: 1.35 !important;
    page-break-inside: auto;
    break-inside: auto;
  }

  body:not(.certificate-print-page) .table > :not(caption) > * > * {
    padding: 3.5pt 4pt !important;
  }

  body:not(.certificate-print-page) thead {
    display: table-header-group;
  }

  body:not(.certificate-print-page) tfoot {
    display: table-footer-group;
  }

  body:not(.certificate-print-page) tr,
  body:not(.certificate-print-page) img,
  body:not(.certificate-print-page) .badge {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body:not(.certificate-print-page) h1,
  body:not(.certificate-print-page) h2,
  body:not(.certificate-print-page) h3,
  body:not(.certificate-print-page) h4 {
    break-after: avoid;
    page-break-after: avoid;
  }
}

/* Hero title size fix: keep long Thai competition names readable */
.public-hero h1,
.theme-public .public-hero h1,
.theme-unit .public-hero h1,
.theme-staff .public-hero h1,
.theme-admin .public-hero h1 {
  max-width: 820px;
  font-size: clamp(2.25rem, 4.2vw, 4rem) !important;
  line-height: 1.12 !important;
  letter-spacing: -0.02em;
  word-break: normal;
  overflow-wrap: anywhere;
}

@media (max-width: 1199.98px) {
  .public-hero h1,
  .theme-public .public-hero h1,
  .theme-unit .public-hero h1,
  .theme-staff .public-hero h1,
  .theme-admin .public-hero h1 {
    font-size: clamp(2rem, 4vw, 3.35rem) !important;
  }
}

@media (max-width: 767.98px) {
  .public-hero h1,
  .theme-public .public-hero h1,
  .theme-unit .public-hero h1,
  .theme-staff .public-hero h1,
  .theme-admin .public-hero h1 {
    font-size: clamp(1.75rem, 7vw, 2.5rem) !important;
    line-height: 1.15 !important;
  }
}

/* Single event logo branding: use only the competition/event logo, not a separate system logo. */
.brand-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
  padding: 4px;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
  flex: 0 0 auto;
}
.brand-logo--login {
  width: 56px;
  height: 56px;
  border-radius: 14px;
}
.sidebar-brand-link .brand-logo + .brand-text {
  margin-left: .25rem;
}
@media print {
  .brand-logo { box-shadow: none; }
}


/* Participant card / QR print */
.card-grid-print{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:12px}.participant-card-print{border:1px solid #d0d7de;border-radius:12px;background:#fff;overflow:hidden;break-inside:avoid}.pcard-head{background:var(--bs-primary,#0d6efd);color:#fff;font-weight:700;padding:8px 12px;text-align:center}.pcard-body{display:flex;gap:10px;align-items:center;padding:12px}.pcard-photo{width:78px;height:78px;border:1px solid #ddd;border-radius:8px;display:flex;align-items:center;justify-content:center;overflow:hidden;background:#f8f9fa;color:#adb5bd;font-size:.8rem}.pcard-photo img{width:100%;height:100%;object-fit:cover}.pcard-info{flex:1;min-width:0}.pcard-qr{width:86px;height:86px;object-fit:contain}@media print{.card-grid-print{grid-template-columns:1fr 1fr;gap:8mm}.participant-card-print{page-break-inside:avoid;border:1px solid #999}.pcard-head{background:#111!important;color:#fff!important;-webkit-print-color-adjust:exact;print-color-adjust:exact}.pcard-qr{width:30mm;height:30mm}}
.live-pulse{display:inline-block;width:.65rem;height:.65rem;background:#dc3545;border-radius:50%;margin-right:.35rem;animation:pyPulse 1.2s infinite}@keyframes pyPulse{0%{opacity:.25}50%{opacity:1}100%{opacity:.25}}

/* Athlete modal: long forms must be scrollable on desktop and mobile */
.athlete-modal-dialog .modal-content {
    max-height: calc(100vh - 1rem);
}
.athlete-modal-dialog .modal-body {
    max-height: calc(100vh - 10rem);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.athlete-modal-dialog .modal-footer,
.athlete-modal-dialog .modal-header {
    flex-shrink: 0;
}
@media (max-width: 576px) {
    .athlete-modal-dialog {
        margin: .5rem;
    }
    .athlete-modal-dialog .modal-body {
        max-height: calc(100vh - 8.5rem);
        padding: .85rem;
    }
    .athlete-modal-dialog .form-select,
    .athlete-modal-dialog .form-control,
    .athlete-modal-dialog .btn {
        min-height: 44px;
    }
}
