/* ==========================================================================
   Stream Box — Admin UI 3.0  (Dark / Light)
   ========================================================================== */

:root,
:root[data-theme="dark"] {
    --bg: #0c0e13;
    --bg-grad: radial-gradient(1200px 600px at 85% -10%, rgba(124, 92, 255, .13), transparent 60%);
    --surface: #14171f;
    --surface-2: #1a1e29;
    --surface-3: #222736;
    --border: #262b3a;
    --border-strong: #343b4f;
    --text: #e9ebf3;
    --text-2: #b9bfd0;
    --muted: #8a92a8;
    --accent: #8b6cff;
    --accent-hover: #9d83ff;
    --accent-soft: rgba(139, 108, 255, .16);
    --accent-text: #ffffff;
    --success: #34c98e;
    --success-soft: rgba(52, 201, 142, .14);
    --danger: #f4636f;
    --danger-soft: rgba(244, 99, 111, .14);
    --warning: #f3b24a;
    --warning-soft: rgba(243, 178, 74, .13);
    --info: #4ea8ff;
    --info-soft: rgba(78, 168, 255, .14);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -12px rgba(0, 0, 0, .6);
    --shadow-pop: 0 24px 64px -16px rgba(0, 0, 0, .75);
    --overlay: rgba(5, 6, 10, .66);
    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg: #f3f4f8;
    --bg-grad: radial-gradient(1200px 600px at 85% -10%, rgba(107, 70, 245, .09), transparent 60%);
    --surface: #ffffff;
    --surface-2: #f6f7fb;
    --surface-3: #eceef5;
    --border: #e3e6ef;
    --border-strong: #cfd4e1;
    --text: #1a1e2b;
    --text-2: #3d4458;
    --muted: #6c7489;
    --accent: #6341ee;
    --accent-hover: #5433da;
    --accent-soft: rgba(99, 65, 238, .1);
    --accent-text: #ffffff;
    --success: #15935f;
    --success-soft: rgba(21, 147, 95, .11);
    --danger: #d83a4a;
    --danger-soft: rgba(216, 58, 74, .09);
    --warning: #a96a06;
    --warning-soft: rgba(214, 143, 20, .13);
    --info: #1c6fd1;
    --info-soft: rgba(28, 111, 209, .1);
    --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 10px 28px -14px rgba(20, 24, 40, .18);
    --shadow-pop: 0 24px 64px -16px rgba(20, 24, 40, .32);
    --overlay: rgba(20, 24, 40, .45);
    color-scheme: light;
}

:root {
    --radius: 14px;
    --radius-sm: 9px;
    --sidebar-w: 248px;
    --topbar-h: 62px;
    --font: "IBM Plex Sans Thai", "Noto Sans Thai", "Sarabun", "Leelawadee UI", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
}

/* ---- Base ---------------------------------------------------------------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg-grad) no-repeat fixed, var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul, ol, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
b, strong { font-weight: 600; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

code { font-family: var(--mono); font-size: .88em; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .9em; }
.center { text-align: center; margin-top: 18px; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.text-danger { color: var(--danger); }

:root[data-theme="dark"] .theme-light-only,
:root[data-theme="light"] .theme-dark-only { display: none; }

/* ---- Layout -------------------------------------------------------------- */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    padding: 16px 12px 12px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    transition: transform .22s ease;
}

.is-app .shell { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.is-guest .shell { min-height: 100vh; display: flex; flex-direction: column; }

.brand { display: inline-flex; align-items: center; gap: 10px; padding: 4px 8px 16px; color: var(--text); font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.brand:hover { color: var(--text); }
.brand b { color: var(--accent); font-weight: 700; }
.brand-mark {
    display: inline-grid; place-items: center;
    width: 34px; height: 34px; border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), #c06cff);
    color: #fff; font-size: 13px; padding-left: 2px;
    box-shadow: 0 6px 16px -6px var(--accent);
}
.brand-mark-lg { width: 56px; height: 56px; border-radius: 17px; font-size: 21px; padding-left: 4px; }

.menu { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.menu-label { padding: 10px 12px 6px; font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.menu-item {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 12px; border-radius: var(--radius-sm);
    color: var(--text-2); font-weight: 500;
    transition: background .15s, color .15s;
}
.menu-item .fa { width: 18px; text-align: center; font-size: 15px; color: var(--muted); transition: color .15s; }
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-item.active { background: var(--accent-soft); color: var(--accent); }
.menu-item.active .fa { color: var(--accent); }

.sidebar-foot { display: flex; align-items: center; gap: 6px; padding-top: 12px; margin-top: 8px; border-top: 1px solid var(--border); }
.user-chip { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius-sm); color: var(--text); }
.user-chip:hover, .user-chip.active { background: var(--surface-2); color: var(--text); }
.avatar { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.user-meta { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.user-meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.user-meta small { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }

.sidebar-backdrop { display: none; }

.topbar {
    position: sticky; top: 0; z-index: 30;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 12px;
    padding: 0 24px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 18px; font-weight: 600; letter-spacing: -.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.topbar-guest .brand { padding: 0; }
.icon-btn.burger { display: none; }

.content { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 24px; }
.content-guest { display: flex; flex-direction: column; justify-content: center; }

/* ---- Buttons ------------------------------------------------------------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 40px; padding: 0 16px;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    background: var(--surface-3); color: var(--text);
    font-weight: 600; font-size: 14.5px; line-height: 1; white-space: nowrap;
    cursor: pointer; user-select: none;
    transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn:hover { color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-text); }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); color: #fff; }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; gap: 6px; }
.btn-lg { height: 46px; font-size: 15.5px; }
.btn-block { width: 100%; }

.icon-btn {
    flex: none; display: inline-grid; place-items: center;
    width: 38px; height: 38px; border-radius: var(--radius-sm);
    border: 1px solid transparent; background: transparent; color: var(--muted);
    font-size: 16px; cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---- Cards --------------------------------------------------------------- */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-narrow { max-width: 560px; margin: 6vh auto 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15.5px; font-weight: 600; display: flex; align-items: center; gap: 9px; min-width: 0; }
.card-head h2 > .fa { color: var(--accent); font-size: 15px; }
.card-head-tools { flex-wrap: wrap; }
.card-body { padding: 20px; }
.card-body > p + form { margin-top: 14px; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: center; }
.card-foot:empty { display: none; }
.count { display: inline-block; padding: 1px 9px; border-radius: 99px; background: var(--surface-3); color: var(--text-2); font-size: 12.5px; font-weight: 600; }
.tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.grid { display: grid; gap: 20px; align-items: start; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-2-1 { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
.grid-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); }
.grid-form { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
.stack { display: grid; gap: 20px; min-width: 0; }

/* ---- Stats --------------------------------------------------------------- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
    display: flex; align-items: center; gap: 14px;
    padding: 18px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
    color: var(--text); transition: border-color .15s, transform .15s;
}
a.stat:hover { border-color: var(--border-strong); transform: translateY(-2px); color: var(--text); }
.stat-icon { flex: none; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 13px; font-size: 18px; }
.stat-body { min-width: 0; display: flex; flex-direction: column; }
.stat-body small { color: var(--muted); font-size: 13px; }
.stat-body b { font-size: 25px; font-weight: 700; line-height: 1.2; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-body b i { font-style: normal; color: var(--muted); font-weight: 400; }
.c-violet { background: var(--accent-soft); color: var(--accent); }
.c-blue { background: var(--info-soft); color: var(--info); }
.c-green { background: var(--success-soft); color: var(--success); }
.c-amber { background: var(--warning-soft); color: var(--warning); }

/* ---- Lists / meters ------------------------------------------------------ */

.list li { display: flex; align-items: center; gap: 14px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; color: var(--text); }
.list-main b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-main:hover b { color: var(--accent); }
.list-main small { display: flex; align-items: center; gap: 10px; font-size: 12.5px; flex-wrap: wrap; }
.list-side { flex: none; font-size: 13.5px; font-variant-numeric: tabular-nums; }

.rank { counter-reset: rank; }
.rank li { counter-increment: rank; display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--border); font-size: 14px; }
.rank li:last-child { border-bottom: 0; }
.rank li::before { content: counter(rank); flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: var(--surface-3); color: var(--text-2); font-size: 12px; font-weight: 700; }
.rank li:first-child::before { background: var(--accent); color: #fff; }
.rank a { flex: 1; min-width: 0; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank a:hover { color: var(--accent); }
.rank span { font-variant-numeric: tabular-nums; }

.meter + .meter { margin-top: 14px; }
.meter-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; margin-bottom: 6px; }
.meter-top .fa { width: 16px; text-align: center; color: var(--muted); }
.meter-bar { height: 7px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.meter-bar span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), #c06cff); }

.meta { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; align-items: center; font-size: 14px; }
.meta dt { color: var(--muted); }
.meta dd { min-width: 0; text-align: right; }

/* ---- Forms --------------------------------------------------------------- */

.field { margin-bottom: 16px; min-width: 0; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 14px; }
.field-label { display: block; margin-bottom: 6px; font-size: 13.5px; font-weight: 500; color: var(--text-2); }
.field-hint { margin-top: 6px; font-size: 12.5px; color: var(--muted); min-height: 0; }
.field-hint:empty { display: none; }
.field-hint.ok { color: var(--success); }
.field-hint.err { color: var(--danger); }

.input {
    display: block; width: 100%; height: 42px; padding: 0 13px;
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.input::placeholder { color: var(--muted); opacity: .8; }
.input:hover { border-color: var(--muted); }
.input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.input[readonly] { color: var(--text-2); background: var(--surface-3); border-color: var(--border); }
textarea.input { height: auto; min-height: 96px; padding: 10px 13px; line-height: 1.55; resize: vertical; }
select.input {
    appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px;
    background-size: 5px 5px; background-repeat: no-repeat;
}

.input-icon { position: relative; }
.input-icon > .fa { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon .input { padding-left: 40px; }
.input-eye { position: absolute; right: 4px; top: 4px; width: 34px; height: 34px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.input-eye:hover { color: var(--text); background: var(--surface-3); }

.check { display: flex; align-items: center; gap: 9px; margin-bottom: 16px; font-size: 14px; color: var(--text-2); cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.form-msg { min-height: 0; margin-bottom: 12px; font-size: 14px; }
.form-msg:empty { display: none; }
.form-msg.ok { color: var(--success); }
.form-msg.err { color: var(--danger); }

.search { position: relative; }
.search .fa { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { width: 260px; max-width: 100%; height: 40px; padding-left: 37px; }

.copy-row { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.copy-row-top { align-items: flex-start; }
.copy-row:last-child { margin-bottom: 0; }
.copy-row .input { flex: 1; min-width: 0; }
.copy-row .btn { flex: none; }

.note { display: flex; gap: 11px; padding: 12px 14px; margin-bottom: 16px; border-radius: var(--radius-sm); font-size: 13.5px; line-height: 1.6; }
.note > .fa { margin-top: 4px; }
.note-warn { background: var(--warning-soft); color: var(--text-2); border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent); }
.note-warn > .fa { color: var(--warning); }
.note code { padding: 1px 6px; border-radius: 5px; background: var(--surface-3); color: var(--text); }

.tips .tip { margin-bottom: 14px; }
.tips .tip:last-child { margin-bottom: 0; }
.tips .tip b { display: block; margin-bottom: 6px; font-size: 13.5px; color: var(--text-2); }
.tips .tip code { display: block; padding: 6px 10px; margin-bottom: 5px; border-radius: 7px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); overflow-x: auto; white-space: nowrap; }

/* ---- Tables -------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th { padding: 11px 16px; text-align: left; font-size: 12.5px; font-weight: 600; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.row-active { background: var(--accent-soft); }
.table th:first-child, .table td:first-child { padding-left: 20px; }
.table th:last-child, .table td:last-child { padding-right: 20px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .col-id { width: 1%; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .actions { width: 1%; white-space: nowrap; text-align: right; }
.table .actions .btn { margin-left: 4px; }
.cell-title { font-weight: 500; word-break: break-word; }
.cell-sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.cell-sub a { color: var(--muted); }
.cell-sub a:hover { color: var(--accent); }
.cell-sub.ellipsis { display: block; max-width: 340px; }

.code-pill { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); cursor: pointer; transition: border-color .15s, color .15s; }
.code-pill:hover { border-color: var(--accent); color: var(--accent); }

.order { display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 6px; border-radius: 8px; background: var(--surface-3); font-weight: 600; font-size: 13px; }
.media-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.media-cell > div { min-width: 0; }
.thumb { position: relative; flex: none; display: grid; place-items: center; width: 84px; height: 44px; border-radius: 8px; overflow: hidden; background: var(--surface-3); border: 1px solid var(--border); color: var(--muted); font-size: 17px; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb-icon { width: 44px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; background: var(--surface-3); color: var(--text-2); font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge .fa { font-size: 11px; }
.badge-type.t-drive { background: var(--success-soft); color: var(--success); }
.badge-type.t-photos { background: var(--warning-soft); color: var(--warning); }
.badge-type.t-youtube { background: var(--danger-soft); color: var(--danger); }
.badge-type.t-facebook, .badge-type.t-daily { background: var(--info-soft); color: var(--info); }
.badge-type.t-hotlink, .badge-type.t-blogger, .badge-type.t-fembed, .badge-type.t-okru { background: var(--accent-soft); color: var(--accent); }

.empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.empty > .fa { font-size: 34px; opacity: .55; margin-bottom: 12px; display: block; }
.empty h2 { font-size: 18px; color: var(--text); margin-bottom: 6px; }
.empty p { margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

.pagination { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.page { display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--border); color: var(--text-2); font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
a.page:hover { border-color: var(--accent); color: var(--accent); }
.page.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page.disabled, .page.dots { color: var(--muted); border-color: transparent; }

/* ---- Player preview ------------------------------------------------------ */

.player-frame { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }
.player-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---- Auth ---------------------------------------------------------------- */

.auth { width: 100%; max-width: 420px; margin: 0 auto; padding: 4vh 0 8vh; }
.auth-hero { text-align: center; margin-bottom: 24px; }
.auth-hero h1 { margin-top: 14px; font-size: 28px; font-weight: 600; letter-spacing: -.02em; }
.auth-hero h1 b { color: var(--accent); }
.auth-hero p { margin-top: 6px; color: var(--muted); }
.auth-card .card-body { padding: 28px; }
.auth-title { font-size: 19px; font-weight: 600; margin-bottom: 18px; }
.auth-alt { margin-top: 18px; text-align: center; color: var(--muted); font-size: 14px; }
.captcha { overflow: hidden; }

/* ---- Modal --------------------------------------------------------------- */

.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; background: var(--overlay); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fade .15s ease; }
.modal-box { width: 100%; max-width: 620px; max-height: calc(100vh - 40px); overflow-y: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow-pop); animation: pop .18s ease; }
.modal-sm { max-width: 440px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 14px 14px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; font-weight: 600; display: flex; gap: 9px; align-items: center; }
.modal-body { padding: 20px; }
.modal-body > .muted { margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.modal-note { margin-top: 8px; font-size: 13.5px; color: var(--warning); }
.modal-note:empty { display: none; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---- Toast --------------------------------------------------------------- */

.toasts { position: fixed; z-index: 80; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 40px)); }
.toast { display: flex; align-items: flex-start; gap: 11px; padding: 13px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow-pop); font-size: 14.5px; animation: toast-in .25s ease; transition: opacity .3s, transform .3s; }
.toast > .fa { margin-top: 3px; font-size: 17px; }
.toast-success { border-left: 3px solid var(--success); }
.toast-success > .fa { color: var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-error > .fa { color: var(--danger); }
.toast.hide { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* ---- Responsive ---------------------------------------------------------- */

@media (max-width: 1100px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-2-1, .grid-1-2, .grid-form { grid-template-columns: minmax(0, 1fr); }
    .hide-md { display: none; }
}

@media (max-width: 860px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-pop); }
    .sidebar-open .sidebar { transform: none; }
    .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: var(--overlay); }
    .is-app .shell { margin-left: 0; }
    .icon-btn.burger { display: inline-grid; }
    .topbar { padding: 0 14px; }
    .content { padding: 16px 14px 28px; }
    .grid-2 { grid-template-columns: minmax(0, 1fr); }
    .hide-sm { display: none; }
    .search, .search .input { width: 100%; }
    .card-head-tools .tools { width: 100%; }
    .card-head-tools .tools .btn { flex: 1; }
}

@media (max-width: 520px) {
    .stats { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .hide-xs { display: none; }
    /* ตาราง → การ์ดรายแถว */
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: auto; }
    .table tbody tr { padding: 14px 16px; border-bottom: 1px solid var(--border); }
    .table tbody tr:last-child { border-bottom: 0; }
    .table td, .table td:first-child, .table td:last-child { padding: 0; border: 0; }
    .table td + td { margin-top: 8px; }
    .table td.hide-xs, .table td.hide-sm { display: none; }
    .table td.num { text-align: left; color: var(--muted); font-size: 13px; }
    .table td.num::before { content: attr(data-label) " "; }
    .table td.col-id { width: auto; }
    .table td.actions { width: auto; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; white-space: normal; }
    .table td.actions .btn { flex: 1; margin: 0; height: 36px; }
    .cell-sub.ellipsis { max-width: 100%; }
    .card-head, .card-body { padding-left: 16px; padding-right: 16px; }
    .auth-card .card-body { padding: 22px 18px; }
    .thumb { width: 56px; height: 34px; }
    .thumb-icon { width: 34px; }
    .copy-row { flex-wrap: wrap; }
    .copy-row .btn { width: 100%; }
}

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