/* หน้าเข้าสู่ระบบ / 2FA — ใช้ token ชุดเดียวกับ dashboard.css (ธีม "Ledger")
   ธีมตามที่ผู้ใช้เลือกไว้ใน dashboard (localStorage portalTheme) → body.light-theme */
body {
    --ink-0: #0c0e12; --ink-2: #161a21; --ink-3: #1c2129; --ink-4: #242a34;
    --line: #262c36; --line-2: #333a46; --field: #12161c;
    --text: #e9ecf1; --text-2: #bcc3ce; --text-muted: #8f98a7;
    --accent: #f4c152; --accent-hover: #ffd27a; --accent-ink: #1c1505; --accent-fg: #f4c152;
    --accent-soft: rgba(244, 193, 82, 0.13); --accent-line: rgba(244, 193, 82, 0.42);
    --ok: #46d68f; --ok-soft: rgba(70, 214, 143, 0.12); --ok-line: rgba(70, 214, 143, 0.38);
    --bad: #ff7676; --bad-soft: rgba(255, 118, 118, 0.12); --bad-line: rgba(255, 118, 118, 0.4);
    --warn: #ff9a4d; --warn-soft: rgba(255, 154, 77, 0.13); --warn-line: rgba(255, 154, 77, 0.45);
    --rule: rgba(255, 255, 255, 0.035);
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    --font-sans: 'IBM Plex Sans Thai', 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', 'Leelawadee UI', Tahoma, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
}
body.light-theme {
    --ink-0: #f4f2ed; --ink-2: #ffffff; --ink-3: #f6f4ef; --ink-4: #ece8df;
    --line: #e3ded3; --line-2: #d2cbbd; --field: #ffffff;
    --text: #16181d; --text-2: #3b414b; --text-muted: #5f6672;
    --accent: #efb23a; --accent-hover: #f6c25a; --accent-fg: #8a5a00;
    --accent-soft: rgba(239, 178, 58, 0.16); --accent-line: rgba(176, 120, 10, 0.45);
    --ok: #0f7a45; --ok-soft: rgba(15, 122, 69, 0.09); --ok-line: rgba(15, 122, 69, 0.35);
    --bad: #c23535; --bad-soft: rgba(194, 53, 53, 0.08); --bad-line: rgba(194, 53, 53, 0.35);
    --warn: #b9530a; --warn-soft: rgba(217, 112, 20, 0.11); --warn-line: rgba(185, 83, 10, 0.4);
    --rule: rgba(60, 45, 10, 0.05);
    --shadow: 0 24px 60px rgba(38, 30, 10, 0.12);
}
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; }
body {
    margin: 0; min-height: 100vh; padding: 32px 16px;
    font-family: var(--font-sans); line-height: 1.6; color: var(--text);
    background-color: var(--ink-0);
    /* เส้นบรรทัดสมุดบัญชีจาง ๆ — ลายเซ็นของธีม */
    background-image: repeating-linear-gradient(180deg, transparent 0 31px, var(--rule) 31px 32px);
    -webkit-font-smoothing: antialiased;
    font-variant-numeric: tabular-nums;
}
body.auth-center { display: flex; align-items: center; justify-content: center; }
a { color: var(--accent-fg); text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
body.light-theme a:hover { color: #603e00; }
code { font-family: var(--font-mono); color: var(--accent-fg); background: var(--accent-soft); padding: 2px 7px; border-radius: 6px; }

.auth-card {
    position: relative; width: 100%; max-width: 400px;
    background: var(--ink-2); border: 1px solid var(--line); border-radius: 18px;
    box-shadow: var(--shadow); padding: 2.25rem 2rem 1.75rem;
}
.auth-card.wide { max-width: 560px; margin: 0 auto; }
.auth-card::before {   /* แถบทองบาง ๆ ขอบบน */
    content: ''; position: absolute; left: 28px; right: 28px; top: -1px; height: 2px; border-radius: 2px; background: var(--accent);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 1.75rem; }
.brand-mark {
    width: 44px; height: 44px; flex: 0 0 auto; border-radius: 12px; display: grid; place-items: center;
    background: var(--accent); color: var(--accent-ink);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand img { width: 44px; height: 44px; border-radius: 12px; object-fit: contain; }
.brand-name { font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; margin: 0; }
.brand-sub { font-size: 0.85rem; color: var(--text-muted); margin: 2px 0 0; }

.auth-title { font-size: 1.3rem; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
.auth-lead { color: var(--text-muted); font-size: 0.9rem; margin: 0 0 1.5rem; }

.form-label { display: block; color: var(--text-2); font-weight: 500; font-size: 0.88rem; margin-bottom: 0.4rem; }
.form-control {
    display: block; width: 100%; font: inherit; font-size: 1rem; color: var(--text);
    background: var(--field); border: 1px solid var(--line-2); border-radius: 10px;
    padding: 0.7rem 0.9rem; transition: border-color 0.15s, box-shadow 0.15s; outline: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-control::placeholder { color: var(--text-muted); opacity: 0.7; }
.form-text { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.35rem; }
.otp-input { font-family: var(--font-mono); text-align: center; font-size: 1.75rem; font-weight: 600; letter-spacing: 0.45em; padding: 0.6rem 0.5rem 0.6rem 0.95rem; }
.field { margin-bottom: 1.1rem; }
.pw-wrap { position: relative; }
.pw-wrap .form-control { padding-right: 4rem; }
#password::-ms-reveal { display: none; }
.pw-toggle {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: transparent; border: none; color: var(--text-muted); font: inherit; font-size: 0.8rem; font-weight: 600;
    padding: 6px 10px; border-radius: 7px; cursor: pointer;
}
.pw-toggle:hover, .pw-toggle:focus-visible { color: var(--text); background: var(--ink-3); outline: none; }

.btn-auth {
    display: block; width: 100%; margin-top: 1.4rem; padding: 0.78rem 1rem;
    font: inherit; font-size: 1rem; font-weight: 600; color: var(--accent-ink);
    background: var(--accent); border: none; border-radius: 10px; cursor: pointer; transition: background-color 0.15s;
}
.btn-auth:hover { background: var(--accent-hover); }
.btn-auth:focus-visible, .form-control:focus-visible, .btn-ghost:focus-visible, .btn-danger-ghost:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-ghost {
    display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 0.85rem; font-weight: 500; text-decoration: none;
    color: var(--text-2); background: transparent; border: 1px solid var(--line-2); border-radius: 8px; padding: 0.35rem 0.75rem;
}
.btn-ghost:hover { color: var(--text); background: var(--ink-3); }
.btn-danger-ghost {
    font: inherit; font-weight: 600; font-size: 0.92rem; color: var(--bad); background: var(--bad-soft);
    border: 1px solid var(--bad-line); border-radius: 10px; padding: 0.65rem 1rem; cursor: pointer; white-space: nowrap;
}
.btn-danger-ghost:hover { background: var(--bad); color: #fff; }

.alert { border-radius: 10px; padding: 0.65rem 0.85rem; font-size: 0.9rem; margin-bottom: 1rem; border: 1px solid var(--line-2); background: var(--ink-3); color: var(--text); }
.alert-danger { background: var(--bad-soft); border-color: var(--bad-line); }
.alert-success { background: var(--ok-soft); border-color: var(--ok-line); }
.alert-warning { background: var(--warn-soft); border-color: var(--warn-line); }

.auth-foot { color: var(--text-muted); font-size: 0.8rem; text-align: center; margin: 1.5rem 0 0; }
.auth-back { display: block; text-align: center; margin-top: 1.1rem; font-size: 0.88rem; }

/* หน้า 2FA */
.setup-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 1.5rem; flex-wrap: wrap; }
.status-box { display: flex; gap: 12px; align-items: flex-start; border-radius: 12px; padding: 0.9rem 1rem; margin-bottom: 1.5rem; border: 1px solid; }
.status-box.on { background: var(--ok-soft); border-color: var(--ok-line); }
.status-box.off { background: var(--warn-soft); border-color: var(--warn-line); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; flex: 0 0 auto; }
.status-box.on .status-dot { background: var(--ok); }
.status-box.off .status-dot { background: var(--warn); }
.status-box strong { display: block; font-weight: 600; }
.status-box p { margin: 2px 0 0; color: var(--text-2); font-size: 0.88rem; }
.steps { list-style: none; counter-reset: s; padding: 0; margin: 0 0 1.5rem; }
.steps li { counter-increment: s; position: relative; padding-left: 36px; margin-bottom: 0.65rem; color: var(--text-2); font-size: 0.92rem; }
.steps li::before {
    content: counter(s); position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 7px;
    display: grid; place-items: center; font-family: var(--font-mono); font-size: 0.78rem; font-weight: 600;
    background: var(--ink-4); color: var(--text);
}
.qr-wrap { display: flex; justify-content: center; margin-bottom: 1rem; }
.qr-frame { background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--line); line-height: 0; }
.secret-box { background: var(--ink-3); border: 1px solid var(--line); border-radius: 10px; padding: 0.8rem 1rem; text-align: center; margin-bottom: 1.5rem; }
.secret-box small { display: block; color: var(--text-muted); margin-bottom: 4px; font-size: 0.8rem; }
.secret-box code { font-size: 1rem; letter-spacing: 0.18em; word-break: break-all; background: transparent; padding: 0; }
.danger-zone { border: 1px solid var(--bad-line); border-radius: 12px; padding: 1rem 1.1rem; }
.danger-zone h2 { font-size: 0.98rem; font-weight: 600; color: var(--bad); margin: 0 0 4px; }
.danger-zone p { color: var(--text-muted); font-size: 0.86rem; margin: 0 0 0.8rem; }
.inline-form { display: flex; gap: 8px; }
.inline-form .form-control { flex: 1 1 auto; min-width: 0; }

@media (max-width: 480px) {
    body { padding: 20px 14px; }
    .auth-card { padding: 1.75rem 1.25rem 1.4rem; border-radius: 16px; }
    .inline-form { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
