/* ============================================
   Sub2Unlock — Modern UI
   พื้นดำสนิท สีธีมปรับได้ทั้งหน้าจริง (ใช้ RGB tuple variable)
   Type: Inter (display/UI) + JetBrains Mono (tokens/data)
   ============================================ */

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

:root {
  --bg:        #08090b;
  --surface:   #111317;
  --surface-2: #161922;
  --surface-3: #1c1f2a;
  --border:    #23262f;
  --border-soft: #1a1c24;

  --text:       #f3f4f6;
  --text-muted: #9197a3;
  --text-faint: #5c6170;

  /* ===== สีธีม =====
     --signal-rgb ถูกคำนวณจาก PHP (hexToRgbTuple) ตามสีที่ผู้ใช้เลือกต่อลิงก์
     ทุกที่ที่ต้องใช้สีธีมแบบมี opacity ต้องเขียนเป็น rgba(var(--signal-rgb), x)
     ห้าม hardcode เป็นเลข hex ตรงๆ เด็ดขาด เพราะจะไม่เปลี่ยนตามสีที่ผู้ใช้ตั้ง */
  --signal-rgb: 189, 242, 74;
  --signal: rgb(var(--signal-rgb));
  --signal-text: #0a0d05; /* สีตัวอักษรบนปุ่มพื้นสีธีม คำนวณจาก PHP (contrastTextColor) */

  --danger:        #f5524a;
  --danger-rgb:    245, 82, 74;
  --danger-bg:     rgba(245, 82, 74, 0.08);
  --danger-border: rgba(245, 82, 74, 0.22);

  --radius:    14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --radius-xl: 26px;

  --font-display: 'Inter', 'Noto Sans Thai', sans-serif;
  --font-mono: 'JetBrains Mono', 'Noto Sans Thai', monospace;

  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-display);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

a { color: var(--signal); text-decoration: none; }
img { max-width: 100%; display: block; }
code, .mono { font-family: var(--font-mono); }

/* ===== Ambient backdrop ===== */
.bg-gradient {
  min-height: 100vh;
  position: relative;
  background:
    radial-gradient(ellipse 70% 50% at 50% -10%, rgba(var(--signal-rgb), 0.10), transparent 60%),
    var(--bg);
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
  position: relative;
  z-index: 1;
}

/* ===== Navbar ===== */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 19px;
  color: var(--text);
  letter-spacing: -0.3px;
}

.brand .logo-dot {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--signal);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--signal-text);
  font-size: 15px;
  font-weight: 800;
  font-family: var(--font-mono);
}

.nav-links { display: flex; gap: 24px; align-items: center; }
.nav-links a { color: var(--text-muted); font-weight: 500; font-size: 14px; transition: color .15s var(--ease); }
.nav-links a:hover { color: var(--signal); }

.navbar-minimal { padding: 18px 0; justify-content: center; }
.brand-sm { font-size: 13px; color: var(--text-faint); font-weight: 600; }
.logo-dot-sm { width: 20px; height: 20px; font-size: 10px; border-radius: 6px; }

/* ===== Hero ===== */
.hero { text-align: center; padding: 64px 0 32px; }

.hero h1 {
  font-size: 42px;
  font-weight: 800;
  margin: 0 0 14px;
  letter-spacing: -1px;
  color: var(--text);
}

.hero h1 span { color: var(--signal); }

.hero p {
  color: var(--text-muted);
  font-size: 16.5px;
  max-width: 540px;
  margin: 0 auto;
}

/* ===== Card ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  padding: 34px;
}

.card-sm { padding: 22px; border-radius: var(--radius-sm); }

/* ===== Form ===== */
.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 8px;
  color: var(--text);
}

.form-hint { font-size: 12.5px; color: var(--text-faint); margin-top: 6px; line-height: 1.6; }

.form-control {
  width: 100%;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}

.form-control::placeholder { color: var(--text-faint); }

.form-control:focus {
  outline: none;
  border-color: rgba(var(--signal-rgb), 0.5);
  box-shadow: 0 0 0 3px rgba(var(--signal-rgb), 0.15);
}

textarea.form-control { resize: vertical; min-height: 90px; }

input[type="color"].form-control { background: var(--surface-2); cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14.5px;
  border: none;
  cursor: pointer;
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), background .18s var(--ease), border-color .18s var(--ease);
  font-family: inherit;
}

.btn-primary {
  background: var(--signal);
  color: var(--signal-text);
}
.btn-primary:hover { box-shadow: 0 8px 24px -8px rgba(var(--signal-rgb), 0.5); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: rgba(var(--signal-rgb), 0.4); color: var(--signal); }

.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.btn-danger:hover { background: rgba(var(--danger-rgb), 0.15); }

.btn-block { width: 100%; }
.btn-sm { padding: 9px 16px; font-size: 13px; }
.btn-icon { width: 40px; height: 40px; padding: 0; border-radius: 10px; }

/* ===== Step editor (create/edit page) ===== */
.step-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 12px;
  background: var(--surface-2);
}

.step-num {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--signal);
  font-weight: 700;
  font-size: 12.5px;
  font-family: var(--font-mono);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 4px;
}

.step-fields { flex: 1; display: grid; gap: 10px; }
.step-fields-row { display: grid; grid-template-columns: 130px 1fr; gap: 10px; }
.step-fields-row-split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .step-fields-row-split { grid-template-columns: 1fr; } }

.step-remove {
  background: none; border: none; color: var(--text-faint);
  cursor: pointer; font-size: 18px; padding: 4px;
  margin-top: 4px;
  transition: color .15s var(--ease);
}
.step-remove:hover { color: var(--danger); }

/* ===== Toggle switch ===== */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background-color: var(--surface-2); border: 1px solid var(--border);
  transition: .2s var(--ease); border-radius: 26px;
}
.slider:before {
  position: absolute; content: ""; height: 18px; width: 18px;
  left: 3px; bottom: 3px; background-color: var(--text-faint); transition: .2s var(--ease); border-radius: 50%;
}
input:checked + .slider { background-color: rgba(var(--signal-rgb), 0.25); border-color: rgba(var(--signal-rgb), 0.45); }
input:checked + .slider:before { transform: translateX(20px); background-color: var(--signal); }

/* ===== Result / Success box ===== */
.result-box {
  background: var(--surface-2);
  border: 1px solid rgba(var(--signal-rgb), 0.3);
  border-radius: var(--radius-sm);
  padding: 28px 24px;
  text-align: center;
}

.link-display {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 16px 0;
}
.link-display input {
  flex: 1; border: none; outline: none; font-size: 13.5px;
  background: transparent; font-family: var(--font-mono); color: var(--text);
}

/* ===== Unlock page ===== */
.unlock-cover-full {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16/9;
  overflow: hidden;
  position: relative;
  z-index: 1;
}
.unlock-cover-full img { width: 100%; height: 100%; object-fit: cover; }
.unlock-cover-full::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(8,9,11,0) 45%, rgba(8,9,11,0.95) 100%);
  pointer-events: none;
}

.unlock-wrap { max-width: 480px; margin: 0 auto; padding: 34px 20px 50px; }

.unlock-title { font-size: 24px; font-weight: 800; text-align: center; margin: 0 0 8px; letter-spacing: -0.5px; }
.unlock-desc { text-align: center; color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }

.step-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 12px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), opacity .2s var(--ease), transform .15s var(--ease);
}
.step-btn:hover:not(:disabled) { border-color: rgba(var(--signal-rgb), 0.35); transform: translateY(-1px); }
.step-btn:active:not(:disabled) { transform: translateY(0); }
.step-btn:disabled { cursor: default; opacity: 0.55; }
.step-btn.is-done { border-color: rgba(var(--signal-rgb), 0.35); background: rgba(var(--signal-rgb), 0.045); }
.step-btn.is-waiting {
  border-color: rgba(var(--signal-rgb), 0.7);
  box-shadow: 0 0 0 1px rgba(var(--signal-rgb), 0.5), 0 8px 24px -8px rgba(var(--signal-rgb), 0.3);
}

.step-btn-icon {
  width: 40px; height: 40px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; background: var(--surface-3); border: 1px solid var(--border);
}
.step-btn-icon svg { width: 19px; height: 19px; }

.step-btn-label { flex: 1; font-weight: 600; font-size: 14.5px; color: var(--text); }

.step-btn-status {
  flex-shrink: 0;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
}
.step-btn-status svg { width: 16px; height: 16px; }

.unlock-progress-text {
  text-align: center;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-faint);
  margin: 20px 0 24px;
  letter-spacing: .02em;
}
.unlock-progress-text span { color: var(--signal); font-weight: 600; }

.check-mark {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--signal); color: var(--signal-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0;
}

.countdown-circle {
  width: 26px; height: 26px;
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
}
.countdown-circle::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--signal);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.final-unlock-box { margin-top: 6px; }

.btn-unlock {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px 24px;
  border-radius: var(--radius-lg);
  font-weight: 700;
  font-size: 15.5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-faint);
  cursor: not-allowed;
  font-family: inherit;
  transition: all .25s var(--ease);
}
.btn-unlock:not(:disabled) {
  background: var(--signal);
  color: var(--signal-text);
  border-color: transparent;
  cursor: pointer;
}
.btn-unlock:not(:disabled):hover { box-shadow: 0 10px 28px -8px rgba(var(--signal-rgb), 0.5); transform: translateY(-1px); }
.btn-unlock:not(:disabled):active { transform: translateY(0); }

.footer-note { text-align: center; color: var(--text-faint); font-size: 12.5px; margin-top: 44px; padding-bottom: 32px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; font-family: var(--font-mono); }
.badge-active { background: rgba(var(--signal-rgb), 0.12); color: var(--signal); }
.badge-active::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--signal); }
.badge-inactive { background: rgba(var(--danger-rgb), 0.12); color: var(--danger); }
.badge-inactive::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--danger); }

/* ===== Admin table ===== */
.table-wrap { overflow-x: auto; }
table.admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.admin-table th, table.admin-table td { padding: 13px 14px; text-align: left; border-bottom: 1px solid var(--border-soft); }
table.admin-table th { color: var(--text-faint); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-family: var(--font-mono); }
table.admin-table tr { transition: background .15s var(--ease); }
table.admin-table tr:hover td { background: var(--surface-2); }
table.admin-table code { color: var(--signal); font-size: 12.5px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 28px; }
@media (max-width: 700px) { .stat-grid { grid-template-columns: 1fr; } }

.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 20px; }
.stat-card .num { font-size: 30px; font-weight: 800; font-family: var(--font-mono); color: var(--signal); }
.stat-card .lbl { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

.alert { padding: 14px 18px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 18px; border: 1px solid; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.alert-success { background: rgba(var(--signal-rgb), 0.08); color: var(--signal); border-color: rgba(var(--signal-rgb), 0.3); }

.spinner-inline {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: currentColor;
  border-radius: 50%; animation: spin .7s linear infinite;
}

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-faint); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--surface-3); }

@media (max-width: 600px) {
  .hero h1 { font-size: 30px; }
  .card { padding: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
