/* ตัวแปรสี */
:root {
    --purple: #6E4DC1;
    --pink: #C56ED2;
    --bg: #050831;
    --surface: #0B1342;
    --surface2: #111B4F;
    --line: #26306B;
    --text: #E8EAF6;
    --muted: #A9B0D6;
    --ok: #34D399;
    --warn: #FBBF24;
    --err: #FB7185;
}

/* รีเซ็ตและฐาน */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* แถบบนสุด */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    font-size: 20px;
    font-weight: 700;
    white-space: nowrap;
}

.logo-baby {
    color: var(--purple);
}

.logo-live {
    color: var(--pink);
}

.nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex: 1;
}

.nav::-webkit-scrollbar {
    display: none;
}

.nav a,
.nav-logout {
    padding: 8px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--muted);
    white-space: nowrap;
    font-size: 15px;
    background: none;
    border: none;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
}

.nav a:hover,
.nav-logout:hover {
    color: var(--text);
    background: var(--surface2);
}

.nav-signup {
    color: var(--pink) !important;
    font-weight: 600;
}

/* แถบแจ้งเตือน */
.flash-container {
    max-width: 960px;
    margin: 16px auto 0;
    padding: 0 16px;
}

.flash {
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 8px;
    font-size: 15px;
}

.flash-success {
    background: rgba(52, 211, 153, 0.15);
    color: var(--ok);
    border: 1px solid var(--ok);
}

.flash-error {
    background: rgba(251, 113, 133, 0.15);
    color: var(--err);
    border: 1px solid var(--err);
}

.flash-info {
    background: rgba(110, 77, 193, 0.15);
    color: var(--purple);
    border: 1px solid var(--purple);
}

/* เนื้อหาหลัก */
.wrap {
    max-width: 960px;
    margin: 0 auto;
    padding: 16px;
    flex: 1;
}

main {
    padding-top: 24px;
    padding-bottom: 32px;
}

/* ปุ่ม */
.btn {
    display: inline-block;
    padding: 12px 24px;
    min-height: 44px;
    border-radius: 12px;
    border: none;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: transform 0.2s, opacity 0.2s;
}

.btn:hover {
    transform: translateY(-1px);
    opacity: 0.9;
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, var(--purple), var(--pink));
    color: white;
}

.btn-ghost {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--line);
}

.btn-block {
    display: block;
    width: 100%;
}

/* การ์ด */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
}

/* ฟอร์ม */
.field {
    margin-bottom: 16px;
}

.field label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    min-height: 44px;
    padding: 12px 16px;
    font-size: 16px;
    font-family: inherit;
    background: var(--surface2);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    transition: border-color 0.2s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--purple);
}

.field textarea {
    min-height: 88px;
    resize: vertical;
}

.hint {
    display: block;
    margin-top: 4px;
    font-size: 14px;
    color: var(--muted);
}

.err-text {
    display: block;
    margin-top: 4px;
    font-size: 14px;
    color: var(--err);
}

/* ป้ายสถานะ */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
}

.badge-ok {
    background: rgba(52, 211, 153, 0.15);
    color: var(--ok);
}

.badge-warn {
    background: rgba(251, 191, 36, 0.15);
    color: var(--warn);
}

.badge-err {
    background: rgba(251, 113, 133, 0.15);
    color: var(--err);
}

/* กริด */
.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 720px) {
    .grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* รหัสไลเซนส์ */
.license-key {
    font-family: "SF Mono", Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 18px;
    letter-spacing: 0.5px;
    background: var(--surface2);
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid var(--line);
    width: 100%;
    color: var(--text);
    user-select: all;
}

/* แถวอุปกรณ์ */
.device-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.device-row:last-child {
    border-bottom: none;
}

/* ตัวอักษรจาง */
.muted {
    color: var(--muted);
}

/* จัดกลาง */
.center {
    text-align: center;
}

/* เรียงแนวตั้ง */
.stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ฟุตเตอร์ */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--line);
    margin-top: auto;
}

.footer-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px;
    text-align: center;
}

.footer-links {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin: 12px 0;
}

.footer-links a {
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
}

.footer-links a:hover {
    color: var(--text);
}

.footer p {
    font-size: 14px;
}

/* โฟกัสที่มองเห็นชัด */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--purple);
    outline-offset: 2px;
}

/* ปิดแอนิเมชันสำหรับคนที่ตั้งค่าลดการเคลื่อนไหว */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
