:root {
    color-scheme: light;
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-sunk: #f3f4f7;
    --line: #e3e5ea;
    --line-strong: #cdd1d9;
    --text: #1c2024;
    --text-2: #5c626c;
    --text-3: #6f747e;
    --accent: #3e63dd;
    --accent-hover: #3358d4;
    --accent-text: #3a5bc7;
    --accent-soft: #edf2fe;
    --accent-line: #c1d0ff;
    --ok: #18794e;
    --ok-soft: #e6f6ec;
    --warn: #a35200;
    --warn-soft: #fff1e0;
    --error: #ce2c31;
    --error-soft: #feebec;
    --off: #5c626c;
    --off-soft: #eff0f3;
    /* Destructive fills stay light-theme red in both themes so white text keeps contrast. */
    --danger-fill: #ce2c31;
    --danger-fill-hover: #b42328;
    --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 2px 6px rgb(16 24 40 / 5%);
    --shadow-pop: 0 10px 32px rgb(16 24 40 / 16%), 0 2px 6px rgb(16 24 40 / 8%);
    --radius: 10px;
    --radius-sm: 7px;
    --font: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC",
        "Segoe UI", system-ui, sans-serif;
    --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
    --ease: cubic-bezier(.16, 1, .3, 1);
}
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #111214;
        --surface: #19191c;
        --surface-sunk: #141517;
        --line: #2b2d31;
        --line-strong: #3d4046;
        --text: #edeef0;
        --text-2: #b1b5bc;
        --text-3: #9a9ea6;
        --accent: #3e63dd;
        --accent-hover: #3358d4;
        --accent-text: #9eb1ff;
        --accent-soft: #182449;
        --accent-line: #2e3f7a;
        --ok: #3dd68c;
        --ok-soft: #132d21;
        --warn: #ffa057;
        --warn-soft: #331e0b;
        --error: #ff9592;
        --error-soft: #3b1219;
        --off: #b1b5bc;
        --off-soft: #222326;
        --shadow: 0 1px 2px rgb(0 0 0 / 40%);
        --shadow-pop: 0 12px 36px rgb(0 0 0 / 55%);
    }
}

* { box-sizing: border-box; }
html { scrollbar-color: var(--line-strong) transparent; }
body {
    margin: 0; min-height: 100vh; font: 14px/1.6 var(--font); color: var(--text);
    background: var(--bg); -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
::selection { color: var(--text); background: var(--accent-line); }
a { color: var(--accent-text); text-underline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
p { color: var(--text-2); }
code {
    font: 12.5px var(--mono); padding: 1px 5px; border-radius: 4px; white-space: nowrap;
    background: var(--surface-sunk);
}
.sprite { display: none; }
.icon {
    width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
}

/* Controls */
button, input, select, textarea { font: inherit; color: inherit; }
button {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 36px; padding: 0 14px; border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none; cursor: pointer; font-weight: 600; white-space: nowrap;
    transition: background-color 120ms, border-color 120ms, color 120ms;
}
.as-button {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 36px; padding: 0 14px; border-radius: var(--radius-sm); font-weight: 600;
    white-space: nowrap; text-decoration: none; transition: background-color 120ms, color 120ms;
}
button:disabled { cursor: not-allowed; opacity: .5; }
.primary { color: #fff; background: var(--accent); }
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.secondary {
    color: var(--accent-text); background: var(--accent-soft); border-color: var(--accent-line);
}
.secondary:hover:not(:disabled) { border-color: var(--accent); }
.ghost { color: var(--text-2); }
.ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-sunk); }
.danger { color: var(--error); }
.icon-button { width: 36px; padding: 0; color: var(--text-2); border-color: var(--line); }
.icon-button:hover { color: var(--text); background: var(--surface-sunk); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea {
    width: 100%; min-height: 38px; padding: 7px 11px; border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm); background: var(--surface); caret-color: var(--accent);
    transition: border-color 120ms, box-shadow 120ms;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[aria-invalid="true"], textarea[aria-invalid="true"] {
    border-color: var(--error); box-shadow: 0 0 0 3px var(--error-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input[readonly] { background: var(--surface-sunk); }
textarea { resize: vertical; font: 13px/1.7 var(--mono); }
textarea::placeholder { font-family: var(--font); }
input[type="number"] { font-variant-numeric: tabular-nums; }
label {
    display: grid; gap: 6px; align-content: start; font-size: 13px; font-weight: 600;
    color: var(--text);
}
label small, fieldset small, .hint { font-size: 12px; font-weight: 400; color: var(--text-3); }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 8px; font-size: 13px; font-weight: 600; }

/* Shell */
.topbar {
    position: sticky; top: 0; z-index: 10; height: 56px; padding: 0 20px; display: flex;
    align-items: center; gap: 16px; background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand {
    display: inline-flex; align-items: center; gap: 10px; color: var(--text);
    font-size: 16px; font-weight: 700; text-decoration: none;
}
.brand-mark {
    display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px;
    color: #fff; background: var(--accent); font-size: 12px; letter-spacing: .02em;
}
/* Views: room work per server, fleet-wide policies and the log viewer are separate pages. */
.views { display: flex; gap: 4px; min-width: 0; overflow-x: auto; }
.views a {
    display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px;
    border-radius: var(--radius-sm); color: var(--text-2); font-weight: 600; white-space: nowrap;
    text-decoration: none; transition: background-color 120ms, color 120ms;
}
.views a:hover { color: var(--text); background: var(--surface-sunk); }
.views a[aria-current="page"] { color: var(--accent-text); background: var(--accent-soft); }
.view-flag {
    padding: 0 6px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--warn);
    background: var(--warn-soft);
}
.connection { margin-left: auto; font-size: 12px; color: var(--text-3); }
.account { display: flex; gap: 4px; }
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.app:not([data-view="rooms"]) { grid-template-columns: minmax(0, 1fr); }
.app:not([data-view="rooms"]) .sidebar { display: none; }
.app:not([data-view="rooms"]) .content { margin: 0 auto; }
.sidebar {
    position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; padding: 18px 12px;
    background: var(--surface); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; gap: 10px;
}
.sidebar-head {
    display: flex; align-items: baseline; justify-content: space-between; padding: 0 8px;
}
.sidebar-head h2 { font-size: 13px; color: var(--text-2); }
#server-count { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.server-list { display: grid; gap: 2px; }
.server-item {
    display: grid; grid-template-columns: minmax(0, 1fr); justify-content: stretch;
    gap: 2px; justify-items: start; width: 100%; min-height: 0; padding: 10px;
    text-align: left; font-weight: 400; color: var(--text);
}
.server-item:hover { background: var(--surface-sunk); }
.server-item[aria-current="true"] { background: var(--accent-soft); }
.server-item[aria-current="true"] strong,
.server-item[aria-current="true"] .meta,
.server-item[aria-current="true"] .state-line { color: var(--accent-text); }
.server-item strong { font-size: 14px; font-weight: 600; }
.state-line {
    display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2);
}
.server-item .meta { font-size: 12px; color: var(--text-3); }
.add-server {
    justify-content: flex-start; padding: 0 10px; color: var(--accent-text); font-weight: 600;
}
.add-server:hover { background: var(--accent-soft); }
.content { padding: 28px 32px 120px; max-width: 1100px; width: 100%; }

/* Status vocabulary */
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--off); }
.tone-ok .dot, .badge.tone-ok::before { background: var(--ok); }
.tone-warn .dot, .badge.tone-warn::before { background: var(--warn); }
.tone-error .dot, .badge.tone-error::before { background: var(--error); }
.tone-busy .dot, .badge.tone-busy::before { background: var(--accent); }
.tone-off .dot, .badge.tone-off::before { background: var(--off); }
.badge {
    display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 11px;
    border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; }
.badge.tone-ok { color: var(--ok); background: var(--ok-soft); }
.badge.tone-warn { color: var(--warn); background: var(--warn-soft); }
.badge.tone-error { color: var(--error); background: var(--error-soft); }
.badge.tone-busy { color: var(--accent-text); background: var(--accent-soft); }
.badge.tone-off { color: var(--off); background: var(--off-soft); }
@media (prefers-reduced-motion: no-preference) {
    .tone-busy .dot, .badge.tone-busy::before { animation: pulse 1.6s var(--ease) infinite; }
}
@keyframes pulse { 50% { opacity: .35; } }

/* Server page */
.notice {
    margin-bottom: 16px; padding: 10px 14px; border-radius: var(--radius-sm);
    color: var(--error); background: var(--error-soft);
}
.notice.success { color: var(--ok); background: var(--ok-soft); }
.server-head, .page-head.with-actions {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
    margin-bottom: 18px;
}
.page-head { margin-bottom: 18px; }
.server-title h1, .page-head h1 {
    font-size: 24px; line-height: 1.3; font-weight: 700; letter-spacing: -.01em;
}
.server-title p, .page-head p { margin-top: 4px; font-size: 13px; }
.page-head p { max-width: 64em; }
.page-actions { display: flex; align-items: center; gap: 14px; flex: none; }
.server-actions {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end;
}
.menu { position: relative; }
.menu-list {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 180px;
    padding: 6px;
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow-pop); display: grid;
}
.menu-list button { justify-content: flex-start; font-weight: 500; }
.menu-list button:hover { background: var(--surface-sunk); }
.banner {
    display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    margin-bottom: 18px; padding: 12px 16px; border-radius: var(--radius);
    background: var(--accent-soft); border: 1px solid var(--accent-line); scroll-margin-top: 72px;
}
.banner p { color: var(--text); }
.banner.tone-warn { background: var(--warn-soft); border-color: transparent; }
.banner.tone-off { background: var(--off-soft); border-color: transparent; }
.banner.tone-error { background: var(--error-soft); border-color: transparent; }
.banner.tone-ok { background: var(--ok-soft); border-color: transparent; }
.banner-actions { display: flex; gap: 8px; }
.panel {
    margin-bottom: 18px; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel-head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
    padding: 18px 20px 14px; border-bottom: 1px solid var(--line);
}
.panel-head h2, .pending h2 { font-size: 16px; font-weight: 700; }
.panel-head p { margin-top: 2px; font-size: 13px; }
.panel > .two-col { padding: 18px 20px 20px; }
#shared-policies form > label { display: grid; gap: 8px; margin: 18px 20px 12px; }
#shared-policies form > p { margin: 8px 20px; }
.policy-actions { display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 20px 20px; }
.count { font-weight: 500; color: var(--text-3); font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
.policy-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.policy-table th, .policy-table td {
    padding: 10px 20px; text-align: left; border-bottom: 1px solid var(--line);
}
.policy-table thead th {
    padding: 8px 20px; font-size: 12px; font-weight: 600; color: var(--text-2);
    background: var(--surface-sunk);
}
.policy-table tbody tr:last-child > * { border-bottom: 0; }
.policy-table tbody th { font-weight: 600; }
.text-button {
    min-height: 0; padding: 0; font-weight: 600; color: var(--text); text-align: left;
    white-space: normal;
}
.text-button:hover {
    color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 16px 20px; }
.pending { padding: 22px; display: grid; gap: 10px; }
.pending ol { margin: 0; padding-left: 20px; color: var(--text-2); display: grid; gap: 4px; }

/* Rooms: compact rows like the Komari tables, each expanding into its form. */
.room-columns, .room-row {
    display: grid; align-items: center; gap: 12px;
    grid-template-columns: 26px minmax(0, 1.1fr) minmax(0, 1.5fr) 58px 44px 72px 56px 20px;
}
.room-columns {
    padding: 8px 20px; font-size: 12px; font-weight: 600; color: var(--text-2);
    background: var(--surface-sunk); border-bottom: 1px solid var(--line);
}
.room + .room { border-top: 1px solid var(--line); }
.room-row { padding: 12px 20px; cursor: pointer; list-style: none; }
.room-row::-webkit-details-marker { display: none; }
.room-row:hover { background: var(--surface-sunk); }
.room[open] > .room-row { border-bottom: 1px dashed var(--line); }
.room-number {
    display: grid; place-items: center; height: 24px; border-radius: 6px; font-size: 12px;
    font-weight: 700; color: var(--accent-text); background: var(--accent-soft);
    font-variant-numeric: tabular-nums;
}
.room-title, .room-tag { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.room-title { font-size: 14px; font-weight: 600; }
.room-tag, .room-port, .room-clients, .room-lock { font-size: 13px; color: var(--text-2); }
.room-port, .room-clients { font-variant-numeric: tabular-nums; }
.pill {
    justify-self: start; white-space: nowrap; padding: 1px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600; color: var(--ok); background: var(--ok-soft);
}
.pill.is-off { color: var(--text-2); background: var(--off-soft); font-weight: 500; }
.room .chevron {
    width: 18px; height: 18px; color: var(--text-3); transform-origin: center;
    transition: transform 160ms;
}
.room[open] .chevron { transform: rotate(180deg); }
.room-body { display: grid; gap: 16px; padding: 18px 20px 20px; }
.room-grid {
    display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px;
    align-items: start;
}
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-3 { grid-column: span 3; }
.span-12 { grid-column: span 12; }
.field { display: grid; gap: 6px; align-content: start; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field-head label { display: inline; }
.budget { font-variant-numeric: tabular-nums; }
.budget.over { color: var(--error); }
.password-field { display: grid; gap: 6px; }
.password-field .pair { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.password-field .pair.is-set { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.primary.danger-fill { background: var(--danger-fill); }
.primary.danger-fill:hover:not(:disabled) { background: var(--danger-fill-hover); }
.room-foot {
    display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
}
.remove-room { min-height: 30px; padding: 0 10px; font-weight: 500; }
.switch { display: inline-flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.switch input {
    appearance: none; width: 34px; min-height: 20px; height: 20px; padding: 0; border: 0;
    border-radius: 999px; background: var(--line-strong); position: relative; cursor: pointer;
    transition: background-color 160ms var(--ease);
}
.switch input::after {
    content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
    border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 25%);
    transition: transform 160ms var(--ease);
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }
.switch input:focus { box-shadow: 0 0 0 3px var(--accent-soft); }
.link-button { min-height: 28px; padding: 0 8px; font-weight: 500; color: var(--text-2); }
.link-button:hover { color: var(--text); background: var(--surface-sunk); }

/* Advanced */
.advanced summary {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 20px; cursor: pointer; list-style: none;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary span { display: grid; gap: 2px; }
.advanced summary strong { font-size: 16px; }
.advanced summary small { font-size: 12px; color: var(--text-3); }
.advanced .chevron {
    width: 20px; height: 20px; flex: none; color: var(--text-3); transition: transform 160ms;
}
.advanced[open] .chevron { transform: rotate(180deg); }
.advanced-body {
    display: grid; gap: 20px; padding: 18px 20px 20px; border-top: 1px solid var(--line);
}
.latency-list { display: flex; flex-wrap: wrap; gap: 10px 14px; }
.latency-list label { grid-template-columns: auto 72px; align-items: center; font-weight: 500; }
.advanced-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Save bar: the one moving element, it rises once when an edit exists. */
.savebar {
    position: sticky; bottom: 16px; z-index: 5; display: flex; align-items: center;
    justify-content: space-between; gap: 16px; padding: 10px 12px 10px 18px;
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-pop);
}
.savebar p { color: var(--text); font-weight: 600; }
.savebar div { display: flex; gap: 8px; }
@media (prefers-reduced-motion: no-preference) {
    .savebar { animation: rise 260ms var(--ease); }
}
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

/* Log viewer: one readable line per event, grouped by day; a line opens into its fields. */
.log-toolbar {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 14px; padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}
.log-toolbar > label:not(.switch) { width: 168px; }
.log-toolbar > .log-custom { width: 214px; }
.log-toolbar > .switch { min-height: 38px; }
.segmented {
    display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
}
.segmented label {
    position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 30px;
    padding: 0 10px; border-radius: 5px; color: var(--text-2); cursor: pointer;
    transition: background-color 120ms, color 120ms;
}
.segmented label:hover { color: var(--text); background: var(--surface-sunk); }
.segmented input {
    position: absolute; inset: 0; width: 100%; min-height: 0; margin: 0; padding: 0; border: 0;
    opacity: 0; cursor: pointer;
}
.segmented label:has(input:checked) { color: var(--accent-text); background: var(--accent-soft); }
.segmented label:has(input:checked) .count { color: var(--accent-text); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.log-status {
    padding: 10px 20px; font-size: 12px; color: var(--text-3); border-bottom: 1px solid var(--line);
}
.log-error { margin: 12px 20px 0; }
.log-list .log-day {
    position: sticky; top: 56px; z-index: 1; padding: 6px 20px; font-size: 12px; font-weight: 600;
    color: var(--text-2); background: var(--surface-sunk); border-bottom: 1px solid var(--line);
}
.log-entry + .log-entry, .log-row + .log-row { border-top: 1px solid var(--line); }
.log-row {
    display: grid; align-items: baseline; gap: 12px; padding: 9px 20px; list-style: none;
    grid-template-columns: 64px 44px minmax(0, 150px) minmax(0, 1fr) 16px;
    grid-template-areas: "time level node text chevron";
}
summary.log-row { cursor: pointer; }
summary.log-row::-webkit-details-marker { display: none; }
summary.log-row:hover, .log-entry[open] > .log-row { background: var(--surface-sunk); }
.log-time {
    grid-area: time; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums;
}
.log-meta { display: contents; }
.log-level {
    grid-area: level; justify-self: start; padding: 0 7px; border-radius: 999px; font-size: 12px;
    font-weight: 600;
}
.log-level:empty { display: none; }
.log-level.tone-warn { color: var(--warn); background: var(--warn-soft); }
.log-level.tone-error { color: var(--error); background: var(--error-soft); }
.log-node {
    grid-area: node; overflow: hidden; font-size: 13px; color: var(--text-2); white-space: nowrap;
    text-overflow: ellipsis;
}
.log-text { grid-area: text; min-width: 0; color: var(--text); overflow-wrap: anywhere; }
.log-row .chevron {
    grid-area: chevron; align-self: center; width: 16px; height: 16px; color: var(--text-3);
    transform-origin: center; transition: transform 160ms;
}
.log-entry[open] .chevron { transform: rotate(180deg); }
.log-detail {
    display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 6px 16px; margin: 0;
    padding: 4px 20px 16px 96px; font-size: 13px; background: var(--surface-sunk);
}
.log-detail dt { color: var(--text-3); }
.log-detail dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.log-detail .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.log-detail .actions > * { min-height: 30px; padding: 0 10px; font-weight: 500; }
.log-empty { padding: 28px 20px; color: var(--text-2); }
.log-foot {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 10px 20px 12px; border-top: 1px solid var(--line);
}
.log-list.in-dialog {
    max-height: min(60vh, 520px); overflow-y: auto; border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}
.log-list.in-dialog .log-day { top: 0; }
.in-dialog .log-row {
    grid-template-columns: 64px 44px minmax(0, 1fr); grid-template-areas: "time level text";
}
.in-dialog .log-node { display: none; }

/* Player search: the first thing on the players page, one field for names, IPs and chat. */
.search-bar {
    display: flex; align-items: center; gap: 10px; margin-bottom: 18px; padding: 6px 6px 6px 14px;
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
    box-shadow: var(--shadow); transition: border-color 120ms, box-shadow 120ms;
}
.search-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-bar > .icon { width: 18px; height: 18px; color: var(--text-3); }
.search-bar input {
    min-height: 40px; padding: 0; border: 0; background: transparent; font-size: 16px;
}
.search-bar input:focus { box-shadow: none; }
.search-bar .primary { min-width: 76px; }

/* Subjects: a player name or address opens its profile wherever it appears. */
.subject {
    display: inline-block; min-height: 0; max-width: 100%; padding: 0; overflow: hidden;
    color: var(--text); font-weight: 600; text-align: left; text-overflow: ellipsis;
}
/* A dotted underline at rest: touch screens have no hover to reveal that names are links. */
.subject {
    text-decoration: underline dotted var(--line-strong); text-underline-offset: 3px;
}
.subject:hover, .subject:focus-visible {
    color: var(--accent-text); text-decoration: underline solid currentColor;
}
.subject.is-ip { font: 12.5px/1.6 var(--mono); color: var(--text-2); }
.subject.is-banned { color: var(--error); text-decoration: line-through; }
.subject.is-banned:hover { color: var(--error); }
.panel-head h2 .count { margin-left: 4px; font-size: 13px; }
.online-servers { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 4px; }

/* Player records reuse the log timeline: time, kind, who, what, where. */
.log-list .log-row.player-row {
    grid-template-columns: 64px 40px minmax(0, 220px) minmax(0, 1fr) minmax(0, 150px);
    grid-template-areas: "time kind who text where";
}
.kind-tag {
    grid-area: kind; justify-self: start; padding: 0 7px; border-radius: 999px; font-size: 12px;
    font-weight: 600; white-space: nowrap; color: var(--text-2); background: var(--off-soft);
}
.kind-tag.tone-ok { color: var(--ok); background: var(--ok-soft); }
.kind-tag.tone-error { color: var(--error); background: var(--error-soft); }
.kind-tag.tone-warn { color: var(--warn); background: var(--warn-soft); }
.player-who { grid-area: who; display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.player-who .subject.is-ip { flex: none; }
.player-row .log-text { color: var(--text-2); }
.player-row .chat-text { color: var(--text); white-space: pre-wrap; }
.player-row.kind-reject .log-text { color: var(--error); }
.player-where {
    grid-area: where; overflow: hidden; font-size: 13px; color: var(--text-3); text-align: right;
    white-space: nowrap; text-overflow: ellipsis;
}
/* The dialog scrolls as a whole; the 40 recent rows need no second scroll area. */
.profile .log-list.in-dialog { max-height: none; overflow: visible; }

/* Tables: bans, room administrators and the online roster share one quiet grammar. */
.table-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 12px 14px; padding: 14px 20px;
    border-bottom: 1px solid var(--line);
}
.filter-field { position: relative; display: block; width: min(320px, 100%); }
.filter-field .icon { position: absolute; top: 11px; left: 11px; color: var(--text-3); }
.filter-field input { padding-left: 34px; }
.capacity { margin-left: auto; font-variant-numeric: tabular-nums; }
.capacity.over { color: var(--error); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
    padding: 10px 20px; text-align: left; vertical-align: middle;
    border-bottom: 1px solid var(--line);
}
.data-table thead th {
    padding: 8px 20px; font-size: 12px; font-weight: 600; color: var(--text-2); white-space: nowrap;
    background: var(--surface-sunk);
}
.data-table tbody tr:last-child > * { border-bottom: 0; }
.data-table tbody th { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.data-table .row-actions { text-align: right; white-space: nowrap; }
.data-table .numeric { font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .muted { color: var(--text-3); white-space: nowrap; }
.data-table .table-empty { padding: 28px 20px; color: var(--text-2); }
.ban-table td:first-child { width: 1%; white-space: nowrap; }
.ban-table td:nth-child(5), .admin-table td:nth-child(3), .admin-table td:nth-child(4) {
    color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.table-foot {
    padding: 10px 20px 12px; font-size: 12px; color: var(--text-3);
    border-top: 1px solid var(--line);
}
.table-foot:empty { display: none; }
.table-foot .state-line { font-size: 12px; }
.pill.kind-name, .pill.kind-ip {
    font-weight: 500; color: var(--text-2); background: var(--off-soft);
}
.pill.is-banned { color: var(--error); background: var(--error-soft); }
.link-button.danger { color: var(--error); }
.link-button.danger:hover { color: var(--error); background: var(--error-soft); }
.row-actions .link-button + .link-button { margin-left: 2px; }

/* Profile: who this is, what is linked to them, and the ban action beside it. */
.profile { gap: 16px; }
.profile-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.profile-name { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-width: 0; }
.dialog-body .profile-name h2 { overflow-wrap: anywhere; }
.dialog-body .profile-name h2.is-ip { font-family: var(--mono); }
.profile-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.profile-summary { font-size: 13px; font-variant-numeric: tabular-nums; }
.profile-summary:empty { display: none; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.profile-actions:empty { display: none; }
.profile h3 { margin-bottom: 4px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.profile-tables { gap: 16px 28px; }
.data-table.compact th, .data-table.compact td { padding: 7px 10px 7px 0; }
.data-table.compact tbody th { font-size: 13px; }
.data-table.compact .row-actions { padding-right: 0; }
.inline-choice { grid-template-columns: 1fr 1fr; }
.inline-choice legend { grid-column: 1 / -1; }
#entry-value.is-ip, #admin-password { font-family: var(--mono); }

/* Chat: rooms on the left, the conversation reads top to bottom like a chat window. */
.chat-layout {
    display: grid; grid-template-columns: 248px minmax(0, 1fr); gap: 18px; align-items: start;
}
.chat-rooms {
    position: sticky; top: 74px; display: grid; gap: 2px; max-height: calc(100vh - 92px);
    margin-bottom: 0; padding: 8px; overflow-y: auto;
}
.chat-server { padding: 10px 10px 4px; font-size: 12px; font-weight: 600; color: var(--text-3); }
.chat-room {
    display: grid; justify-content: stretch; justify-items: start; gap: 2px; width: 100%;
    min-height: 0; padding: 8px 10px; color: var(--text); font-weight: 400; text-align: left;
}
.chat-room:hover { background: var(--surface-sunk); }
.chat-room[aria-current="true"] { color: var(--accent-text); background: var(--accent-soft); }
.chat-room-title {
    display: flex; align-items: center; gap: 8px; max-width: 100%; min-width: 0; font-weight: 600;
}
.chat-room-title .room-number { width: 24px; height: 20px; flex: none; }
.chat-room-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-room-meta { font-size: 12px; color: var(--text-3); }
.chat-room-server { display: none; }
.chat-room[aria-current="true"] .chat-room-meta { color: var(--accent-text); }
.chat-panel { margin-bottom: 0; }
.chat-toolbar > label:not(.switch) { width: 200px; }
.chat-log { height: min(62vh, 640px); overflow-y: auto; overscroll-behavior: contain; }
.chat-older { display: flex; justify-content: center; padding: 6px; }
.chat-older:has(> [hidden]) { display: none; }
.chat-day {
    position: sticky; top: 0; z-index: 1; padding: 6px 20px; font-size: 12px; font-weight: 600;
    color: var(--text-2); background: var(--surface-sunk); border-block: 1px solid var(--line);
}
.chat-line {
    display: grid; grid-template-columns: 44px minmax(0, 1fr); column-gap: 12px;
    padding: 8px 20px 0;
}
.chat-line.is-grouped { padding-top: 2px; }
.chat-line:last-child { padding-bottom: 12px; }
.chat-time {
    grid-column: 1; padding-top: 1px; font-size: 12px; color: var(--text-3);
    font-variant-numeric: tabular-nums;
}
.chat-line.is-grouped .chat-time { visibility: hidden; }
.chat-line.is-grouped:hover .chat-time { visibility: visible; }
.chat-meta { grid-column: 2; display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.chat-where { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.chat-message {
    grid-column: 2; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat-presence {
    grid-column: 2; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px;
    font-size: 13px; color: var(--text-3);
}
.chat-presence .subject.is-name { font-weight: 500; color: var(--text-2); }

/* Login and empty */
.login { display: grid; place-items: center; min-height: calc(100vh - 56px); padding: 24px 16px; }
.login-card {
    width: min(400px, 100%); display: grid; gap: 12px; padding: 28px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; }
.login-card .primary { margin-top: 6px; min-height: 40px; }
.empty {
    display: grid; justify-items: start; gap: 10px; padding: 36px; background: var(--surface);
    border: 1px dashed var(--line-strong); border-radius: var(--radius);
}
.empty h1 { font-size: 20px; }

/* Dialogs */
dialog {
    width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0;
    border-radius: 12px; color: var(--text); background: var(--surface);
    box-shadow: var(--shadow-pop);
}
dialog.wide-dialog { width: min(820px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(17 18 20 / 45%); }
.dialog-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 24px; }
.dialog-body h2 { font-size: 18px; font-weight: 700; }
.dialog-body > p { line-height: 1.7; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.choice { display: grid; gap: 8px; }
.choice label {
    grid-template-columns: auto 1fr; align-items: start; gap: 10px; padding: 12px;
    border: 1px solid var(--line); border-radius: var(--radius-sm); font-weight: 400;
    cursor: pointer;
}
.choice label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice label:has(input:checked) small { color: var(--accent-text); }
.choice label:has(input:disabled) { opacity: .5; cursor: not-allowed; }
.choice input { width: 16px; min-height: 16px; margin: 3px 0 0; accent-color: var(--accent); }
.choice span { display: grid; gap: 2px; }
.choice em { font-style: normal; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font: 13px var(--mono); }
.steps {
    display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin: 0; padding-left: 20px;
    font-size: 13px; color: var(--text-2);
}
.steps li { overflow-wrap: anywhere; }
.command { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.command code {
    flex: 1; min-width: 0; overflow-x: auto; padding: 8px 10px; white-space: pre;
    color: var(--text);
}
.icon-button.copied { color: var(--ok); border-color: var(--ok); }
#token-config { white-space: pre; overflow-x: auto; }
.field-error { color: var(--error); }

@media (max-width: 1100px) {
    /* Seven sections need the bar: account actions keep their names for assistive tech only. */
    .account button { width: 36px; padding: 0; }
    .account button span {
        position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
    }
    .log-list .log-row.player-row {
        grid-template-columns: 64px 40px minmax(0, 180px) minmax(0, 1fr);
        grid-template-areas: "time kind who text" ". . . where";
    }
    .player-where { text-align: left; }
}
@media (max-width: 900px) {
    /* minmax(0, …) keeps wide content (tables, long names) from widening the page. */
    .app { grid-template-columns: minmax(0, 1fr); }
    .brand-name { display: none; }
    .chat-layout { grid-template-columns: minmax(0, 1fr); }
    .chat-rooms {
        position: static; display: flex; max-height: none; overflow-x: auto; overflow-y: hidden;
    }
    .chat-server { display: none; }
    .chat-room-server { display: inline; }
    .chat-room { width: auto; min-width: 150px; max-width: 220px; border: 1px solid var(--line); }
    .sidebar {
        position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto;
        padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line);
    }
    .sidebar-head { display: none; }
    .server-list { display: flex; gap: 6px; }
    .server-item { width: auto; min-width: 150px; border: 1px solid var(--line); }
    .add-server { flex: none; }
    .content { padding: 20px 16px 120px; }
}
@media (max-width: 640px) {
    /* Two rows: brand and account, then the view tabs across the full width. */
    .topbar { position: static; height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
    /* Seven sections wrap onto two rows instead of hiding behind a scroll. */
    .views {
        order: 3; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%;
        overflow: visible;
    }
    .views a { justify-content: center; padding: 0 6px; }
    .connection { display: none; }
    .account { margin-left: auto; }
    .account button { padding: 0 8px; }
    .server-head, .page-head.with-actions { flex-direction: column; }
    /* The sync table stacks: server name, then one labelled line per state. */
    .policy-table thead { display: none; }
    .policy-table tbody tr {
        display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 14px;
        padding: 12px 16px; border-bottom: 1px solid var(--line);
    }
    .policy-table tbody tr:last-child { border-bottom: 0; }
    .policy-table tbody th { grid-column: 1 / -1; padding: 0; border: 0; }
    .policy-table tbody td { display: contents; }
    .policy-table tbody td::before {
        content: attr(data-label); font-size: 12px; color: var(--text-3);
    }
    /* Data tables stack the same way; the first cell becomes the row title. */
    .data-table:not(.compact) thead { display: none; }
    .data-table:not(.compact) tbody tr {
        display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px;
        padding: 12px 16px; border-bottom: 1px solid var(--line);
    }
    .data-table:not(.compact) tbody tr:last-child { border-bottom: 0; }
    .data-table:not(.compact) tbody th { grid-column: 1 / -1; padding: 0; border: 0; }
    .data-table:not(.compact) tbody td { display: contents; }
    .data-table:not(.compact) tbody td::before {
        content: attr(data-label); font-size: 12px; color: var(--text-3);
    }
    .data-table:not(.compact) tbody td.row-actions,
    .data-table:not(.compact) tbody td.table-empty {
        display: block; grid-column: 1 / -1; padding: 0; text-align: left; border: 0;
    }
    .ban-table tbody tr td:first-child { display: none; }
    .table-toolbar { padding: 12px 16px; }
    .filter-field { width: 100%; }
    .capacity { margin-left: 0; }
    .table-foot { padding: 10px 16px 12px; }
    .search-bar input { font-size: 14px; }
    .log-list .log-row.player-row {
        gap: 2px 10px; grid-template-columns: 52px minmax(0, 1fr);
        grid-template-areas: "time who" "kind text" ". where";
    }
    .chat-line { padding-left: 16px; padding-right: 16px; }
    .chat-day { padding: 6px 16px; }
    .chat-toolbar > label:not(.switch) { width: calc(50% - 7px); }
    .log-toolbar { padding: 14px 16px; }
    .log-toolbar > label:not(.switch), .log-toolbar > .log-custom { width: calc(50% - 7px); }
    .segmented { width: 100%; }
    .segmented label { flex: 1; justify-content: center; padding: 0 6px; }
    .log-status, .log-foot, .log-empty { padding-left: 16px; padding-right: 16px; }
    .log-error { margin: 12px 16px 0; }
    .log-list .log-day { top: 0; padding: 6px 16px; }
    .log-row {
        gap: 2px 10px; padding: 10px 16px;
        grid-template-columns: 52px minmax(0, 1fr) 16px;
        grid-template-areas: "time text chevron" ". meta chevron";
    }
    .log-meta { grid-area: meta; display: flex; align-items: center; gap: 8px; min-width: 0; }
    .in-dialog .log-row {
        grid-template-columns: 52px minmax(0, 1fr); grid-template-areas: "time text" ". meta";
    }
    .log-detail { grid-template-columns: 64px minmax(0, 1fr); padding: 4px 16px 14px; }
    .server-actions { justify-content: flex-start; }
    .two-col { grid-template-columns: 1fr; }
    .room-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .room-columns { display: none; }
    .room-row { grid-template-columns: 26px minmax(0, 1fr) auto auto 20px; padding: 12px 16px; }
    .room-tag, .room-clients, .room-lock { display: none; }
    .room-body { padding: 16px; }
    .span-4, .span-6, .span-12 { grid-column: span 2; }
    .span-3 { grid-column: span 1; }
    .panel-head { flex-direction: column; }
    .savebar { flex-direction: column; align-items: stretch; }
    .savebar div { justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
