/* PRASAT Business Hub – one stylesheet. Brand: navy #102858, blue #184878, sky #1A89C5, secondary #2875AC. */

:root {
  --navy: #102858; --blue: #184878; --sky: #1A89C5; --blue-2: #2875AC;
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #eef2f8; --line: #dbe2ec;
  --text: #0f1b33; --muted: #4c5a73; --dim: #6b7890;
  --accent: #14679a; --accent-soft: #e2f0f9; --on-accent: #ffffff;
  --side: #102858; --side-text: #c9d6ea; --side-active: rgba(26, 137, 197, .22);
  --ok: #157a46; --ok-soft: #e1f4ea; --warn: #9a5b00; --warn-soft: #fdf0dc; --bad: #b42335; --bad-soft: #fbe6e9;
  --shadow: 0 1px 2px rgba(16, 40, 88, .06), 0 4px 16px rgba(16, 40, 88, .06);
  --radius: 10px;
  --font: 'IBM Plex Sans', 'Noto Sans Khmer', system-ui, sans-serif;
  --font-display: 'Space Grotesk', 'Noto Sans Khmer', system-ui, sans-serif;
  --font-km: 'Noto Sans Khmer', 'IBM Plex Sans', sans-serif;
  --font-logo: 'Montserrat', system-ui, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0a1426; --surface: #111e36; --surface-2: #172743; --line: #24365a;
  --text: #e8eef8; --muted: #a8b6cc; --dim: #8a99b3;
  --accent: #4fb0e3; --accent-soft: rgba(79, 176, 227, .14); --on-accent: #06192e;
  --side: #081022; --side-text: #b5c3da; --side-active: rgba(79, 176, 227, .18);
  --ok: #4cc98a; --ok-soft: rgba(76, 201, 138, .14); --warn: #f0b04f; --warn-soft: rgba(240, 176, 79, .14);
  --bad: #ff7b8c; --bad-soft: rgba(255, 123, 140, .14);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 18px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }
.km, [lang="km"] { font-family: var(--font-km); }
.muted { color: var(--muted); } .dim { color: var(--dim); font-size: .88em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- logo ---------- */
.logo { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.logo img { width: 34px; height: 28px; }
.logo b { font: 800 15px/1 var(--font-logo); letter-spacing: .06em; color: #fff; }
.logo b span { color: var(--sky); }
.logo small { display: block; font: 600 10px/1.4 var(--font); letter-spacing: .14em; text-transform: uppercase; color: var(--side-text); margin-top: 3px; }

/* ---------- buttons, inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text);
  font: 600 14px/1 var(--font); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn svg { width: 18px; height: 18px; flex: none; }
.icon-btn { width: 44px; padding: 0; }

label.field { display: block; margin-bottom: 14px; }
label.field > span:first-child, .field-label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); font: 15px/1.45 var(--font);
}
textarea.input { min-height: 110px; resize: vertical; }
textarea.input.km, .input.km { font-family: var(--font-km); line-height: 1.7; }
.input:focus { outline: 2px solid var(--sky); outline-offset: -1px; border-color: transparent; }
.hint { font-size: 12.5px; color: var(--dim); margin-top: 5px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { min-height: 40px; padding: 0 14px; border: 0; background: none; color: var(--muted); font: 600 13px var(--font); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* ---------- cards, chips, badges ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid-2 > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; line-height: 1.6;
}
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge::first-letter { text-transform: uppercase; }
.badge.draft { background: var(--surface-2); color: var(--muted); }
.badge.scheduled { background: var(--accent-soft); color: var(--accent); }
.badge.due { background: var(--warn-soft); color: var(--warn); }
.badge.posted { background: var(--ok-soft); color: var(--ok); }
.badge.failed { background: var(--bad-soft); color: var(--bad); }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.shell > div { min-width: 0; }
.side { background: var(--side); color: var(--side-text); padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 8px;
  color: var(--side-text); text-decoration: none; font-weight: 500;
}
.nav a svg { width: 20px; height: 20px; flex: none; opacity: .85; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a[aria-current="page"] { background: var(--side-active); color: #fff; }
.nav a[aria-current="page"] svg { color: var(--sky); opacity: 1; }
.nav .nav-label { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; opacity: .6; padding: 14px 12px 4px; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
select.ws-switch { width: 100%; background: rgba(255, 255, 255, .06); color: #fff; border: 1px solid rgba(255, 255, 255, .12); }
.ws-switch option { color: #000; }
.side .btn-ghost { color: var(--side-text); justify-content: flex-start; }
.side .btn-ghost:hover { background: rgba(255, 255, 255, .06); color: #fff; }

.main { min-width: 0; padding: 28px 32px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.topbar { display: none; }

/* ---------- home ---------- */
.banner { display: grid; grid-template-columns: 1fr 300px; align-items: center; gap: 20px; background: linear-gradient(120deg, var(--navy), var(--blue)); color: #fff; border-radius: var(--radius); padding: 22px 26px; margin-bottom: 18px; }
.banner h1 { color: #fff; } .banner p { color: #c9d6ea; margin: 0 0 14px; }
.banner img { width: 100%; max-height: 190px; object-fit: contain; margin: -10px 0; }
.banner .btn { border-color: transparent; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; }
.stat:hover { border-color: var(--accent); }
.stat b { display: block; font: 700 1.6rem/1.1 var(--font-display); }
.stat span { font-size: 13px; color: var(--muted); }
.stat.warn b { color: var(--warn); }

/* ---------- library ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .input { width: auto; min-width: 140px; }
.toolbar .search { flex: 1 1 220px; }
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; display: flex; align-items: center; gap: 16px;
  background: var(--surface); margin-bottom: 16px; transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--sky); background: var(--accent-soft); }
.drop img { width: 72px; height: 72px; object-fit: contain; }
.assets { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.asset { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; text-align: left; padding: 0; font: inherit; color: inherit; display: flex; flex-direction: column; }
.asset:hover { border-color: var(--accent); }
.asset.selected { outline: 3px solid var(--sky); outline-offset: -1px; }
.asset .thumb { aspect-ratio: 1; background: var(--surface-2) repeating-conic-gradient(var(--line) 0 25%, transparent 0 50%) 0 0 / 16px 16px; }
.asset .thumb img { width: 100%; height: 100%; object-fit: contain; }
.asset .meta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.asset .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty img { width: 200px; margin: 0 auto 12px; }
.tag-group { margin-bottom: 12px; }
.tag-group .chips { gap: 6px; }
.tag-toggle { min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font: 600 13px var(--font); cursor: pointer; }
.tag-toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.upload-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.upload-list div { font-size: 13px; color: var(--muted); }

/* ---------- dialog, toast ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(6, 14, 30, .55); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 14px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-head h2 { margin: 0; flex: 1; }
.dlg-body { padding: 18px 20px; }
.dlg-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.asset-edit { display: grid; grid-template-columns: 240px 1fr; gap: 20px; }
.asset-edit .preview { background: var(--surface-2); border-radius: 8px; overflow: hidden; align-self: start; }
.toast-wrap { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; width: min(440px, calc(100vw - 32px)); }
.toast { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; }
.toast.bad { background: var(--bad); }
.link-box { display: flex; gap: 8px; } .link-box .input { font-size: 13px; }

/* ---------- publisher ---------- */
.publish { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 420px); gap: 20px; align-items: start; }
.previews { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 14px; }
.picked { display: flex; gap: 14px; align-items: center; }
.picked .pthumb { width: 96px; height: 96px; border-radius: 8px; background: var(--surface-2); overflow: hidden; flex: none; display: grid; place-items: center; }
.picked .pthumb img { width: 100%; height: 100%; object-fit: cover; }
.platforms { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px 14px; }
.platforms .check small { color: var(--dim); font-size: 11.5px; display: block; line-height: 1.2; }
.cap-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cap-head .field-label { margin: 0; flex: 1; }
.counter { font-size: 12px; color: var(--dim); text-align: right; margin-top: 4px; }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 240px; max-height: 320px; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; }
.menu-list button { display: block; width: 100%; text-align: left; padding: 10px 12px; min-height: 44px; border: 0; background: none; border-radius: 6px; color: var(--text); font: 14px var(--font); cursor: pointer; }
.menu-list button:hover, .menu-list button:focus-visible { background: var(--surface-2); }
.menu-list button small { display: block; color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.overrides details { border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; margin-bottom: 8px; }
.overrides summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 600; font-size: 14px; }
.overrides details[open] { padding-bottom: 12px; }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.checks li { display: flex; gap: 8px; font-size: 13.5px; padding: 8px 10px; border-radius: 8px; }
.checks li::before { font-weight: 800; flex: none; width: 16px; text-align: center; }
.checks .error { background: var(--bad-soft); color: var(--bad); } .checks .error::before { content: '!'; }
.checks .warn { background: var(--warn-soft); color: var(--warn); } .checks .warn::before { content: '!'; }
.checks .ok { background: var(--ok-soft); color: var(--ok); } .checks .ok::before { content: '✓'; }
.checks .tip { background: var(--surface-2); color: var(--muted); } .checks .tip::before { content: 'i'; }
.actions-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions-bar .input { width: auto; }

/* platform previews (simplified look of each feed) */
.pv-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.pv-tabs button { flex: none; }
.pv { background: #fff; color: #050505; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); font: 14px/1.4 -apple-system, 'Segoe UI', Roboto, 'Noto Sans Khmer', sans-serif; }
.pv-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.pv-ava { width: 36px; height: 36px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; overflow: hidden; }
.pv-ava img { width: 100%; height: 100%; object-fit: cover; }
.pv-name { font-weight: 700; font-size: 14px; } .pv-sub { font-size: 12px; color: #65676b; }
.pv-text { padding: 0 12px 10px; white-space: pre-wrap; word-break: break-word; }
.pv-text .more { color: #65676b; font-weight: 600; }
.pv-text .over { background: #ffd7dc; color: #8a0012; }
.pv-img { background: #000; position: relative; overflow: hidden; }
.pv-img img { width: 100%; height: 100%; object-fit: cover; }
.pv-img.contain img { object-fit: contain; }
.pv-noimg { aspect-ratio: 1; display: grid; place-items: center; color: #8a8d91; background: #f0f2f5; font-size: 13px; }
.pv-bar { display: flex; gap: 18px; padding: 8px 12px; color: #65676b; font-size: 13px; font-weight: 600; border-top: 1px solid #e4e6eb; }
.pv-ig .pv-text { padding-top: 8px; } .pv-ig .pv-text b { margin-right: 5px; }
.pv-tg { background: #a7c6a1 linear-gradient(135deg, #b9d3a8, #8fb69a); padding: 14px; border: 0; }
.pv-tg .bubble { background: #fff; border-radius: 12px; overflow: hidden; max-width: 340px; box-shadow: 0 1px 1px rgba(0,0,0,.15); }
.pv-tg .pv-name { color: #2b7fbf; padding: 8px 10px 0; font-size: 13px; }
.pv-tg .pv-text { padding: 6px 10px 4px; } .pv-tg .meta { text-align: right; font-size: 11px; color: #8a9aa8; padding: 0 10px 6px; }
.pv-tt { background: #000; color: #fff; border: 0; position: relative; }
.pv-tt .pv-img { aspect-ratio: 9 / 16; max-height: 520px; margin: 0 auto; }
.pv-tt .overlay { position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 12px 14px; background: linear-gradient(transparent, rgba(0,0,0,.7)); }
.pv-tt .pv-text { padding: 4px 0 0; color: #fff; } .pv-tt .pv-text .more { color: #ddd; }
.pv-limits { font-size: 12px; color: var(--dim); padding: 6px 2px 0; }

/* ---------- posts ---------- */
.post-list { display: flex; flex-direction: column; gap: 10px; }
.post-item { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 10px 10px; text-decoration: none; color: inherit; }
.post-item:hover { border-color: var(--accent); }
.post-item .pthumb { width: 64px; height: 64px; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.post-item .pthumb img { width: 100%; height: 100%; object-fit: cover; }
.post-item .cap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.post-item .info { font-size: 13px; color: var(--muted); }
.manual { display: flex; flex-direction: column; gap: 12px; }
.manual-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; }
.manual-row.done { background: var(--ok-soft); border-color: transparent; }
.manual-row h3 { margin: 0 0 2px; }
.manual-row .row { justify-content: flex-end; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-art { position: relative; overflow: hidden; background: #0b1c40; color: #fff; display: flex; flex-direction: column; justify-content: space-between; padding: 36px 44px; }
.auth-art img.art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 66% 50%; }
.auth-art > :not(img.art) { position: relative; }
.auth-art::after { content: ''; position: absolute; inset: 0; background: linear-gradient(transparent 60%, rgba(8, 20, 46, .85)), linear-gradient(90deg, transparent 78%, #0a1426); }
.auth-art p { position: relative; z-index: 1; color: #d5e1f2; max-width: 420px; font-size: 1.05rem; margin: 0; }
.auth-art .logo { z-index: 1; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; }
.auth-form form { width: min(380px, 100%); }
.auth-form h1 { font-size: 1.7rem; }
.err { color: var(--bad); background: var(--bad-soft); padding: 10px 12px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }
.theme-fab { position: fixed; top: 14px; right: 14px; }

/* ---------- phone ---------- */
@media (max-width: 1100px) {
  .publish { grid-template-columns: 1fr; }
  .previews { position: static; }
  .stats { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30; background: var(--side); padding: 8px 12px 8px 16px; min-height: 56px; }
  .topbar .ws-switch { flex: 1; min-width: 0; max-width: 220px; margin-left: auto; min-height: 40px; }
  .topbar .btn-ghost { color: var(--side-text); }
  .tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--accent); }
  .main { padding: 18px 16px 90px; }
  .banner { grid-template-columns: 1fr; } .banner img { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats .stat:last-child { grid-column: span 2; }
  .grid-2 { grid-template-columns: 1fr; }
  .asset-edit { grid-template-columns: 1fr; }
  .asset-edit .preview { max-width: 260px; }
  .assets { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .drop img { display: none; }
  .toolbar .input { flex: 1 1 40%; min-width: 0; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .manual-row { grid-template-columns: 1fr; }
  .manual-row .row { justify-content: flex-start; }
  .post-item { grid-template-columns: 56px 1fr; }
  .post-item .pthumb { width: 56px; height: 56px; }
  .post-item .badge { grid-column: 2; justify-self: start; }
  h1 { font-size: 1.35rem; }
}
@media (min-width: 821px) { .tabbar { display: none; } }

/* ---------- insights ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi.hero { border-color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi b { font: 700 1.9rem/1.15 var(--font-display); }
.kpi b.dim-b { color: var(--dim); }
.delta { font-size: 12.5px; color: var(--muted); }
.delta.up { color: var(--ok); } .delta.down { color: var(--bad); }
.delta .dim { font-size: 12px; }
.ins .grid-2 { gap: 16px; align-items: start; margin-bottom: 16px; }
.ins .grid-2 > .card { margin: 0; }
.ins > .card { margin-bottom: 16px; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar { fill: var(--accent); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--dim); font: 11px var(--font); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit.on { fill: var(--accent); fill-opacity: .08; }
.chart .tip { position: absolute; top: -6px; transform: translate(-50%, -100%); background: var(--navy); color: #fff; padding: 6px 10px; border-radius: 8px; font-size: 13px; white-space: nowrap; pointer-events: none; box-shadow: var(--shadow); }
.table-toggle { margin: -4px 0 16px; }
.table-toggle summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--accent); font-weight: 600; font-size: 14px; }
.meter { display: inline-block; vertical-align: middle; width: calc(100% - 52px); max-width: 220px; height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.meter-n { display: inline-block; width: 44px; text-align: right; font-size: 13px; }
table.src td:nth-child(2) { width: 55%; }
.lead-types { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.lead-types li { display: grid; grid-template-columns: 120px 1fr 40px; gap: 10px; align-items: center; font-size: 14px; }
.lead-types .meter { width: 100%; max-width: none; }
.lead-types b { text-align: right; }
.post-nums { display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; white-space: nowrap; }
td.path { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 13px; word-break: break-all; }
.input.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 12.5px; }
.setup code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.ins-wrap { position: relative; }
.ins-wrap.locked .ins { filter: blur(5px) grayscale(.3); opacity: .55; pointer-events: none; user-select: none; }
.lock-card { position: absolute; z-index: 5; left: 50%; top: 120px; transform: translateX(-50%); width: min(460px, calc(100% - 24px)); text-align: center; }
.lock-card img { width: 160px; height: 160px; margin: -8px auto 4px; }
.setup-art { width: 72px; height: 72px; margin: -8px 0 -8px -6px; }
.lock-card h2 { display: flex; align-items: center; justify-content: center; gap: 8px; }
.lock-card h2 svg { width: 22px; height: 22px; color: var(--accent); }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 820px) {
  .kpi b { font-size: 1.5rem; }
  .lead-types li { grid-template-columns: 100px 1fr 32px; }
  .lock-card { top: 60px; }
  .page-head .seg { order: 3; }
  .chart .axis { font-size: 19px; }
}
.main:focus { outline: none; }

/* ---------- batch 1: dialogs, password toggle, badges, autosave, phone preview, filters ---------- */
dialog.small-dlg { width: min(440px, calc(100vw - 32px)); }
dialog.small-dlg h2 { margin-bottom: 8px; }
.btn-danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-solid:hover { filter: brightness(1.08); border-color: var(--bad); }
.pw-wrap { position: relative; display: block; }
.pw-wrap .input { padding-right: 48px; }
.pw-toggle { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 44px; height: 40px; border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; border-radius: 6px; }
.pw-toggle:hover { color: var(--text); }
.pw-toggle svg { width: 20px; height: 20px; }
.nav-badge { margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--sky); color: #04162b; font: 700 12px/22px var(--font); text-align: center; }
.nav-badge.bad { background: var(--bad); color: #fff; }
.tabbar a { position: relative; }
.tabbar .nav-badge { position: absolute; top: 6px; left: calc(50% + 6px); margin: 0; min-width: 18px; height: 18px; padding: 0 5px; font-size: 11px; line-height: 18px; }
.save-state { font-size: 13px; color: var(--dim); display: inline-flex; align-items: center; gap: 6px; min-height: 24px; }
.save-state.dirty { color: var(--warn); }
.save-state.err { color: var(--bad); }
.save-state::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .8; }
.save-state:empty::before { display: none; }
.fab-preview { display: none; }
@media (max-width: 1100px) {
  .fab-preview { display: inline-flex; position: fixed; right: 16px; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 25; box-shadow: 0 6px 20px rgba(6, 14, 30, .35); border-radius: 999px; }
}
@media (max-width: 820px) { .fab-preview { bottom: calc(72px + env(safe-area-inset-bottom)); } }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: -4px 0 14px; }
.filter-chip { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 6px 0 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); border: 0; font: 600 13px var(--font); cursor: pointer; }
.filter-chip svg { width: 16px; height: 16px; }
.drop .btn { flex: none; }
.upload-list .up-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); padding: 6px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.upload-list .up-row.failed { color: var(--bad); border-color: var(--bad); }
.upload-list .up-row .spacer { flex: 1; }
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--text); margin-bottom: 14px; font-size: 14px; }
.notice svg { width: 20px; height: 20px; color: var(--accent); flex: none; margin-top: 1px; }
.chart svg:focus-visible { outline: 2px solid var(--sky); outline-offset: 4px; border-radius: 4px; }
.chart .hit.pinned { fill: var(--accent); fill-opacity: .14; }

/* ---------- PRASAT loader: tiers stack from the base, lights blink upward ---------- */
:root { --tier1: #1A89C5; --tier2: #2875AC; --tier3: #184878; --tier4: #102858; --tier-line: rgba(255, 255, 255, .55); --tier-led: #ffffff; }
:root[data-theme="dark"] { --tier1: #53a6d4; --tier2: #7fb8dc; --tier3: #b3d3ea; --tier4: #ffffff; --tier-line: rgba(16, 40, 88, .45); --tier-led: #102858; }
.prasat-loader { width: 64px; height: 54px; overflow: visible; display: block; }
.prasat-loader .t1 .slab { fill: var(--tier1); } .prasat-loader .t2 .slab { fill: var(--tier2); }
.prasat-loader .t3 .slab { fill: var(--tier3); } .prasat-loader .t4 .slab { fill: var(--tier4); }
.prasat-loader .line { fill: var(--tier-line); }
.prasat-loader .led { fill: var(--tier-led); }
.prasat-loader .tier { animation: tier-in 2.4s cubic-bezier(.2, .7, .2, 1) infinite both; }
.prasat-loader .t4 { animation-delay: 0s; } .prasat-loader .t3 { animation-delay: .16s; }
.prasat-loader .t2 { animation-delay: .32s; } .prasat-loader .t1 { animation-delay: .48s; }
.prasat-loader .led { animation: led-blink 2.4s ease-in-out infinite both; }
.prasat-loader .t4 .led { animation-delay: .7s; } .prasat-loader .t3 .led { animation-delay: .85s; }
.prasat-loader .t2 .led { animation-delay: 1s; } .prasat-loader .t1 .led { animation-delay: 1.15s; }
@keyframes tier-in {
  0% { opacity: 0; transform: translateY(-7px); }
  14% { opacity: 1; transform: translateY(0); }
  82% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(0); }
}
@keyframes led-blink {
  0%, 30% { opacity: .35; }
  38% { opacity: 1; fill: #8fd3ff; }
  52%, 100% { opacity: .35; }
}
/* On a dark mark the lights glow sky; on a light mark they flash white. */
:root[data-theme="dark"] .prasat-loader .led { animation-name: led-blink-dark; }
@keyframes led-blink-dark { 0%, 30% { opacity: .5; } 38% { opacity: 1; fill: #1A89C5; } 52%, 100% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) {
  .prasat-loader .tier { animation: tier-pulse 2.4s ease-in-out infinite both; }
  @keyframes tier-pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }
}
.loader { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 64px 16px; color: var(--muted); font-size: 14px; }
.loader-label { letter-spacing: .02em; }
/* Small version inside buttons: same mark, no labels, light tiers on solid buttons. */
.prasat-loader.mini { width: 20px; height: 17px; }
.btn-primary .prasat-loader.mini, .btn-danger-solid .prasat-loader.mini { --tier1: #ffffff; --tier2: #e3f2fb; --tier3: #c5e2f4; --tier4: #a6d2ee; --tier-line: transparent; --tier-led: #102858; }
.btn[aria-busy="true"] { opacity: 1; cursor: progress; }
.prasat-loader.big { width: 96px; height: 80px; margin: 0 auto 10px; }
.process { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px; background: rgba(6, 14, 30, .55); opacity: 0; transition: opacity .2s; }
.process.on { opacity: 1; }
.process-card { background: var(--surface); border-radius: 16px; padding: 28px 32px 22px; text-align: center; width: min(380px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.process-card h2 { margin: 0 0 6px; }
.process-card p { margin: 0; min-height: 1.5em; }
.upload-list .up-row .prasat-loader.mini { flex: none; }

/* ---------- content research ---------- */
.research-ask { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.trends { margin: 6px 0 10px; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.trends a, .sources a { font-size: 12.5px; }
.sources { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.ideas { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; margin-top: 16px; }
.ideas .card + .card { margin-top: 0; }
.idea { display: flex; flex-direction: column; gap: 10px; }
.idea h3 { margin: 0; font-size: 1.08rem; }
.idea p { margin: 0; font-size: 14px; }
.idea-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.idea-lang { align-self: flex-start; }
.idea-cap { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 14px; max-height: 220px; overflow: auto; }
.idea-cap.km { font-family: var(--font-km); line-height: 1.75; }
.idea-tags { display: flex; flex-direction: column; gap: 6px; }
.idea-tags .field-label { margin-bottom: 2px; font-size: 12px; color: var(--dim); }
.idea-photo { display: grid; grid-template-columns: 72px 1fr; gap: 12px; align-items: start; }
.idea-thumb { width: 72px; height: 72px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; color: var(--dim); }
.idea-thumb img { width: 100%; height: 100%; object-fit: cover; }
.idea-thumb svg { width: 26px; height: 26px; }
.idea-actions { margin-top: auto; padding-top: 4px; }
@media (max-width: 820px) { .ideas { grid-template-columns: 1fr; } .research-ask .btn { flex: 1; } }
/* API keys */
table.keys td { vertical-align: top; }
table.keys td:first-child { width: 40%; }
.key-actions { text-align: right; white-space: nowrap; }
.key-actions .btn + .btn { margin-left: 6px; }
.mono-sm { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 12px; margin-top: 4px; }
.steps-list { margin: 0 0 14px; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
@media (max-width: 820px) {
  table.keys tr { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.keys td { border: 0; padding: 0; width: auto !important; }
  .key-actions { text-align: left; white-space: normal; }
}
