/* =========================================================
   TIÊN HIỆP THEME — Jade / Gold / Mystic Violet
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@500;600;700&family=Be+Vietnam+Pro:wght@400;500;600;700&display=swap');

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }

:root {
    --ink-deep: #0a0714;
    --violet-veil: #241a3d;
    --lilac: #cabde6;
    --moon: #f3ecd8;
    --accent: #9b7fe0;
    --accent-dim: #7c5cbf;

    --jade: #2fae7a;
    --jade-glow: #6fe3b4;
    --gold: #e9c46a;
    --gold-soft: #f4e3ad;
    --gold-deep: #b8862f;

    --font-title: 'Cormorant Garamond', 'Times New Roman', serif;
    --font-body: 'Be Vietnam Pro', 'Segoe UI', Tahoma, sans-serif;

    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
}

/* ---------- Base / background ---------- */
body {
    font-family: var(--font-body);
    background-color: var(--ink-deep);
    background-image:
        linear-gradient(180deg, rgba(8,6,18,0.75) 0%, rgba(10,7,20,0.45) 35%, rgba(8,6,18,0.85) 100%),
        url('bg.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px calc(20px + var(--safe-r)) calc(20px + var(--safe-b)) calc(20px + var(--safe-l));
    padding-top: calc(20px + var(--safe-t));
    color: var(--lilac);
    position: relative;
    overflow-x: hidden;
}

/* Twinkling star-dust overlay across the whole app */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image:
        radial-gradient(1.5px 1.5px at 10% 20%, rgba(244,227,173,0.9) 0%, transparent 60%),
        radial-gradient(1.5px 1.5px at 80% 15%, rgba(207,182,255,0.8) 0%, transparent 60%),
        radial-gradient(1px 1px at 25% 70%, rgba(244,227,173,0.7) 0%, transparent 60%),
        radial-gradient(1.5px 1.5px at 60% 80%, rgba(111,227,180,0.6) 0%, transparent 60%),
        radial-gradient(1px 1px at 90% 60%, rgba(244,227,173,0.8) 0%, transparent 60%),
        radial-gradient(1.5px 1.5px at 40% 35%, rgba(207,182,255,0.7) 0%, transparent 60%),
        radial-gradient(1px 1px at 50% 5%, rgba(244,227,173,0.7) 0%, transparent 60%),
        radial-gradient(1.5px 1.5px at 15% 90%, rgba(111,227,180,0.5) 0%, transparent 60%);
    background-repeat: repeat;
    background-size: 100% 100%;
    animation: twinkle 5s ease-in-out infinite alternate;
}
@keyframes twinkle {
    0%   { opacity: 0.35; }
    50%  { opacity: 0.9; }
    100% { opacity: 0.5; }
}

/* Everything above the star layer */
.topbar, .card, .admin-card, .admin-wrap, .chat-stage, .chat-wrap {
    position: relative;
    z-index: 1;
}

/* ---------- Jade & Gold ornamental frame (shared) ---------- */
.card, .admin-card, .chat-wrap {
    background: rgba(20, 14, 34, 0.74);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 0;
    box-shadow:
        0 10px 40px rgba(0,0,0,0.5),
        inset 0 0 30px rgba(155, 127, 224, 0.08);
    padding: 34px 30px;
    width: 100%;
    max-width: 420px;
    color: var(--lilac);
}
.admin-card, .admin-wrap .admin-card { max-width: 900px; }
.chat-wrap { padding: 0; }

/* Titles */
.card h1, .admin-card h1, h1, h2 {
    font-family: var(--font-title);
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-top: 0;
    font-size: clamp(22px, 4vw, 28px);
    background: linear-gradient(180deg, var(--gold-soft) 0%, var(--gold) 55%, var(--gold-deep) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 18px rgba(233, 196, 106, 0.35);
}

/* ---------- Forms ---------- */
label { color: var(--lilac); font-size: 13px; }
input[type=text], input[type=password] {
    width: 100%;
    padding: 12px 14px;
    margin: 8px 0 16px;
    border: 1px solid rgba(233, 196, 106, 0.28);
    border-radius: 0;
    font-size: 16px; /* prevents iOS auto-zoom on focus */
    font-family: var(--font-body);
    background: rgba(255,255,255,0.06);
    color: var(--moon);
    transition: border-color .2s, box-shadow .2s;
}
input[type=text]:focus, input[type=password]:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(233, 196, 106, 0.18), 0 0 14px rgba(111, 227, 180, 0.25);
}
input[type=text]::placeholder, input[type=password]::placeholder { color: rgba(202, 189, 230, 0.5); }

button, .btn {
    background: linear-gradient(180deg, var(--jade) 0%, #1f8a5f 100%);
    color: #fff;
    border: 1px solid rgba(233, 196, 106, 0.4);
    padding: 12px 20px;
    border-radius: 0;
    cursor: pointer;
    font-size: 15px;
    font-family: var(--font-body);
    font-weight: 600;
    letter-spacing: 0.3px;
    text-decoration: none;
    display: inline-block;
    min-height: 44px;
    box-shadow: 0 4px 16px rgba(47, 174, 122, 0.25);
    transition: transform .15s, box-shadow .15s, background .2s;
    -webkit-user-select: none;
    user-select: none;
}
button:hover, .btn:hover {
    background: linear-gradient(180deg, var(--jade-glow) 0%, var(--jade) 100%);
    box-shadow: 0 6px 22px rgba(111, 227, 180, 0.4);
}
button:active, .btn:active { transform: scale(0.97); }

.error { color: #ff9b9b; margin-bottom: 12px; font-size: 14px; }
.success { color: var(--jade-glow); margin-bottom: 12px; font-size: 14px; }
.link { text-align: center; margin-top: 14px; font-size: 14px; color: var(--lilac); }
.link a { color: var(--gold); text-decoration: none; }
.link a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar {
    position: fixed; top: 0; left: 0; right: 0;
    background: rgba(15, 11, 26, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(233, 196, 106, 0.25);
    padding: 12px 20px;
    padding-top: calc(12px + var(--safe-t));
    padding-left: calc(20px + var(--safe-l));
    padding-right: calc(20px + var(--safe-r));
    display: flex;
    flex-wrap: wrap;
    row-gap: 6px;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 16px rgba(0,0,0,0.4);
    color: var(--lilac);
    font-family: var(--font-title);
    font-size: 18px;
}
.topbar a {
    color: var(--lilac);
    text-decoration: none;
    margin-left: 14px;
    font-size: 14px;
    font-family: var(--font-body);
    padding: 4px 2px;
}
.topbar a:hover { color: var(--gold); }

/* ---------- Tên trang web (site-brand) ---------- */
.site-brand {
    margin: 70px auto 0;
    padding: 0 16px;
    text-align: center;
    font-family: var(--font-title);
    font-weight: 700;
    letter-spacing: 0.5px;
    font-size: clamp(22px, 5vw, 32px);
    background: linear-gradient(180deg, var(--gold-soft) 0%, var(--gold) 55%, var(--gold-deep) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 18px rgba(233, 196, 106, 0.35);
}

/* ---------- Chat stage ---------- */
.chat-stage {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 0;
    margin-top: 60px;
    width: 100%;
}
.chat-stage.has-brand { margin-top: 14px; }

.character-art {
    height: 70vh;
    max-height: 640px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 20px 40px rgba(0,0,0,0.5)) drop-shadow(0 0 34px rgba(111, 227, 180, 0.3));
    margin-right: -30px;
    pointer-events: none;
    user-select: none;
    animation: characterFloat 6s ease-in-out infinite, characterAura 4s ease-in-out infinite;
    transform-origin: 50% 85%;
    will-change: transform, filter;
}

/* Bồng bềnh nhẹ như đang lơ lửng vận công, kèm nghiêng rất nhẹ cho tự nhiên */
@keyframes characterFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50%      { transform: translateY(-16px) rotate(0.6deg); }
}

/* Hào quang tím quanh người nhấp nháy nhẹ như linh khí đang lưu chuyển */
@keyframes characterAura {
    0%, 100% {
        filter: drop-shadow(0 20px 40px rgba(0,0,0,0.5))
                drop-shadow(0 0 34px rgba(111, 227, 180, 0.3))
                drop-shadow(0 0 18px rgba(155, 127, 224, 0.25));
    }
    50% {
        filter: drop-shadow(0 20px 40px rgba(0,0,0,0.5))
                drop-shadow(0 0 48px rgba(111, 227, 180, 0.45))
                drop-shadow(0 0 34px rgba(155, 127, 224, 0.55));
    }
}

@media (max-width: 900px) {
    .character-art { display: none; }
}

.chat-wrap {
    width: 100%; max-width: 600px;
    display: flex; flex-direction: column;
    height: 70vh;
    overflow: hidden;
}
.chat-header {
    padding: 14px 18px;
    border-bottom: 1px solid rgba(233, 196, 106, 0.2);
    font-weight: 600;
    font-family: var(--font-title);
    font-size: 19px;
    color: var(--gold-soft);
    display: flex; align-items: center; gap: 10px;
    flex-shrink: 0;
}
.chat-body {
    flex: 1; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
}
.msg-row { display: flex; align-items: flex-end; gap: 8px; max-width: 88%; }
.msg-row.bot { align-self: flex-start; }
.msg-row.user { align-self: flex-end; }
.avatar {
    width: 32px; height: 32px; border-radius: 0; object-fit: cover;
    box-shadow: 0 0 0 1px rgba(233, 196, 106, 0.5), 0 0 10px rgba(111, 227, 180, 0.4);
    flex-shrink: 0;
}
.avatar-header { width: 28px; height: 28px; }
.msg { max-width: 100%; padding: 11px 15px; border-radius: 0; font-size: 14.5px; line-height: 1.5; word-break: break-word; }
.msg.user { background: linear-gradient(135deg, var(--accent-dim), var(--accent)); color: #fff; border-bottom-right-radius: 0; }
.msg.bot {
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(233, 196, 106, 0.12);
    color: var(--lilac);
    border-bottom-left-radius: 0;
}
.chat-input {
    display: flex; padding: 12px;
    padding-bottom: calc(12px + var(--safe-b));
    border-top: 1px solid rgba(233, 196, 106, 0.2);
    gap: 8px;
    flex-shrink: 0;
    background: rgba(15, 11, 26, 0.4);
}
.chat-input input {
    flex: 1; margin: 0; padding: 12px 16px; border-radius: 0;
    border: 1px solid rgba(233, 196, 106, 0.28);
    background: rgba(255,255,255,0.06); color: var(--moon);
    font-size: 16px;
}
.chat-input button { border-radius: 0; padding: 10px 20px; }

/* ---------- Tables / Admin ---------- */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 0; }
table {
    width: 100%; min-width: 480px; border-collapse: collapse; margin-top: 16px;
    background: rgba(20, 14, 34, 0.6); border-radius: 0; overflow: hidden; color: var(--lilac);
}
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid rgba(233, 196, 106, 0.12); font-size: 14px; white-space: normal; word-break: break-word; overflow-wrap: anywhere; max-width: 360px; }
th { background: rgba(233, 196, 106, 0.12); color: var(--gold-soft); font-family: var(--font-title); font-weight: 600; letter-spacing: 0.3px; white-space: nowrap; max-width: none; }
td.nowrap { white-space: nowrap; }
.badge { padding: 3px 10px; border-radius: 0; font-size: 12px; color: #fff; display: inline-block; }
.badge.admin { background: linear-gradient(135deg, var(--gold-deep), var(--gold)); color: #241a0a; font-weight: 700; }
.badge.user { background: #6b6480; }
.admin-wrap { max-width: 900px; width: 100%; margin-top: 70px; margin-bottom: 30px; }
.page-wrap { max-width: 420px; width: 100%; margin-top: 70px; margin-bottom: 30px; display: flex; justify-content: center; }
.action-btn { font-size: 12px; padding: 7px 12px; margin: 2px 4px 2px 0; min-height: 34px; }
.action-btn.danger { background: linear-gradient(180deg, #d1544a, #96291d); border-color: rgba(255,255,255,0.15); }
.action-btn.danger:hover { background: linear-gradient(180deg, #e06a5f, #b0362a); }

/* ---------- Topbar action forms (styled as links) ---------- */
.topbar form { display: inline; }
.topbar .link-btn {
    background: none;
    border: none;
    color: var(--lilac);
    text-decoration: none;
    margin-left: 14px;
    padding: 4px 2px;
    font-size: 14px;
    font-family: var(--font-body);
    cursor: pointer;
    min-height: auto;
    box-shadow: none;
}
.topbar .link-btn:hover { color: var(--gold); background: none; box-shadow: none; }

.hint { color: var(--lilac); font-size: 13px; text-align: center; margin-top: -4px; margin-bottom: 18px; opacity: 0.85; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    body { padding: 12px calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l)); }
    .card, .admin-card { padding: 26px 18px; max-width: 100%; }
    .admin-wrap { margin-top: 64px; }
    .page-wrap { margin-top: 64px; }
    .topbar { font-size: 16px; padding: 10px 14px; padding-top: calc(10px + var(--safe-t)); }
    .topbar a { margin-left: 10px; font-size: 13px; }
    .chat-stage { margin-top: 54px; }
    .chat-stage.has-brand { margin-top: 10px; }
    .site-brand { margin-top: 60px; }
    .chat-wrap { height: calc(100dvh - 90px); border-radius: 0; box-shadow: none; }
    .chat-header { font-size: 17px; }
    .msg-row { max-width: 94%; }
    button, .btn { width: 100%; }
    .chat-input button, .action-btn, .topbar .link-btn { width: auto; }
    th, td { padding: 9px 10px; font-size: 13px; }
}

@media (min-width: 641px) and (max-width: 900px) {
    .card, .admin-card { max-width: 460px; }
}

@media (prefers-reduced-motion: reduce) {
    body::before { animation: none; }
    * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
