/* ===========================================================
   Buddy Budder — MWIT36/6
   Visual identity: MWIT school colors, tuned for UI use.
   Blue = Buddy · Yellow/gold = Budder · single clean white theme
   =========================================================== */

:root{
  --paper:      #FFFFFF;
  --paper-2:    #F3F4F7;
  --ink:        #14171C;
  --ink-soft:   #5B6270;
  --navy:       #123A73;  /* น้ำเงินโรงเรียน เข้ม — ใช้กับพื้นผิวใหญ่/ปุ่มหลัก */
  --navy-2:     #1B4C93;  /* น้ำเงินโรงเรียน อ่อนลงมาหน่อย */
  --coral:      #2557B8;  /* บัดดี้ — น้ำเงินโรงเรียน โทนสด */
  --coral-dark: #1A3F8F;
  --teal:       #D9A62E;  /* บัดเดอร์ — เหลืองโรงเรียน ปรับให้เข้มพออ่านง่ายบนพื้นขาว */
  --teal-dark:  #A87E1B;
  --gold:       #D9A62E;  /* สถานะเลือกแล้ว/สำเร็จ — เหลืองโรงเรียนตัวเดียวกับบัดเดอร์ */
  --danger:     #DC2626;  /* ข้อความ error จริงๆ แยกออกจากสีธีม */
  --danger-bg:  #FCEAEA;
  --line:       #E4E6EC;
  --white:      #FFFFFF;
  --radius:     18px;
  --shadow:     0 10px 26px -14px rgba(20,23,28,.16);

  /* พื้นผิวกระจก (glassmorphism) ใช้กับการ์ดหลักทั่วเว็บ */
  --glass-bg:      rgba(255,255,255,.66);
  --glass-bg-2:    rgba(255,255,255,.8);
  --glass-border:  rgba(255,255,255,.6);
  --glass-blur:    18px;
  --glass-shadow:  0 12px 34px -16px rgba(18,58,115,.22);

  font-family:'Kanit', sans-serif;
}

*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  font-family:'Kanit', sans-serif;
  background:var(--paper) url('../background.webp') center top / cover no-repeat fixed;
  color:var(--ink);
  -webkit-font-smoothing:antialiased;
  position:relative;
  min-height:100vh;
  overflow-x:hidden;
}
/* ออร่าฟ้า-เหลืองจางๆ ลอยอยู่หลังทุกหน้า ให้การ์ดกระจกด้านบนมีอะไรให้เบลอ */
body::before, body::after{
  content:'';
  position:fixed;
  width:460px; height:460px;
  border-radius:999px;
  filter:blur(130px);
  z-index:0;
  pointer-events:none;
}
body::before{ background:color-mix(in srgb, var(--coral) 55%, transparent); top:-140px; left:-120px; }
body::after{ background:color-mix(in srgb, var(--teal) 60%, transparent); bottom:-140px; right:-120px; }
a{color:inherit;text-decoration:none;}
button, input, textarea{font-family:'Kanit', sans-serif;}

@media (prefers-reduced-motion: reduce){
  *{animation-duration:.001ms !important; transition-duration:.001ms !important;}
}

/* ---------- shared bits ---------- */
.eyebrow{
  font-weight:500; font-size:.78rem; letter-spacing:.14em;
  color:var(--coral-dark); text-transform:uppercase; margin:0 0 4px;
}
h1{font-weight:800; font-size:2.6rem; margin:.1em 0 .2em; line-height:1.05;}
.stitch{
  border:none; height:0; margin:22px 0;
  background:none;
  border-top:2px dashed var(--line);
}
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:.5em;
  font-weight:600; font-size:1rem; padding:14px 22px; border-radius:999px;
  border:2px solid var(--navy); background:var(--navy); color:var(--paper);
  cursor:pointer; transition:transform .15s ease, box-shadow .15s ease;
}
.btn:hover{transform:translateY(-2px); box-shadow:var(--shadow);}
.btn:active{transform:translateY(0);}
.btn.outline{background:transparent; color:var(--navy);}
.btn.coral{background:var(--coral); border-color:var(--coral-dark); color:var(--white);}
.btn.teal{background:var(--teal-dark); border-color:var(--teal-dark); color:var(--white);}
.btn:disabled{opacity:.45; cursor:not-allowed; transform:none; box-shadow:none;}

/* ---------- Focus ring (สม่ำเสมอทุกฟอร์มในเว็บ) ---------- */
input, textarea, select{
  transition:border-color .15s ease, box-shadow .15s ease;
}
input:focus, textarea:focus, select:focus{
  outline:none;
  border-color:var(--coral);
  box-shadow:0 0 0 3px color-mix(in srgb, var(--coral) 18%, transparent);
}
.switch input:focus + .slider{
  box-shadow:0 0 0 3px color-mix(in srgb, var(--coral) 25%, transparent);
}

/* ================= LOGIN ================= */
.page-login{min-height:100vh; display:flex; align-items:center; justify-content:center; position:relative; overflow:hidden; z-index:1;}
.knot-bg{
  position:absolute; inset:0; z-index:-1;
  background:
    radial-gradient(circle at 15% 20%, color-mix(in srgb, var(--coral) 20%, transparent), transparent 42%),
    radial-gradient(circle at 85% 80%, color-mix(in srgb, var(--teal) 24%, transparent), transparent 44%);
}
.login-card{
  position:relative; z-index:1;
  background:var(--glass-bg-2);
  backdrop-filter:blur(var(--glass-blur));
  -webkit-backdrop-filter:blur(var(--glass-blur));
  padding:48px 40px;
  border-radius:28px; box-shadow:var(--glass-shadow); text-align:center; max-width:380px; width:90%;
  border:1px solid var(--glass-border);
}
.login-mark{margin-bottom:14px;}
.login-sub{color:var(--ink-soft); margin:0 0 26px; font-weight:300;}
.login-error{background:var(--danger-bg); color:var(--danger); padding:10px 14px; border-radius:12px; font-size:.9rem; margin-bottom:16px;}
.btn-google{
  display:flex; align-items:center; justify-content:center; gap:10px;
  width:100%; padding:14px; border-radius:14px; border:1.5px solid var(--glass-border);
  background:rgba(255,255,255,.85); font-weight:500; box-shadow:0 2px 0 var(--line);
  transition:border-color .15s ease, transform .15s ease;
}
.btn-google:hover{border-color:var(--coral); transform:translateY(-1px);}

/* ================= SHELL / NAV ================= */
.shell{max-width:900px; margin:0 auto; padding:28px 20px 80px; position:relative; z-index:1;}
.topbar{
  display:flex; align-items:center; justify-content:space-between; margin-bottom:28px;
}
.topbar .brand{display:flex; align-items:center; gap:10px; font-weight:700; font-size:1.05rem;}
.topbar .brand .dot-pair{display:flex;}
.topbar .brand .dot-pair span{width:11px;height:11px;border-radius:50%;margin-left:-4px;border:2px solid var(--white);}
.topbar .brand .dot-pair span:first-child{background:var(--coral); margin-left:0;}
.topbar .brand .dot-pair span:last-child{background:var(--teal);}
.topbar nav{display:flex; gap:14px; align-items:center; font-size:.92rem;}
.topbar nav a{color:var(--ink-soft); font-weight:500; transition:color .15s ease;}
.topbar nav a:hover{color:var(--coral);}
.topbar nav a.current{color:var(--navy); font-weight:700;}
.avatar{width:34px;height:34px;border-radius:50%; object-fit:cover; border:2px solid var(--white); box-shadow:0 0 0 2px var(--line);}

/* ================= DASHBOARD ================= */
.hero-card{
  background:var(--navy); color:var(--paper); border-radius:24px; padding:34px 30px;
  position:relative; overflow:hidden; margin-bottom:26px;
}
.hero-card .eyebrow{color:var(--gold);}
.hero-card h1{color:var(--white);}
.hero-card p{color:#C9D2E6; font-weight:300; max-width:60ch;}
.countdown{
  display:flex; gap:10px; margin-top:18px;
}
.countdown .box{
  background:rgba(255,255,255,.08); border:1px solid rgba(255,255,255,.18);
  border-radius:12px; padding:10px 14px; min-width:64px; text-align:center;
}
.countdown .box b{display:block; font-size:1.5rem;}
.countdown .box span{font-size:.7rem; color:#B8C2DA;}

.card-row{display:grid; grid-template-columns:1fr 1fr; gap:16px; margin-bottom:16px;}
@media (max-width:560px){.card-row{grid-template-columns:1fr;}}
.pair-card{
  background:var(--glass-bg-2);
  backdrop-filter:blur(var(--glass-blur));
  -webkit-backdrop-filter:blur(var(--glass-blur));
  border-radius:20px; padding:22px; border:1px solid var(--glass-border);
  display:flex; flex-direction:column; gap:10px;
  transition:transform .18s cubic-bezier(.16,1,.3,1), box-shadow .18s cubic-bezier(.16,1,.3,1), border-color .18s ease;
}
.pair-card:hover{transform:translateY(-3px); box-shadow:var(--glass-shadow); border-color:var(--glass-border);}
.pair-card.buddy{border-top:5px solid var(--coral);}
.pair-card.budder{border-top:5px solid var(--teal);}
.pair-card h3{margin:0; font-size:1.15rem;}
.pair-card .role-tag{font-size:.72rem; letter-spacing:.08em; text-transform:uppercase; font-weight:600;}
.pair-card.buddy .role-tag{color:var(--coral-dark);}
.pair-card.budder .role-tag{color:var(--teal-dark);}
.pair-card .waiting{color:var(--ink-soft); font-weight:300; font-size:.92rem;}
.pair-card .person{display:flex; align-items:center; gap:12px;}
.pair-card .person img{width:48px;height:48px;border-radius:50%;object-fit:cover;}
.pair-card .person .mystery-avatar{width:48px;height:48px;font-size:1.3rem;}

/* ================= CLAIM GRID ================= */
.claim-legend{display:flex; gap:22px; align-items:center; font-size:.88rem; color:var(--ink-soft); margin:18px 0 10px; flex-wrap:wrap;}
.claim-legend .swatch{width:14px;height:14px;border-radius:50%; display:inline-block; margin-right:6px; vertical-align:-2px;}
.sw-open{background:#3FA66B;}
.sw-taken{background:#C7CBD1;}
.sw-mine{background:var(--gold); box-shadow:0 0 0 3px color-mix(in srgb, var(--gold) 30%, transparent);}

.grid-24{
  display:grid; grid-template-columns:repeat(4, 1fr); gap:14px; margin-top:16px;
}
@media (min-width:520px){.grid-24{grid-template-columns:repeat(4, 1fr); max-width:420px; margin-inline:auto;}}
.code-btn{
  aspect-ratio:1; border-radius:50%; border:none; cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  font-size:1.3rem; font-weight:700; color:var(--white);
  background:#3FA66B; transition:transform .12s ease, filter .12s ease;
  box-shadow:0 6px 0 rgba(0,0,0,.12);
}
.code-btn:hover:not(:disabled){transform:translateY(-3px);}
.code-btn:active:not(:disabled){transform:translateY(1px); box-shadow:0 2px 0 rgba(0,0,0,.12);}
.code-btn.taken{background:#C7CBD1; cursor:not-allowed; box-shadow:none;}
.code-btn.mine{background:var(--gold); box-shadow:0 0 0 4px color-mix(in srgb, var(--gold) 35%, transparent);}
.code-btn:disabled{cursor:not-allowed;}

.claim-status-msg{margin-top:14px; font-weight:500; min-height:1.4em;}
.claim-status-msg.err{color:var(--danger);}
.claim-status-msg.ok{color:var(--teal-dark);}

/* ================= CHAT ================= */
.chat-shell{max-width:640px; margin:0 auto; padding:0; height:100vh; display:flex; flex-direction:column; position:relative; z-index:1;}
.chat-head{
  display:flex; align-items:center; gap:12px; padding:16px 18px;
  background:var(--glass-bg-2);
  backdrop-filter:blur(var(--glass-blur));
  -webkit-backdrop-filter:blur(var(--glass-blur));
  border-bottom:1px solid var(--glass-border); position:sticky; top:0; z-index:2;
}
.chat-head img{width:40px;height:40px;border-radius:50%;object-fit:cover;}
.chat-head .who{font-weight:700;}
.chat-head .role{font-size:.75rem; text-transform:uppercase; letter-spacing:.06em; font-weight:600;}
.chat-head.buddy .role{color:var(--coral-dark);}
.chat-head.budder .role{color:var(--teal-dark);}
.chat-head .back{margin-right:4px; font-size:1.3rem; color:var(--ink-soft);}
.mystery-avatar{
  width:40px;height:40px;border-radius:50%; background:var(--navy); color:var(--paper);
  display:flex; align-items:center; justify-content:center; font-weight:700; font-size:1.1rem; flex-shrink:0;
}
.secret-banner{
  background:var(--navy); color:#C9D2E6; font-size:.78rem; text-align:center;
  padding:8px 14px; letter-spacing:.02em;
}

.chat-body{flex:1; overflow-y:auto; padding:18px; display:flex; flex-direction:column; gap:8px; background:rgba(255,255,255,.55);}
.bubble{max-width:74%; padding:10px 14px; border-radius:18px; font-size:.95rem; line-height:1.45; word-wrap:break-word;}
.bubble img{max-width:100%; border-radius:12px; display:block; margin-top:4px;}
.bubble.mine{align-self:flex-end; background:var(--navy); color:var(--white); border-bottom-right-radius:4px;}
.bubble.theirs{align-self:flex-start; background:var(--white); border:1px solid var(--line); border-bottom-left-radius:4px;}
.bubble .time{display:block; font-size:.65rem; opacity:.6; margin-top:3px;}

.chat-input{
  display:flex; gap:8px; padding:12px 14px;
  background:var(--glass-bg-2);
  backdrop-filter:blur(var(--glass-blur));
  -webkit-backdrop-filter:blur(var(--glass-blur));
  border-top:1px solid var(--glass-border);
}
.chat-input textarea{
  flex:1; resize:none; border:1.5px solid var(--line); border-radius:20px; padding:10px 16px;
  font-size:.95rem; max-height:110px; min-height:44px;
}
.chat-input button{
  width:44px; height:44px; border-radius:50%; border:none; background:var(--coral); color:var(--white);
  display:flex; align-items:center; justify-content:center; cursor:pointer; flex-shrink:0;
}
.chat-input .attach{background:var(--teal-dark);}

#send-btn{position:relative;}
.send-spinner{
  width:16px; height:16px; border-radius:50%;
  border:2px solid rgba(255,255,255,.4); border-top-color:#fff;
  animation:bb-spin .7s linear infinite;
}
@keyframes bb-spin{ to{ transform:rotate(360deg); } }

.send-error{
  padding:8px 14px; background:var(--danger-bg); color:var(--danger);
  font-size:.82rem; text-align:center;
}

.bubble.pending{opacity:.72;}
.pending-row{display:flex; align-items:center; gap:6px; margin-top:5px;}
.mini-spinner{
  width:12px; height:12px; border-radius:50%; flex-shrink:0;
  border:2px solid rgba(0,0,0,.15); border-top-color:currentColor;
  animation:bb-spin .7s linear infinite;
}
.bubble.mine .mini-spinner{border-color:rgba(255,255,255,.3); border-top-color:#fff;}
.pending-label{font-size:.72rem; opacity:.85;}

.attach-preview{
  display:flex; align-items:center; gap:10px; padding:8px 14px; background:var(--paper-2);
  border-top:1px solid var(--line);
}
.attach-preview img{width:44px;height:44px;border-radius:10px;object-fit:cover; flex-shrink:0;}
.attach-preview-name{flex:1; font-size:.82rem; color:var(--ink-soft); overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.attach-preview-cancel{
  width:26px;height:26px;border-radius:50%; border:none; background:var(--line); color:var(--ink);
  cursor:pointer; flex-shrink:0; font-size:.8rem; display:flex; align-items:center; justify-content:center;
}
.attach-preview-cancel:hover{background:var(--danger-bg); color:var(--danger);}

/* ================= PROFILE ================= */
.profile-form{
  background:var(--glass-bg-2);
  backdrop-filter:blur(var(--glass-blur));
  -webkit-backdrop-filter:blur(var(--glass-blur));
  border-radius:20px; padding:26px; border:1px solid var(--glass-border); margin-bottom:18px;
}
.profile-form h3{margin-top:0;}
.profile-form label{display:block; font-weight:500; margin:14px 0 6px; font-size:.9rem;}
.profile-form textarea, .profile-form input[type=text]{
  width:100%; border:1.5px solid var(--line); border-radius:12px; padding:10px 12px; font-size:.95rem;
}
.preview-card{
  margin-top:14px; background:var(--paper-2); border:1px dashed var(--line);
  border-radius:14px; padding:14px 16px;
}
.preview-tag{
  display:block; font-size:.7rem; letter-spacing:.08em; text-transform:uppercase;
  font-weight:600; color:var(--ink-faint); margin-bottom:10px;
}
.preview-row{display:flex; align-items:center; gap:12px;}
.preview-row img{width:40px;height:40px;border-radius:50%;object-fit:cover; flex-shrink:0;}
.preview-name{font-weight:700; font-size:.95rem;}
.preview-bio{font-size:.85rem; color:var(--ink-soft); font-weight:300; margin-top:2px; white-space:pre-line;}
.file-preview{
  display:flex; align-items:center; gap:10px; margin-top:8px; padding:8px 10px;
  background:var(--paper-2); border-radius:10px; font-size:.82rem; color:var(--ink-soft);
}
.file-preview img{width:36px;height:36px;border-radius:8px;object-fit:cover; flex-shrink:0;}
.file-preview span{overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.toggle-row{display:flex; align-items:center; justify-content:space-between; gap:12px; margin-top:16px;}
.switch{position:relative; width:46px; height:26px; flex-shrink:0;}
.switch input{opacity:0; width:0; height:0;}
.slider{position:absolute; inset:0; background:var(--line); border-radius:999px; cursor:pointer; transition:.2s;}
.slider:before{content:'';position:absolute;width:20px;height:20px;left:3px;top:3px;background:var(--white);border-radius:50%;transition:.2s;}
.switch input:checked + .slider{background:var(--teal);}
.switch input:checked + .slider:before{transform:translateX(20px);}

/* ================= ADMIN ================= */
.admin-grid{display:grid; grid-template-columns:1fr 1fr; gap:16px;}
@media (max-width:640px){.admin-grid{grid-template-columns:1fr;}}
.admin-panel{
  background:var(--glass-bg-2);
  backdrop-filter:blur(var(--glass-blur));
  -webkit-backdrop-filter:blur(var(--glass-blur));
  border-radius:20px; padding:22px; border:1px solid var(--glass-border);
  transition:box-shadow .18s ease, border-color .18s ease;
}
.admin-panel:hover{box-shadow:var(--glass-shadow);}
.admin-panel h3{margin-top:0;}
.admin-panel input[type=datetime-local]{
  width:100%; padding:10px 12px; border:1.5px solid var(--line); border-radius:10px; font-size:.95rem; margin:8px 0 14px;
}
table.roster{width:100%; border-collapse:collapse; font-size:.88rem;}
table.roster tbody tr{transition:background .15s ease;}
table.roster tbody tr:hover{background:var(--paper-2);}
table.roster th, table.roster td{padding:8px 10px; text-align:left; border-bottom:1px solid var(--line);}
table.roster select{padding:6px 8px; border-radius:8px; border:1.5px solid var(--line);}
.badge{display:inline-block; padding:3px 10px; border-radius:999px; font-size:.72rem; font-weight:600;}
.badge.green{background:#DFF3E4; color:#1F7A3D;}
.badge.grey{background:#EEF0F3; color:var(--ink-soft);}
.wheel-btn{margin-top:10px;}

.owncode-grid{display:grid; grid-template-columns:repeat(auto-fill, minmax(180px,1fr)); gap:10px; margin-top:14px;}
.owncode-row{display:flex; align-items:center; justify-content:space-between; gap:8px; background:var(--paper); border:1px solid var(--line); border-radius:10px; padding:8px 10px;}
.owncode-row label{font-size:.85rem; font-weight:500; margin:0;}
.owncode-row label span{font-weight:300; color:var(--ink-soft);}
.owncode-row input{width:56px; text-align:center; padding:6px 4px; border:1.5px solid var(--line); border-radius:8px; font-size:.9rem; font-weight:600;}
.owncode-row input:disabled{background:var(--paper-2); color:var(--ink-soft);}
