/* =========================================================
   Linkclub Backoffice — design system
   tokens → base → layout (sidebar) → components → pages
   ========================================================= */

/* ---------- tokens ---------- */
:root {
    --bg: #f8f9fb;
    --surface: #ffffff;
    --surface-2: #f3f5f9;
    --border: #e8ebf0;
    --border-strong: #d8dce6;
    --text: #12141f;
    --text-2: #454a5e;
    --muted: #7b8194;

    --primary: #0ea5e9;
    --primary-2: #0284c7;
    --primary-soft: #e0f2fe;
    --primary-ring: rgba(14, 165, 233, .2);
    --grad: linear-gradient(135deg, #22d3ee 0%, #0ea5e9 55%, #0284c7 100%);

    --success: #12a150;
    --success-soft: #e8f7ee;
    --warning: #b45309;
    --warning-soft: #fff4e5;
    --danger: #dc2626;
    --danger-soft: #fdecec;
    --info: #0369a1;
    --info-soft: #e0f2fe;

    --radius-sm: 10px;
    --radius: 14px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
    --shadow: 0 1px 2px rgba(15, 23, 42, .03), 0 8px 24px rgba(15, 23, 42, .06);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, .1);

    --sb-w: 260px;
    --nav-h: 64px;
    --sb-bg: #ffffff;
    --sb-text: #4a4e68;
    --sb-muted: #8a8fa8;
    --sb-hover: #f3f4f8;

    /* chart (dataviz: series เดียว + chrome หม่น) */
    --series-1: #0ea5e9;
    --grid: #e6e5df;
    --axis: #c3c2b7;
    --ink-muted: #898781;
    --delta-up: #0b7a3b;
    --delta-down: #d03b3b;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }

body.admin {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Sukhumvit Set", sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
.i { flex-shrink: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.hint { display: block; margin-top: 4px; font-size: .84rem; color: var(--muted); }
.error { color: var(--danger); font-size: .84rem; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 560px) { .hide-sm { display: none; } }

.wrap { max-width: 1120px; padding: 28px 16px 96px; margin: 0 auto; }

/* =========================================================
   Sidebar — พื้นขาว เมนูหลัก 3 รายการ + บัญชี/ออกจากระบบด้านล่าง
   ========================================================= */
.sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    width: var(--sb-w);
    display: flex; flex-direction: column;
    background: var(--sb-bg);
    border-right: 1px solid var(--border);
    color: var(--sb-text);
}
.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 24px 16px 28px 24px; }
.sb-brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 800; font-size: 1.15rem; letter-spacing: -.01em; }
.sb-brand img { border-radius: 9px; }
.sb-close { display: none; }

.sb-menu { flex: 1; min-height: 0; overflow-y: auto; padding: 0 14px 16px; }
.sb-label { margin: 0 0 10px; padding: 0 14px; font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--sb-muted); }
.sb-menu ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.sb-item {
    display: flex; align-items: center; gap: 12px;
    width: 100%; min-height: 44px; padding: 0 14px;
    border: 0; border-radius: 12px;
    background: transparent;
    color: var(--sb-text); text-decoration: none;
    font: inherit; font-size: .95rem; font-weight: 600; text-align: left;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.sb-item > .i { color: var(--sb-muted); transition: color .15s; }
.sb-item:hover { background: var(--sb-hover); color: var(--text); }
.sb-item:hover > .i { color: var(--text-2); }
.sb-item.is-active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 14px rgba(14, 165, 233, .32);
}
.sb-item.is-active > .i { color: #fff; }
.sb-item.is-active:hover { background: var(--primary-2); color: #fff; }
.sb-item.is-active:hover > .i { color: #fff; }

.sb-footer { margin: 0 14px; padding: 14px 0 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.sb-footer form { margin: 0; }
.sb-account { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; text-decoration: none; }
.sb-account:hover { background: var(--sb-hover); }
.sb-account.is-active { background: var(--primary-soft); }
.sb-avatar {
    width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--grad); color: #fff; font-weight: 800;
}
.sb-user-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.sb-user-text strong { color: var(--text); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-text small { color: var(--sb-muted); font-size: .78rem; }
.sb-logout:hover { background: var(--danger-soft); color: var(--danger); }
.sb-logout:hover > .i { color: var(--danger); }

.sb-item:focus-visible, .sb-brand:focus-visible, .sb-account:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 2px;
}

body.has-sidebar { padding-left: var(--sb-w); }
/* พื้นหลังหลังบ้าน — แสงฟ้าจางมุมบน เหมือนกันทุกหน้า (เริ่มนับจากขอบ sidebar) */
body.has-sidebar {
    background:
        radial-gradient(900px 420px at var(--sb-w) 0, rgba(14, 165, 233, 0.07), transparent 55%),
        radial-gradient(700px 380px at 100% 8%, rgba(14, 165, 233, 0.05), transparent 50%),
        var(--bg);
    background-repeat: no-repeat;
}
body.has-sidebar .wrap { max-width: 1440px; margin: 0 auto; padding: 20px 40px 40px; }

.sb-overlay { display: none; }

/* ---------- Top navbar (desktop + mobile) ---------- */
.app-navbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    min-height: var(--nav-h); padding: 10px 24px 10px 20px;
    background: rgba(255, 255, 255, .94);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
.nb-left { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.nb-menu {
    display: none;
    align-items: center; justify-content: center;
    width: 44px; height: 44px; padding: 0; flex-shrink: 0;
    border: 0; border-radius: 12px; background: transparent; color: var(--text); cursor: pointer;
}
.nb-menu:hover { background: var(--surface-2); }
.nb-title-wrap { min-width: 0; }
.nb-eyebrow { margin: 0; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.nb-title { margin: 2px 0 0; font-size: 1.15rem; font-weight: 800; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nb-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.nb-user-menu { position: relative; }
.nb-user-menu > summary { list-style: none; cursor: pointer; }
.nb-user-menu > summary::-webkit-details-marker { display: none; }
.nb-user {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px 6px 6px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: border-color .15s, box-shadow .15s;
}
.nb-user:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.nb-user > .i:last-child { color: var(--muted); transition: transform .15s; }
.nb-user-menu[open] > summary .nb-user > .i:last-child { transform: rotate(90deg); }
.nb-user-text { display: flex; flex-direction: column; line-height: 1.2; text-align: left; min-width: 0; }
.nb-user-text strong { font-size: .88rem; color: var(--text); max-width: 14ch; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nb-user-text small { font-size: .74rem; color: var(--muted); }
.nb-avatar { width: 38px; height: 38px; font-size: .95rem; }
.nb-dropdown {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
    min-width: 220px; padding: 6px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.nb-drop-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 10px 12px; border-radius: 10px;
    font: inherit; font-size: .9rem; font-weight: 600; color: var(--text-2);
    text-decoration: none; background: transparent; border: 0; cursor: pointer; text-align: left;
}
.nb-drop-item:hover { background: var(--surface-2); color: var(--text); }
.nb-drop-btn { color: var(--danger); }
.nb-drop-btn:hover { background: var(--danger-soft); color: var(--danger); }
.nb-user-menu form { margin: 0; }

@media (max-width: 959px) {
    body.has-sidebar { padding-left: 0; }
    body.has-sidebar {
        background:
            radial-gradient(600px 320px at 0 0, rgba(14, 165, 233, 0.07), transparent 55%),
            var(--bg);
        background-repeat: no-repeat;
    }
    body.has-sidebar .wrap { margin: 0 auto; padding: 14px 16px 32px; }

    .app-navbar { padding: 8px 12px; }
    .nb-menu { display: inline-flex; }
    .nb-eyebrow { display: none; }
    .nb-title { font-size: 1.05rem; }
    .nb-user-text { display: none; }
    .nb-user { padding: 4px; border-radius: 50%; border-color: transparent; box-shadow: none; }
    .nb-user > .i:last-child { display: none; }

    .sidebar { transform: translateX(-100%); transition: transform .25s cubic-bezier(.2, .7, .2, 1); box-shadow: 0 0 40px rgba(0, 0, 0, .18); border-right: 0; }
    .sidebar-open .sidebar { transform: none; }
    .sb-close {
        display: inline-flex; align-items: center; justify-content: center;
        width: 36px; height: 36px; padding: 0;
        border: 0; border-radius: 10px; background: var(--sb-hover); color: var(--text-2); cursor: pointer;
    }
    .sb-overlay {
        position: fixed; inset: 0; z-index: 35; display: block;
        background: rgba(10, 12, 24, .45);
        opacity: 0; pointer-events: none; transition: opacity .25s;
    }
    .sidebar-open .sb-overlay { opacity: 1; pointer-events: auto; }
    .sidebar-open { overflow: hidden; }
}

/* =========================================================
   Components
   ========================================================= */

/* ---------- page header ---------- */
.ph { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.ph-toolbar { align-items: center; margin-bottom: 16px; }
.ph-toolbar-end { justify-content: flex-end; }
.ph-toolbar .ph-back + .ph-lead { margin-top: 6px; }
.ph-lead { margin: 0; color: var(--muted); font-size: .92rem; max-width: 60ch; }
.ph-main { min-width: 0; }
.ph-back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 6px; font-size: .85rem; font-weight: 600; color: var(--muted); text-decoration: none; }
.ph-back:hover { color: var(--primary); }
.ph-title { font-size: clamp(1.45rem, 2.5vw, 1.75rem); font-weight: 800; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ph-sub { margin-top: 6px; color: var(--muted); font-size: .92rem; max-width: 52ch; }
.ph-sub a { color: var(--muted); }
.ph-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- หัว Folder + แท็บ ---------- */
.folder-head { margin-bottom: 16px; }
.folder-id {
    display: flex; align-items: center; flex-wrap: wrap; gap: 14px 16px;
    margin-top: 8px;
}
.folder-id-text { flex: 1; min-width: 0; }
.folder-id-name { margin: 0; font-size: 1.2rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }
.folder-id-meta { margin: 4px 0 0; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: .88rem; }
.folder-id-url {
    display: inline-flex; align-items: center; gap: 4px;
    min-width: 0; max-width: 100%;
    color: var(--muted); text-decoration: none; font-size: .84rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.folder-id-url:hover { color: var(--primary); }
.folder-id-url .i { flex-shrink: 0; }
.folder-id-meta .btn-icon { width: 26px; min-width: 26px; min-height: 26px; color: var(--muted); }
.folder-id-tools {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
    margin-left: auto;
}
.folder-id-tools .page-card-actions {
    flex-direction: row; align-items: stretch;
    margin: 0; padding: 0; border: 0;
}
.folder-id-tools .page-card-toggle-form { flex: 0 1 auto; min-width: 88px; }
.folder-id-tools .page-card-toggle { width: auto; min-width: 88px; }

.folder-panel { padding: 0; overflow: hidden; margin-bottom: 16px; }
.folder-panel-top {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.folder-panel-top-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.folder-panel-leading { flex-shrink: 0; }
.folder-panel-heading { min-width: 0; }
.folder-panel-sub { margin: 2px 0 0; font-size: .82rem; color: var(--muted); }
.folder-panel-sub strong { color: var(--text-2); font-weight: 700; }
.folder-panel-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.01em;
}
.folder-panel-actions { flex-shrink: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.folder-panel-body { padding: 20px; }
.folder-panel-body > .section-bar.toolbar-card:first-child { margin-top: 0; }
.folder-panel-body > .empty-state { margin: 0; }
.folder-panel-body .link-list { margin: 0; }

/* หน้า ลิงก์ / ตั้งค่า / สถิติ ของ Folder — โซนเต็ม main */
.folder-workspace {
    position: relative;
    isolation: isolate;
    flex: 1;
    width: 100%;
    margin: 0;
    padding: 18px 16px 28px;
    border-top: 1px solid var(--border);
    min-height: calc(100dvh - var(--nav-h));
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.folder-workspace > * { position: relative; }
.folder-workspace .folder-head { width: 100%; margin-bottom: 0; }
.folder-workspace .folder-panel {
    flex: 1;
    width: 100%;
    max-width: none;
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.folder-workspace .folder-panel-body {
    flex: 1;
    padding: 20px 22px 24px;
}
@media (min-width: 960px) {
    .folder-workspace { padding: 22px 40px 36px; }
    .folder-workspace .folder-panel-body { padding: 24px 28px 28px; }
}

.tabs { display: flex; gap: 4px; margin-top: 20px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 10px 14px; margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    color: var(--muted); text-decoration: none; font-weight: 600; font-size: .92rem; white-space: nowrap;
    transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); background: linear-gradient(to top, var(--primary-soft), transparent 70%); }
.tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; border-radius: 8px 8px 0 0; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-height: 44px; padding: 0 16px;
    font: inherit; font-size: .9rem; font-weight: 600; line-height: 1;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    text-decoration: none; white-space: nowrap;
    cursor: pointer;
    transition: background .15s, border-color .15s, box-shadow .15s, transform .1s;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn:active:not(.btn-primary):not(.btn-warning):not(.btn-info):not(.btn-success):not(.btn-danger) {
    transform: translateY(1px);
    box-shadow: none;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--primary-ring); border-color: var(--primary); }
.btn:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }

/* ปุ่มสี — เรียบ ไม่ 3D */
.btn.btn-primary,
.btn.btn-warning,
.btn.btn-info,
.btn.btn-success,
.btn.btn-danger {
    border: none;
    color: #fff;
    box-shadow: none;
    transition: background .15s, filter .15s;
}
.btn.btn-primary { background: #0ea5e9; }
.btn.btn-warning { background: #f59e0b; }
.btn.btn-info { background: #38bdf8; }
.btn.btn-success { background: #22c55e; }
.btn.btn-danger { background: #ef4444; }
.btn.btn-primary:hover,
.btn.btn-warning:hover,
.btn.btn-info:hover,
.btn.btn-success:hover,
.btn.btn-danger:hover {
    filter: brightness(1.05);
    border-color: transparent;
}
.btn.btn-primary:active,
.btn.btn-warning:active,
.btn.btn-info:active,
.btn.btn-success:active,
.btn.btn-danger:active {
    filter: brightness(0.96);
    transform: none;
    box-shadow: none;
}
.btn.btn-primary:focus-visible { box-shadow: 0 0 0 3px var(--primary-ring); }
.btn.btn-warning:focus-visible { box-shadow: 0 0 0 3px rgba(245, 158, 11, .35); }
.btn.btn-info:focus-visible { box-shadow: 0 0 0 3px rgba(56, 189, 248, .4); }
.btn.btn-success:focus-visible { box-shadow: 0 0 0 3px rgba(34, 197, 94, .35); }
.btn.btn-danger:focus-visible { box-shadow: 0 0 0 3px rgba(239, 68, 68, .35); }

.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: #eef0f5; border-color: transparent; }
/* ปุ่มในแถว = สีทึบ (คัดลอก ฟ้า · แก้ไข ส้ม · ลบ แดง) เหมือนปุ่มสถานะ */
.btn-danger-ghost { color: var(--danger); box-shadow: none; }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: #f6c6c6; }

.btn-sm { min-height: 30px; padding: 0 9px; font-size: .8rem; font-weight: 600; border-radius: 8px; gap: 5px; }
.btn-sm .i { width: 15px; height: 15px; }
.btn-icon {
    width: 30px;
    min-width: 30px;
    min-height: 30px;
    padding: 0;
    border-radius: 8px;
}
.btn-icon .i { width: 16px; height: 16px; }
.btn-icon .i { margin: 0; }
.btn-group { display: inline-flex; gap: 4px; }

/* ---------- badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px;
    font-size: .74rem; font-weight: 700; line-height: 1.6;
    border-radius: 999px;
    background: #eef0f5; color: var(--text-2);
    white-space: nowrap;
}
.badge::before { content: ""; display: none; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-amber { background: var(--warning-soft); color: var(--warning); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-violet { background: var(--primary-soft); color: var(--primary); }
.badge-dot::before { display: inline-block; }
.badge-off { background: var(--warning-soft); color: var(--warning); }
.badge-btn {
    margin: 0;
    border: none;
    font: inherit;
    cursor: pointer;
    transition: filter .12s, transform .1s;
}
.badge-btn:hover { filter: brightness(.94); }
.badge-btn:active { transform: scale(.97); }
.badge-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.badge-btn-readonly { cursor: help; }
.badge-btn-readonly:hover { filter: none; }
.user-status-form { display: inline; margin: 0; }
/* ปุ่มสถานะ ใช้งาน / ปิดการใช้งาน — กว้างเท่ากันทุกหน้า */
.btn.btn-status { min-width: 7.5rem; }
.btn.btn-readonly { cursor: help; }
.btn.btn-readonly:hover { filter: none; }
.admin-table td[data-label="สถานะ"] { vertical-align: middle; }
.user-username {
    font-family: ui-monospace, Consolas, monospace;
    font-size: .88rem;
    color: var(--text-2);
    background: var(--surface-2);
    padding: 2px 8px;
    border-radius: 6px;
}

/* ---------- alerts ---------- */
.alert {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px; margin-bottom: 16px;
    border-radius: var(--radius);
    font-size: .92rem; font-weight: 500;
    border: 1px solid transparent;
}
.alert-success { background: var(--success-soft); color: #0b6b35; border-color: #c8ecd6; }
.alert-error { background: var(--danger-soft); color: #b91c1c; border-color: #f6c9c9; }
.alert > span { flex: 1; min-width: 0; }
.alert { transition: opacity .2s ease, transform .2s ease; }
.alert.is-leaving { opacity: 0; transform: translateY(-4px); }
.alert-close {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 32px; height: 32px; margin: -6px -6px -6px 0;
    border: 0; border-radius: var(--radius-sm); background: transparent; color: inherit;
    opacity: .7; cursor: pointer;
}
.alert-close:hover { opacity: 1; background: rgba(0, 0, 0, .06); }
.alert-close:focus-visible { opacity: 1; outline: 2px solid currentColor; outline-offset: 1px; }

/* ---------- confirm dialog ---------- */
.confirm {
    width: min(400px, calc(100vw - 32px));
    padding: 24px; border: 0; border-radius: var(--radius-lg);
    background: var(--surface); color: inherit; box-shadow: var(--shadow-lg);
    text-align: center;
}
.confirm::backdrop { background: rgba(17, 20, 42, .5); }
.confirm[open] { animation: confirm-in .16s ease-out; }
@keyframes confirm-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.confirm-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 48px; height: 48px; margin-bottom: 12px;
    border-radius: 50%; background: var(--danger-soft); color: var(--danger);
}
.confirm-title { margin: 0 0 6px; font-size: 1.08rem; line-height: 1.4; overflow-wrap: anywhere; }
.confirm-desc { margin: 0 0 20px; color: var(--muted); font-size: .9rem; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; }

.user-create-modal {
    width: min(440px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    overflow: auto;
    padding: 22px 22px 20px;
    text-align: left;
}
.user-create-title { margin-bottom: 14px; text-align: center; }
.user-create-alert { margin-bottom: 12px; text-align: left; }
.user-create-fields { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.user-create-fields .field { margin: 0; }
.user-create-fields .hint { margin: 4px 0 0; }
.user-create-names { gap: 0 12px; }
.user-create-actions { margin-top: 4px; }
.users-row-actions { justify-content: flex-end; flex-wrap: wrap; }

/* ---------- cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin: 0 0 16px;
    min-width: 0;
}
.card-title { font-size: 1rem; font-weight: 700; margin: 0 0 12px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; }

/* ฟอร์มแบบแบ่งหมวด: ซ้ายคำอธิบาย / ขวาช่องกรอก */
.form-card { padding: 0; overflow: hidden; box-shadow: var(--shadow); }
.fs { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 22px 20px; }
.fs + .fs, .fs-more, .fs-more .fs { border-top: 1px solid var(--border); }
@media (min-width: 900px) {
    .fs { grid-template-columns: 240px minmax(0, 1fr); gap: 48px; padding: 28px 32px; align-items: start; }
    .fs-info { position: sticky; top: 20px; }
}
.fs-info h2 {
    position: relative; margin: 0; padding-left: 14px;
    font-size: 1.02rem; font-weight: 800; letter-spacing: -.01em; color: var(--text);
}
.fs-info h2::before {
    content: ""; position: absolute; left: 0; top: .2em; bottom: .2em; width: 4px;
    border-radius: 4px; background: var(--primary);
}
.fs-info p { margin-top: 8px; font-size: .86rem; line-height: 1.45; color: var(--muted); }
.fs-body { min-width: 0; display: flex; flex-direction: column; gap: 0; }

.fs-more > summary {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 16px 28px; cursor: pointer; list-style: none;
    font-weight: 600; font-size: .92rem; color: var(--text-2);
    background: var(--surface-2); border-top: 1px solid var(--border);
}
.fs-more > summary::-webkit-details-marker { display: none; }
.fs-more > summary:hover { background: #eef2f8; color: var(--text); }
.fs-more[open] > summary { color: var(--primary); background: var(--primary-soft); }
.fs-more > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.fs-more > summary .i { transition: transform .2s; color: var(--muted); }
.fs-more[open] > summary .i { transform: rotate(90deg); }
.fs-more > summary small { font-weight: 400; color: var(--muted); }
@media (max-width: 899px) { .fs-more > summary { padding: 16px 20px; } }

/* แถบบันทึก — ติดขอบล่างจอเสมอ */
.savebar {
    position: sticky; bottom: 16px; z-index: 5;
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 20px;
    margin-top: 16px; padding: 12px 14px 12px 18px;
    background: rgba(255, 255, 255, .94);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.savebar .switch { padding: 0; }
.savebar-actions { display: flex; gap: 8px; margin-left: auto; }
@media (max-width: 560px) { .savebar-actions { width: 100%; } .savebar-actions .btn { flex: 1; } }

/* โซนลบ */
.danger-zone {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 20px;
    margin-top: 32px; padding: 18px 22px;
    border: 1px solid #f3c9c9; border-radius: var(--radius-lg); background: #fffafa;
    box-shadow: var(--shadow-sm);
}
.danger-zone h2 { font-size: .95rem; color: var(--danger); }
.danger-zone p { font-size: .86rem; color: var(--muted); margin-top: 2px; }
.danger-zone form { margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }
.field-label, .field > span:first-child { font-weight: 600; font-size: .88rem; color: var(--text-2); }
.field-label .req { color: var(--danger); }

.input, .field input[type=text], .field input[type=url], .field input[type=password], .field input[type=email], .field select, .field textarea, .filters select {
    width: 100%;
    min-height: 44px;
    padding: 10px 13px;
    font: inherit; font-size: 15px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    transition: border-color .15s, box-shadow .15s;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: #bfc3d1; }
.field input:focus, .field select:focus, .field textarea:focus, .filters select:focus, .filters input:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring);
}
.field input[readonly] { background: var(--surface-2); color: var(--muted); }
.field.has-error .field-label { color: var(--danger); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); background: #fffcfc; }
.field.has-error .input-prefix { border-color: var(--danger); }
.field.has-error .editor { border-color: var(--danger); }
.field .error {
    margin: 0; padding: 8px 11px;
    font-size: .84rem; font-weight: 500; line-height: 1.4;
    color: #b91c1c; background: var(--danger-soft);
    border-radius: var(--radius-sm); border: 1px solid #f6c9c9;
}
@media (max-width: 560px) { .field input, .field select, .field textarea { font-size: 16px; } }

input[type=color] { width: 56px; height: 44px; padding: 3px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); cursor: pointer; }
/* ช่องข้อความ + ปุ่มเลือกสีท้ายช่อง */
.input-color { display: flex; gap: 8px; align-items: stretch; }
.input-color input[type=text] { flex: 1; min-width: 0; }
.input-color input[type=color] { flex-shrink: 0; height: auto; min-height: 44px; }
input[type=file] { font: inherit; font-size: .88rem; max-width: 100%; color: var(--text-2); }
input[type=file]::file-selector-button {
    margin-right: 10px; padding: 8px 14px;
    font: inherit; font-weight: 600; font-size: .85rem;
    color: var(--text); background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: 9px; cursor: pointer;
}
input[type=file]::file-selector-button:hover { background: #eef0f5; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

.input-prefix { display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.input-prefix:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
/* prefix ไม่หด — แสดง URL เต็ม เว้นจอแคบจริงๆ ถึงตัดด้วย … (ช่องกรอกเหลืออย่างน้อย 8em) */
.input-prefix span { display: flex; align-items: center; flex: 0 1 auto; min-width: 0; padding: 0 12px; background: var(--surface-2); color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--border); }
.field .input-prefix input { flex: 1 0 8em; min-width: 8em; border: 0; border-radius: 0; box-shadow: none; }

/* switch (checkbox แบบสวิตช์) */
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; padding: 4px 0; position: relative; }
.switch + .switch { margin-top: 12px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
    position: relative; flex-shrink: 0;
    width: 42px; height: 24px; margin-top: 1px;
    border-radius: 999px; background: #cfd3de;
    transition: background .2s;
}
.switch-track::after {
    content: ""; position: absolute; top: 3px; left: 3px;
    width: 18px; height: 18px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
    transition: transform .2s;
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 4px var(--primary-ring); }
.switch input:disabled + .switch-track { opacity: .5; }
.switch input:disabled ~ .switch-text { opacity: .6; }
.switch-text { display: flex; flex-direction: column; }
.switch-text strong { font-size: .92rem; font-weight: 600; }
.switch-text small { font-size: .82rem; color: var(--muted); }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .86rem; color: var(--text-2); }
.check input { width: 16px; height: 16px; accent-color: var(--danger); }

/* รูปภาพในฟอร์ม */
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.upload-box, .image-field {
    display: flex; flex-direction: column; gap: 10px; padding: 16px;
    border: 1px dashed var(--border-strong); border-radius: var(--radius-lg);
    background: var(--surface-2);
}
.upload-box { margin-bottom: 18px; }
.upload-box:last-child { margin-bottom: 0; }
.image-field { margin: 0; }
.image-field .field-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.image-row { display: flex; gap: 14px; align-items: center; }
.image-input { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
.image-input .hint { margin: 0; }
.preview { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; background: #e9ebf2; border: 1px solid var(--border); flex-shrink: 0; }
.preview.wide { width: 128px; height: 72px; }
.preview.is-empty { display: none; }
.preview-empty { display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; border-radius: 12px; background: #e9ebf2; color: #a5a9bb; flex-shrink: 0; }
.preview-empty.wide { width: 128px; height: 72px; }
.preview:not(.is-empty) + .preview-empty { display: none; }
/* ช่องอัปโหลดรูป — ปุ่มลบมุมขวาบนแบบเดียวกับรูปโปรไฟล์ */
.image-thumb { position: relative; flex-shrink: 0; display: inline-flex; }
.upload-box .image-row { align-items: flex-start; }
.upload-box .preview,
.upload-box .preview-empty { width: 160px; height: 160px; border-radius: 14px; }
/* รูปลิงก์ (16:9) — แสดงทั้งรูปไม่ครอป */
.upload-box .preview.wide,
.upload-box .preview-empty.wide { width: 240px; max-width: 45vw; height: auto; aspect-ratio: 16 / 9; }
.upload-box .preview.wide { object-fit: contain; }

/* รูปโปรไฟล์ — กล่องสี่เหลี่ยม กดแล้วเลือกไฟล์ รูปเต็มกล่อง */
.avatar-drop-wrap { margin-top: 16px; max-width: 160px; }
.avatar-drop-shell { position: relative; width: 100%; }
.avatar-drop-del {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 4;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 50%;
    color: #fff;
    background: var(--danger);
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .28), 0 0 0 2px rgba(255, 255, 255, .85);
    transition: filter .15s, transform .15s, box-shadow .15s;
}
.avatar-drop-del:hover {
    filter: brightness(1.05);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .32), 0 0 0 2px rgba(255, 255, 255, .9);
}
.avatar-drop-del:active { transform: translateY(0) scale(.94); }
.avatar-drop-del:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.avatar-drop-del .i { pointer-events: none; }
.avatar-drop {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 1;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
    cursor: pointer;
    overflow: hidden;
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.avatar-drop-label {
    position: absolute;
    inset: 0;
    z-index: 0;
    cursor: pointer;
}
.avatar-drop:hover { border-color: var(--primary); background: var(--primary-soft); }
.avatar-drop:focus-within {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-color: var(--primary);
}
.avatar-drop-input {
    position: absolute;
    inset: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}
.avatar-drop-img {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: none;
    border-radius: 0;
    background: transparent;
}
.avatar-drop-img.is-empty { display: none; }
.avatar-drop-empty {
    position: absolute;
    inset: 0;
    z-index: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    text-align: center;
    font-size: .78rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--muted);
    pointer-events: none;
}
.avatar-drop:has(.avatar-drop-img:not(.is-empty)) .avatar-drop-empty { display: none; }
.fs-profile .fs-body { gap: 12px; }
.fs-profile .fs-body .field:last-child { margin-bottom: 0; }
@media (max-width: 899px) {
    .fs-profile .avatar-drop-wrap { max-width: 140px; }
}

/* sticky action bar */
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.form-actions.sticky {
    position: sticky; bottom: 0; z-index: 5;
    margin: 4px 0 0; padding: 14px 0;
    background: linear-gradient(to top, var(--bg) 72%, rgba(245, 246, 250, 0));
}
.form-actions[hidden] { display: none; }

/* radio cards (ประเภทลิงก์) */
.radio-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.radio-card { position: relative; }
.radio-card input { position: absolute; opacity: 0; }
.radio-card-body {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 18px 14px; min-height: 120px;
    border: 1.5px solid var(--border-strong); border-radius: var(--radius-lg);
    cursor: pointer; font-weight: 600; font-size: .9rem; text-align: center;
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.radio-card-body small { font-weight: 400; color: var(--muted); font-size: .8rem; }
.radio-card input:checked + .radio-card-body { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px var(--primary-ring); }
.radio-card input:focus-visible + .radio-card-body { outline: 2px solid var(--primary); outline-offset: 2px; }
.type-demo { display: block; width: 78%; border-radius: 6px; background: #d4d8e4; }
.radio-card input:checked + .radio-card-body .type-demo { background: #7dd3fc; }
.type-featured_card { height: 46px; }
.type-bar { height: 14px; margin: 16px 0; }

/* theme picker */
.theme-picker { display: grid; grid-template-columns: repeat(auto-fill, 80px); gap: 8px; }
.theme-name { white-space: nowrap; font-size: .76rem !important; }
.theme-option { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; }
.theme-option input { position: absolute; opacity: 0; }
.theme-name { font-size: .8rem; font-weight: 600; color: var(--text-2); }
.theme-swatch {
    display: flex; flex-direction: column; justify-content: center; gap: 5px;
    width: 100%; aspect-ratio: 4 / 5; padding: 8px;
    border-radius: 12px; border: 2px solid var(--border);
    background: var(--bg);
    --pi: color-mix(in oklab, var(--bg) 82%, #000);
    transition: border-color .15s, box-shadow .15s;
}
.theme-swatch span { display: block; height: 12px; border-radius: 4px; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.theme-swatch span:first-child { height: 26px; }
.theme-option input:checked + .theme-swatch { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.theme-option input:focus-visible + .theme-swatch { outline: 2px solid var(--primary); outline-offset: 2px; }
.swatch-gradient { background: linear-gradient(170deg, color-mix(in oklab, var(--bg) 65%, #fff), var(--bg) 50%, color-mix(in oklab, var(--bg) 78%, #000)); }
.swatch-dots { background-image: radial-gradient(var(--pi) 1.2px, transparent 1.4px); background-size: 9px 9px; }
.swatch-grid { background-image: linear-gradient(var(--pi) 1px, transparent 1px), linear-gradient(90deg, var(--pi) 1px, transparent 1px); background-size: 12px 12px; }
.swatch-stripes { background-image: repeating-linear-gradient(135deg, transparent 0 7px, var(--pi) 7px 8px); }
.swatch-glass {
    background:
        radial-gradient(60% 45% at 15% 10%, color-mix(in oklab, var(--bg) 55%, #fff), transparent 70%),
        radial-gradient(55% 40% at 90% 40%, color-mix(in oklab, var(--bg) 70%, #ff6aa2), transparent 70%),
        radial-gradient(60% 45% at 30% 95%, color-mix(in oklab, var(--bg) 70%, #5b8cff), transparent 70%),
        var(--bg);
}
.swatch-glass span { background: rgba(255, 255, 255, .6); }
.swatch-dark { background: radial-gradient(80% 45% at 50% 0%, color-mix(in oklab, var(--bg) 45%, transparent), transparent 75%), #0e0e12; }
.swatch-dark span { background: #1f1f27; box-shadow: none; }

/* ---------- empty state ---------- */
.empty-state {
    display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px;
    padding: 48px 20px;
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
}
.empty-icon { display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 14px; background: var(--primary-soft); color: var(--primary); margin-bottom: 4px; }
.empty-state h3 { font-size: 1.05rem; }
.empty-state p { color: var(--muted); font-size: .9rem; max-width: 40ch; }
.empty-state .btn { margin-top: 10px; }

/* ---------- avatar ---------- */
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: #eef0f5; }
.avatar-initial { display: inline-flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; background: var(--grad); }
.avatar-sm { width: 36px; height: 36px; font-size: .9rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.3rem; }

/* ---------- table ---------- */
.table-card { padding: 0; overflow: hidden; box-shadow: var(--shadow); }
.table-card .table tbody tr { transition: background .12s; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
    text-align: left; padding: 12px 16px;
    font-size: .76rem; font-weight: 700; letter-spacing: .02em; color: var(--muted);
    background: var(--surface-2); border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table td { padding: 14px 16px; border-bottom: 1px solid #eff0f5; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfd; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; width: 1%; }
.table .center { text-align: center; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.cell-user { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell-user strong { display: flex; align-items: center; gap: 6px; }
.cell-user small { color: var(--muted); }
@media (max-width: 640px) {
    .admin-table.table--stacked thead { display: none; }
    .admin-table.table--stacked,
    .admin-table.table--stacked tbody,
    .admin-table.table--stacked tr,
    .admin-table.table--stacked td { display: block; width: 100%; }
    .admin-table.table--stacked tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
    .admin-table.table--stacked td { padding: 4px 0; border: 0; text-align: left !important; width: auto !important; }
    .admin-table.table--stacked td[data-label]::before { content: attr(data-label) " · "; color: var(--muted); font-size: .8rem; }
}

/* =========================================================
   Pages
   ========================================================= */

/* ---------- Folder ---------- */

.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; align-content: start; }
.page-card {
    display: flex; flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: visible;
    transition: box-shadow .2s, border-color .2s, transform .2s;
}
.page-card:hover { box-shadow: var(--shadow); border-color: var(--border-strong); transform: translateY(-2px); }
.page-card { position: relative; cursor: pointer; }
.page-card-hit {
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: var(--radius-lg);
    text-decoration: none;
}
.page-card-hit:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}
.page-card-cover,
.page-card-body { pointer-events: none; }
.page-card-copy,
.page-card-actions,
.page-card-actions * { pointer-events: auto; }
.page-card-cover {
    position: relative; z-index: 2;
    height: 56px; background: var(--cover, #e9ebf2);
    border-radius: calc(var(--radius-lg) - 1px) calc(var(--radius-lg) - 1px) 0 0;
}
.page-card-status {
    position: absolute; top: 10px; right: 10px;
    background: rgba(255, 255, 255, .92);
    box-shadow: var(--shadow-sm);
    font-size: .76rem;
}
.page-card.is-off .page-card-cover { background: var(--surface-2); }
.page-card.is-off .avatar-lg { filter: grayscale(.6); opacity: .75; }
.page-card:hover .page-card-name { color: var(--primary-2); }
/* การ์ด Folder — «จัดการลิงก์» ปุ่มหลัก · ที่เหลือ (รวมเปิด/ปิด) ในเมนู ⋮ */
.page-card-actions {
    display: flex; align-items: stretch; gap: 8px;
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.page-card-main { flex: 1; min-width: 0; min-height: 42px; font-size: .88rem; }
.page-card-toggle-form { flex: 1; min-width: 0; margin: 0; display: flex; }
.page-card-toggle {
    width: 100%;
    min-height: 42px;
    font-size: .86rem;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}
.page-card-toggle.btn-warning,
.page-card-toggle.btn-success { width: 100%; }

.page-card-menu { position: relative; flex-shrink: 0; }
.page-card-menu-trigger {
    width: 42px; min-width: 42px; min-height: 42px; padding: 0;
    list-style: none; cursor: pointer;
}
.page-card-menu-trigger::-webkit-details-marker { display: none; }
.page-card-menu[open] > .page-card-menu-trigger {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
}
.page-card-menu-panel {
    position: absolute; right: 0; z-index: 20;
    min-width: 212px; padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.page-card-menu--foot .page-card-menu-panel {
    bottom: calc(100% + 8px);
    top: auto;
}
.page-card-menu form { margin: 0; }
.page-card-menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 10px 12px; border: 0; border-radius: 10px;
    font: inherit; font-size: .88rem; font-weight: 600; line-height: 1.25;
    color: var(--text-2); text-decoration: none; text-align: left;
    background: transparent; cursor: pointer;
    transition: background .12s, color .12s;
}
.page-card-menu-item .i { color: var(--muted); flex-shrink: 0; }
.page-card-menu-item:hover { background: var(--surface-2); color: var(--text); }
.page-card-menu-item:hover .i { color: var(--text-2); }
.page-card-menu-item.is-danger { color: var(--danger); }
.page-card-menu-item.is-danger .i { color: var(--danger); }
.page-card-menu-item.is-danger:hover { background: var(--danger-soft); color: var(--danger); }
.page-card-menu-sep { height: 1px; margin: 4px 8px; background: var(--border); }

.page-crud-inline {
    display: inline-flex; flex-wrap: nowrap; align-items: center; justify-content: flex-end; gap: 4px;
}
.page-crud-form { margin: 0; display: inline-flex; }
.page-crud-inline .btn { min-height: 30px; font-size: .8rem; }

.page-card-body {
    position: relative; z-index: 2;
    padding: 0 20px 18px; display: flex; flex-direction: column; gap: 12px; flex: 1;
}
.page-card-top {
    display: flex; align-items: flex-end; gap: 10px;
    margin-top: -20px;
    position: relative; z-index: 2;
}
.page-card .avatar-lg {
    position: relative; z-index: 1;
    border: 3px solid #fff; box-shadow: var(--shadow-sm);
    background: var(--surface);
}
.page-card-name { font-size: clamp(1.25rem, 2.2vw, 1.45rem); font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.page-card-head { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.page-card-url-row { display: flex; align-items: center; gap: 2px; min-width: 0; }
.page-card-url {
    min-width: 0; font-size: .84rem; color: var(--muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.page-card-copy { position: relative; z-index: 3; width: 26px; min-width: 26px; min-height: 26px; color: var(--muted); }
.page-card-copy:hover { color: var(--primary); }
.page-card-stats {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px;
    font-size: .88rem; color: var(--muted);
}
.page-card-stats > span { display: inline-flex; align-items: center; gap: 6px; }
.page-card-stats strong { color: var(--text); font-size: 1.05em; font-weight: 800; }
.page-card-new {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
    min-height: 200px;
    border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg);
    color: var(--muted); text-decoration: none; font-weight: 600;
    transition: border-color .15s, color .15s, background .15s;
}
.page-card-new:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.page-card-new .empty-icon { margin: 0; }

/* หน้า Folder / ใน Folder — main เต็มความกว้าง (ไม่ถูก max-width 1120/1440 บีบ) */
body.has-sidebar .wrap:has(.pages-canvas),
body.has-sidebar .wrap:has(.folder-workspace) {
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - var(--nav-h));
}
body.has-sidebar .wrap:has(.pages-canvas) > .alert,
body.has-sidebar .wrap:has(.folder-workspace) > .alert {
    margin: 14px 24px 0;
    flex-shrink: 0;
}
@media (min-width: 960px) {
    body.has-sidebar .wrap:has(.pages-canvas) > .alert,
    body.has-sidebar .wrap:has(.folder-workspace) > .alert { margin-inline: 40px; }
}

/* โซน Folder — พื้นหลังใช้ของ body.has-sidebar ร่วมกับทุกหน้า */
.pages-canvas {
    position: relative;
    isolation: isolate;
    flex: 1;
    width: 100%;
    margin: 0;
    padding: 18px 16px 28px;
    border-radius: 0;
    border: 0;
    border-top: 1px solid var(--border);
    min-height: calc(100dvh - var(--nav-h));
    overflow: hidden;
    background: transparent;
}
.pages-canvas > * { position: relative; z-index: 1; }
.pages-canvas .ph-toolbar { margin-bottom: 14px; max-width: 1600px; }
.pages-canvas .pages-toolbar,
.pages-canvas .pages-no-match,
.pages-canvas .page-grid,
.pages-canvas .pages-views,
.pages-canvas .pages-list-card {
    position: relative;
    z-index: 0;
    max-width: 1600px;
    width: 100%;
}
.pages-canvas .page-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
}
.pages-canvas .empty-state-inset { max-width: 560px; margin-inline: auto; }

.pages-toolbar { max-width: 1600px; width: 100%; margin-bottom: 12px; gap: 8px; }
.pages-search {
    flex: 1 1 220px;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: border-color .15s, box-shadow .15s;
}
.pages-search:focus-within {
    border-color: rgba(14, 165, 233, .45);
    box-shadow: 0 0 0 3px var(--primary-ring);
    background: var(--surface);
}
.pages-search-ic { color: var(--muted); display: inline-flex; }
.pages-search-input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: .92rem;
    color: var(--text);
    outline: none;
}
.pages-search-input::placeholder { color: var(--muted); }
.pages-status-wrap { flex-shrink: 0; }
.pages-sort-wrap { flex-shrink: 0; }
.pages-select,
.pages-sort {
    min-height: 40px;
    padding: 8px 32px 8px 12px;
    font: inherit;
    font-size: .87rem;
    font-weight: 600;
    color: var(--text-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237b8194' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
    appearance: none;
    cursor: pointer;
}
/* dropdown กรอง/เรียง — เมนูแทน select native (admin.js) */
.lc-select-native { display: none !important; }
.admin-table-card:has(.lc-select.is-open) { overflow: visible; }
.admin-table-toolbar:has(.lc-select.is-open) { position: relative; z-index: 20; }
.lc-select { position: relative; }
.lc-select-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding-right: 10px;
    background-image: none;
    text-align: left;
    transition: border-color .15s, box-shadow .15s;
}
.lc-select-btn:hover { border-color: var(--border-strong); }
.lc-select-btn:focus-visible,
.lc-select.is-open .lc-select-btn {
    outline: none;
    border-color: rgba(14, 165, 233, .45);
    box-shadow: 0 0 0 3px var(--primary-ring);
}
.lc-select-text { flex: 1; white-space: nowrap; }
.lc-select-chev { display: inline-flex; color: var(--muted); transition: transform .18s; }
.lc-select.is-open .lc-select-chev { transform: rotate(180deg); color: var(--primary); }
.lc-select-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 40;
    min-width: 100%;
    max-width: min(360px, calc(100vw - 32px));
    max-height: 280px;
    margin: 0;
    padding: 6px;
    list-style: none;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    outline: none;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity .15s, transform .15s, visibility 0s .15s;
}
.lc-select.is-open .lc-select-menu {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: opacity .15s, transform .15s;
}
.lc-select-opt {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    font-size: .87rem;
    font-weight: 500;
    color: var(--text-2);
    white-space: nowrap;
    border-radius: 8px;
    cursor: pointer;
}
.lc-select-opt-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.lc-select-text { overflow: hidden; text-overflow: ellipsis; }
.lc-select-check { display: inline-flex; color: var(--primary); visibility: hidden; }
.lc-select-opt.is-active { background: var(--surface-2); color: var(--text); }
.lc-select-opt[aria-selected="true"] { color: var(--primary-2); font-weight: 600; }
.lc-select-opt[aria-selected="true"] .lc-select-check { visibility: visible; }
.pages-filter-meta {
    margin: 0;
    margin-left: auto;
    font-size: .84rem;
    color: var(--muted);
    white-space: nowrap;
}
.pages-no-match {
    max-width: 1600px;
    margin: 0 0 12px;
}
.pages-canvas > .admin-table-empty {
    padding: 12px 14px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
[data-page-item].is-filtered-out,
[data-user-item].is-filtered-out,
[data-table-paginate] tbody tr.is-page-hidden { display: none !important; }
.users-no-match { margin-bottom: 12px; }

/* ---------- ตารางหลังบ้าน (รูปแบบเดียวกันทุกหน้า) ---------- */
.admin-table-card {
    padding: 0;
    margin-bottom: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.admin-table-card > .card-title {
    margin: 0;
    padding: 14px 14px 10px;
    font-size: 1rem;
}
.admin-table-card > .empty { margin: 0; padding: 8px 14px 14px; }
.admin-table-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.admin-table-toolbar .pages-search { min-height: 40px; flex: 1 1 180px; min-width: 0; }
.admin-table-toolbar .pages-status-wrap,
.admin-table-toolbar .pages-sort-wrap { flex-shrink: 0; }
.admin-table-toolbar .pages-select,
.admin-table-toolbar .pages-sort { min-height: 38px; }
.admin-table-toolbar .pages-filter-meta {
    flex: 1 1 100%;
    margin: 0;
    text-align: right;
    font-size: .82rem;
}
@media (min-width: 900px) {
    .admin-table-toolbar .pages-filter-meta {
        flex: 0 0 auto;
        margin-left: auto;
    }
}
.pages-canvas .pages-toolbar.admin-table-toolbar {
    max-width: 1600px;
    width: 100%;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.pages-canvas:has(.pages-views[data-view="list"]) > .pages-toolbar.admin-table-toolbar {
    margin-bottom: 0;
    border-bottom: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: none;
}
.pages-canvas:has(.pages-views[data-view="list"]) > .admin-table-empty {
    margin-bottom: 0;
    border-radius: 0;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}
.pages-views[data-view="list"] .pages-list-card.admin-table-card {
    margin-top: 0;
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    box-shadow: var(--shadow);
}
.pages-canvas:has(.pages-views[data-view="list"]) > .pages-toolbar.admin-table-toolbar,
.pages-views[data-view="list"] .pages-list-card.admin-table-card {
    max-width: 1600px;
    width: 100%;
    margin-inline: auto;
}
.admin-table-empty {
    margin: 0;
    border: 0;
    border-radius: 0;
    border-bottom: 1px dashed var(--border-strong);
    padding: 10px 12px;
    box-shadow: none;
    max-width: none;
    text-align: center;
    font-size: .9rem;
    color: var(--text-2);
    background: var(--surface);
}
.admin-table-empty[hidden] { display: none !important; }
[data-table-paginate] .admin-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: .9rem;
}
[data-table-paginate] .admin-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: .76rem;
    font-weight: 700;
    letter-spacing: .02em;
    color: var(--muted);
    background: var(--surface);
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
}
[data-table-paginate] .admin-table td {
    padding: 10px 14px;
    border-bottom: 1px solid #eff0f5;
    vertical-align: middle;
}
[data-table-paginate] .admin-table tbody tr:last-child td { border-bottom: 0; }
[data-table-paginate] .admin-table tbody tr:hover { background: #fafbfd; }
[data-table-paginate] .admin-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    width: 1%;
}
[data-table-paginate] .admin-table .actions { text-align: right; white-space: nowrap; }
[data-table-paginate] .admin-table col.col-main { width: 46%; }
[data-table-paginate] .admin-table col.col-status { width: 9rem; }
[data-table-paginate] .admin-table col.col-num { width: 7.5rem; }
[data-table-paginate] .admin-table col.col-actions { width: 17rem; }
[data-table-paginate] .admin-table-cols-3 col.col-main { width: 52%; }
.admin-table col.col-username { width: 24%; }
.cell-username { color: var(--text-2); }
[data-table-paginate] .admin-table-cols-3 col.col-actions { width: 18rem; }
[data-table-paginate] .admin-table th:nth-child(2):not(.num):not(.actions),
[data-table-paginate] .admin-table td:nth-child(2):not(.num):not(.actions) {
    width: 9rem;
}
[data-table-paginate] .admin-table .actions .page-crud-inline {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 6px;
    max-width: 100%;
}
[data-table-paginate] .admin-table .actions .page-crud-inline .btn {
    min-height: 30px;
    padding: 0 8px;
    font-size: .78rem;
    border-radius: 8px;
}
[data-table-paginate] .admin-table .actions .page-crud-inline .btn-icon {
    width: 30px;
    min-width: 30px;
    padding: 0;
}
[data-table-paginate] > .table-pagination {
    border-top: 1px solid var(--border);
    border-radius: 0;
}
.table-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px 12px;
    padding: 10px 14px;
    background: var(--surface);
    font-size: .86rem;
}
.table-pagination[hidden] { display: none !important; }
.table-pagination--server {
    margin: 0;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}
.table-pagination span.btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.table-pagination-info { color: var(--muted); font-variant-numeric: tabular-nums; }
.admin-table-empty-cell {
    text-align: center;
    color: var(--muted);
    padding: 22px 16px;
    font-size: .9rem;
}
.pages-canvas > .table-pagination--server {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
}
.table-view .admin-table-wrap {
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--surface);
}
.users-page .ph-toolbar { margin-bottom: 10px; }
.users-page-hint { margin-top: 6px; }

/* เลือกมุมมอง Folder */
.view-picker { position: relative; }
.view-picker > summary { list-style: none; }
.view-picker > summary::-webkit-details-marker { display: none; }
.view-picker-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 12px 0 14px;
    font-weight: 600;
    color: var(--text-2);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.view-picker-trigger:hover { border-color: var(--border-strong); color: var(--text); }
.view-picker-trigger > .i:last-of-type { color: var(--muted); transition: transform .15s; }
.view-picker[open] .view-picker-trigger > .i:last-of-type { transform: rotate(90deg); }
.view-picker-label { font-size: .9rem; }
.view-picker-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 20;
    min-width: 240px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.view-picker-opt {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    font: inherit;
    text-align: left;
    color: var(--text-2);
    cursor: pointer;
    transition: background .12s, color .12s;
}
.view-picker-opt > .i { margin-top: 2px; color: var(--muted); flex-shrink: 0; }
.view-picker-opt span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.view-picker-opt strong { font-size: .9rem; color: var(--text); font-weight: 700; }
.view-picker-opt small { font-size: .78rem; color: var(--muted); font-weight: 500; line-height: 1.35; }
.view-picker-opt:hover { background: var(--surface-2); }
.view-picker-opt.is-active {
    background: var(--primary-soft);
    color: var(--primary-2);
}
.view-picker-opt.is-active > .i,
.view-picker-opt.is-active strong { color: var(--primary-2); }

.pages-list-card { background: var(--surface); }
.pages-list-name { display: flex; align-items: center; gap: 14px; min-width: 0; }
.pages-list-link { font-weight: 700; color: inherit; text-decoration: none; }
.pages-list-link:hover { color: var(--primary); }
.pages-list-slug { display: block; font-size: .82rem; color: var(--muted); margin-top: 2px; }
.pages-list-table .avatar { width: 56px; height: 56px; font-size: 1.2rem; }
.pages-canvas .page-card,
.pages-canvas .page-card-new {
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.05);
}
.empty-state-inset {
    margin: 8px 0 0;
    padding: 48px 20px;
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.72);
    border: 1px dashed color-mix(in srgb, var(--border) 80%, transparent);
    backdrop-filter: blur(6px);
}
@media (min-width: 960px) {
    .pages-canvas { padding: 22px 40px 36px; }
    .pages-canvas .ph-toolbar,
    .pages-canvas .pages-toolbar,
    .pages-canvas .pages-no-match,
    .pages-canvas .pages-views,
    .pages-canvas .page-grid,
    .pages-canvas .pages-list-card { margin-inline: auto; }
    .pages-filter-meta { margin-left: 0; width: 100%; text-align: right; }
}
@media (max-width: 720px) {
    .pages-toolbar { flex-direction: column; align-items: stretch; }
    .pages-select,
    .pages-sort { width: 100%; }
    .lc-select { width: 100%; }
}

/* ---------- ลิงก์ ---------- */

.section-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.section-bar h2 { font-size: 1rem; margin: 0; }
.section-bar.toolbar-card { margin-bottom: 14px; }

.link-sheet {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

/* แถบโหมดจัดลำดับ — แสดงเฉพาะตอนกด «จัดลำดับ» */
.link-reorder-bar {
    display: none;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 10px 20px;
    font-size: .84rem;
    color: var(--info);
    background: var(--primary-soft);
    border-bottom: 1px solid #bae6fd;
}
.link-reorder-bar.is-visible { display: flex; }

.link-sheet:not(.link-sheet--reorder) .link-row-grip { display: none; }
.link-sheet--reorder .link-row-actions,
.link-sheet--reorder .link-row-status { visibility: hidden; pointer-events: none; }
.link-sheet--reorder .drag-handle { color: var(--primary); background: var(--primary-soft); }

.link-list { list-style: none; margin: 0; padding: 0; }
.link-row {
    display: grid;
    grid-template-columns: var(--link-cols);
    align-items: center;
    gap: 12px 16px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    transition: background .12s;
}
.link-row:last-child { border-bottom: none; }
.link-row:hover { background: #fafbfd; }
/* คอลัมน์แถว = คอลัมน์หัวตาราง (.link-cols) */
.link-sheet { --link-cols: 2rem 72px minmax(0, 1fr) 8rem 8.5rem 9.5rem; }
.link-sheet--reorder { --link-cols: 32px 2rem 72px minmax(0, 1fr) 8rem 8.5rem 9.5rem; }
.link-cols {
    display: grid;
    grid-template-columns: var(--link-cols);
    gap: 0 16px;
    padding: 9px 20px;
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.link-cols-no { grid-column: -7 / -6; text-align: center; }
.link-cols-main { grid-column: -6 / -4; }
.link-cols-status { text-align: center; }
.link-row-status { display: flex; justify-content: center; }
.link-row-no {
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-size: .85rem;
    font-weight: 600;
    color: var(--muted);
}
.link-cols-stat { text-align: center; }
.link-row.is-off { background: #fafafb; }
.link-row.is-off .link-title-text,
.link-row.is-off .link-thumb { opacity: .5; }
.link-row.is-dragging { opacity: .55; background: var(--primary-soft); }

.link-row-grip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 4px;
}
.drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 56px;
    border-radius: 6px;
    color: #a5a9bb;
    cursor: grab;
    touch-action: none;
}
.drag-handle:hover { color: var(--text-2); background: #eef0f5; }
.drag-handle:active { cursor: grabbing; }
.link-row-nudge {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
/* ปุ่มลูกศรไว้ใช้บนจอสัมผัสเท่านั้น (ลากด้วยนิ้วไม่ได้) */
@media (hover: hover) and (pointer: fine) { .link-row-nudge { display: none; } }
.link-nudge { width: 28px; min-width: 28px; min-height: 24px; border-radius: 6px; }
.link-nudge .i { width: 14px; height: 14px; }

.link-row-media { display: flex; align-items: center; width: 72px; }
.link-thumb {
    width: 72px; height: 72px; border-radius: 14px; object-fit: cover; flex-shrink: 0;
    background: var(--surface-2); color: #a5a9bb;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border);
}
.link-thumb-zoom { position: relative; display: inline-flex; border-radius: 14px; cursor: zoom-in; }
.link-thumb-zoom-icon {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: inherit;
    color: #fff; background: rgba(15, 23, 42, .45);
    opacity: 0; transition: opacity .15s;
}
.link-thumb-zoom:hover .link-thumb-zoom-icon,
.link-thumb-zoom:focus-visible .link-thumb-zoom-icon { opacity: 1; }
.link-thumb-zoom:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.swal-zoom.swal2-popup { width: auto; max-width: min(92vw, 720px); }
.swal-zoom .swal2-image { max-width: 100%; max-height: 70vh; object-fit: contain; margin: 1rem auto .5rem; border-radius: 10px; }
/* รูปการ์ด/โลโก้ — ขนาดเท่ากันทุกแถว แสดงครบไม่ครอป */
img.link-thumb.is-card { object-fit: contain; background: #fff; padding: 3px; }

.link-row-body { min-width: 0; }
.link-title {
    display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px;
    margin-bottom: 2px;
}
.link-title-text { font-weight: 600; font-size: .92rem; color: var(--text); line-height: 1.35; }
.link-dest {
    display: block;
    font-size: .8rem;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.link-dest:hover { color: var(--primary); text-decoration: underline; }

.link-row-stat {
    display: inline-flex; align-items: center; justify-content: center; gap: 5px;
    color: var(--muted);
    font-size: .78rem;
}
.link-row-stat .i { width: 14px; height: 14px; }
.link-stat-num {
    font-variant-numeric: tabular-nums;
    font-size: .9rem;
    font-weight: 700;
    color: var(--text);
}

.link-row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}
@media (max-width: 820px) {
    .link-cols { display: none; }
    .link-row,
    .link-sheet--reorder .link-row {
        grid-template-columns: 60px minmax(0, 1fr);
        grid-template-areas:
            "media body"
            ". stat"
            "status actions";
        gap: 8px 12px;
        padding: 14px 12px;
    }
    .link-sheet--reorder .link-row {
        grid-template-areas:
            "grip grip"
            "media body";
    }
    .link-row-grip { grid-area: grip; flex-direction: row; align-items: center; }
    .link-row-nudge { flex-direction: row; }
    .link-row-no { display: none; }
    .link-row-media { grid-area: media; width: 60px; }
    .link-thumb { width: 60px; height: 60px; }
    .link-row-body { grid-area: body; }
    .link-row-stat { grid-area: stat; justify-content: flex-start; min-width: 0; white-space: nowrap; }
    .link-row-status { grid-area: status; justify-content: flex-start; white-space: nowrap; }
    .link-sheet--reorder .link-row-stat,
    .link-sheet--reorder .link-row-status,
    .link-sheet--reorder .link-row-actions { display: none; }
    .link-row-actions { grid-area: actions; }
}

/* =========================================================
   Analytics
   ========================================================= */
.toolbar-card {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px;
    margin-bottom: 20px; padding: 14px 16px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.toolbar-card .filters { margin-bottom: 0; flex: 1; min-width: 0; }
@media (max-width: 720px) {
    .toolbar-card { flex-direction: column; align-items: stretch; }
    .toolbar-card .filters-label { order: -1; width: 100%; margin-left: 0; justify-content: flex-start; }
    .toolbar-card .filter-custom { width: 100%; }
    .toolbar-card .filter-custom .date-field { flex: 1; min-width: 0; }
}
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 20px; }
.filters-label { order: 9; margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: .86rem; color: var(--muted); }
.filters form { display: flex; align-items: center; gap: 6px; margin: 0; }
.filter-custom { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.filters select { width: auto; min-width: 150px; min-height: 40px; padding: 8px 12px; }
.filters input[type=date] { min-height: 40px; padding: 7px 10px; font: inherit; font-size: 14px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); }
/* ช่องวันที่ + ปฏิทิน (admin.js: datepicker) — แสดง วัน/เดือน/ปี พ.ศ. */
.date-field { display: inline-flex; }
.date-field-btn {
    display: inline-flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-width: 140px; min-height: 40px;
    padding: 7px 10px 7px 12px; font: inherit; font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums;
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
}
.date-field-btn svg { color: var(--muted); flex-shrink: 0; }
.date-field-btn:hover { border-color: var(--series-1); }
.date-field-btn:hover svg, .date-field.is-open .date-field-btn svg { color: var(--primary); }
.date-field-btn:focus-visible, .date-field.is-open .date-field-btn { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 165, 233, .18); }

.dp {
    position: absolute; z-index: 1000; width: 296px; padding: 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, .14), 0 2px 6px rgba(15, 23, 42, .06);
    font-size: 14px; color: var(--text); animation: dp-in .12s ease-out;
}
@keyframes dp-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.dp button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.dp button:disabled { cursor: default; }
.dp button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.dp-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-bottom: 8px; }
.dp-title { flex: 1; padding: 6px 8px; border-radius: 8px; font-weight: 700; font-size: .95rem; }
.dp-title:hover { background: var(--surface-2); color: var(--primary); }
.dp-nav { width: 32px; height: 32px; border-radius: 8px; font-size: 1.3rem; line-height: 1; color: var(--text-2); }
.dp-nav:hover:not(:disabled) { background: var(--surface-2); color: var(--primary); }
.dp-nav:disabled { opacity: .3; }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 2px; }
.dp-dow { padding: 4px 0 6px; text-align: center; font-size: .75rem; font-weight: 600; color: var(--muted); }
.dp-dow:nth-child(n+6) { color: var(--delta-down); } /* ส. อา. */
.dp-day { position: relative; height: 36px; border-radius: 10px; font-variant-numeric: tabular-nums; }
.dp-day:hover:not(:disabled), .dp-day.is-hover { background: rgba(14, 165, 233, .12); }
.dp-day.is-out { color: var(--muted); opacity: .55; }
.dp-day:disabled { color: var(--muted); opacity: .3; text-decoration: line-through; }
.dp-day.is-today { font-weight: 700; color: var(--primary); }
.dp-day.is-today::after { content: ""; position: absolute; left: 50%; bottom: 4px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: currentColor; }
.dp-day.in-range { background: rgba(14, 165, 233, .12); border-radius: 0; }
.dp-day.range-start { border-radius: 10px 0 0 10px; }
.dp-day.range-end { border-radius: 0 10px 10px 0; }
.dp-day.range-start, .dp-day.range-end { background: rgba(14, 165, 233, .28); }
.dp-day.is-selected, .dp-day.is-selected:hover { background: var(--primary); color: #fff; font-weight: 700; opacity: 1; }
.dp-day.is-selected::after { background: #fff; }
.dp-months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.dp-month { height: 44px; border-radius: 10px; font-weight: 600; }
.dp-month:hover:not(:disabled) { background: rgba(14, 165, 233, .12); color: var(--primary); }
.dp-month.is-selected { background: var(--primary); color: #fff; }
.dp-month:disabled { opacity: .3; }
.dp-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.dp-hint { font-size: .78rem; color: var(--muted); }
.dp-today { padding: 6px 12px; border-radius: 8px; font-weight: 600; color: var(--primary) !important; }
.dp-today:hover:not(:disabled) { background: rgba(14, 165, 233, .1); }
.dp-today:disabled { opacity: .35; }
.segmented { display: inline-flex; flex-wrap: wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px; gap: 2px; }
.segmented a,
.segmented button {
    padding: 8px 14px; min-height: 36px; border-radius: 999px;
    text-decoration: none; color: var(--text-2); font-size: .87rem; font-weight: 600;
    white-space: nowrap; border: 1px solid transparent;
    background: transparent; font-family: inherit; cursor: pointer;
}
.segmented a:hover,
.segmented button:hover { color: var(--text); background: rgba(255, 255, 255, .6); }
.segmented a.is-active,
.segmented button.is-active { background: var(--surface); color: var(--primary); border-color: rgba(14, 165, 233, .35); box-shadow: 0 1px 4px rgba(15, 23, 42, .08); }

/* ปุ่ม Compare (สวิตช์เปิด/ปิดการเปรียบเทียบกับช่วงก่อนหน้า) */
.compare-toggle {
    display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 14px 6px 8px;
    border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface);
    color: var(--text-2); font-size: .87rem; font-weight: 600; text-decoration: none; white-space: nowrap;
    font-family: inherit; cursor: pointer;
}
.compare-toggle:hover { color: var(--text); border-color: var(--series-1); }
.compare-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.compare-toggle.is-active { color: var(--primary); border-color: rgba(14, 165, 233, .45); background: rgba(14, 165, 233, .06); }
.compare-switch { position: relative; width: 30px; height: 18px; border-radius: 999px; background: var(--axis); transition: background .15s; }
.compare-switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, .25); transition: transform .15s; }
.compare-toggle.is-active .compare-switch { background: var(--series-1); }
.compare-toggle.is-active .compare-switch::after { transform: translateX(12px); }
/* แถวเลือกช่วงที่ใช้เทียบ (แสดงเมื่อเปิด Compare) */
.compare-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; width: 100%; padding-top: 12px; border-top: 1px dashed var(--grid); }
.compare-bar-label { display: inline-flex; align-items: center; gap: 8px; font-size: .86rem; font-weight: 600; color: var(--text-2); }
.compare-bar .filter-custom label { font-size: .86rem; color: var(--muted); }
.compare-range { margin-left: auto; font-size: .86rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.compare-range small { color: var(--muted); }
@media (max-width: 720px) {
    .compare-bar { flex-direction: column; align-items: stretch; }
    .compare-bar .segmented { justify-content: flex-start; }
    .compare-bar .filter-custom .date-field { flex: 1; min-width: 0; }
    .compare-range { margin-left: 0; }
}

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
/* การ์ดแรกกว้างกว่า ที่เหลือแบ่งเท่ากันตามจำนวนการ์ด */
@media (min-width: 900px) { .kpis { grid-auto-flow: column; grid-template-columns: 1.4fr; grid-auto-columns: minmax(0, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; min-width: 0; transition: box-shadow .2s, border-color .2s; }
.kpi:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.kpi-hero { grid-column: 1 / -1; }
@media (min-width: 900px) { .kpi-hero { grid-column: auto; } }
.kpi-label { font-size: .82rem; color: var(--muted); }
.kpi-value { font-size: 1.6rem; font-weight: 800; line-height: 1.15; }
.kpi-hero .kpi-value { font-size: 2.6rem; }
.kpi-delta { font-size: .8rem; font-weight: 600; }
.kpi-delta small { font-weight: 400; color: var(--muted); }
.delta-up { color: var(--delta-up); }
.delta-down { color: var(--delta-down); }
.delta-flat { color: var(--muted); }

.chart-card { position: relative; }
.chart-empty { position: absolute; left: 0; right: 0; top: 45%; text-align: center; z-index: 1; pointer-events: none; color: var(--muted); }
.chart { --plot-h: 230px; padding-left: 36px; }
.chart-plot { position: relative; height: var(--plot-h); }
.chart-grid { position: absolute; left: 0; right: 0; border-top: 1px solid var(--grid); }
.chart-grid.is-base { border-top-color: var(--axis); }
.chart-grid span { position: absolute; right: calc(100% + 6px); top: -.6em; font-size: .72rem; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.chart-bars { position: absolute; inset: 0; display: grid; column-gap: 2px; align-items: end; }
.chart-slot { position: relative; height: 100%; display: flex; align-items: flex-end; justify-content: center; outline: none; }
.chart-slot:hover, .chart-slot:focus-visible { background: rgba(14, 165, 233, .08); border-radius: 4px; }
.chart-slot:focus-visible { box-shadow: inset 0 0 0 2px var(--series-1); }
.chart-dot { position: absolute; left: 50%; width: 10px; height: 10px; margin: 0 0 -5px -5px; border-radius: 50%; background: var(--series-1); box-shadow: 0 0 0 3px var(--surface); opacity: 0; transition: opacity .1s; pointer-events: none; }
.chart-dot.is-prev { width: 8px; height: 8px; margin: 0 0 -4px -4px; background: var(--surface); border: 2px solid var(--ink-muted); box-shadow: none; }
.chart-slot:hover .chart-dot, .chart-slot:focus-visible .chart-dot { opacity: 1; }
.chart-x { display: grid; column-gap: 2px; margin-top: 6px; height: 1.2em; }
.chart-x span { display: flex; justify-content: center; font-size: .72rem; color: var(--ink-muted); white-space: nowrap; }
.chart-tip {
    position: fixed; z-index: 50; pointer-events: none;
    background: #fff; border: 1px solid rgba(11, 11, 11, .1); border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .12);
    padding: 6px 10px; font-size: .82rem; line-height: 1.35;
}
.chart-tip strong { display: block; font-size: .95rem; }
.chart-tip span { color: var(--muted); }
.chart-tip em { display: block; font-style: normal; color: var(--text-2); margin-top: 2px; }

/* เทียบช่วงก่อนหน้า — เส้นประสีเทาทับกราฟแท่ง */
.chart-prev { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.chart-prev polyline { fill: none; stroke: var(--ink-muted); stroke-width: 2; stroke-dasharray: 5 4; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-head-side { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px 16px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; padding: 0; list-style: none; font-size: .8rem; color: var(--text-2); }
.chart-legend li { display: inline-flex; align-items: center; gap: 6px; }
.lg-line { width: 18px; border-top: 2px dashed var(--ink-muted); }
.link-delta { display: block; font-size: .74rem; font-weight: 600; margin-top: 2px; }
.link-delta.delta-flat { font-weight: 400; }

/* ช่วงเวลาที่มีคนกดมาก */
.peak-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.peak-stat { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; background: var(--surface-2); border-radius: 12px; min-width: 0; }
.peak-stat strong { font-size: 1.25rem; font-weight: 800; line-height: 1.25; }
.peak-stat-sub { font-size: .8rem; color: var(--muted); }
.peak-stat-prev { font-size: .76rem; color: var(--ink-muted); margin-top: 4px; padding-top: 6px; border-top: 1px dashed var(--grid); }
.hour-chart { --plot-h: 200px; }
.line-plot { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.line-plot polyline { fill: none; stroke: var(--series-1); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.line-area { fill: rgba(14, 165, 233, .12); stroke: none; }
.hour-dot { position: absolute; width: 10px; height: 10px; margin: 0 0 -5px -5px; border-radius: 50%; background: var(--series-1); box-shadow: 0 0 0 3px var(--surface); pointer-events: none; }
.hour-chart .chart-x span { font-variant-numeric: tabular-nums; }
.hour-legend { justify-content: flex-end; margin-bottom: 10px; }
.lg-solid { width: 18px; border-top: 2.5px solid var(--series-1); }

.table-view { margin-top: 12px; font-size: .88rem; }
.table-view summary { cursor: pointer; color: var(--primary); font-weight: 600; }
/* .data-table → ใช้ .admin-table ใน [data-table-paginate] แทน */
.rank-name { font-weight: 600; margin-right: 4px; }
.rank-bar { display: block; height: 6px; margin-top: 6px; background: #eef0f6; border-radius: 3px; overflow: hidden; }
.rank-bar span { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }
a.rank-name,
button.rank-name { color: var(--text); text-decoration: none; }
button.rank-name { padding: 0; border: 0; background: none; font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
a.rank-name:hover,
button.rank-name:hover { color: var(--primary-2); text-decoration: underline; }

/* Traffic แต่ละลิงก์ — กราฟแท่งเล็กต่อแถว (สเกลของแต่ละลิงก์เอง) */
/* กำหนดความกว้างคอลัมน์เอง (ตาราง data-table-paginate ใช้ table-layout: fixed) */
.link-traffic col.col-spark { width: 34%; }
.link-traffic col.col-n { width: 6.5rem; }
[data-table-paginate] .link-traffic th,
[data-table-paginate] .link-traffic td,
[data-table-paginate] .link-traffic .num { width: auto; }
.link-traffic col.col-folder { width: 11rem; }
.rank-folder { display: inline-flex; align-items: center; gap: 8px; min-width: 0; color: var(--text-2); font-weight: 600; }
.rank-folder > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-folder .avatar { width: 28px; height: 28px; font-size: .78rem; flex-shrink: 0; }
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.chart-head .card-title { margin-bottom: 4px; }
.chart-total { margin: 0; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; color: var(--muted); }
.chart-total strong { font-size: 2rem; font-weight: 800; color: var(--text); letter-spacing: -.02em; line-height: 1.1; }

.link-traffic td:first-child { overflow-wrap: anywhere; }
.link-traffic tr.is-focus td { background: var(--primary-soft); }
.spark { position: relative; height: 34px; }
.spark svg { display: block; width: 100%; height: 100%; overflow: visible; }
.spark-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark-area { fill: rgba(14, 165, 233, .12); stroke: none; }
.spark-prev { fill: none; stroke: var(--ink-muted); stroke-width: 1.5; stroke-dasharray: 3 3; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
/* ช่องโปร่งใสต่อช่วงเวลา — ใช้แสดง tooltip */
.spark-hit { position: absolute; inset: 0; display: grid; }
.spark-hit span:hover { background: rgba(14, 165, 233, .1); border-radius: 2px; }
.spark-x { display: flex; justify-content: space-between; margin-top: 3px; font-size: .7rem; color: var(--muted); }



/* =========================================================
   Login
   ========================================================= */
body.is-auth {
    min-height: 100vh; min-height: 100dvh;
    background:
        radial-gradient(55% 45% at 12% 8%, rgba(14, 165, 233, .14), transparent 72%),
        radial-gradient(45% 40% at 92% 18%, rgba(34, 211, 238, .12), transparent 70%),
        radial-gradient(50% 40% at 50% 100%, rgba(2, 132, 199, .08), transparent 70%),
        var(--bg);
}
body.is-auth .wrap { padding: 0 16px; max-width: none; }
body.is-auth .wrap > .alert { max-width: 400px; margin: 24px auto 0; }
.auth { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 32px 0; }
.auth-card {
    width: 100%; max-width: 400px;
    padding: 36px 28px 30px;
    background: rgba(255, 255, 255, .92);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, .8);
    border-radius: 24px;
    box-shadow: 0 1px 2px rgba(16, 24, 64, .04), 0 12px 40px rgba(16, 24, 64, .10);
    animation: auth-in .4s cubic-bezier(.2, .7, .2, 1) both;
}
@keyframes auth-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.auth-logo { display: block; width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 16px; box-shadow: 0 8px 22px rgba(14, 165, 233, .28); }
.auth-title { margin: 0; text-align: center; font-size: 1.55rem; font-weight: 800; letter-spacing: -.02em; }
.auth-sub { margin: 6px 0 22px; text-align: center; color: var(--muted); font-size: .92rem; }
.auth-error { display: flex; align-items: flex-start; gap: 8px; margin: -8px 0 18px; padding: 10px 12px; border-radius: 12px; background: var(--danger-soft); color: var(--danger); font-size: .9rem; }
.auth-error svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 2px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-label { font-size: .88rem; font-weight: 600; color: #3a3a44; }
.auth-input { position: relative; display: flex; align-items: center; }
.auth-input > svg { position: absolute; left: 14px; width: 20px; height: 20px; color: #9a9aa6; pointer-events: none; transition: color .15s; }
.auth-input input {
    width: 100%; height: 50px; padding: 0 14px 0 44px;
    font: inherit; font-size: 16px; color: var(--text);
    background: #f7f8fb; border: 1.5px solid #e4e6ee; border-radius: 14px;
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.auth-input input[data-password] { padding-right: 48px; }
.auth-input input:hover { border-color: #d3d6e2; }
.auth-input input:focus { outline: none; background: #fff; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
.auth-input:focus-within > svg { color: var(--primary); }
.auth-eye { position: absolute; right: 6px; display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 10px; background: transparent; color: #9a9aa6; cursor: pointer; }
.auth-eye:hover { background: #eef0f6; color: var(--text); }
.auth-eye:focus-visible { outline: 2px solid var(--primary); }
.auth-eye svg { width: 20px; height: 20px; }
.auth-eye .eye-closed { display: none; }
.auth-eye[aria-pressed="true"] .eye-open { display: none; }
.auth-eye[aria-pressed="true"] .eye-closed { display: block; }
.auth-submit {
    position: relative; height: 50px; margin-top: 6px;
    border: 0; border-radius: 14px;
    background: var(--primary); color: #fff;
    font: inherit; font-size: 1rem; font-weight: 700; cursor: pointer;
    box-shadow: 0 6px 18px rgba(14, 165, 233, .32);
    transition: transform .12s, box-shadow .15s, filter .15s;
}
.auth-submit:hover { filter: brightness(1.05); box-shadow: 0 8px 24px rgba(14, 165, 233, .38); }
.auth-submit:active { transform: scale(.985); }
.auth-submit:focus-visible { outline: 3px solid rgba(14, 165, 233, .45); outline-offset: 2px; }
.auth-submit:disabled { cursor: progress; filter: saturate(.7); }
.auth-spinner { display: none; position: absolute; top: 50%; left: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; border: 2.5px solid rgba(255, 255, 255, .4); border-top-color: #fff; border-radius: 50%; animation: auth-spin .7s linear infinite; }
.auth-submit.is-loading .auth-submit-text { visibility: hidden; }
.auth-submit.is-loading .auth-spinner { display: block; }
@keyframes auth-spin { to { transform: rotate(360deg); } }

/* แถวที่เพิ่งเลื่อน/ซ่อน — ไฮไลต์ชั่วครู่ให้รู้ว่าอยู่ตรงไหน */
.link-row.is-flash { animation: row-flash 1.6s ease-out; }
@keyframes row-flash { from { background: var(--primary-ring); border-color: var(--primary); } }

@media (prefers-reduced-motion: reduce) {
    .auth-card, .sidebar, .sb-overlay, .page-card, .alert, .confirm[open], .fs-more > summary .i { animation: none; transition: none; }
    .link-row.is-flash { animation: none; outline: 2px solid var(--primary); outline-offset: 2px; }
}

.empty { color: var(--muted); text-align: center; padding: 12px; font-size: .9rem; }

/* ช่องในกริด 2 คอลัมน์ — เว้นระยะเท่ากันเมื่อจอแคบเรียงเป็นคอลัมน์เดียว */
.grid-2 > .field:last-child { margin-bottom: 18px; }
.fs-body > .grid-2:last-child > .field:last-child { margin-bottom: 0; }

/* คำแนะนำ "ลากเพื่อเรียง" แสดงเฉพาะอุปกรณ์ที่มีเมาส์ */
.drag-hint { display: none; }
@media (hover: hover) and (pointer: fine) { .drag-hint { display: inline-flex; align-items: center; gap: 4px; } }

@media (max-width: 640px) {
    .segmented-input { display: flex; width: 100%; }
    .segmented-input label { flex: 1; }
    .segmented-input span { text-align: center; padding-left: 10px; padding-right: 10px; }
    .radio-cards { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
    .folder-id-tools { width: 100%; margin-left: 0; justify-content: flex-start; }
    .folder-panel-top { flex-direction: column; align-items: stretch; padding: 0 12px; }
    .folder-panel-actions { width: 100%; }
    .folder-panel-actions .btn { width: 100%; justify-content: center; }
    /* แถบบันทึกบนมือถือ: สวิตช์ + ปุ่มบันทึก บรรทัดเดียว (ย้อนกลับใช้ลิงก์ด้านบน) */
    .savebar { bottom: 8px; padding: 10px 10px 10px 14px; flex-wrap: nowrap; }
    .savebar .switch-text small { display: none; }
    .savebar-actions { width: auto; }
    .savebar-actions .btn:not(.btn-primary) { display: none; }
}

/* ---------- ฟอร์มลิงก์: ประเภท / ไอคอน ---------- */
.radio-card-icon { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 12px; background: #eef0f5; color: var(--text-2); }
.radio-card input:checked + .radio-card-body .radio-card-icon { background: #fff; color: var(--primary); }

/* ปุ่มเลือกแบบแบ่งช่อง (radio) */
.segmented-input {
    display: inline-flex; flex-wrap: wrap; gap: 3px; padding: 4px; margin-bottom: 16px;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
}
.segmented-input label { position: relative; cursor: pointer; }
.segmented-input input { position: absolute; opacity: 0; }
.segmented-input span {
    display: block; min-height: 40px; padding: 8px 16px; line-height: 1.25;
    border-radius: 999px; font-size: .88rem; font-weight: 600; color: var(--text-2); white-space: nowrap;
    border: 1px solid transparent;
}
.segmented-input input:checked + span {
    background: var(--surface); color: var(--primary);
    border-color: rgba(14, 165, 233, .35); box-shadow: 0 1px 4px rgba(15, 23, 42, .08);
}
.segmented-input input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 1px; }

.icon-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.icon-option { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; }
.icon-option input { position: absolute; opacity: 0; }
.icon-swatch {
    display: inline-flex; align-items: center; justify-content: center;
    width: 100%; height: 52px; border-radius: 12px;
    border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--text-2);
    transition: border-color .15s, background .15s, color .15s;
}
.icon-option:hover .icon-swatch { border-color: #bfc3d1; color: var(--text); }
.icon-option input:checked + .icon-swatch { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.icon-option input:focus-visible + .icon-swatch { outline: 2px solid var(--primary); outline-offset: 2px; }
.icon-name { font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ---------- ตัวเขียนบทความ ---------- */
.editor { border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); }
.editor:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
.field.has-error .editor { border-color: var(--danger); }
.editor-toolbar {
    position: sticky; top: 0; z-index: 2;
    display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
    padding: 6px; border-bottom: 1px solid var(--border);
    background: var(--surface-2); border-radius: 12px 12px 0 0;
}
.editor-toolbar[hidden] { display: none; }
.editor-toolbar button {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 36px; height: 36px; padding: 0 8px;
    border: 0; border-radius: 8px; background: transparent; color: var(--text-2);
    font: inherit; font-size: .9rem; font-weight: 700; cursor: pointer;
}
.editor-toolbar button:hover { background: #e7e9f0; color: var(--text); }
.editor-toolbar button[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); }
.editor-toolbar button:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.editor-sep { width: 1px; height: 22px; margin: 0 4px; background: var(--border-strong); }

.editor-area {
    min-height: 280px; max-height: 70vh; overflow-y: auto;
    padding: 14px 18px; outline: none;
    font-size: 1rem; line-height: 1.7; overflow-wrap: anywhere;
}
.editor-area > * { margin: 0 0 12px; }
.editor-area h2 { font-size: 1.3rem; margin-top: 18px; }
.editor-area h3 { font-size: 1.12rem; margin-top: 14px; }
.editor-area ul, .editor-area ol { padding-left: 1.4em; }
.editor-area blockquote { padding: 2px 0 2px 14px; border-left: 4px solid var(--border-strong); color: var(--text-2); font-style: italic; }
.editor-area hr { border: 0; border-top: 1px solid var(--border-strong); margin: 18px 0; }
.editor-area a { color: var(--primary); }
.editor-area figure { margin-left: 0; margin-right: 0; border-radius: 10px; cursor: pointer; }
.editor-area figure.is-selected { outline: 3px solid var(--primary); outline-offset: 2px; }
.editor-area img { display: block; max-width: 100%; height: auto; border-radius: 10px; }
.editor-area iframe { display: block; width: 100%; max-width: 560px; aspect-ratio: 16 / 9; height: auto; border: 0; border-radius: 10px; pointer-events: none; background: #000; }
.editor-area:has(> p:only-child > br:only-child)::before { content: attr(data-placeholder); position: absolute; color: var(--muted); pointer-events: none; }
.editor-area { position: relative; }
.editor-fallback { width: 100%; min-height: 240px; padding: 12px; border: 0; border-radius: 12px; font: .9rem/1.5 ui-monospace, Consolas, monospace; resize: vertical; }
.editor-fallback[hidden] { display: none; }
.editor-status { margin: 0; padding: 0 14px; font-size: .84rem; color: var(--muted); }
.editor-status:empty { display: none; }
.editor-status:not(:empty) { padding: 8px 14px; border-top: 1px solid var(--border); }
.editor-status.is-error { color: var(--danger); }

.editor-prompt { text-align: left; }
.editor-prompt .input { margin: 12px 0 4px; }
.editor-prompt .error { min-height: 1.2em; margin-bottom: 12px; }

/* แถวลิงก์ในหลังบ้าน: ไอคอนสำเร็จรูป */
.link-thumb.is-icon { color: var(--text-2); }

/* SweetAlert ตั้ง aria-hidden บน sidebar — บังคับให้เมนูหลังบ้านมองเห็นเสมอ */
body.admin > .sidebar,
body.admin > .app-navbar {
    visibility: visible !important;
}

/* ---------- SweetAlert2 — โทนเดียวกับหลังบ้าน (self-hosted) ---------- */
.swal2-popup {
    font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Sukhumvit Set", sans-serif;
    border-radius: var(--radius-lg);
    padding: 1.5rem 1.25rem 1.25rem;
}
.swal2-title { font-size: 1.15rem; font-weight: 800; color: var(--text); letter-spacing: -.01em; }
.swal2-html-container, .swal2-html-container.swal2-html-container { font-size: .92rem; color: var(--muted); }
.swal2-actions { gap: 10px; }
.swal2-styled.swal2-confirm, .swal2-styled.swal2-cancel {
    min-height: 44px; padding: 0 18px; font-size: .9rem; font-weight: 600; border-radius: 10px;
}
.swal2-toast {
    border-radius: 12px; box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.swal2-toast .swal2-title { font-size: .92rem; font-weight: 600; }

/* ---------- บัญชีของฉัน (โหมดดู) ---------- */
.account-view { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.account-view > div { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 12px; align-items: baseline; }
.account-view dt { font-size: .86rem; font-weight: 600; color: var(--muted); }
.account-view dd { margin: 0; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
@media (max-width: 560px) {
    .account-view > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
}

/* ---------- Loading (admin.js) ---------- */
.lc-progress {
    position: fixed; top: 0; left: 0; z-index: 10000;
    width: 100%; height: 3px;
    background: var(--grad);
    box-shadow: 0 0 8px rgba(14, 165, 233, .5);
    transform: scaleX(0); transform-origin: left;
    opacity: 0; pointer-events: none;
}
.lc-progress.is-active { opacity: 1; animation: lc-progress 8s cubic-bezier(.08, .7, .2, 1) forwards; }
@keyframes lc-progress {
    0%   { transform: scaleX(0); }
    10%  { transform: scaleX(.35); }
    100% { transform: scaleX(.92); }
}

.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
    content: ""; position: absolute; top: 50%; left: 50%;
    width: 18px; height: 18px; margin: -9px 0 0 -9px;
    border: 2.5px solid rgba(18, 20, 31, .2); border-top-color: var(--text-2);
    border-radius: 50%;
    animation: lc-spin .7s linear infinite;
}
.btn-primary.is-loading::after,
.btn-warning.is-loading::after,
.btn-info.is-loading::after,
.btn-success.is-loading::after,
.btn-danger.is-loading::after { border-color: rgba(255, 255, 255, .35); border-top-color: #fff; }
@keyframes lc-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .lc-progress.is-active { animation: none; transform: scaleX(.6); }
    .btn.is-loading::after { animation-duration: 1.6s; }
}
