/* ============ Liquid Glass · UnKnow Luxury (Jet Black / Charcoal / Antique Gold) ============ */
:root {
  --bg-0: #080808;
  --bg-1: #101010;
  --ink: #ece7db;
  --ink-2: #c4bda9;
  --ink-3: #8a8577;
  --gold: #c8a24a;
  --gold-hi: #e6c877;
  --gold-deep: #6e561f;
  --brown: #4a3a1c;
  --brown-deep: #241c0d;
  --accent: var(--gold);
  --ok: #9dbb85;
  --bad: #d68a7a;
  --warn: #c8a24a;
  --glass: rgba(200, 162, 74, 0.035);
  --glass-hi: rgba(200, 162, 74, 0.07);
  --glass-edge: rgba(200, 162, 74, 0.16);
  --glass-inner: inset 0 1px 0 rgba(230, 200, 119, 0.1), inset 0 -1px 0 rgba(0, 0, 0, 0.5);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font: 'IBM Plex Sans Thai', 'Sarabun', 'Segoe UI', sans-serif;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-0);
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---- ambient light blobs ---- */
.blobs { position: fixed; inset: 0; z-index: -2; overflow: hidden; background:
  radial-gradient(ellipse 90% 60% at 50% -10%, #16120a 0%, transparent 60%),
  var(--bg-0); }
.blob { position: absolute; border-radius: 50%; filter: blur(100px); opacity: 0.3; will-change: transform; }
.blob-1 { width: 46vw; height: 46vw; left: -12vw; top: -14vh; background: radial-gradient(circle, #6e561f 0%, transparent 70%); animation: drift1 26s ease-in-out infinite alternate; }
.blob-2 { width: 38vw; height: 38vw; right: -10vw; top: 24vh; background: radial-gradient(circle, #3a2c17 0%, transparent 70%); animation: drift2 32s ease-in-out infinite alternate; }
.blob-3 { width: 30vw; height: 30vw; left: 28vw; bottom: -16vh; background: radial-gradient(circle, #4a3a1c 0%, transparent 70%); animation: drift3 38s ease-in-out infinite alternate; }
@keyframes drift1 { to { transform: translate(9vw, 7vh) scale(1.12); } }
@keyframes drift2 { to { transform: translate(-7vw, -9vh) scale(0.92); } }
@keyframes drift3 { to { transform: translate(-6vw, -6vh) scale(1.18); } }

/* grain overlay */
body::after {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---- glass primitives ---- */
.glass, .card {
  position: relative;
  background: var(--glass);
  backdrop-filter: blur(28px) saturate(1.5);
  -webkit-backdrop-filter: blur(28px) saturate(1.5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--glass-inner), 0 24px 60px -24px rgba(4, 10, 34, 0.9);
  transition: background 0.35s var(--ease), transform 0.35s var(--ease), box-shadow 0.35s var(--ease);
}

/* spotlight ขอบสว่างตามเมาส์ */
.card::before {
  content: ''; position: absolute; inset: -1px; border-radius: inherit; pointer-events: none;
  background: radial-gradient(420px circle at var(--mx, 50%) var(--my, 0%), rgba(230, 200, 119, 0.12), transparent 45%);
  opacity: 0; transition: opacity 0.4s var(--ease);
}
.card:hover::before { opacity: 1; }

/* ---- header ---- */
header {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 26px; margin: 14px 18px 0; border-radius: 18px;
  background: rgba(12, 12, 12, 0.62);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid rgba(200, 162, 74, 0.22);
  box-shadow: var(--glass-inner), 0 18px 44px -20px rgba(0, 0, 0, 0.95);
}
.brand { font-size: 1.12rem; font-weight: 600; letter-spacing: 0.01em; display: flex; align-items: center; gap: 11px; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 11px; overflow: hidden; flex-shrink: 0;
  border: 1px solid rgba(200, 162, 74, 0.45);
  box-shadow: inset 0 1px 0 rgba(230, 200, 119, 0.3), 0 6px 16px -6px rgba(200, 162, 74, 0.5);
}
.brand .logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand .brand-name {
  background: linear-gradient(120deg, var(--gold-hi) 0%, var(--gold) 45%, #a8842e 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  font-weight: 700; letter-spacing: 0.02em;
}
.brand .brand-sub { display: block; font-size: 0.62rem; font-weight: 500; letter-spacing: 0.24em; color: var(--ink-3); text-transform: uppercase; margin-top: 1px; }
.welcome { color: var(--ink-2); margin-right: 14px; font-size: 0.92rem; }

/* ---- layout ---- */
main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 34px 22px 44px; }
.card { padding: 30px; margin-bottom: 22px; }
.auth-card { max-width: 460px; margin: 5vh auto 0; text-align: center; }
.hero-logo {
  width: 74px; height: 74px; margin: 0 auto 14px; border-radius: 20px; overflow: hidden;
  border: 1px solid rgba(200, 162, 74, 0.5);
  box-shadow: inset 0 1px 0 rgba(230, 200, 119, 0.35), 0 14px 34px -12px rgba(200, 162, 74, 0.55);
}
.hero-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-title {
  font-size: 2rem; font-weight: 700; letter-spacing: 0.02em; line-height: 1.1;
  background: linear-gradient(120deg, var(--gold-hi) 0%, var(--gold) 50%, #8a6d2e 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub { color: var(--ink-3); font-size: 0.82rem; letter-spacing: 0.14em; text-transform: uppercase; margin: 6px 0 22px; }
.auth-card .tabs, .auth-card form { text-align: left; }

h2 { font-size: 1.22rem; font-weight: 600; letter-spacing: -0.015em; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }

/* ---- tabs ---- */
.tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 24px;
  padding: 6px; border-radius: 16px;
  background: rgba(0, 0, 0, 0.28); border: 1px solid rgba(200, 162, 74, 0.11);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.35);
}
.tab {
  padding: 10px; background: transparent; color: var(--ink-3); border: none; border-radius: 11px;
  cursor: pointer; font-size: 0.95rem; font-family: var(--font); font-weight: 500;
  transition: all 0.3s var(--ease);
}
.tab:hover { color: var(--ink-2); }
.tab.active {
  color: var(--gold-hi);
  background: linear-gradient(160deg, rgba(200, 162, 74, 0.16), rgba(200, 162, 74, 0.05));
  border: 1px solid rgba(200, 162, 74, 0.35);
  box-shadow: inset 0 1px 0 rgba(230, 200, 119, 0.2), 0 6px 18px -8px rgba(0, 0, 0, 0.7);
}

/* ---- forms ---- */
.form label { display: block; margin-bottom: 15px; font-size: 0.84rem; font-weight: 500; color: var(--ink-2); letter-spacing: 0.02em; }
.form input, .form select, .form textarea, .search, .inline-form input {
  display: block; width: 100%; margin-top: 7px; padding: 12px 15px;
  background: rgba(0, 0, 0, 0.42); border: 1px solid rgba(200, 162, 74, 0.16);
  border-radius: var(--radius-sm); color: var(--ink); font-size: 0.95rem; font-family: var(--font);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.45);
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease), background 0.25s var(--ease);
}
.form textarea { resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus, .search:focus, .inline-form input:focus {
  outline: none; border-color: rgba(200, 162, 74, 0.6); background: rgba(0, 0, 0, 0.5);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.45), 0 0 0 4px rgba(200, 162, 74, 0.12);
}
.form input::placeholder, .inline-form input::placeholder { color: var(--ink-3); }
.row { display: flex; gap: 12px; }
.row label { flex: 1; }
input[type="date"] { color-scheme: dark; }

/* ---- buttons ---- */
.btn {
  padding: 11px 20px; border: none; border-radius: 12px; cursor: pointer;
  font-size: 0.93rem; font-weight: 600; font-family: var(--font); letter-spacing: 0.01em;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), background 0.25s var(--ease), opacity 0.25s;
  will-change: transform;
}
.btn:active { transform: scale(0.97) translateY(1px); }
.btn.primary {
  color: #141006;
  background: linear-gradient(160deg, var(--gold-hi) 0%, var(--gold) 55%, #a8842e 100%);
  box-shadow: inset 0 1px 0 rgba(255, 244, 200, 0.6), 0 10px 26px -10px rgba(200, 162, 74, 0.75);
}
.btn.primary:hover { transform: translateY(-1px); box-shadow: inset 0 1px 0 rgba(255, 244, 200, 0.6), 0 14px 34px -10px rgba(200, 162, 74, 0.95); }
.btn.ghost {
  background: rgba(200, 162, 74, 0.07); border: 1px solid rgba(200, 162, 74, 0.3); color: var(--ink-2);
  box-shadow: inset 0 1px 0 rgba(230, 200, 119, 0.12);
}
.btn.ghost:hover { background: rgba(200, 162, 74, 0.13); color: var(--gold-hi); }
.btn.danger, .btn.warn, .btn.sm {
  background: rgba(200, 162, 74, 0.07); padding: 6px 13px; font-size: 0.8rem; font-weight: 500;
  border: 1px solid rgba(200, 162, 74, 0.18); box-shadow: inset 0 1px 0 rgba(230, 200, 119, 0.08);
}
.btn.danger { color: var(--bad); border-color: rgba(224, 138, 122, 0.35); }
.btn.danger:hover { background: rgba(224, 138, 122, 0.12); }
.btn.warn { color: var(--gold); border-color: rgba(200, 162, 74, 0.35); }
.btn.warn:hover { background: rgba(200, 162, 74, 0.12); }

/* ---- messages / hints ---- */
.msg { margin-top: 14px; font-size: 0.88rem; min-height: 1.3em; text-wrap: pretty; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--bad); }
.hint { color: var(--ink-3); font-size: 0.84rem; margin-bottom: 15px; line-height: 1.6; text-wrap: pretty; }
a { color: var(--accent); }

/* ---- password strength ---- */
.strength { margin: -6px 0 15px; }
.strength-bar {
  height: 6px; background: rgba(0, 0, 0, 0.35); border: 1px solid rgba(200, 162, 74, 0.13);
  border-radius: 6px; overflow: hidden; margin-bottom: 7px; box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}
#strengthFill { height: 100%; width: 0; border-radius: 6px; background: var(--bad); transition: width 0.35s var(--ease), background 0.35s var(--ease); }
.strength-text { font-size: 0.8rem; color: var(--ink-2); margin-bottom: 7px; }
.strength-rules { list-style: none; font-size: 0.77rem; color: var(--ink-3); }
.strength-rules li { transition: color 0.3s; }
.strength-rules li::before { content: '✗ '; color: var(--bad); }
.strength-rules li.pass { color: var(--ok); }
.strength-rules li.pass::before { content: '✓ '; }
#regConfirm.mismatch { border-color: rgba(255, 125, 138, 0.7) !important; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid rgba(200, 162, 74, 0.11); font-size: 0.88rem; }
th { color: var(--ink-3); font-weight: 500; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.07em; }
tbody tr { transition: background 0.25s var(--ease); }
tbody tr:hover { background: rgba(200, 162, 74, 0.06); }
tbody tr:last-child td { border-bottom: none; }

/* ---- keybox ---- */
.keybox {
  background: linear-gradient(160deg, rgba(99, 216, 168, 0.1), rgba(99, 216, 168, 0.04));
  border: 1px solid rgba(99, 216, 168, 0.3); border-radius: var(--radius-md);
  padding: 16px 18px; margin-bottom: 16px; font-size: 0.87rem;
  box-shadow: inset 0 1px 0 rgba(200, 162, 74, 0.13);
  animation: rise 0.5s var(--ease);
}
.keybox code { display: block; margin-top: 8px; word-break: break-all; color: var(--ok); font-size: 0.92rem; font-family: ui-monospace, 'Cascadia Code', monospace; }

/* ---- admin ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  display: flex; gap: 14px; align-items: center; padding: 20px;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.5); -webkit-backdrop-filter: blur(24px) saturate(1.5);
  border-radius: var(--radius-md); border: 1px solid var(--glass-edge);
  box-shadow: var(--glass-inner);
  transition: transform 0.3s var(--ease), background 0.3s var(--ease);
}
.stat:hover { transform: translateY(-2px); background: var(--glass-hi); }
.stat-icon { font-size: 1.55rem; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4)); }
.stat-value { font-size: 1.55rem; font-weight: 600; letter-spacing: -0.02em; }
.stat-label { color: var(--ink-3); font-size: 0.78rem; }
.search { margin-bottom: 16px; }
.badge {
  padding: 4px 11px; border-radius: 8px; font-size: 0.74rem; font-weight: 600; letter-spacing: 0.02em;
  border: 1px solid;
}
.badge.ok { background: rgba(99, 216, 168, 0.1); color: var(--ok); border-color: rgba(99, 216, 168, 0.3); }
.badge.bad { background: rgba(255, 125, 138, 0.1); color: var(--bad); border-color: rgba(255, 125, 138, 0.3); }
.actions { white-space: nowrap; text-align: right; }
.actions .btn { margin-left: 5px; }
code.cid { font-size: 0.76rem; color: var(--accent); word-break: break-all; font-family: ui-monospace, 'Cascadia Code', monospace; }

/* ---- social ---- */
.social-sep { display: flex; align-items: center; gap: 12px; margin: 18px 0 12px; color: var(--ink-3); font-size: 0.78rem; }
.social-sep::before, .social-sep::after { content: ''; flex: 1; height: 1px; background: rgba(200, 162, 74, 0.16); }
.social-btns { display: grid; gap: 8px; }
.social-btn {
  background: rgba(200, 162, 74, 0.1); border: 1px solid rgba(200, 162, 74, 0.28); color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(200, 162, 74, 0.16); cursor: pointer;
}
.social-btn:hover:not(:disabled) { background: rgba(200, 162, 74, 0.18); }
.social-row {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px; margin-bottom: 9px;
  background: rgba(0, 0, 0, 0.24); border: 1px solid rgba(200, 162, 74, 0.13);
  border-radius: var(--radius-sm); flex-wrap: wrap;
}
.social-name { font-weight: 500; min-width: 110px; }
.social-status { flex: 1; font-size: 0.82rem; }
.social-status.on { color: var(--ok); }
.social-status.off { color: var(--ink-3); }
@media (max-width: 640px) { .social-name { min-width: 100%; } .social-status { min-width: 100%; } .social-row .btn { margin-left: auto; } }
.inline-form { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 180px; margin-top: 0; }
.inline-form .btn { align-self: center; }

#profileInfo { color: var(--ink-2); line-height: 2; font-size: 0.92rem; }
#profileInfo strong { color: var(--ink); font-size: 1.05rem; }

/* ---- footer ---- */
footer {
  text-align: center; padding: 22px; color: var(--ink-3); font-size: 0.8rem;
  letter-spacing: 0.03em;
}

/* ---- entry animation ---- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.auth-card, .card, .stat { animation: rise 0.55s var(--ease) backwards; }
.card:nth-child(2), .stats-grid + .card:nth-of-type(2) { animation-delay: 0.06s; }
.card:nth-child(3) { animation-delay: 0.12s; }

/* ---- responsive ---- */

/* แท็บเล็ต */
@media (max-width: 860px) {
  main { padding: 24px 16px 40px; }
  header { padding: 12px 18px; flex-wrap: wrap; gap: 10px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card { padding: 24px; }
  th:nth-child(4), td:nth-child(4) { display: none; } /* ซ่อนคอลัมน์วันที่บนจอแคบ */
}

/* มือถือ — ตารางเปลี่ยนเป็นการ์ดซ้อน */
@media (max-width: 640px) {
  header { margin: 8px 10px 0; padding: 10px 14px; }
  .welcome { font-size: 0.84rem; margin-right: 0; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  main { padding: 18px 12px 34px; }
  .card { padding: 20px 16px; border-radius: 18px; }
  .auth-card { margin-top: 3vh; }
  .row { flex-direction: column; gap: 0; }
  .inline-form { flex-direction: column; }
  .inline-form .btn { width: 100%; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat { padding: 14px; gap: 10px; }
  .stat-icon { font-size: 1.25rem; }
  .stat-value { font-size: 1.2rem; }

  /* ตาราง -> การ์ด */
  table, thead, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody tr {
    background: rgba(200, 162, 74, 0.05);
    border: 1px solid rgba(200, 162, 74, 0.13);
    border-radius: 14px; padding: 6px 14px; margin-bottom: 12px;
    box-shadow: inset 0 1px 0 rgba(200, 162, 74, 0.1);
  }
  tbody tr:hover { background: rgba(200, 162, 74, 0.08); }
  tbody tr td {
    border-bottom: none; padding: 8px 0; font-size: 0.9rem;
    display: flex; justify-content: space-between; align-items: center; gap: 14px;
  }
  tbody tr td::before {
    content: attr(data-label);
    color: var(--ink-3); font-size: 0.76rem; font-weight: 500;
    letter-spacing: 0.03em; flex-shrink: 0;
  }
  tbody tr td:not(.actions) { text-align: right; word-break: break-word; }
  td.actions { justify-content: flex-end; border-top: 1px dashed rgba(200, 162, 74, 0.16); padding-top: 10px; margin-top: 4px; }
  td.actions .btn { margin-left: 0; margin-right: 6px; }
  th:nth-child(4), td:nth-child(4) { display: flex; } /* คืนคอลัมน์วันที่เป็นบรรทัดในการ์ด */
  #noApps { text-align: center; }
}

/* จอเล็กมาก */
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr; }
  .brand { font-size: 0.92rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- toast ---- */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: rgba(12, 17, 32, 0.75); backdrop-filter: blur(20px) saturate(1.5); -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border: 1px solid rgba(255, 125, 138, 0.35); color: var(--bad);
  border-radius: 14px; padding: 12px 22px; font-size: 0.88rem;
  box-shadow: var(--glass-inner), 0 18px 44px -14px rgba(4, 10, 34, 0.95);
  opacity: 0; pointer-events: none; z-index: 50;
  transition: opacity 0.35s var(--ease), transform 0.35s var(--ease);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.ok { border-color: rgba(99, 216, 168, 0.35); color: var(--ok); }
