* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", "Khmer OS", "Khmer UI", sans-serif; background: #f3f4f6; color: #222; }
header { background: #4472c4; padding: 12px 24px; }
header a { color: #fff; font-weight: 600; font-size: 18px; text-decoration: none; }
main { max-width: 1200px; margin: 20px auto; padding: 0 16px; }
.flash { background: #d1fae5; border: 1px solid #6ee7b7; padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=text] { flex: 1; min-width: 200px; }
input[type=text], textarea { width: 100%; padding: 8px 10px; border: 1px solid #bbb; border-radius: 6px; font: inherit; }
textarea { min-height: 90px; }
label { display: block; font-weight: 600; margin: 14px 0 4px; }
.btn { display: inline-block; padding: 7px 14px; border: 0; border-radius: 6px; background: #4472c4; color: #fff; text-decoration: none; cursor: pointer; font: inherit; font-size: 14px; }
.btn.gray { background: #6b7280; }
.btn.red { background: #dc2626; }
.btn.small { padding: 3px 9px; font-size: 12px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th { background: #b4c6e7; padding: 10px; border: 1px solid #333; }
td { border: 1px solid #333; padding: 8px 10px; vertical-align: middle; background: #d9d9d9; }
td.name { text-align: center; font-size: 22px; }
td.no { text-align: center; }
td img { max-width: 260px; max-height: 110px; display: block; }
td a.url { display: block; word-break: break-all; }
.actions { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.actions form { margin: 0; }
.card { background: #fff; border-radius: 8px; padding: 20px; max-width: 640px; }
.thumb { max-width: 260px; display: block; margin: 8px 0; }
.muted { color: #6b7280; }
header { display: flex; align-items: center; gap: 24px; }
header nav { display: flex; gap: 16px; }
header nav a { font-size: 15px; font-weight: 400; opacity: .9; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border-radius: 8px; padding: 16px; }
.stat .n { font-size: 32px; font-weight: 700; color: #4472c4; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.card.wide { max-width: none; }
.card h3 { margin-top: 0; }
.bar-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.bar-label { width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: inherit; text-decoration: none; }
.bar { flex: 1; background: #e5e7eb; border-radius: 4px; height: 14px; }
.bar span { display: block; height: 100%; background: #4472c4; border-radius: 4px; }
.recent { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.rcard { display: flex; flex-direction: column; gap: 4px; padding: 10px; border: 1px solid #ddd; border-radius: 8px; color: inherit; text-decoration: none; }
.rcard img { width: 100%; height: 80px; object-fit: contain; background: #f3f4f6; }
body { font-family: "Noto Sans Khmer", "Segoe UI", "Khmer UI", sans-serif; }
header { flex-wrap: wrap; }
header .brand { color: #fff; font-weight: 600; font-size: 18px; text-decoration: none; }
header nav a { color: #fff; text-decoration: none; padding: 4px 8px; border-radius: 6px; }
header nav a.on, header nav a:hover { background: rgba(255,255,255,.22); }
header .right { margin-left: auto; display: flex; align-items: center; gap: 8px; color: #fff; font-size: 14px; }
header .right a.lang { color: #fff; opacity: .7; text-decoration: none; font-size: 13px; }
header .right a.lang.on { opacity: 1; font-weight: 700; text-decoration: underline; }
.err { color: #dc2626; }
.c { text-align: center; }
.card.login { margin: 40px auto; max-width: 380px; }
input[type=password], input[type=date], select { padding: 8px 10px; border: 1px solid #bbb; border-radius: 6px; font: inherit; background: #fff; }
.card input[type=password], .card select { width: 100%; }
.toolbar select { width: auto; }
.toolbar { align-items: center; }
form.inline { display: inline-flex; gap: 4px; margin: 0 4px 0 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #e5e7eb; color: #333; text-decoration: none; }
.badge.st-active { background: #bbf7d0; } .badge.st-banned { background: #fecaca; }
.badge.st-closed { background: #e5e7eb; color: #555; } .badge.st-unchecked { background: #fef08a; }
.badge.cat { background: #bfdbfe; } .badge.tag { background: #ddd6fe; } .badge.fol { background: #fed7aa; }
.badge.act-delete { background: #fecaca; } .badge.act-create { background: #bbf7d0; } .badge.act-update { background: #bfdbfe; }
.note { font-size: 13px; color: #444; margin-top: 4px; font-weight: 400; text-align: left; }
.imgs { display: flex; flex-wrap: wrap; gap: 6px; }
.imgs img { max-width: 260px; max-height: 110px; cursor: zoom-in; background: #fff; }
.imgbox { display: flex; flex-direction: column; gap: 4px; margin: 0; font-weight: 400; font-size: 13px; }
.imgs.edit img, #imgPreview img { max-width: 160px; max-height: 90px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; background: #9ca3af; }
.dot.ok { background: #16a34a; } .dot.bad { background: #dc2626; }
.dup { background: #fef3c7; border: 1px solid #fcd34d; padding: 8px 12px; border-radius: 6px; margin-top: 6px; }
.dup ul { margin: 4px 0 0; padding-left: 20px; }
.dupgroup { margin-bottom: 10px; }
.pager { display: flex; gap: 4px; margin: 14px 0; flex-wrap: wrap; }
.pager a, .pager span { padding: 4px 10px; border: 1px solid #ccc; border-radius: 6px; background: #fff; color: #333; text-decoration: none; }
.pager a.cur { background: #4472c4; color: #fff; border-color: #4472c4; }
.chart { width: 100%; height: auto; }
ul.plain { list-style: none; padding: 0; margin: 0 0 8px; font-size: 14px; }
ul.plain li { padding: 3px 0; border-bottom: 1px solid #eee; }
a.stat { color: inherit; text-decoration: none; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 99; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 95vh; }
@media (max-width: 700px) { .two { grid-template-columns: 1fr; } table { font-size: 14px; } td.name { font-size: 18px; } }

/* ===== Sidebar layout (dark sidebar + light content) ===== */
:root { --side: #111418; --side2: #1b2027; --accent: #2447f5; --bg: #eaf1fe; --line: #dbe4f3; }
body { background: var(--bg); color: #111827; font-size: 14px; }
.app { display: flex; min-height: 100vh; }
.sidebar { width: 270px; flex: 0 0 270px; background: var(--side); color: #cfd6e0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; transition: width .2s, flex-basis .2s; }
.content { flex: 1; min-width: 0; }
.content main { max-width: none; margin: 0; padding: 28px 40px; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 22px 20px 18px; border-bottom: 1px solid #262c35; }
.brand { display: flex; align-items: center; gap: 10px; color: #2f54ff; font-weight: 700; font-size: 18px; text-decoration: none; white-space: nowrap; }
.collapse { width: 26px; height: 26px; border-radius: 50%; border: 0; background: #2a3039; color: #cfd6e0; cursor: pointer; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 14px 20px; font-size: 13px; color: #aab3c0; border-bottom: 1px solid #262c35; }
.sidebar nav { display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: 14px; padding: 11px 12px; border-radius: 8px; color: #e5e9f0; text-decoration: none; font-size: 15px; white-space: nowrap; }
.sidebar nav a:hover { background: var(--side2); }
.sidebar nav a.on { background: #1a2340; color: #6b86ff; }
.ic { width: 20px; height: 20px; flex: 0 0 20px; }
.side-bottom { margin-top: auto; padding: 14px 16px 20px; border-top: 1px solid #262c35; display: flex; flex-direction: column; gap: 10px; }
.langs { display: flex; gap: 6px; }
.langs a.lang { color: #cfd6e0; text-decoration: none; padding: 3px 10px; border-radius: 6px; background: var(--side2); font-size: 13px; }
.langs a.lang.on { background: var(--accent); color: #fff; }
.logout { display: flex; align-items: center; gap: 12px; width: 100%; background: transparent; border: 0; color: #cfd6e0; padding: 8px 4px; cursor: pointer; font: inherit; }
.logout:hover { color: #fff; }
.sidebar.collapsed { width: 68px; flex-basis: 68px; }
.sidebar.collapsed .lbl, .sidebar.collapsed .langs { display: none; }
.sidebar.collapsed .side-top { flex-direction: column; gap: 10px; padding: 16px 0; }
.sidebar.collapsed nav a, .sidebar.collapsed .side-user, .sidebar.collapsed .logout { justify-content: center; }
.sidebar.collapsed .collapse { transform: rotate(180deg); }

/* ===== Content styling ===== */
h2 { font-size: 26px; margin: 0 0 20px; }
.card, .stat, .rcard { border: 1px solid var(--line); box-shadow: none; }
.card { background: #fbfdff; border-radius: 12px; }
.stats { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.stat { background: #fbfdff; border-radius: 10px; padding: 16px 14px; }
.stat .muted { order: -1; font-size: 13px; color: #55607a; margin-bottom: 6px; }
.stat { display: flex; flex-direction: column; }
.stat .n { font-size: 24px; color: #111827; font-weight: 700; }
.btn { background: var(--accent); border-radius: 8px; }
.btn.gray { background: #eef2f9; color: #1f2a44; border: 1px solid var(--line); }
.btn.red { background: #dc2626; color: #fff; border: 0; }
.bar span { background: #6366f1; } .bar { background: #e6ecf8; }
input[type=text], input[type=password], input[type=date], textarea, select { background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.toolbar select, .toolbar input[type=text] { padding: 8px 10px; }

table { background: #fbfdff; border: 1px solid var(--line); border-collapse: separate; border-spacing: 0; border-radius: 12px; overflow: hidden; }
th { background: #eef3fc; color: #334155; border: 0; border-bottom: 1px solid var(--line); text-align: left; font-weight: 600; }
td { background: #fbfdff; border: 0; border-bottom: 1px solid var(--line); border-right: 1px solid #edf1f9; }
td:last-child { border-right: 0; }
td.name, td.no { background: #f6f9ff; }
td.name { font-size: 20px; }

/* ===== Chart card ===== */
.chart-card { margin-top: 16px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.chart-head h3 { margin: 0; font-size: 18px; } .chart-head h3 small { font-weight: 400; color: #55607a; font-size: 14px; }
.seg { display: flex; gap: 6px; }
.seg a { padding: 5px 12px; border-radius: 6px; border: 1px solid var(--line); color: #111827; text-decoration: none; font-size: 13px; background: #fff; }
.seg a.on { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0; font-size: 13px; color: #55607a; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 2px; margin-right: 6px; }
.gchart { width: 100%; height: auto; }
@media (max-width: 800px) { .sidebar { position: fixed; z-index: 20; width: 68px; flex-basis: 68px; } .sidebar .lbl, .sidebar .langs { display: none; } .content { margin-left: 68px; } .content main { padding: 18px 14px; } }
.app.guest .sidebar { display: none; } .app.guest .content main { max-width: 480px; margin: 0 auto; }
.dot.unk { background: #f59e0b; }
.autoread { margin-top: 14px; padding: 12px 14px; background: #eef3fc; border: 1px solid var(--line); border-radius: 8px; } label.chk { display: flex; gap: 8px; align-items: center; margin: 0 0 6px; }

/* ===== Collapsible members list ===== */
table.members { table-layout: fixed; }
tr.mrow { cursor: pointer; }
tr.mrow td { background: #fbfdff; padding: 12px 14px; }
tr.mrow:hover td { background: #f1f6ff; }
tr.mrow td.mname { font-size: 18px; font-weight: 600; text-align: left; }
tr.mrow .chev { display: inline-block; width: 18px; color: #6b7a99; transition: transform .15s; }
tr.mrow.open .chev { transform: rotate(90deg); }
tr.mrow.open td { background: #eef3fc; }
.count { display: inline-block; min-width: 34px; text-align: center; padding: 2px 10px; border-radius: 12px; background: #dbe4ff; color: #1d3bd1; font-weight: 700; }
tr.detail > td { background: #f6f9ff; padding: 14px 16px 18px; border-bottom: 2px solid var(--line); }
table.inner { background: #fff; border-radius: 8px; table-layout: auto; }
table.inner td { background: #fff; vertical-align: top; text-align: left; }
tr.detail[hidden] { display: none; }
td.mact .actions { margin: 0; justify-content: flex-end; }
td.mnote { text-align: left; font-size: 13px; color: #374151; white-space: normal; word-break: break-word; }

/* ===== Theming via settings (colour variables come from brand_head()) ===== */
.sidebar { color: var(--side-fg); }
.sidebar nav a { color: var(--side-fg); }
.sidebar nav a:hover { background: var(--side2); }
.sidebar nav a.on { background: color-mix(in srgb, var(--accent) 24%, var(--side)); color: color-mix(in srgb, var(--accent) 55%, var(--side-fg)); }
.side-top, .side-user, .side-bottom { border-color: var(--side-line); }
.side-user { color: var(--side-fg2); }
.brand { color: color-mix(in srgb, var(--accent) 55%, var(--side-fg)); }
.collapse { background: var(--side2); color: var(--side-fg); }
.langs a.lang { background: var(--side2); color: var(--side-fg); }
.langs a.lang.on { background: var(--accent); color: #fff; }
.logout { color: var(--side-fg); }
.stat .n { color: var(--accent); }
.count { background: color-mix(in srgb, var(--accent) 14%, #fff); color: var(--accent); }
.bar span { background: var(--accent); }
.pager a.cur, .seg a.on { background: var(--accent); border-color: var(--accent); }
tr.mrow.open td { background: color-mix(in srgb, var(--accent) 7%, #fff); }
tr.detail > td { background: color-mix(in srgb, var(--accent) 4%, #fff); }
img.logo { height: 34px; max-width: 150px; object-fit: contain; border-radius: 6px; }
.sidebar.collapsed img.logo { height: 30px; max-width: 40px; }
.login-logo { display: block; max-height: 64px; max-width: 220px; margin: 0 auto 12px; object-fit: contain; }
.foot { padding: 14px 40px 24px; color: #55607a; font-size: 13px; text-align: center; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 9px 16px; color: #475569; text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.colors { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 8px; }
.colors input[type=color] { width: 64px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.icons-prev { display: flex; gap: 10px; align-items: center; margin: 6px 0; }
.icons-prev img, .logo-prev { border: 1px solid var(--line); border-radius: 10px; background: repeating-conic-gradient(#e5e7eb 0 25%, #fff 0 50%) 0 0 / 14px 14px; }
.logo-prev { max-height: 70px; max-width: 220px; }
#installBtn { width: 100%; }
.sidebar.collapsed #installBtn { padding: 6px 0; }

/* ===== Member cards + member page ===== */
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.mcard { display: flex; flex-direction: column; gap: 10px; padding: 16px; background: #fbfdff; border: 1px solid var(--line); border-radius: 14px; color: inherit; text-decoration: none; transition: transform .12s, box-shadow .12s, border-color .12s; }
.mcard:hover, .mcard:focus-visible { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(30, 50, 100, .12); border-color: var(--accent); outline: none; }
.mcard-top { display: flex; align-items: center; gap: 12px; }
.mavatar { flex: 0 0 48px; width: 48px; height: 48px; border-radius: 12px; overflow: hidden; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 14%, #fff); color: var(--accent); font-weight: 700; font-size: 20px; }
.mavatar img { width: 100%; height: 100%; object-fit: cover; }
.mtitle { flex: 1; min-width: 0; }
.mname2 { font-size: 18px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mnote2 { font-size: 13px; color: #374151; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.mnote2.full { display: block; -webkit-line-clamp: unset; font-size: 14px; margin: 8px 0; }
.mcard-foot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.vhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 14px; }
.vnav { display: flex; gap: 6px; }
.vcard { margin-bottom: 16px; }
.vtitle { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.pcard h3 { margin: 0 0 6px; font-size: 17px; }
.pcard .urls { margin: 8px 0; }
.pcard .imgs { margin: 10px 0; }
.pcard .imgs img { max-width: 100%; }
@media (max-width: 600px) { .mgrid, .pgrid { grid-template-columns: 1fr; } .toolbar > * { flex: 1 1 140px; } }

/* Member box: whole box clickable through the name link, buttons stay on top */
.mcard { position: relative; }
.mcard a.stretch { color: inherit; text-decoration: none; display: block; }
.mcard a.stretch::after { content: ""; position: absolute; inset: 0; border-radius: 14px; }
.mcard .mact2 { position: relative; z-index: 2; margin: 2px 0 0; padding-top: 10px; border-top: 1px solid var(--line); }
.mcard .mcard-foot a, .mcard .mcard-foot span { position: relative; }

/* ===== Small screens: menu hidden by default, slides in from the left ===== */
.topbar, .backdrop { display: none; }
@media (max-width: 800px) {
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30; padding: 10px 14px; background: var(--side); color: var(--side-fg); border-bottom: 1px solid var(--side-line); }
  .menu-btn { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 10px; background: var(--side2); color: var(--side-fg); cursor: pointer; }
  .topbrand { color: var(--side-fg); font-weight: 700; text-decoration: none; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app.guest .topbar { display: none; }

  .sidebar, .sidebar.collapsed { position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; width: min(290px, 85vw); flex: none; height: 100%; transform: translateX(-102%); transition: transform .22s ease; box-shadow: none; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  .sidebar .lbl, .sidebar .langs, .sidebar.collapsed .lbl, .sidebar.collapsed .langs { display: revert; }
  .sidebar.collapsed .side-top { flex-direction: row; padding: 22px 20px 18px; gap: 0; }
  .sidebar.collapsed nav a, .sidebar.collapsed .side-user, .sidebar.collapsed .logout { justify-content: flex-start; }
  .sidebar .langs { display: flex; }
  .sidebar img.logo, .sidebar.collapsed img.logo { height: 34px; max-width: 150px; }
  .collapse { display: none; }

  .backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.menu-open .backdrop { opacity: 1; pointer-events: auto; }
  body.menu-open { overflow: hidden; }

  .content { margin-left: 0; }
  .content main { padding: 18px 14px; }
  .foot { padding: 14px; }
}
