/* English by P'M — ระบบคลิปวิดีโอ */

:root {
  --ink:        #0E1230;
  --ink-2:      #171C42;
  --ink-3:      #222963;
  --line:       #2C3370;
  --paper:      #F5F3EE;
  --muted:      #9AA0CC;
  --violet:     #7C5CFF;
  --violet-dim: #5B41C7;
  --citron:     #C6F24E;
  --danger:     #FF6B6B;
  --ok:         #4ADE80;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --shadow: 0 18px 50px rgba(6, 8, 28, .45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: 'Sarabun', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}

body {
  background-image:
    radial-gradient(1100px 500px at 8% -8%, rgba(124, 92, 255, .28), transparent 60%),
    radial-gradient(900px 460px at 105% 6%, rgba(198, 242, 78, .10), transparent 55%);
  background-attachment: fixed;
}

h1, h2, h3, .display {
  font-family: 'Prompt', system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: -.01em;
  line-height: 1.25;
  margin: 0;
}

.mono {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-size: .82rem;
  letter-spacing: .01em;
}

a { color: var(--citron); }

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 20px 72px;
}

.hidden { display: none !important; }

/* ---------- หัวเรื่อง ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 34px;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: linear-gradient(140deg, var(--violet), var(--violet-dim));
  display: grid; place-items: center;
  font-family: 'Prompt', sans-serif;
  font-weight: 700; font-size: .95rem;
  color: #fff;
  flex: 0 0 auto;
}
.brand-text { font-family: 'Prompt', sans-serif; font-weight: 500; font-size: .95rem; }
.brand-text span { display: block; font-size: .72rem; color: var(--muted); font-weight: 400; }

/* ขีดเน้นข้อความด้วยปากกาไฮไลต์ — องค์ประกอบประจำตัวของแบรนด์ */
.mark {
  position: relative;
  display: inline;
  color: #EAFFB4;
  background-image: linear-gradient(transparent 82%, rgba(198, 242, 78, .55) 82%, rgba(198, 242, 78, .55) 96%, transparent 96%);
  background-size: 0% 100%;
  background-repeat: no-repeat;
  animation: swipe .7s .25s cubic-bezier(.22,.61,.36,1) forwards;
}
@keyframes swipe { to { background-size: 100% 100%; } }

/* ---------- การ์ด ---------- */
.card {
  background: linear-gradient(170deg, var(--ink-2), var(--ink));
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 26px 24px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }

.eyebrow {
  font-family: 'Prompt', sans-serif;
  font-size: .72rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.lede { color: var(--muted); margin: 10px 0 0; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  padding: 14px 20px;
  border: 0;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--violet), var(--violet-dim));
  color: #fff;
  font-family: 'Prompt', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease;
}
.btn:hover { filter: brightness(1.09); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-line { background: linear-gradient(135deg, #06C755, #04A344); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--paper);
}
.btn-sm { width: auto; padding: 8px 14px; font-size: .85rem; border-radius: var(--r-sm); }
.btn-danger { background: transparent; border: 1px solid rgba(255,107,107,.5); color: var(--danger); }

*:focus-visible { outline: 2px solid var(--citron); outline-offset: 3px; }

/* ---------- ฟอร์ม ---------- */
label {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 7px;
}
input[type=text], input[type=email], input[type=password], select {
  width: 100%;
  padding: 13px 15px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .28);
  color: var(--paper);
  font-family: inherit;
  font-size: 1rem;
}
input::placeholder { color: #5C6394; }
.field + .field, .field + .btn, form .btn { margin-top: 16px; }

/* ---------- บัตรประจำตัว (พร้อมตัวอย่างลายน้ำ) ---------- */
.idcard {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background:
    linear-gradient(150deg, rgba(124,92,255,.30), rgba(23,28,66,.9) 55%),
    var(--ink-2);
  padding: 24px;
}
.idcard-wm {
  position: absolute; inset: 0;
  pointer-events: none;
  display: flex; flex-wrap: wrap;
  align-content: center; justify-content: center;
  gap: 26px 34px;
  opacity: .17;
  transform: rotate(-19deg) scale(1.5);
  font-family: ui-monospace, monospace;
  font-size: .62rem;
  white-space: nowrap;
  color: #fff;
}
.idcard-body { position: relative; z-index: 1; }
.idcard-name { font-family: 'Prompt', sans-serif; font-size: 1.5rem; font-weight: 600; }
.idcard-email { color: var(--muted); word-break: break-all; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(198, 242, 78, .12);
  border: 1px solid rgba(198, 242, 78, .3);
  color: var(--citron);
  font-size: .8rem;
}
.chip-plain { background: rgba(255,255,255,.06); border-color: var(--line); color: var(--muted); }

/* ---------- รายการให้เลือก (กรณีอีเมลซ้ำ) ---------- */
.pick {
  width: 100%;
  text-align: left;
  padding: 15px 17px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: rgba(0,0,0,.22);
  color: var(--paper);
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 10px;
}
.pick:hover { border-color: var(--violet); background: rgba(124,92,255,.14); }
.pick small { display: block; color: var(--muted); font-size: .8rem; }

/* ---------- แจ้งเตือน ---------- */
.note {
  border-radius: var(--r-md);
  padding: 13px 16px;
  font-size: .9rem;
  margin-top: 16px;
  border: 1px solid;
}
.note-err { background: rgba(255,107,107,.09); border-color: rgba(255,107,107,.4); color: #FFC0C0; }
.note-ok  { background: rgba(74,222,128,.09);  border-color: rgba(74,222,128,.4);  color: #BBF7D0; }
.note-info{ background: rgba(124,92,255,.10);  border-color: rgba(124,92,255,.4);  color: #D7CDFF; }

/* ---------- โหลด ---------- */
.spin {
  width: 17px; height: 17px;
  border: 2px solid rgba(255,255,255,.28);
  border-top-color: #fff;
  border-radius: 50%;
  animation: rot .7s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }

.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mt { margin-top: 18px; }
.mt-s { margin-top: 10px; }

/* ---------- โครงร่างหน้าแอดมิน ---------- */
.admin-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 22px;
}
.wrap-wide { max-width: 1180px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  background: rgba(0,0,0,.2);
}
.stat b { display: block; font-family: 'Prompt', sans-serif; font-size: 1.7rem; font-weight: 600; }
.stat span { font-size: .78rem; color: var(--muted); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.toolbar .field { flex: 1 1 220px; margin: 0; }

.table-scroll { overflow-x: auto; border-radius: var(--r-md); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 780px; }
th, td { padding: 11px 13px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  font-family: 'Prompt', sans-serif; font-weight: 500; font-size: .76rem;
  letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  background: rgba(0,0,0,.3); position: sticky; top: 0;
}
tbody tr:hover { background: rgba(124,92,255,.07); }
td .mono { font-size: .74rem; color: var(--muted); word-break: break-all; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; border: 1px solid; }
.tag-sheet { color: var(--citron); border-color: rgba(198,242,78,.4); background: rgba(198,242,78,.1); }
.tag-bind  { color: #BFA8FF; border-color: rgba(124,92,255,.45); background: rgba(124,92,255,.12); }
.tag-none  { color: var(--muted); border-color: var(--line); }

@media (max-width: 560px) {
  .wrap { padding: 20px 15px 60px; }
  .card { padding: 22px 18px; }
  .idcard-name { font-size: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .mark { background-size: 100% 100%; }
}

/* ================= Phase 2: แกลเลอรีและเครื่องเล่น ================= */

.idcard-slim { padding: 18px 20px; }
.idcard-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.idcard-slim .idcard-name { font-size: 1.2rem; }

.gallery-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin: 30px 0 14px;
}
.gallery-head h2 { font-size: 1.15rem; }

.gallery { display: grid; gap: 12px; }

.clip {
  display: grid;
  grid-template-columns: 116px 1fr;
  gap: 14px;
  align-items: stretch;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: linear-gradient(140deg, rgba(23,28,66,.9), rgba(14,18,48,.9));
  overflow: hidden;
  text-align: left;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  transition: border-color .15s ease, transform .12s ease;
}
.clip:hover { border-color: var(--violet); }
.clip:active { transform: scale(.995); }
.clip[disabled] { cursor: not-allowed; opacity: .62; }
.clip[disabled]:hover { border-color: var(--line); }

.clip-thumb {
  position: relative;
  background: #0A0D24 center/cover no-repeat;
  min-height: 76px;
}
.clip-thumb::after {
  content: attr(data-order);
  position: absolute; left: 6px; top: 6px;
  background: rgba(10,13,36,.82);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 7px;
  font-family: ui-monospace, monospace;
  font-size: .68rem;
  color: var(--citron);
}
.clip-dur {
  position: absolute; right: 6px; bottom: 6px;
  background: rgba(10,13,36,.85);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: ui-monospace, monospace;
  font-size: .68rem;
}

.clip-body { padding: 13px 14px 13px 0; display: flex; flex-direction: column; gap: 5px; }
.clip-title { font-family: 'Prompt', sans-serif; font-weight: 500; font-size: 1rem; line-height: 1.35; }
.clip-desc { font-size: .82rem; color: var(--muted); }
.clip-foot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 6px; }

.pill {
  font-size: .7rem; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.pill-ok { color: var(--citron); border-color: rgba(198,242,78,.35); }
.pill-warn { color: #FFD08A; border-color: rgba(255,208,138,.35); }
.pill-lock { color: #FFB4B4; border-color: rgba(255,107,107,.35); }

/* ---------- เครื่องเล่น ---------- */
.back-link {
  background: none; border: 0; color: var(--muted);
  font-family: 'Prompt', sans-serif; font-size: .92rem;
  cursor: pointer; padding: 4px 0; margin-bottom: 12px;
}
.back-link:hover { color: var(--paper); }

.player-shell { border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--ink-2); }
.player-stage { position: relative; background: #000; aspect-ratio: 16 / 9; }
.player-stage video { width: 100%; height: 100%; display: block; background: #000; }

.player-busy {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(0,0,0,.55);
}
.player-busy.hidden { display: none !important; }

/* ลายน้ำเลื่อนตำแหน่ง */
.wm-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.wm-tag {
  position: absolute;
  font-family: ui-monospace, monospace;
  font-size: clamp(8px, 1.5vw, 12px);
  line-height: 1.35;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.85);
  white-space: nowrap;
  opacity: .3;
  transition: opacity .5s ease;
}
.wm-tag.center { opacity: .16; font-size: clamp(10px, 2.1vw, 17px); }

.player-meta { padding: 18px 20px 22px; }
.player-meta h2 { font-size: 1.15rem; }

@media (max-width: 560px) {
  .clip { grid-template-columns: 96px 1fr; }
  .clip-body { padding: 11px 12px 11px 0; }
  .clip-title { font-size: .93rem; }
}

/* ================= Phase 2: หลังบ้าน ================= */

.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: 'Prompt', sans-serif;
  font-size: .9rem;
  padding: 8px 18px;
  border-radius: var(--r-md);
  cursor: pointer;
}
.tab.active { background: rgba(124,92,255,.18); border-color: var(--violet); color: var(--paper); }

textarea {
  width: 100%;
  padding: 13px 15px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: rgba(0,0,0,.28);
  color: var(--paper);
  font-family: ui-monospace, monospace;
  font-size: .85rem;
  resize: vertical;
}

.bulk-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 12px;
  border: 1px solid var(--violet);
  border-radius: var(--r-md);
  background: rgba(124,92,255,.12);
  font-size: .85rem;
}

.st {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .78rem;
}
.st::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-ready { color: var(--ok); }
.st-queued { color: #FFD08A; }
.st-processing { color: #8FB8FF; }
.st-error { color: var(--danger); }

.dot-pub { color: var(--citron); }
.dot-hidden { color: var(--muted); }

/* กล่องแก้ไข */
.modal {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(6,8,28,.78);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 20px;
}
.modal.hidden { display: none !important; }
.modal-card {
  width: min(620px, 100%);
  max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.modal-head, .modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 22px;
}
.modal-head { border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 1.1rem; }
.modal-foot { border-top: 1px solid var(--line); }
.modal-body { padding: 20px 22px; overflow-y: auto; }

.course-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px; margin-top: 8px;
  max-height: 220px; overflow-y: auto;
  padding: 4px;
}
.check {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: rgba(0,0,0,.2);
  font-size: .85rem;
  cursor: pointer;
}
.check:hover { border-color: var(--violet); }
.check input { accent-color: var(--violet); width: 16px; height: 16px; }
.check.on { border-color: var(--violet); background: rgba(124,92,255,.14); }

input[type=datetime-local], input[type=number] {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: rgba(0,0,0,.28);
  color: var(--paper);
  font-family: inherit;
  font-size: .95rem;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .two-col { grid-template-columns: 1fr; } }
