:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--muted);
  display: block;
}

.nav {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}

.nav-btn:hover {
  color: var(--text);
  background: var(--surface2);
}

.nav-btn.active {
  color: var(--text);
  background: var(--surface2);
  border-color: var(--border);
}

.nav-btn.discord {
  background: #5865F2;
  color: white;
  border: none;
}

.nav-btn.discord:hover {
  background: #4752c4;
}

/* Main */
main {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.view.active {
  display: flex;
}

/* Map */
#view-map {
  position: relative;
}

#chart {
  flex: 1;
  width: 100%;
  min-height: 0;
}

/* Form panel */
.panel {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: min(340px, calc(100% - 24px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 10;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s;
}

.panel.collapsed .form-body {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.panel-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.25rem;
}

.form-body {
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

.opt {
  font-weight: 400;
  opacity: 0.7;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="search"],
select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus {
  border-color: var(--accent);
}

.coord-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.primary-btn, .secondary-btn {
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.primary-btn {
  background: var(--accent);
  color: white;
  margin-top: 0.25rem;
}

.primary-btn:hover {
  background: var(--accent-hover);
}

.secondary-btn {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.secondary-btn:hover {
  background: var(--border);
}

.tiny {
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
}

.warning {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid var(--warning);
  color: #fcd34d;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  font-size: 0.8rem;
}

.warning.hidden, .hidden {
  display: none !important;
}

/* Detail card */
.detail-card {
  position: absolute;
  top: 12px;
  left: 12px;
  width: min(300px, calc(100% - 24px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  z-index: 11;
}

.detail-card h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  padding-right: 1.5rem;
}

.close-detail {
  position: absolute;
  top: 0.5rem;
  right: 0.6rem;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

#detail-body {
  font-size: 0.85rem;
  color: var(--muted);
}

#detail-body strong {
  color: var(--text);
}

#detail-body .meta {
  margin: 0.35rem 0;
}

/* List & Admin tables */
.list-controls {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
}

.list-controls input[type="search"] {
  flex: 1;
  min-width: 160px;
  max-width: 320px;
}

.count {
  font-size: 0.8rem;
  color: var(--muted);
  margin-left: auto;
}

.table-wrap {
  flex: 1;
  overflow: auto;
  padding: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th, td {
  padding: 0.55rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  background: var(--surface2);
  position: sticky;
  top: 0;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  z-index: 1;
}

tbody tr:hover {
  background: rgba(59, 130, 246, 0.08);
}

td.num {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, monospace;
}

.del-btn {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.del-btn:hover {
  background: var(--danger);
  color: white;
}

/* Admin */
.admin-box {
  max-width: 420px;
  margin: 3rem auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.admin-box h2 {
  font-size: 1.25rem;
}

.admin-box p {
  color: var(--muted);
  font-size: 0.9rem;
}

.admin-box code {
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.admin-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.admin-header h2 {
  font-size: 1.1rem;
  margin-right: auto;
}

/* Footer */
.footer {
  padding: 0.45rem 1rem;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 600px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .detail-card {
    top: auto;
    bottom: 12px;
    left: 12px;
    right: auto;
  }
}

/* Auth */
.auth-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.login-btn {
  background: #5865F2 !important;
  color: white !important;
  border: none !important;
}
.login-btn:hover {
  background: #4752c4 !important;
}
.user-menu {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}
.user-menu.hidden { display: none; }
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
}
.extra-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.detail-actions {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.detail-actions.hidden { display: none; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: min(420px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.modal-content h2 {
  font-size: 1.15rem;
}
.modal-content form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}
