:root {
  --bg: #15171a;
  --bg2: #1d2024;
  --bg3: #262a2f;
  --line: #33383f;
  --text: #e6e3dc;
  --muted: #8f949b;
  --accent: #cd412b;
  --accent2: #e8674f;
  --online: #5fbf6a;
  --offline: #5b6068;
  --warn: #e0a83a;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
code { background: var(--bg3); padding: 2px 6px; border-radius: 4px; font-size: 12px; }
a { color: var(--accent2); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }

/* buttons */
.btn {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: #4a5058; background: #2d3238; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg3); }
.btn-danger { color: #ff8b7a; }
.btn-small { padding: 4px 9px; font-size: 13px; }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.icon { font-size: 18px; padding: 4px 10px; }

.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; letter-spacing: .04em; }
.badge-warn { background: #4a3a14; color: var(--warn); }

/* topbar */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 0 12px; height: 50px;
  background: var(--bg2); border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; margin-right: 8px; }
.logo { width: 20px; height: 20px; border-radius: 5px; background: var(--accent); position: relative; }
.logo::after { content: ""; position: absolute; inset: 5px; border: 2px solid #fff; border-radius: 50%; }
.server-tabs { display: flex; gap: 4px; overflow-x: auto; min-width: 0; }
.server-tab {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  background: transparent; border: 1px solid transparent; max-width: 240px;
}
.server-tab:hover { background: var(--bg3); }
.server-tab.active { background: var(--bg3); border-color: var(--line); }
.server-tab .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-tab .n { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--offline); flex-shrink: 0; display: inline-block; }
.dot.on { background: var(--online); box-shadow: 0 0 6px #5fbf6a88; }
.dot.warn { background: var(--warn); }

/* main */
main { flex: 1; min-height: 0; display: flex; }
.empty-state { margin: auto; text-align: center; max-width: 480px; padding: 24px; }
.empty-state p { color: var(--muted); line-height: 1.6; }
.server-view { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.server-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.server-title { min-width: 0; }
.server-title h2 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { color: var(--muted); font-size: 12px; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.server-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.poll-status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.poll-status.err { color: #ff8b7a; }

.layout { flex: 1; display: flex; min-height: 0; }
.map-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); }
.map-toolbar { display: flex; gap: 6px; padding: 8px 10px; align-items: center; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.map-hint { font-size: 12px; color: var(--warn); }
.map-status { font-size: 12px; color: var(--muted); max-width: 380px; text-align: right; }
.map-status.warn { color: var(--warn); }
.map-status a { margin-left: 6px; }
.old-markers { font-size: 12px; color: var(--warn); display: flex; align-items: center; gap: 4px; }
.old-markers button { background: none; border: none; color: var(--accent2); cursor: pointer; padding: 0 4px; text-decoration: underline; }
.marker.old { opacity: .45; filter: grayscale(1); }
.map-viewport { flex: 1; position: relative; overflow: hidden; background: #0f1113; cursor: grab; touch-action: none; }
.map-viewport.panning { cursor: grabbing; }
.map-viewport.placing { cursor: crosshair; }
.map-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.map-stage img { display: block; user-select: none; -webkit-user-drag: none; }
.map-placeholder {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  background: radial-gradient(circle at 50% 50%, #2a3b35, #1a2422 70%); color: var(--muted); font-size: 28px;
  border: 4px dashed #3c4a45; font-size: 72px; line-height: 1.3;
}
.map-placeholder small { font-size: 40px; }
.map-grid { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.map-grid line { stroke: rgba(0,0,0,.45); }
.map-grid text { fill: rgba(0,0,0,.65); font-weight: 600; }
.marker-layer { position: absolute; inset: 0; pointer-events: none; }

.marker {
  position: absolute; pointer-events: auto; cursor: pointer;
  transform: translate(-50%, -100%) scale(var(--inv, 1)); transform-origin: 50% 100%;
  display: flex; flex-direction: column; align-items: center;
}
.marker .pin {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--c, #f2c94c); border: 2px solid rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.marker .pin span { transform: rotate(45deg); font-size: 13px; line-height: 1; }
.marker .lbl {
  position: absolute; bottom: 100%; margin-bottom: 4px; white-space: nowrap; font-size: 12px; font-weight: 600;
  background: rgba(15,17,19,.85); padding: 2px 6px; border-radius: 4px; display: flex; gap: 5px; align-items: center;
}
.marker .lbl .gcount { font-size: 11px; color: var(--muted); }
.marker .lbl .gcount.on { color: var(--online); }
.marker.dragging { opacity: .7; cursor: grabbing; }
.marker.selected .pin { outline: 2px solid #fff; outline-offset: 2px; }

.popover {
  position: absolute; z-index: 10; width: 260px; background: var(--bg2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.5); cursor: default;
}
.popover h4 { margin: 0 0 4px; font-size: 14px; }
.popover .sub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.popover .note { white-space: pre-wrap; font-size: 13px; margin: 8px 0; }
.popover .actions { display: flex; gap: 6px; margin-top: 10px; }

/* side panel */
.side { width: 400px; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.side-tabs { display: flex; border-bottom: 1px solid var(--line); }
.side-tab { flex: 1; padding: 11px 6px; background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; color: var(--muted); }
.side-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.count { font-size: 11px; background: var(--bg3); border-radius: 99px; padding: 1px 7px; margin-left: 4px; color: var(--online); }
.side-body { flex: 1; overflow-y: auto; padding: 12px; }

.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
input[type=search], input[type=text], input[type=password], input[type=number], select, textarea {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--bg3); border: 1px solid var(--line); border-radius: 99px; padding: 3px 11px; cursor: pointer; font-size: 12px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.select-bar { display: flex; align-items: center; gap: 8px; background: var(--bg3); padding: 6px 10px; border-radius: 6px; margin-bottom: 8px; font-size: 13px; }
.select-bar span { flex: 1; }

.player-list { list-style: none; margin: 0; padding: 0; }
.player {
  display: flex; align-items: center; gap: 8px; padding: 7px 6px; border-radius: 6px; cursor: pointer;
}
.player:hover { background: var(--bg2); }
.player input[type=checkbox] { margin: 0; accent-color: var(--accent); }
.player .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .when { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.player .when.on { color: var(--online); }
.gchip { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-left: 4px; vertical-align: middle; }
.star { background: none; border: none; cursor: pointer; color: var(--offline); font-size: 15px; padding: 0 2px; }
.star.on { color: var(--warn); }
.list-empty { color: var(--muted); text-align: center; padding: 24px 8px; }

.group-list { display: flex; flex-direction: column; gap: 10px; }
.group-card { background: var(--bg2); border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: var(--radius); padding: 10px 12px; }
.group-card header { display: flex; align-items: center; gap: 8px; }
.group-card h3 { margin: 0; font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-card .gstat { font-size: 12px; color: var(--muted); }
.group-card .gstat.on { color: var(--online); }
.group-card .gnote { font-size: 12px; color: var(--muted); margin: 6px 0 0; white-space: pre-wrap; }
.members { list-style: none; padding: 0; margin: 8px 0 0; }
.members li { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
.members li .pname { flex: 1; cursor: pointer; }
.members li .when { font-size: 12px; color: var(--muted); }
.members li .x { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0 4px; }
.members li .x:hover { color: #ff8b7a; }
.add-member { margin-top: 8px; display: flex; gap: 6px; }
.add-member input { padding: 4px 8px; font-size: 13px; }
.mini-actions { display: flex; gap: 2px; }

/* timeline */
.timeline { margin-top: 12px; }
.tl-axis { position: relative; height: 18px; margin-left: 110px; font-size: 10px; color: var(--muted); border-bottom: 1px solid var(--line); }
.tl-axis span { position: absolute; transform: translateX(-50%); top: 2px; }
.tl-group { margin-top: 14px; }
.tl-ghead { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.tl-row { display: flex; align-items: center; height: 20px; }
.tl-row .tl-name { width: 110px; flex-shrink: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 6px; cursor: pointer; }
.tl-track { position: relative; flex: 1; height: 12px; background: var(--bg2); border-radius: 3px; }
.tl-bar { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: var(--c); opacity: .85; min-width: 2px; }
.tl-bar.live { box-shadow: 0 0 0 1px #fff8; }
.tl-heat { position: relative; flex: 1; height: 10px; border-radius: 3px; overflow: hidden; background: var(--bg2); }
.tl-heat i { position: absolute; top: 0; bottom: 0; background: var(--c); }
.tl-now { position: absolute; top: -2px; bottom: -2px; width: 1px; background: #fff6; right: 0; }
.tl-gridline { position: absolute; top: 0; bottom: 0; width: 1px; background: #ffffff10; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal.wide { max-width: 760px; }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font-size: 15px; }
.modal .body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; color: var(--muted); }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }
.help { font-size: 12px; color: var(--muted); line-height: 1.5; }
input[type=color] { width: 44px; height: 34px; padding: 2px; background: var(--bg3); border: 1px solid var(--line); border-radius: 6px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatch { width: 22px; height: 22px; border-radius: 5px; border: 2px solid transparent; cursor: pointer; }
.swatch.sel { border-color: #fff; }
.type-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.type-pick button { background: var(--bg3); border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; cursor: pointer; }
.type-pick button.sel { border-color: var(--accent); background: #3a221d; }

/* player detail */
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { background: var(--bg3); border-radius: 6px; padding: 8px 12px; min-width: 100px; }
.stat b { display: block; font-size: 16px; }
.stat small { color: var(--muted); font-size: 11px; }
.week { display: flex; flex-direction: column; gap: 3px; }
.week .tl-row .tl-name { width: 70px; cursor: default; }
.hours { display: flex; align-items: flex-end; gap: 2px; height: 60px; margin-left: 70px; }
.hours i { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 1px; opacity: .85; }
.hours-axis { display: flex; margin-left: 70px; font-size: 10px; color: var(--muted); }
.hours-axis span { flex: 1; text-align: center; }
.names { font-size: 12px; color: var(--muted); }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 0 -4px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.5); max-width: 90vw; }
.toast.err { border-color: #a5432f; color: #ffb3a6; }
.tooltip { position: fixed; z-index: 120; pointer-events: none; background: #000d; padding: 4px 8px; border-radius: 4px; font-size: 12px; white-space: nowrap; }

.menu { position: absolute; z-index: 60; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 4px; min-width: 180px; box-shadow: 0 8px 28px rgba(0,0,0,.5); }
.menu button { display: block; width: 100%; text-align: left; background: none; border: none; padding: 7px 10px; border-radius: 5px; cursor: pointer; }
.menu button:hover { background: var(--bg3); }
.menu hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .map-pane { border-right: none; border-bottom: 1px solid var(--line); min-height: 45vh; }
  .side { width: 100%; flex: 1; }
}
