:root {
  --bg: #07080b; --panel: #0e1117; --panel2: #131720; --line: #1f2530;
  --text: #e8ecf3; --muted: #8b95a7; --blue: #2f7bff; --blue-d: #0b1c3d;
  --green: #2ecc71; --red: #ef4444; --amber: #f5a524;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
a { color: var(--blue); text-decoration: none; } a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .small { font-size: 12px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .08em; font-size: 16px; }
.brand small { font-weight: 500; color: var(--muted); letter-spacing: 0; }
.brand .logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, #1459e0, #2d7bff); color: #fff; }
.brand.big { font-size: 22px; } .brand.big .logo { width: 40px; height: 40px; font-size: 20px; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
input, select, textarea { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; outline: none; }
input:focus, select:focus { border-color: var(--blue); }
.error { color: #ff8a8a; background: #2a0f12; border: 1px solid #5b1a1f; padding: 8px 10px; border-radius: 10px; }

.btn { border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 9px 14px; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 600; }
.btn:hover { border-color: #31405a; } .btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: linear-gradient(135deg, #1459e0, #2d7bff); border-color: transparent; color: #fff; }
.btn.danger { color: #ff7b7b; border-color: #5b1a1f; background: #230d10; }
.btn.ok { color: #6fe6a0; border-color: #1c5a37; background: #0b1f15; }
.btn.ghost { background: transparent; } .small-btn { padding: 6px 10px; font-size: 12px; }

.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
#nav { display: grid; gap: 4px; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--muted); font-weight: 600; }
#nav a:hover { background: var(--panel2); color: var(--text); text-decoration: none; }
#nav a.active { background: var(--blue-d); color: #6aa2ff; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; }
.main { min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 18px 24px; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 20px; }
.page { padding: 22px 24px 60px; display: grid; gap: 18px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.stat b { display: block; font-size: 26px; margin-top: 2px; } .stat span { color: var(--muted); font-size: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 15px; }
.row2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; height: 100%; }
.bars .bar i { display: block; width: 100%; background: linear-gradient(180deg, #2d7bff, #1459e0); border-radius: 5px 5px 0 0; min-height: 2px; }
.bars .bar em { font-style: normal; font-size: 10px; color: var(--muted); } .bars .bar u { text-decoration: none; font-size: 10px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar input[type=search], .toolbar select { min-width: 200px; }
.tablewrap { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
td.wrap { white-space: normal; min-width: 220px; max-width: 420px; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; background: var(--panel2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; } tbody tr:hover { background: #0f131b; }
td.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; border: 1px solid var(--line); color: var(--muted); }
.badge.blue { color: #6aa2ff; background: var(--blue-d); border-color: #1d3a73; }
.badge.green { color: #6fe6a0; background: #0b1f15; border-color: #1c5a37; }
.badge.red { color: #ff8a8a; background: #2a0f12; border-color: #5b1a1f; }
.badge.amber { color: #ffcf7a; background: #2b1f08; border-color: #6b4a10; }
.who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--blue-d); color: #6aa2ff; display: grid; place-items: center; font-weight: 700; font-size: 12px; overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.thumb { width: 56px; height: 40px; object-fit: cover; border-radius: 6px; background: var(--panel2); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { position: relative; width: 100%; max-width: 640px; max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px; }
.modal-x { position: absolute; top: 10px; right: 14px; background: none; border: 0; color: var(--muted); font-size: 26px; cursor: pointer; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; margin: 14px 0; } .kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #16203a; border: 1px solid #2a4380; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 60; }
.toast.err { background: #2a0f12; border-color: #5b1a1f; }
#map { height: 460px; border-radius: 14px; border: 1px solid var(--line); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  #nav { display: flex; flex-wrap: wrap; } .sidebar-foot { margin: 0 0 0 auto; display: flex; align-items: center; }
  .row2 { grid-template-columns: 1fr; } .page { padding: 14px; } .topbar { padding: 12px 14px; }
}

/* confirmation dialog */
.modal.dialog { z-index: 100; background: rgba(0,0,0,.72); backdrop-filter: blur(3px); }
.dialog-card { max-width: 400px; text-align: center; display: grid; gap: 10px; padding: 26px 24px 20px; animation: dlg-in .14s ease-out; }
.dialog-card h3 { margin: 0; font-size: 18px; }
.dialog-msg { margin: 0; color: var(--muted); line-height: 1.5; }
.dialog-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 2px; font-size: 24px; background: var(--blue-d); }
.dialog-icon.danger { background: #2a1013; }
.dialog-card label { text-align: left; margin-top: 4px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.dialog-actions .btn { min-width: 96px; }
@keyframes dlg-in { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Glow theme (blue / black / white) ===== */
:root { --bg: #040a16; --panel: rgba(9,18,38,.82); --panel2: rgba(14,28,58,.7); --line: rgba(47,123,255,.28); --glow: 0 0 0 1px rgba(47,123,255,.18), 0 0 22px rgba(30,100,255,.16); }
html, body { background-color: #030812; }
body {
  background-image:
    linear-gradient(115deg, transparent 0 38%, rgba(30,90,230,.10) 38% 46%, transparent 46% 100%),
    linear-gradient(115deg, transparent 0 58%, rgba(30,90,230,.07) 58% 62%, transparent 62% 100%),
    radial-gradient(900px 500px at 85% 0%, rgba(30,110,255,.22), transparent 60%),
    radial-gradient(700px 500px at 0% 100%, rgba(20,80,220,.16), transparent 60%);
  background-attachment: fixed;
}
.ico { width: 20px; height: 20px; flex: none; }

.brand .logo { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; background: #000; box-shadow: 0 0 0 1px rgba(47,123,255,.5), 0 0 14px rgba(47,123,255,.35); }
.brand.big .logo { width: 56px; height: 56px; }
.brand { font-size: 18px; }

.sidebar { margin: 10px; height: calc(100vh - 20px); top: 10px; border: 1px solid rgba(47,123,255,.45); border-radius: 22px; background: linear-gradient(180deg, rgba(8,18,40,.92), rgba(4,10,24,.94)); box-shadow: var(--glow), inset 0 0 30px rgba(30,100,255,.06); }
#nav a { padding: 11px 14px; border-radius: 12px; font-weight: 500; }
#nav a .ico { opacity: .9; }
#nav a:hover { background: rgba(47,123,255,.12); }
#nav a.active { background: linear-gradient(180deg, #1f7bff, #0b5cff); color: #fff; box-shadow: 0 0 18px rgba(30,120,255,.55); }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 12px; }
#logout { width: 100%; justify-content: center; border-color: var(--line); background: rgba(10,22,48,.8); }

.topbar { border-bottom: 0; padding: 22px 28px 6px; }
.topbar h1 { font-size: 30px; font-weight: 800; position: relative; padding-bottom: 12px; }
.topbar h1::after { content: ""; position: absolute; left: 0; bottom: 0; width: 44px; height: 3px; border-radius: 3px; background: #2f7bff; box-shadow: 0 0 10px #2f7bff; }
#refresh { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; font-size: 14px; border-color: #2f7bff; border-radius: 12px; box-shadow: var(--glow); }

.panel, .tablewrap, .stat, .login-card, .modal-card {
  background: linear-gradient(180deg, rgba(10,22,46,.86), rgba(6,14,32,.88));
  border: 1px solid rgba(47,123,255,.4); border-radius: 16px; box-shadow: var(--glow);
}
.stat { display: flex; align-items: center; gap: 14px; text-decoration: none; color: inherit; padding: 16px; }
.stat:hover { text-decoration: none; border-color: #2f7bff; }
.stat-ico { color: #4f9bff; display: grid; place-items: center; } .stat-ico .ico { width: 34px; height: 34px; }
.stat-txt { display: grid; } .stat-txt span { color: var(--text); font-size: 13px; } .stat-txt b { font-size: 30px; margin-top: 0; }
th { background: transparent; color: #7fb0ff; border-bottom: 1px solid var(--line); }
td, th { border-bottom-color: rgba(47,123,255,.14); }
tbody tr:hover { background: rgba(47,123,255,.07); }
.btn { background: rgba(10,22,48,.8); border-color: rgba(47,123,255,.4); border-radius: 12px; }
.btn:hover { border-color: #2f7bff; }
.btn.primary { background: linear-gradient(180deg, #1f7bff, #0b5cff); box-shadow: 0 0 20px rgba(30,120,255,.5); }
.btn.danger { background: rgba(60,10,16,.7); border-color: rgba(239,68,68,.55); color: #ff6b6b; box-shadow: 0 0 12px rgba(239,68,68,.2); }
input, select, textarea { background: rgba(8,18,40,.85); border-color: rgba(47,123,255,.35); border-radius: 12px; }
input:focus, select:focus { box-shadow: 0 0 0 3px rgba(47,123,255,.25); }
.badge.blue { background: rgba(31,123,255,.18); border-color: rgba(47,123,255,.6); color: #7fb0ff; }
.avatar { background: #0b45c9; color: #fff; }
.bars .bar i { background: linear-gradient(180deg, #4f9bff, #0b5cff); box-shadow: 0 0 10px rgba(47,123,255,.5); }
#map { border-color: rgba(47,123,255,.4); box-shadow: var(--glow); }

.login-wrap { background: radial-gradient(500px 420px at 50% 20%, rgba(30,100,255,.35), transparent 70%); }
.login-card { max-width: 440px; padding: 34px; gap: 16px; }
.login-card .brand.big { justify-content: center; }
.login-card .muted { text-align: center; margin: 0; }
.login-card .btn.primary { padding: 14px; font-size: 16px; border-radius: 12px; }
.secure { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; justify-content: center; }
.secure span { flex: 1; height: 1px; background: var(--line); }
@media (max-width: 860px) { .sidebar { margin: 0; height: auto; top: 0; border-radius: 0; } }

/* ---- Audit log + page header (matches design) ---- */
.title-wrap { display: flex; align-items: flex-start; gap: 16px; }
.page-ico svg { width: 44px; height: 44px; color: #3b8bff; filter: drop-shadow(0 0 8px rgba(47,123,255,.6)); margin-top: 2px; }
.topbar h1::after { display: none; }
.topbar h1 { padding-bottom: 0; font-size: 30px; }
.page-sub { margin: 6px 0 0; color: #b9c8e6; font-size: 14px; }
#refresh { border: 2px solid #2f7bff; border-radius: 12px; padding: 12px 20px; font-size: 15px; font-weight: 700; color: #fff; background: rgba(10,30,80,.6); box-shadow: 0 0 16px rgba(47,123,255,.55), inset 0 0 12px rgba(47,123,255,.25); }
th .ico { width: 17px; height: 17px; margin-right: 8px; vertical-align: -3px; color: #3b8bff; }
th { text-transform: uppercase; letter-spacing: .04em; font-size: 12px; color: #dfe9ff; }
td.au-when, td.au-admin { display: table-cell; }
.au-when, .au-admin { white-space: nowrap; }
td.au-when > *, td.au-admin > * { display: inline-block; vertical-align: middle; }
.au-ico svg { width: 24px; height: 24px; color: #3b8bff; margin-right: 14px; }
td.au-admin .avatar { width: 46px; height: 46px; font-size: 15px; margin-right: 14px; box-shadow: 0 0 0 2px rgba(47,123,255,.5); }
.au-main { color: #fff; font-weight: 600; font-size: 15px; }
.au-sub { color: #93a6cc; font-size: 13px; margin-top: 3px; }
.au-pill { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 12px; font-weight: 700; font-size: 14px; border: 1px solid; }
.au-pill .ico { width: 16px; height: 16px; }
.au-pill.red { color: #ff7a7a; background: rgba(120,20,30,.45); border-color: rgba(255,80,90,.5); }
.au-pill.blue { color: #7fb0ff; background: rgba(31,123,255,.18); border-color: rgba(47,123,255,.6); }
.au-details { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: rgba(4,12,34,.8); border: 1px solid rgba(47,123,255,.3); border-radius: 12px; padding: 10px 10px 10px 16px; }
.au-details code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; color: #e6eeff; word-break: break-all; }
.au-copy { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; border: 1px solid rgba(47,123,255,.7); background: rgba(31,123,255,.18); color: #7fb0ff; cursor: pointer; }
.au-copy:hover { background: rgba(31,123,255,.4); }
.au-copy .ico { width: 18px; height: 18px; }
.pager .small-btn { width: 46px; height: 46px; padding: 0; display: grid; place-items: center; border-radius: 12px; border: 1px solid rgba(47,123,255,.6); background: rgba(10,30,80,.6); color: #fff; }
.pager .small-btn .ico { width: 20px; height: 20px; }
.pager { color: #dfe9ff; font-size: 15px; margin-top: 14px; }

/* Keep Leaflet panes (z-index up to 1000) below dialogs */
#map { position: relative; z-index: 0; isolation: isolate; }
.modal, .modal.dialog { z-index: 2000; }
.toast { z-index: 2100; }

/* ---------- New challenge form ---------- */
.nc { display: grid; gap: 16px; width: 100%; }
.nc-head { display: flex; gap: 12px; align-items: center; }
.nc-head .ico { width: 40px; height: 40px; padding: 9px; border-radius: 12px; background: var(--blue-d); color: #6aa2ff; border: 1px solid #1d3a73; flex: none; }
.nc-head h2 { margin: 0; font-size: 20px; } .nc-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.nc-sec { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.02); }
.nc-sec > h4 { margin: 0; font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: #6aa2ff; }
.nc-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .nc-row { grid-template-columns: 1fr; } }
.nc label { color: var(--text); font-weight: 600; font-size: 12.5px; }
.nc label .hint { color: var(--muted); font-weight: 400; }
.nc input, .nc select, .nc textarea { width: 100%; box-sizing: border-box; }
.nc textarea { resize: vertical; min-height: 76px; }
.nc-count { justify-self: end; color: var(--muted); font-size: 11px; margin-top: -6px; }
.nc-unit { position: relative; }
.nc-unit input { padding-right: 78px; }
.nc-unit i { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 12px; pointer-events: none; }
.nc-seg { display: grid; grid-auto-flow: column; gap: 6px; background: var(--panel2); border: 1px solid var(--line); padding: 4px; border-radius: 12px; }
.nc-seg button { border: 0; background: transparent; color: var(--muted); padding: 8px 6px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; }
.nc-seg button.on { background: var(--blue); color: #fff; box-shadow: 0 2px 10px rgba(47,123,255,.35); }
.nc-prize { position: relative; }
.nc-prize b { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: #fbbf24; font-size: 16px; }
.nc-prize input { padding-left: 32px; font-size: 16px; font-weight: 700; }
.nc-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.nc-chips button { border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 5px 12px; border-radius: 999px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.nc-chips button:hover { border-color: var(--blue); color: #6aa2ff; }
.nc-note { font-size: 12px; color: var(--muted); background: rgba(251,191,36,.07); border: 1px solid rgba(251,191,36,.25); border-radius: 10px; padding: 8px 10px; }
.nc-sum { font-size: 12.5px; color: var(--muted); padding: 10px 12px; border-radius: 12px; background: var(--blue-d); border: 1px solid #1d3a73; }
.nc-sum b { color: var(--text); }
.nc-actions { display: flex; gap: 10px; justify-content: flex-end; }
.nc-actions .btn { padding: 11px 20px; }
.nc-actions .primary { min-width: 190px; }
