/* Fembeq Admin — UI ใหม่ (2026) */
:root {
  --bg: #0d0f13;
  --bg-2: #12151b;
  --panel: #161a21;
  --panel-2: #1c212a;
  --line: #262c37;
  --line-2: #323a48;
  --text: #e8eaef;
  --muted: #8b93a3;
  --faint: #5d6575;
  --accent: #ff6a3d;
  --accent-ink: #1a0b05;
  --accent-soft: rgba(255, 106, 61, .14);
  --ok: #2fd47c;
  --ok-soft: rgba(47, 212, 124, .13);
  --bad: #ff4d5e;
  --bad-soft: rgba(255, 77, 94, .13);
  --info: #5aa9ff;
  --info-soft: rgba(90, 169, 255, .13);
  --warn: #f5b83d;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 10px 30px -12px rgba(0,0,0,.6);
  --sans: "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --side-w: 248px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-2: #eceef2;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e3e6ec;
  --line-2: #d3d8e0;
  --text: #171a21;
  --muted: #5d6576;
  --faint: #9098a8;
  --accent: #e8531f;
  --accent-ink: #ffffff;
  --accent-soft: rgba(232, 83, 31, .1);
  --ok: #12a05a;
  --ok-soft: rgba(18, 160, 90, .1);
  --bad: #dc2f45;
  --bad-soft: rgba(220, 47, 69, .09);
  --info: #2f7de1;
  --info-soft: rgba(47, 125, 225, .1);
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 8px 24px -16px rgba(16,24,40,.18);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
code, .mono { font-family: var(--mono); font-size: .92em; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
::selection { background: var(--accent); color: var(--accent-ink); }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 15px;
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.02em; }
.brand-name span { color: var(--muted); font-weight: 500; }
.nav-label { font-size: 12px; letter-spacing: .02em; font-weight: 500; color: var(--faint); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; margin: 1px 0;
  border-radius: var(--radius-sm); color: var(--muted); font-weight: 500; position: relative;
}
.nav a .fa { width: 18px; text-align: center; font-size: 15px; }
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.on { background: var(--panel); color: var(--text); }
.nav a.on::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav a .count { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--faint); }
.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); }
.me:hover { background: var(--panel); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line-2); font-weight: 600; text-transform: uppercase; }
.me-name { font-weight: 600; line-height: 1.2; }
.me-role { font-size: 12px; color: var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 60px; display: flex; align-items: center; gap: 12px;
  padding: 0 28px; background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.crumbs { color: var(--muted); font-size: 13.5px; display: flex; gap: 8px; align-items: center; }
.crumbs b { color: var(--text); font-weight: 600; }
.topbar .grow { flex: 1; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm); display: inline-grid; place-items: center;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--line-2); }
.menu-btn { display: none; }
.content { padding: 28px; max-width: 1320px; width: 100%; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- Cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.card-h h2 { font-size: 15px; }
.card-h .sub { color: var(--muted); font-size: 13px; }
.card-b { padding: 18px; }
.card-b.flush { padding: 0; }
.grid { display: grid; gap: 18px; }
.g-2 { grid-template-columns: 1fr 1fr; }
.g-3-2 { grid-template-columns: 3fr 2fr; }
.g-2-1 { grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); }
.stack > * + * { margin-top: 18px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { padding: 16px 18px; position: relative; overflow: hidden; }
.stat .k { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.stat .k .fa { color: var(--faint); }
.stat .v { font-family: var(--mono); font-size: 28px; font-weight: 600; margin-top: 6px; letter-spacing: -.02em; }
.stat .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat.hot { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.stat.hot .v { color: var(--accent); }
.bar { height: 6px; border-radius: 4px; background: var(--bad-soft); overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-weight: 500; font-size: 12.5px; color: var(--faint); padding: 11px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover td { background: var(--panel-2); }
.t .title { font-weight: 500; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t .num { font-family: var(--mono); text-align: right; white-space: nowrap; }
.t .acts { text-align: right; white-space: nowrap; }
.t .muted { color: var(--muted); }
.empty { padding: 44px 18px; text-align: center; color: var(--muted); }
.empty > .fa { font-size: 28px; color: var(--faint); display: block; margin-bottom: 10px; }

/* ---------- Badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 3px 9px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.badge.bad { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.badge.info { color: var(--info); background: var(--info-soft); border-color: transparent; }
.badge.plain::before { display: none; }
.id { font-family: var(--mono); font-size: 12.5px; padding: 2px 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); cursor: copy; }
.type { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  font: 500 14px var(--sans); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.btn.block { width: 100%; height: 44px; }
.btn.icon { width: 30px; padding: 0; }
.btn.icon.danger-h:hover { color: var(--bad); border-color: var(--bad); background: var(--bad-soft); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 500; margin-bottom: 6px; font-size: 13.5px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.input, select.input, textarea.input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: var(--bg-2); color: var(--text); font: 14px var(--sans); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 12px; font-family: var(--mono); font-size: 12.5px; resize: vertical; line-height: 1.5; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--faint); }
.search { position: relative; }
.search .fa { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search .input { padding-left: 36px; min-width: 260px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-2); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 14px; cursor: pointer; color: var(--muted); font-size: 13.5px; }
.seg input:checked + span { background: var(--panel-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }

/* ---------- Tips ---------- */
.tips { color: var(--muted); font-size: 13.5px; }
.tips dt { color: var(--text); font-weight: 500; margin-top: 12px; }
.tips dt:first-child { margin-top: 0; }
.tips dd { margin: 4px 0 0; }
.tips code { display: block; padding: 6px 10px; margin-top: 4px; border-radius: 6px; background: var(--bg-2); border: 1px dashed var(--line-2); word-break: break-all; }
.tips code b { color: var(--accent); font-weight: 500; }

/* ---------- Copy box ---------- */
.copy { display: flex; gap: 8px; align-items: stretch; }
.copy .input { font-family: var(--mono); font-size: 12.5px; }
.player { position: relative; padding-bottom: 56.25%; height: 0; border-radius: var(--radius); overflow: hidden; background: #000; border: 1px solid var(--line); }
.player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------- Pager ---------- */
.pager { display: flex; gap: 4px; justify-content: center; padding: 16px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 34px; height: 34px; display: grid; place-items: center; padding: 0 8px; border-radius: 8px; font-family: var(--mono); font-size: 13px; color: var(--muted); border: 1px solid transparent; }
.pager a:hover { border-color: var(--line-2); color: var(--text); }
.pager .cur { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pager .off { opacity: .35; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 40px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--panel);
  border: 1px solid var(--line-2); box-shadow: 0 16px 40px -12px rgba(0,0,0,.5); animation: tin .25s ease-out;
}
.toast .fa { margin-top: 3px; }
.toast.success .fa { color: var(--ok); }
.toast.error .fa { color: var(--bad); }
.toast.info .fa { color: var(--info); }
.toast.out { animation: tout .2s ease-in forwards; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }
@keyframes tout { to { opacity: 0; transform: translateX(16px); } }

/* ---------- Modal ---------- */
dialog.modal { border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 30px 80px -20px rgba(0,0,0,.7); }
dialog.modal::backdrop { background: rgba(5,6,9,.6); backdrop-filter: blur(3px); }
.modal .card-b p { margin: 0 0 14px; color: var(--muted); }

/* ---------- Cache ---------- */
.cache-btn { position: relative; }
.cache-btn .dot-count { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font: 600 10px/18px var(--mono); text-align: center; box-shadow: 0 0 0 2px var(--bg); }
.cache-list { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.cache-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.cache-row:last-child { border-bottom: 0; }
.cache-row:hover { background: var(--panel-2); }
.cache-row input { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.cache-row .grow { flex: 1; min-width: 0; }
.cache-row b { display: block; font-weight: 500; }
.cache-row small { display: block; color: var(--muted); font-size: 12.5px; }
.cache-n { color: var(--muted); font-size: 13px; }
.cache-row .btn { flex: none; }
.cache-total { display: flex; align-items: baseline; gap: 8px; margin-bottom: 14px; }
.cache-total .v { font-family: var(--mono); font-size: 26px; font-weight: 600; }

/* ---------- Auth page ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art {
  position: relative; overflow: hidden; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(1200px 600px at -10% 110%, var(--accent-soft), transparent 60%), var(--bg-2);
  border-right: 1px solid var(--line);
}
.auth-art .lines { position: absolute; inset: 0; opacity: .5;
  background-image: repeating-linear-gradient(0deg, transparent 0 3px, rgba(255,255,255,.025) 3px 4px); pointer-events: none; }
.auth-art h2 { font-size: clamp(28px, 3.4vw, 44px); line-height: 1.15; max-width: 14ch; letter-spacing: -.03em; }
.auth-art h2 em { font-style: normal; color: var(--accent); }
.auth-art p { color: var(--muted); max-width: 42ch; }
.onair { display: inline-flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 12px; letter-spacing: .14em; color: var(--accent); }
.onair::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px transparent; } }
.auth-form { display: grid; place-items: center; padding: 32px 20px; }
.auth-box { width: min(380px, 100%); }
.auth-box h1 { font-size: 26px; margin-bottom: 6px; }
.auth-box .lead { color: var(--muted); margin: 0 0 26px; }
.auth-foot { margin-top: 24px; font-size: 12.5px; color: var(--faint); text-align: center; }
.form-msg { min-height: 20px; font-size: 13.5px; margin: -4px 0 12px; }
.form-msg.err { color: var(--bad); }
.form-msg.ok { color: var(--ok); }

/* ---------- Misc ---------- */
.list-rows { list-style: none; margin: 0; padding: 0; }
.list-rows li { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line); }
.list-rows li:last-child { border-bottom: 0; }
.list-rows .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank { width: 22px; font-family: var(--mono); color: var(--faint); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.note { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--info-soft); color: var(--text); font-size: 13.5px; display: flex; gap: 10px; }
.note .fa { color: var(--info); margin-top: 3px; }
.note.warn { background: var(--bad-soft); }
.note.warn .fa { color: var(--bad); }
.hide-sm { }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .t thead { display: none; }
  .t, .t tbody, .t tr { display: block; width: 100%; }
  .t tr { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .t tbody tr:last-child { border-bottom: 0; }
  .t td { display: block; padding: 0; border: 0 !important; }
  .t tbody tr:hover td { background: transparent; }
  .t td.c-title { order: -1; flex: 1 1 100%; }
  .t td.c-title .title { white-space: normal; max-width: none; }
  .t td.num { text-align: left; color: var(--muted); }
  .t td.acts { margin-left: auto; }
  .page-head form.btn-row .search { flex: 1 1 100%; }
  .page-head form.btn-row > select, .page-head form.btn-row > .btn { flex: 1; }
}
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .g-2-1, .g-3-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: var(--side-w); z-index: 60; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .side { transform: none; box-shadow: 20px 0 60px rgba(0,0,0,.5); }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 16px; }
  .content { padding: 18px 16px; }
  .g-2 { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .hide-sm { display: none; }
  .search .input { min-width: 0; }
  .page-head .btn-row { width: 100%; }
  .page-head .search { flex: 1; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .v { font-size: 22px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 10px; }
}
