*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fafafa;
  --bg-secondary: #f0efeb;
  --bg-tertiary: #e8e7e2;
  --border: #e0ded6;
  --border-secondary: #cccac0;
  --text-primary: #1a1a18;
  --text-secondary: #5f5e5a;
  --text-tertiary: #9e9c96;
  --accent: #a07840;
  --accent-dim: #f5ede0;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', monospace;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1a; --bg-secondary: #242422; --bg-tertiary: #2c2c2a;
    --border: #333330; --border-secondary: #3a3a37;
    --text-primary: #e8e6df; --text-secondary: #a8a69e; --text-tertiary: #6e6c66;
    --accent: #c8a96e; --accent-dim: #3d3020;
  }
}
html[data-theme="light"] {
  --bg: #fafafa; --bg-secondary: #f0efeb; --bg-tertiary: #e8e7e2;
  --border: #e0ded6; --border-secondary: #cccac0;
  --text-primary: #1a1a18; --text-secondary: #5f5e5a; --text-tertiary: #9e9c96;
  --accent: #a07840; --accent-dim: #f5ede0;
}
html[data-theme="dark"] {
  --bg: #1c1c1a; --bg-secondary: #242422; --bg-tertiary: #2c2c2a;
  --border: #333330; --border-secondary: #3a3a37;
  --text-primary: #e8e6df; --text-secondary: #a8a69e; --text-tertiary: #6e6c66;
  --accent: #c8a96e; --accent-dim: #3d3020;
}

body { background: var(--bg); color: var(--text-primary); font-family: var(--font); font-size: 13px; line-height: 1.5; min-height: 100vh; }
.app { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Topbar ── */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 10px 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 100;
}
.topbar-title {
  font-size: 13px; font-weight: 600; color: var(--accent);
  letter-spacing: 0.07em; text-transform: uppercase;
  align-self: center;
}
.topbar-actions {
  display: flex; gap: 8px; align-items: center; justify-content: flex-end;
}
.search-wrap {
  grid-column: 1 / -1;
  position: relative;
}
.search-wrap input {
  width: 100%;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 36px 8px 32px;
  color: var(--text-primary); font-family: var(--font); font-size: 16px;
  outline: none; transition: border-color 0.15s;
  -webkit-text-size-adjust: 100%;
  transform-origin: left center;
}
.search-wrap input:focus { border-color: var(--border-secondary); }
.search-wrap input::placeholder { color: var(--text-tertiary); }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); font-size: 14px; pointer-events: none; }
.search-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; border-radius: 50%; background: var(--text-tertiary); border: none; color: var(--bg); font-size: 11px; cursor: pointer; display: none; align-items: center; justify-content: center; line-height: 1; padding: 0; }
.search-clear.visible { display: flex; }

/* ── Theme toggle ── */
.theme-toggle { display: flex; gap: 2px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 99px; padding: 3px; }
.theme-btn { font-size: 11px; padding: 3px 9px; border-radius: 99px; border: none; background: transparent; color: var(--text-tertiary); cursor: pointer; font-family: var(--font); transition: all 0.15s; }
.theme-btn.active { background: var(--bg); color: var(--text-primary); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

/* ── Buttons ── */
.btn { padding: 7px 14px; border-radius: var(--radius); font-size: 12px; font-weight: 500; font-family: var(--font); cursor: pointer; border: 1px solid transparent; transition: all 0.15s; white-space: nowrap; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover { color: var(--text-primary); border-color: var(--border-secondary); }
.btn-danger { background: #c0392b; color: #fff; border-color: #c0392b; }
.btn-danger:hover { opacity: 0.9; }

/* ── Tabs ── */
.tab-bar { display: flex; gap: 0; padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--bg); overflow-x: auto; }
.tab-btn { padding: 10px 14px; font-size: 12px; font-weight: 500; font-family: var(--font); color: var(--text-tertiary); background: transparent; border: none; border-bottom: 2px solid transparent; cursor: pointer; transition: all 0.15s; margin-bottom: -1px; white-space: nowrap; }
.tab-btn:hover { color: var(--text-secondary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-count { display: inline-block; background: var(--bg-tertiary); border-radius: 99px; padding: 1px 6px; font-size: 10px; margin-left: 4px; color: var(--text-tertiary); }
.tab-btn.active .tab-count { background: var(--accent-dim); color: var(--accent); }

.tab-btn.tab-gm.active { color: #c0392b; border-bottom-color: #c0392b; }
.tab-btn.tab-exploit.active { color: #6b28a8; border-bottom-color: #6b28a8; }
.tab-btn.tab-griefer.active { color: #2836a0; border-bottom-color: #2836a0; }
.tab-btn.tab-gm.active .tab-count { background: #fde8e8; color: #c0392b; }
.tab-btn.tab-exploit.active .tab-count { background: #f3e8fe; color: #6b28a8; }
.tab-btn.tab-griefer.active .tab-count { background: #e8eafe; color: #2836a0; }

html[data-theme="dark"] .tab-btn.tab-gm.active { color: #f4a0a0; border-bottom-color: #f4a0a0; }
html[data-theme="dark"] .tab-btn.tab-gm.active .tab-count { background: #3d1212; color: #f4a0a0; }
html[data-theme="dark"] .tab-btn.tab-exploit.active { color: #c48ae8; border-bottom-color: #c48ae8; }
html[data-theme="dark"] .tab-btn.tab-exploit.active .tab-count { background: #2a1a2e; color: #c48ae8; }
html[data-theme="dark"] .tab-btn.tab-griefer.active { color: #8a9ee8; border-bottom-color: #8a9ee8; }
html[data-theme="dark"] .tab-btn.tab-griefer.active .tab-count { background: #1a1a2e; color: #8a9ee8; }
@media (prefers-color-scheme: dark) {
  .tab-btn.tab-gm.active { color: #f4a0a0; border-bottom-color: #f4a0a0; }
  .tab-btn.tab-gm.active .tab-count { background: #3d1212; color: #f4a0a0; }
  .tab-btn.tab-exploit.active { color: #c48ae8; border-bottom-color: #c48ae8; }
  .tab-btn.tab-exploit.active .tab-count { background: #2a1a2e; color: #c48ae8; }
  .tab-btn.tab-griefer.active { color: #8a9ee8; border-bottom-color: #8a9ee8; }
  .tab-btn.tab-griefer.active .tab-count { background: #1a1a2e; color: #8a9ee8; }
}

.content { padding: 16px; flex: 1; }
.list-panel { display: none; }
.list-panel.visible { display: block; }

/* ── Table ── */
.tbl-wrap { overflow-x: auto; margin-bottom: 20px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; font-size: 10px; font-weight: 500; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-tertiary); padding: 0 12px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; line-height: 1.45; }
tr:last-child td { border-bottom: none; }
tr.data-row { cursor: pointer; user-select: none; -webkit-user-select: none; }
tr.data-row:hover td { background: var(--bg-secondary); }
tr.data-row.pressing td { background: var(--bg-tertiary); }
.player-name { font-weight: 500; color: var(--text-primary); font-family: var(--font-mono); font-size: 11px; }
.cross-list-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: 5px;
  vertical-align: middle;
  flex-shrink: 0;
}
.cross-list-badge.godmode { background: #c0392b; }
.cross-list-badge.exploit { background: #6b28a8; }
.cross-list-badge.griefer { background: #2836a0; }

html[data-theme="dark"] .cross-list-badge.godmode { background: #f4a0a0; }
html[data-theme="dark"] .cross-list-badge.exploit { background: #c48ae8; }
html[data-theme="dark"] .cross-list-badge.griefer { background: #8a9ee8; }
@media (prefers-color-scheme: dark) {
  .cross-list-badge.godmode { background: #f4a0a0; }
  .cross-list-badge.exploit { background: #c48ae8; }
  .cross-list-badge.griefer { background: #8a9ee8; }
}
.cell-muted { color: var(--text-secondary); }
.cell-note { color: var(--text-secondary); font-size: 11px; }
.letter-row td { font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); padding: 12px 12px 4px; border-bottom: none; background: transparent !important; }

/* ── Badges ── */
.badge { display: inline-block; font-size: 10px; padding: 1px 7px; border-radius: 99px; white-space: nowrap; margin: 1px 2px 1px 0; }
.badge-facility { background: #fde8e8; color: #8b2020; }
.badge-regular { background: var(--bg-tertiary); color: var(--text-secondary); }
.badge-vehicle { background: #fef3e2; color: #7a4500; }
.badge-airplane, .badge-avenger { background: #e8f0fe; color: #1a56a0; }
.badge-offradar { background: #e6f4ee; color: #1a6644; }
.badge-unidentified { background: var(--bg-tertiary); color: var(--text-tertiary); border: 1px dashed var(--border-secondary); }
.badge-exploit { background: #f3e8fe; color: #6b28a8; }
.badge-tactic { background: #e8eafe; color: #2836a0; }

html[data-theme="dark"] .badge-facility, [data-theme="dark"] .badge-facility { background: #3d1212; color: #f4a0a0; }
html[data-theme="dark"] .badge-vehicle { background: #2a1f00; color: #c8953a; }
html[data-theme="dark"] .badge-airplane, html[data-theme="dark"] .badge-avenger { background: #0d2340; color: #7ab3e8; }
html[data-theme="dark"] .badge-offradar { background: #0d2d20; color: #6ecba8; }
html[data-theme="dark"] .badge-exploit { background: #2a1a2e; color: #c48ae8; }
html[data-theme="dark"] .badge-tactic { background: #1a1a2e; color: #8a9ee8; }
@media (prefers-color-scheme: dark) {
  .badge-facility { background: #3d1212; color: #f4a0a0; }
  .badge-vehicle { background: #2a1f00; color: #c8953a; }
  .badge-airplane, .badge-avenger { background: #0d2340; color: #7ab3e8; }
  .badge-offradar { background: #0d2d20; color: #6ecba8; }
  .badge-exploit { background: #2a1a2e; color: #c48ae8; }
  .badge-tactic { background: #1a1a2e; color: #8a9ee8; }
}

/* ── Action sheet ── */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 300; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.sheet-backdrop.visible { opacity: 1; pointer-events: all; }
.action-sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 301;
  background: var(--bg); border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0; padding: 8px 0 32px;
  transform: translateY(100%); transition: transform 0.25s cubic-bezier(0.32,0.72,0,1);
}
.action-sheet.visible { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; background: var(--border-secondary); border-radius: 2px; margin: 8px auto 12px; }
.sheet-player { font-size: 12px; font-weight: 600; color: var(--text-tertiary); text-align: center; padding: 0 20px 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-family: var(--font-mono); }
.sheet-btn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 20px; font-size: 15px; font-family: var(--font); background: none; border: none; color: var(--text-primary); cursor: pointer; text-align: left; transition: background 0.1s; }
.sheet-btn:hover { background: var(--bg-secondary); }
.sheet-btn.danger { color: #c0392b; }
.sheet-btn .sheet-icon { font-size: 18px; width: 24px; text-align: center; }

/* ── Form ── */
.add-section { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; }
.add-section-title { font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-tertiary); margin-bottom: 14px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 2px; }
.form-input, .form-select { background: var(--bg); border: 1px solid var(--border-secondary); border-radius: var(--radius); padding: 8px 10px; color: var(--text-primary); font-family: var(--font); font-size: 13px; outline: none; transition: border-color 0.15s; width: 100%; }
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-tertiary); }

.preset-block { background: var(--bg); border: 1px solid var(--border-secondary); border-radius: var(--radius); overflow: hidden; }
.preset-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; cursor: pointer; user-select: none;
  background: var(--bg-tertiary);
  transition: background 0.15s;
}
.preset-toggle:hover { background: var(--bg-secondary); }
.preset-toggle-label { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-secondary); }
.preset-toggle-icon { font-size: 10px; color: var(--text-tertiary); transition: transform 0.2s; }
.preset-toggle-icon.open { transform: rotate(180deg); }
.preset-body { padding: 8px; transition: max-height 0.25s ease, padding 0.25s ease; overflow: hidden; }
.preset-body.collapsed { max-height: 0 !important; padding-top: 0; padding-bottom: 0; }

.chips-wrap { display: flex; flex-wrap: wrap; gap: 5px; min-height: 32px; }
.chip { display: inline-flex; align-items: center; font-size: 11px; padding: 3px 10px; border-radius: 99px; cursor: pointer; border: 1px solid var(--border-secondary); color: var(--text-secondary); background: var(--bg-secondary); transition: all 0.12s; user-select: none; white-space: nowrap; }
.chip:hover { border-color: var(--accent); color: var(--text-primary); }
.chip.selected { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.chip.edit-mode { padding-right: 4px; gap: 4px; }
.chip-delete { background: none; border: none; color: var(--text-tertiary); cursor: pointer; font-size: 11px; padding: 0 2px; line-height: 1; display: flex; align-items: center; border-radius: 99px; }
.chip-delete:hover { color: #c0392b; background: rgba(192,57,43,0.1); }
.chip.edit-mode input { background: none; border: none; outline: none; font-size: 11px; font-family: var(--font); color: inherit; width: auto; min-width: 40px; max-width: 160px; padding: 0; }
 #preset-edit-btn.active, #preset-edit-btn-exploit.active, #preset-edit-btn-griefer.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.custom-section-label { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-tertiary); margin-top: 10px; margin-bottom: 4px; padding-left: 10px; border-left: 2px solid var(--border-secondary); }
.custom-tags-wrap { display: flex; flex-wrap: wrap; gap: 5px; min-height: 0; margin-bottom: 4px; padding-left: 12px; }
.custom-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 3px 8px 3px 10px; border-radius: 99px; border: 1px solid var(--border-secondary); color: var(--text-primary); background: var(--bg-tertiary); white-space: nowrap; }
.custom-tag-remove { background: none; border: none; color: var(--text-tertiary); cursor: pointer; font-size: 12px; padding: 0; line-height: 1; display: flex; align-items: center; }
.custom-tag-remove:hover { color: #c0392b; }
.custom-input-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; padding-left: 12px; position: relative; }
.custom-input-row .form-input { flex: 1; }
.save-preset-label { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 500; color: var(--text-secondary); white-space: nowrap; cursor: pointer; user-select: none; padding: 4px 0; }
.save-preset-label input[type=checkbox] { accent-color: var(--accent); cursor: pointer; width: 14px; height: 14px; flex-shrink: 0; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }

/* ── Threat level ── */
.threat-toggle { display: flex; gap: 6px; }
.threat-btn { padding: 5px 14px; border-radius: var(--radius); font-size: 11px; font-weight: 600; font-family: var(--font); cursor: pointer; border: 1px solid var(--border-secondary); background: var(--bg); color: var(--text-secondary); transition: all 0.15s; }
.threat-btn:hover { color: var(--text-primary); }
.threat-btn.threat-low.active { background: #f1c40f; border-color: #f1c40f; color: #000; }
.threat-btn.threat-medium.active { background: #e67e22; border-color: #e67e22; color: #fff; }
.threat-btn.threat-high.active { background: #c0392b; border-color: #c0392b; color: #fff; }

/* ── Priority flag in table ── */
.priority-flag { font-size: 14px; line-height: 1; }
.priority-cell { width: 32px; text-align: center; padding: 10px 4px; white-space: nowrap; }

/* ── Associate suggestions ── */
.associate-suggestions {
  position: absolute;
  z-index: 200;
  background: var(--bg);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius);
  margin-top: 2px;
  max-height: 160px;
  overflow-y: auto;
  width: 100%;
  display: none;
  top: 100%;
  left: 12px;
}
.associate-suggestions.visible { display: block; }
.associate-suggestion-item {
  padding: 8px 12px;
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.associate-suggestion-item:hover { background: var(--bg-secondary); }
.associate-suggestion-item .linked-badge {
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 1px 6px;
  border-radius: 99px;
}

/* ── Associate links in table ── */
.associate-link {
  cursor: pointer;
  color: var(--accent);
  white-space: nowrap;
}
.associate-link:hover { text-decoration: none; }
.associate-link:hover span { text-decoration: underline; }
.associates-cell { white-space: nowrap; }

/* ── Status bar ── */
.status-bar { position: fixed; bottom: 20px; right: 20px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 14px; font-size: 12px; color: var(--text-secondary); opacity: 0; transform: translateY(8px); transition: all 0.2s; pointer-events: none; z-index: 400; }
.status-bar.visible { opacity: 1; transform: translateY(0); }
.status-bar.success { color: #1a6644; border-color: #c6e8d4; background: #f0faf5; }
.status-bar.error { color: #8b2020; border-color: #fde8e8; background: #fff5f5; }
.status-bar.warning { color: #7a4f00; border-color: #fde8b0; background: #fffbeb; }
.status-bar.delete { color: var(--text-secondary); border-color: var(--border-secondary); background: var(--bg-secondary); }
html[data-theme="dark"] .status-bar.success { color: #6ecba8; border-color: #0d2d20; background: #0d2d20; }
html[data-theme="dark"] .status-bar.error { color: #f4a0a0; border-color: #3d1212; background: #3d1212; }
html[data-theme="dark"] .status-bar.warning { color: #f0c060; border-color: #5a3a00; background: #3a2800; }
@media (prefers-color-scheme: dark) {
  .status-bar.success { color: #6ecba8; border-color: #0d2d20; background: #0d2d20; }
  .status-bar.error { color: #f4a0a0; border-color: #3d1212; background: #3d1212; }
  .status-bar.warning { color: #f0c060; border-color: #5a3a00; background: #3a2800; }
}

.loading { text-align: center; padding: 40px; color: var(--text-tertiary); font-size: 12px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-tertiary); font-size: 12px; }