:root {
    color-scheme: dark;
    --bg: #0b0d12;
    --panel: #121620;
    --panel-2: #181d28;
    --border: #252b38;
    --text: #f1f4f8;
    --muted: #8e98aa;
    --accent: #6d7cff;
    --accent-2: #98a3ff;
    --green: #48d597;
    --gold: #f2bd58;
    --red: #ff6b75;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.topbar {
    height: 64px;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: rgba(11, 13, 18, .95);
    display: flex;
    align-items: center;
    gap: 36px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { font-size: 18px; font-weight: 800; letter-spacing: -.02em; }
.topbar nav { display: flex; align-items: stretch; height: 100%; gap: 4px; flex: 1; }
.topbar nav a { color: var(--muted); padding: 21px 14px 17px; border-bottom: 3px solid transparent; }
.topbar nav a:hover, .topbar nav a.active { color: var(--text); border-color: var(--accent); }
.topbar form { display: flex; align-items: center; gap: 14px; }
.admin-name { color: var(--muted); font-size: 14px; }
.link-button { background: none; color: var(--text); border: 0; cursor: pointer; padding: 8px; }

.page { max-width: 1180px; margin: 0 auto; padding: 48px 28px 80px; }
.page.wide { max-width: 1500px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 30px; }
.page-heading h1 { margin: 3px 0 0; font-size: 30px; letter-spacing: -.04em; }
.eyebrow { margin: 0; color: var(--accent-2); font-size: 12px; font-weight: 800; letter-spacing: .14em; }
.status { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.status i { width: 8px; height: 8px; background: var(--green); border-radius: 50%; box-shadow: 0 0 14px var(--green); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 42px; }
.metric-grid.economy-core { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 10px; }
.metric {
    min-height: 126px;
    padding: 22px;
    border: 1px solid var(--border);
    background: linear-gradient(145deg, var(--panel-2), var(--panel));
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.metric span { color: var(--muted); font-size: 14px; }
.metric strong { font-size: 27px; letter-spacing: -.04em; overflow-wrap: anywhere; }
.metric.accent { border-color: #4d58b7; }
.metric.gold strong { color: var(--gold); }
.metric.silver strong { color: #c9d0dc; }
h2 { font-size: 18px; margin: 0 0 15px; }

.notice { background: #12182a; border: 1px solid #27325a; border-radius: 12px; padding: 18px 20px; }
.notice p { color: var(--muted); margin: 7px 0 0; line-height: 1.55; }
.muted { color: var(--muted); }
.form-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 24px; margin-bottom: 34px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px; }
.form-grid label { display: block; color: #c6ccda; font-size: 13px; margin-bottom: 7px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid small { color: var(--muted); display: block; margin-top: 6px; }
.readonly-value { min-height: 43px; padding: 11px 13px; background: #0e1118; border: 1px solid var(--border); border-radius: 9px; font-weight: 700; }
.checkbox-row { display: flex; align-items: center; gap: 10px; padding-top: 25px; }
.checkbox-row input { width: 17px; height: 17px; }
.checkbox-row label { margin: 0; }
.form-panel .muted { font-size: 13px; }

.search-form { display: flex; gap: 10px; max-width: 620px; margin-bottom: 22px; }
input, select, textarea {
    width: 100%;
    background: #0e1118;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 11px 13px;
    outline: none;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109,124,255,.14); }
button {
    background: var(--accent);
    color: white;
    border: 0;
    border-radius: 9px;
    padding: 11px 18px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
button:hover { filter: brightness(1.08); }
button:disabled { cursor: not-allowed; opacity: .5; filter: none; }
.button-link { background: var(--accent); color: white; border-radius: 9px; padding: 10px 16px; font-weight: 700; font-size: 14px; }

.table-wrap { border: 1px solid var(--border); border-radius: 12px; overflow: auto; }
.section-gap { margin-bottom: 36px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { color: var(--muted); text-align: left; font-weight: 600; background: var(--panel-2); }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover { background: rgba(255,255,255,.025); }
td small { display: block; color: var(--muted); margin-top: 3px; }
td.detail { max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-block; color: var(--muted); background: #252a35; padding: 3px 7px; border-radius: 999px; font-size: 11px; }
.badge.online { color: #081a12; background: var(--green); }
.badge.danger { color: white; background: #74343d; margin-left: 5px; }

.login-page { display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 0, #1c2450, var(--bg) 48%); }
.login-card { width: min(100%, 390px); padding: 34px; border: 1px solid var(--border); border-radius: 18px; background: rgba(18,22,32,.96); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.brand-mark { width: 46px; height: 46px; display: grid; place-items: center; background: var(--accent); border-radius: 11px; font-weight: 900; }
.login-card h1 { margin: 22px 0 5px; font-size: 27px; }
.login-card > p { margin-top: 0; }
.login-card label { display: block; color: #c6ccda; font-size: 13px; margin: 17px 0 7px; }
.login-card button { width: 100%; margin-top: 23px; }
.login-card .security-note { font-size: 12px; text-align: center; margin: 18px 0 0; color: var(--muted); }
.alert { padding: 11px 12px; border-radius: 8px; margin: 18px 0 4px; font-size: 13px; }
.alert.error { background: #3b1e24; color: #ffb8bf; }
.alert.success { background: #153629; color: #a5f0ce; }

.reward-builder {
    margin: 6px 0 2px;
    padding: 20px;
    background: #0e1118;
    border: 1px solid var(--border);
    border-radius: 12px;
}
.builder-heading { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.builder-heading h3 { margin: 0 0 3px; font-size: 16px; }
.builder-heading small { margin: 0; }
.builder-fields { display: grid; grid-template-columns: minmax(0, 3fr) minmax(110px, 1fr); gap: 12px; }
.autocomplete { position: relative; }
.suggestions {
    position: absolute;
    z-index: 20;
    top: calc(100% + 5px);
    left: 0;
    right: 0;
    max-height: 310px;
    overflow-y: auto;
    background: #171c27;
    border: 1px solid #343d50;
    border-radius: 10px;
    box-shadow: 0 18px 45px rgba(0,0,0,.45);
}
.suggestions.compact { max-height: 260px; }
.suggestion-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    color: var(--text);
    text-align: left;
    background: transparent;
    border-radius: 0;
    border-bottom: 1px solid var(--border);
}
.suggestion-row:last-child { border-bottom: 0; }
.suggestion-row:hover { background: #222938; filter: none; }
.suggestion-row > span { min-width: 0; }
.suggestion-row strong, .suggestion-row small { display: block; overflow: hidden; text-overflow: ellipsis; }
.suggestion-row small { margin-top: 3px; }
.suggestion-row img, .chosen-item img, .reward-item img, .confirmation-item img {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    object-fit: contain;
    image-rendering: pixelated;
    background: #090b10;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.suggestion-row img.image-missing, .reward-item img.image-missing { visibility: hidden; }
.suggestion-message { padding: 13px; color: var(--muted); font-size: 13px; }
.chosen-item {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    padding: 11px;
    background: #171c27;
    border: 1px solid var(--border);
    border-radius: 10px;
}
.chosen-item[hidden] { display: none; }
.chosen-item strong, .chosen-item small { display: block; }
.option-builder {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(110px, 1fr) auto;
    gap: 12px;
    align-items: end;
    margin-top: 17px;
}
.secondary-button { color: var(--text); background: #272e3e; border: 1px solid #394256; }
.danger-button { color: #ffc1c6; background: #46252b; }
.option-chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0; }
.option-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 6px 5px 10px;
    color: #d9ddff;
    background: #242b4f;
    border-radius: 999px;
    font-size: 12px;
}
.chip-remove {
    min-width: 23px;
    padding: 1px 6px;
    color: #d9ddff;
    background: transparent;
    border-radius: 999px;
}
.reward-items { display: grid; gap: 9px; margin-top: 15px; }
.empty-state { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.reward-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px;
    background: #171c27;
    border: 1px solid var(--border);
    border-radius: 10px;
}
.reward-item-content { flex: 1; min-width: 0; }
.reward-item-content strong, .reward-item-content small { display: block; }
.reward-item-content p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 12px;
    white-space: normal;
}
.confirm-dialog {
    width: min(680px, calc(100% - 28px));
    max-height: calc(100vh - 36px);
    overflow: auto;
    padding: 0;
    color: var(--text);
    background: var(--panel);
    border: 1px solid #343d50;
    border-radius: 15px;
    box-shadow: 0 30px 90px rgba(0,0,0,.65);
}
.confirm-dialog::backdrop { background: rgba(2,4,8,.78); backdrop-filter: blur(3px); }
.confirm-dialog form { padding: 22px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; }
.dialog-heading h2 { margin: 4px 0 0; font-size: 23px; }
.icon-button { padding: 2px 10px 5px; color: var(--muted); background: transparent; font-size: 25px; }
.confirmation-content { margin: 20px 0; }
.confirmation-summary { display: grid; gap: 8px; padding: 14px; background: #0e1118; border-radius: 10px; }
.confirmation-line { display: flex; justify-content: space-between; gap: 18px; font-size: 13px; }
.confirmation-line span { color: var(--muted); }
.confirmation-line strong { text-align: right; overflow-wrap: anywhere; }
.confirmation-content h3 { margin: 20px 0 10px; font-size: 15px; }
.confirmation-items { display: grid; gap: 8px; }
.confirmation-item { display: flex; align-items: center; gap: 11px; padding: 10px; border: 1px solid var(--border); border-radius: 9px; }
.confirmation-item strong, .confirmation-item small { display: block; }
.confirmation-item small { margin-top: 4px; color: var(--muted); line-height: 1.4; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 16px; border-top: 1px solid var(--border); }

.insight-section { margin: 38px 0; }
.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 15px;
}
.section-heading h2 { margin: 4px 0 0; }
.filter-form {
    display: flex;
    align-items: flex-end;
    gap: 9px;
    width: min(100%, 650px);
}
.filter-form label {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 11px;
}
.filter-form input, .filter-form select { min-width: 210px; }
.filter-form > input, .filter-form > select { flex: 1; }
.filter-form.multi-filter > div { flex: 1; }
.ip-groups { display: grid; gap: 10px; }
.ip-group {
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 11px;
}
.ip-group summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
}
.ip-summary-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ip-group summary > button { margin-left: auto; }
.ip-group[open] summary { border-bottom: 1px solid var(--border); }
.ip-group .table-wrap { border: 0; border-radius: 0; }
.ip-group .badge.danger { margin-left: 0; }
.block-reason { margin: 0; padding: 10px 16px; color: #ffbdc3; background: #29191d; font-size: 12px; }
.action-cell { display: flex; align-items: center; gap: 7px; }
.action-cell button { padding: 9px 13px; }
.notice-inline { padding: 11px; color: #ffc7cc; background: #351e23; border-radius: 8px; line-height: 1.45; }
.confirm-dialog label { display: block; margin: 14px 0 6px; color: #c6ccda; font-size: 13px; }
.danger-zone {
    padding: 24px;
    margin-bottom: 38px;
    background: linear-gradient(145deg, #281419, #171116);
    border: 1px solid #6d313a;
    border-radius: 14px;
}
.test-starter-zone {
    padding: 24px;
    margin-bottom: 24px;
    background: linear-gradient(145deg, #12241d, #111916);
    border: 1px solid #285542;
    border-radius: 14px;
}
.test-starter-zone.enabled {
    background: linear-gradient(145deg, #301d13, #1d1511);
    border-color: #9f5b29;
}
.test-starter-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.test-starter-heading h2 { margin: 0; }
.test-starter-zone > p { color: #c9d0cc; line-height: 1.55; }
.test-starter-zone > button { margin-top: 16px; }
.test-starter-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 9px;
    margin: 18px 0;
}
.test-starter-stats article {
    min-width: 0;
    padding: 13px;
    background: rgba(0,0,0,.2);
    border-radius: 9px;
}
.test-starter-stats span, .test-starter-stats strong { display: block; }
.test-starter-stats span { color: var(--muted); font-size: 11px; }
.test-starter-stats strong { margin-top: 6px; font-size: 18px; }
.test-starter-stats .phase-id {
    overflow: hidden;
    font-family: monospace;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.danger-zone h2 { margin-bottom: 8px; color: #ff9da6; }
.danger-zone p { margin: 7px 0; color: #c9aeb2; line-height: 1.55; }
.danger-zone > button { margin-top: 19px; }
.reset-preview {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 9px;
    margin-top: 18px;
}
.reset-preview article { padding: 13px; background: rgba(0,0,0,.2); border-radius: 9px; }
.reset-preview span, .reset-preview strong { display: block; }
.reset-preview span { color: var(--muted); font-size: 11px; }
.reset-preview strong { margin-top: 6px; font-size: 20px; }

@media (max-width: 900px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric-grid.economy-core { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .topbar { padding: 0 16px; gap: 16px; overflow-x: auto; }
    .topbar nav { min-width: max-content; }
    .admin-name { display: none; }
    .section-heading { align-items: stretch; flex-direction: column; }
    .filter-form { width: 100%; }
    .reset-preview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .test-starter-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
    .metric-grid { grid-template-columns: 1fr; }
    .metric-grid.economy-core { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: auto; }
    .page { padding: 30px 16px 60px; }
    .page-heading { align-items: flex-start; gap: 16px; flex-direction: column; }
    .reward-builder { padding: 15px; }
    .builder-fields, .option-builder { grid-template-columns: 1fr; }
    .option-builder button { width: 100%; }
    .reward-item { align-items: flex-start; flex-wrap: wrap; }
    .reward-item-content { width: calc(100% - 62px); }
    .reward-item .danger-button { margin-left: 60px; }
    .confirmation-line { display: grid; gap: 3px; }
    .confirmation-line strong { text-align: left; }
    .dialog-actions { flex-direction: column-reverse; }
    .dialog-actions button { width: 100%; }
    .filter-form, .filter-form.multi-filter { align-items: stretch; flex-direction: column; }
    .filter-form input, .filter-form select { min-width: 0; }
    .filter-form button { width: 100%; }
    .reset-preview { grid-template-columns: 1fr; }
    .test-starter-stats { grid-template-columns: 1fr; }
}
