@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700;800;900&family=Kanit:wght@400;500;600;700&family=Space+Grotesk:wght@600;700&display=swap');

:root {
  --navy-950: #050814;
  --navy-900: #0A0F26;
  --navy-800: #111A3D;
  --navy-700: #1A275A;
  --gold-300: #F1D97B;
  --gold-400: #E8C255;
  --gold-500: #D4AF37;
  --gold-600: #B8912A;
  --ivory: #F8F5EC;
  --queen: #C9457A;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(120% 120% at 50% -10%, var(--navy-700) 0%, var(--navy-900) 55%, var(--navy-950) 100%);
  background-attachment: fixed;
  color: var(--ivory);
  font-family: 'Kanit', sans-serif;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, .font-display {
  font-family: 'Playfair Display', 'Kanit', serif;
}

.gold-text {
  background: linear-gradient(135deg, #F1D97B 0%, #D4AF37 45%, #8F6E1E 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: rgba(241, 217, 123, 0.8);
}

.glass-card {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid rgba(212, 175, 55, 0.15);
  background: rgba(255, 255, 255, 0.035);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.45);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 12px;
  padding: 10px 20px;
  font-family: 'Kanit', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: transform 0.15s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-gold {
  background: linear-gradient(135deg, #F1D97B 0%, #D4AF37 45%, #8F6E1E 100%);
  color: var(--navy-950);
  box-shadow: 0 0 0 1px rgba(212,175,55,0.35), 0 8px 30px -8px rgba(212,175,55,0.35);
}
.btn-gold:hover { transform: scale(1.02); }
.btn-ghost {
  background: rgba(255,255,255,0.03);
  color: var(--ivory);
  border: 1px solid rgba(212,175,55,0.3);
}
.btn-ghost:hover { background: rgba(255,255,255,0.08); }
.btn-danger {
  background: rgba(244,63,94,0.1);
  color: #fda4af;
  border: 1px solid rgba(244,63,94,0.3);
}
.btn-danger:hover { background: rgba(244,63,94,0.2); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-field {
  width: 100%;
  border-radius: 8px;
  border: 1px solid rgba(212,175,55,0.25);
  background: rgba(5,8,20,0.6);
  color: var(--ivory);
  padding: 10px 14px;
  font-family: 'Kanit', sans-serif;
  font-size: 14px;
  outline: none;
}
.input-field:focus { border-color: var(--gold-400); box-shadow: 0 0 0 2px rgba(232,194,85,0.3); }

.label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 500; color: rgba(248,245,236,0.7); }

.tabular { font-variant-numeric: tabular-nums; }

/* ===== Layout ===== */
.page-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.admin-shell { display: flex; min-height: 100vh; width: 100%; }
.admin-sidebar {
  width: 250px;
  flex-shrink: 0;
  border-right: 1px solid rgba(212,175,55,0.15);
  background: rgba(10,15,38,0.92);
  backdrop-filter: blur(16px);
  padding: 24px 16px;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 50;
  box-sizing: border-box;
}
.sidebar-brand { padding: 8px 8px 20px; }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.sidebar-user {
  margin-top: auto;
  border-top: 1px solid rgba(212,175,55,0.15);
  padding-top: 16px;
}
.user-name { font-size: 13px; font-weight: 600; margin: 0 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 11px; color: rgba(248,245,236,0.4); margin: 0 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-logout { width: 100%; text-align: center; }
.nav-link-live { margin-top: 12px; border: 1px solid rgba(212,175,55,0.25); color: var(--gold-400); }

.admin-main { flex: 1; margin-left: 250px; padding: 32px 40px; width: calc(100% - 250px); box-sizing: border-box; }

.btn-winner-stage {
  position: absolute;
  top: 24px;
  right: 32px;
  background: rgba(212,175,55,0.15);
  border: 1px solid rgba(212,175,55,0.4);
  color: #F1D97B;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  z-index: 10;
  transition: all 0.3s ease;
}
.btn-winner-stage:hover {
  background: var(--gold-400);
  color: #060B1E;
}

/* ===== Mobile & Tablet Responsive Layout (< 900px) ===== */
@media (max-width: 900px) {
  .admin-shell { display: block; width: 100%; }
  .admin-sidebar {
    position: relative !important;
    width: 100% !important;
    height: auto !important;
    top: auto; left: auto; bottom: auto;
    border-right: none;
    border-bottom: 1px solid rgba(212,175,55,0.2);
    padding: 16px;
    box-sizing: border-box;
  }
  .sidebar-brand { padding: 0 0 12px; text-align: center; }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-bottom: 12px;
  }
  .nav-link { padding: 8px 14px; font-size: 13px; text-align: center; }
  .nav-link-live { margin-top: 0; }
  .sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 12px;
  }
  .user-role { margin-bottom: 0; }
  .btn-logout { width: auto; padding: 6px 14px; }

  .admin-main {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 16px 12px !important;
    box-sizing: border-box;
  }

  .btn-winner-stage {
    position: static !important;
    display: inline-block !important;
    margin: 0 auto 12px !important;
    font-size: 12px !important;
    padding: 6px 14px !important;
  }
}

.nav-link {
  display: block;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: rgba(248,245,236,0.6);
  margin-bottom: 4px;
}
.nav-link:hover { background: rgba(255,255,255,0.05); color: var(--ivory); }
.nav-link.active { background: rgba(212,175,55,0.15); color: var(--gold-300); }

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  background: rgba(10,15,38,0.95);
  border: 1px solid rgba(212,175,55,0.4);
  color: var(--gold-300);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toast-in 0.2s ease;
}
.toast.error { border-color: rgba(244,63,94,0.4); color: #fda4af; }
@keyframes toast-in { from { opacity:0; transform: translateY(-10px);} to {opacity:1; transform:translateY(0);} }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(5,8,20,0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-box { width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; padding: 24px; }

/* ===== Contestant row (admin) ===== */
.contestant-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 16px;
  margin-bottom: 12px;
}
.contestant-photo {
  width: 56px; height: 56px; border-radius: 10px;
  object-fit: cover; border: 1px solid rgba(212,175,55,0.2);
  flex-shrink: 0;
}
.score-pill { font-family: 'Space Grotesk', monospace; font-weight: 700; }

/* ===== Category tabs ===== */
.tabs {
  display: inline-flex;
  gap: 14px;
  padding: 0;
  border-radius: 0;
  border: none;
  background: transparent;
}
.tab-btn {
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--gold-300);
  background: rgba(10,15,38,0.75);
  border: 1.5px solid var(--gold-500);
  cursor: pointer;
  font-family: 'Kanit', sans-serif;
  box-shadow: 0 0 10px rgba(212,175,55,0.25);
  transition: all 0.2s ease;
}
.tab-btn.active {
  color: var(--navy-950);
  background: linear-gradient(135deg, #F1D97B 0%, #D4AF37 45%, #8F6E1E 100%);
  border-color: var(--gold-300);
  box-shadow: 0 0 18px rgba(212,175,55,0.6);
}
.tabs-lg .tab-btn { padding: 12px 32px; font-size: 17px; }
.tabs-lg .tab-btn { padding: 12px 32px; font-size: 17px; }

/* ===== Stage display ===== */
.stage-video-bg {
  position: fixed; inset: 0; width: 100%; height: 100%;
  object-fit: cover; z-index: 0;
}
.stage-overlay { position: fixed; inset: 0; background: rgba(5,8,20,0.35); z-index: 0; }
.stage-content { position: relative; z-index: 1; max-width: 1400px; margin: 0 auto; padding: 32px 24px; }

.live-badge {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: 999px; border: 1px solid rgba(212,175,55,0.3);
  background: rgba(212,175,55,0.1); padding: 6px 14px; margin-bottom: 12px;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #f43f5e; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.chart-wrap { display: flex; align-items: flex-end; justify-content: space-between; gap: 6px; padding: 16px; }
.bar-col { display: flex; flex-direction: column; align-items: center; flex: 1; min-width: 0; padding: 0 2px; }
.bar-score { font-family: 'Space Grotesk', monospace; font-weight: 800; font-size: clamp(12px, 1.6vw, 22px); }
.bar-track {
  display: flex; align-items: flex-end; justify-content: center;
  width: 100%; height: 320px; margin-top: 4px;
  border-radius: 999px; overflow: hidden;
  
}
.bar-fill {
  position: relative;
  width: 55%; max-width: 48px; border-radius: 999px;
  background: linear-gradient(0deg, #B8912A, #D4AF37 50%, #F1D97B);
  box-shadow: 0 0 24px 4px rgba(212,175,55,0.5), inset 0 0 14px rgba(255,255,255,0.25);
  transition: height 0.6s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.6s ease;
}
.bar-fill::after {
  content: '';
  position: absolute;
  top: 6%; bottom: 6%; left: 50%;
  width: 3px; transform: translateX(-50%);
  background: linear-gradient(180deg, #fff, #FFE9A8 50%, #fff);
  border-radius: 999px;
  box-shadow: 0 0 8px 2px rgba(255, 255, 255, 0.9), 0 0 16px 4px rgba(255, 224, 130, 0.7);
  animation: line-glow 1.8s ease-in-out infinite;
}

@keyframes line-glow {
  0%, 100% { opacity: 0.75; box-shadow: 0 0 8px 2px rgba(255,255,255,0.9), 0 0 16px 4px rgba(255,224,130,0.7); }
  50% { opacity: 1; box-shadow: 0 0 14px 4px rgba(255,255,255,1), 0 0 26px 8px rgba(255,224,130,0.9); }
}

.bar-fill.leader {
  box-shadow: 0 0 36px 10px rgba(212,175,55,0.85), inset 0 0 16px rgba(255,255,255,0.4);
}
.bar-photo {
  width: clamp(28px, 4vw, 56px); height: clamp(28px, 4vw, 56px);
  border-radius: 50%; object-fit: cover; margin-top: -18px;
  border: 2px solid var(--gold-500);
  box-shadow: 0 0 12px 2px rgba(212,175,55,0.6);
}
.bar-photo.leader {
  border-color: var(--gold-300);
  box-shadow: 0 0 20px 5px rgba(241,217,123,0.9);
}
.bar-photo.leader { border-color: var(--gold-300); }
.bar-code { margin-top: 4px; font-family: 'Space Grotesk', monospace; font-size: clamp(9px, 1vw, 13px); font-weight: 700; color: var(--gold-400); }
.bar-name {
  width: 100%; text-align: center; font-size: clamp(8px, 0.9vw, 12px);
  color: rgba(248,245,236,0.6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar-track-miss   { border-color: rgba(212,175,55,0.4); }
   .bar-track-mister { border-color: rgba(220,38,38,0.4); }
/* ===== ปรับหน้าจอเวทีสำหรับมือถือ/จอแคบ ===== */
@media (max-width: 700px) {
  .stage-content { padding: 20px 12px; }

  .tabs { flex-wrap: wrap; justify-content: center; gap: 8px; }
  .tabs-lg .tab-btn { padding: 9px 18px; font-size: 13px; }

  .chart-wrap {
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding: 12px 10px;
  }
  .bar-col {
    flex: 0 0 auto;
    width: 78px;
    scroll-snap-align: start;
  }
  .bar-track { height: 220px; }
  .bar-fill { max-width: 34px; }
  .bar-photo { width: 40px; height: 40px; }
  .bar-score { font-size: 15px; }
  .bar-name { font-size: 10px; }

  /* บอกใบ้ว่าเลื่อนดูได้ */
  .chart-wrap::after {
    content: '';
  }
}
