:root {
    --bg: #f0f2f5;
    --card: #fff;
    --text: #1c1e21;
    --muted: #65676b;
    --border: #dddfe2;
    --primary: #1877f2;
    --primary-dark: #166fe5;
    --danger: #e41e3f;
    --success: #31a24c;
    --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Khmer", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .5rem 0 1rem; }
h3, h4 { margin-top: 0; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: .8rem; font-weight: normal; margin-left: .5rem; }

/* Top bar */
.topbar { background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar .wrap { display: flex; align-items: center; gap: 1rem; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 1.4rem; color: var(--primary); }
.brand span { color: var(--text); }
.brand:hover { text-decoration: none; }
.menu { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; align-items: center; }
.menu a { padding: .4rem .7rem; border-radius: 6px; color: var(--muted); font-weight: 600; }
.menu a:hover { background: var(--bg); text-decoration: none; }
.menu a.active { color: var(--primary); background: #e7f3ff; }
.menu .sep { width: 1px; height: 22px; background: var(--border); margin: 0 .4rem; }
.who { display: flex; gap: .6rem; align-items: center; font-weight: 600; }

main { padding: 1.25rem 16px 2rem; }
.foot { color: var(--muted); font-size: .85rem; padding-bottom: 2rem; }

/* Cards & layout */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card.auth { max-width: 400px; margin: 3rem auto; }
.card.empty { text-align: center; color: var(--muted); padding: 2rem; }
.grid { display: grid; grid-template-columns: 1fr 300px; gap: 1rem; align-items: start; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; }
.stat .n { font-size: 2rem; font-weight: 800; color: var(--primary); }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
@media (max-width: 800px) { .grid, .grid-2 { grid-template-columns: 1fr; } }

/* Forms */
label { display: block; margin-bottom: .8rem; font-weight: 600; font-size: .9rem; }
label.check { display: inline-flex; gap: .3rem; align-items: center; margin: 0; font-weight: normal; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=url], input[type=date], select, textarea {
    display: block; width: 100%; margin-top: .3rem; padding: .6rem .75rem; font: inherit; font-weight: normal;
    border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px #e7f3ff; }
.btn { display: inline-block; background: var(--primary); color: #fff; border: 0; border-radius: 6px; padding: .6rem 1.1rem; font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-light { background: #e4e6eb; color: var(--text); }
.btn-light:hover { background: #d8dadf; }
.btn-danger { background: var(--danger); }
.auth .btn { width: 100%; padding: .75rem; font-size: 1rem; }
button.link { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0; font: inherit; }
button.link:hover { text-decoration: underline; }
.danger { color: var(--danger) !important; }
form.inline { display: inline; }
.searchbar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.searchbar input { margin: 0; font-size: 1.05rem; }
.filters, .form-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filters input, .filters select, .form-row input, .form-row select { width: auto; flex: 1 1 140px; margin: 0; }
.form-row { margin-top: .75rem; }

/* Alerts & badges */
.alert { padding: .7rem 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: #e9f7ec; border-color: #b6e2c0; color: #1e6b32; }
.alert-error   { background: #fdecee; border-color: #f5b5bf; color: #a3122b; }
.alert-warning { background: #fff8e1; border-color: #f3dc8e; color: #7a5b00; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.badge-success { background: #e9f7ec; color: var(--success); }
.badge-failed  { background: #fdecee; color: var(--danger); }
.tag { font-size: .75rem; background: #e7f3ff; color: var(--primary); padding: .1rem .5rem; border-radius: 999px; margin-left: .4rem; vertical-align: middle; }

/* Results & lists */
.result h3 { margin-bottom: .3rem; }
.result p { margin: .3rem 0; }
.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.chips a { display: inline-block; background: var(--bg); padding: .25rem .7rem; border-radius: 999px; color: var(--text); }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: .3rem 0; border-bottom: 1px solid var(--bg); display: flex; justify-content: space-between; }

/* Tables */
.table-wrap { overflow-x: auto; padding: 0; }
.table-wrap h3 { padding: 1rem 1.25rem 0; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .6rem .9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #f7f8fa; font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.ua { max-width: 320px; color: var(--muted); font-size: .8rem; word-break: break-word; }
td.actions { white-space: nowrap; }
td.actions > * { margin-right: .5rem; }
td.actions button.link { margin-right: .5rem; }

.pagination { display: flex; gap: .3rem; flex-wrap: wrap; margin: 1rem 0; }
.pagination a, .pagination span { padding: .35rem .75rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card); }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }
details summary { cursor: pointer; }
.input-btn { display: flex; gap: .5rem; align-items: stretch; margin-top: .3rem; }
.input-btn input { margin-top: 0; }
.input-btn .btn { font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: wait; }
#kw-gemini-status { margin: -.4rem 0 .8rem; min-height: 1em; }
.copy-btn { margin-left: .4rem; padding: .1rem .5rem; font: inherit; font-size: .75rem; font-weight: 600; color: var(--primary); background: #e7f3ff; border: 1px solid #c9e0fb; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.copy-btn:hover { background: #d8eaff; }
.copy-btn.copied { color: var(--success); background: #e9f7ec; border-color: #b6e2c0; }
.menu-count { margin-left: -.35rem; margin-right: .2rem; background: var(--danger); color: #fff; border-radius: 999px; font-size: .7rem; font-weight: 700; padding: 0 .4rem; line-height: 1.3; }
.tabs { display: flex; gap: .3rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .4rem .9rem; border-radius: 6px; background: var(--card); border: 1px solid var(--border); color: var(--muted); font-weight: 600; }
.tabs a.active { background: #e7f3ff; color: var(--primary); border-color: #c9e0fb; }
.tabs .count { font-size: .75rem; background: var(--bg); border-radius: 999px; padding: 0 .4rem; margin-left: .2rem; }
.btn-small { padding: .25rem .6rem; font-size: .8rem; }
.badge-pending { background: #fff8e1; color: #7a5b00; }
.badge-added { background: #e9f7ec; color: var(--success); }
.badge-rejected { background: #fdecee; color: var(--danger); }
.card.empty p { margin: .4rem 0; }
.card.empty form { margin: .8rem 0 .2rem; }
.auth-logo-wrap { text-align: center; margin: -.25rem 0 .5rem; }
.auth-logo { display: inline-block; width: 160px; max-width: 100%; height: auto; border-radius: 6px; }
.auth h1 { text-align: center; }
.auth-contact { text-align: center; }
