:root {
  --bg:        #05060d;
  --bg-2:      #0b0d1a;
  --panel:     rgba(18, 21, 38, 0.85);
  --panel-2:   rgba(12, 14, 28, 0.9);
  --line:      rgba(120, 140, 220, 0.18);
  --text:      #e8ecff;
  --muted:     #8b93b8;
  --red:       #ff2d55;
  --red-glow:  rgba(255, 45, 85, 0.55);
  --blue:      #2f7bff;
  --blue-glow: rgba(47, 123, 255, 0.55);
  --green:     #1fd17a;
  --amber:     #ffb020;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 18% -10%, rgba(255,45,85,0.16), transparent 60%),
    radial-gradient(1100px 700px at 88% 110%, rgba(47,123,255,0.18), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
.hidden { display: none !important; }

/* ---------------- Login ---------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 360px; max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 34px 28px;
  text-align: center;
  backdrop-filter: blur(14px);
  box-shadow: 0 0 60px rgba(0,0,0,0.6), 0 0 1px var(--blue-glow);
}
.login-logo { width: 96px; height: 96px; border-radius: 50%; object-fit: cover;
  box-shadow: 0 0 32px var(--red-glow), 0 0 48px var(--blue-glow); }
.login-card h1 { margin: 18px 0 2px; font-size: 22px; letter-spacing: 3px; }
.login-card .sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.login-card input, .modal input, .modal textarea, .modal select {
  width: 100%; margin: 7px 0; padding: 12px 14px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; color: var(--text); font-size: 14px; outline: none;
}
.login-card input:focus, .modal input:focus, .modal textarea:focus {
  border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-glow);
}
button {
  cursor: pointer; border: none; border-radius: 10px;
  font-weight: 600; font-size: 14px; color: #fff;
  padding: 12px 16px;
  background: linear-gradient(100deg, var(--red), var(--blue));
  box-shadow: 0 6px 20px rgba(0,0,0,0.4), 0 0 18px rgba(47,123,255,0.25);
  transition: transform .08s ease, filter .15s ease;
}
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
.login-card button { width: 100%; margin-top: 12px; }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---------------- Layout ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(5,6,13,0.7); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; letter-spacing: 2px; }
.brand img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover;
  box-shadow: 0 0 16px var(--red-glow), 0 0 22px var(--blue-glow); }
button.ghost {
  background: transparent; border: 1px solid var(--line); box-shadow: none;
  color: var(--muted); padding: 8px 14px;
}
button.ghost:hover { color: var(--text); border-color: var(--blue); }
button.mini { padding: 5px 10px; font-size: 12px; border-radius: 8px; }

.layout { display: grid; grid-template-columns: 320px 1fr; gap: 18px; padding: 18px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; margin-bottom: 16px;
  backdrop-filter: blur(10px);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.panel-head h2 { font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); margin: 0; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; margin-bottom: 6px;
}
.list li:hover { background: var(--panel-2); }
.list li.active { border-color: var(--blue); background: rgba(47,123,255,0.10); }
.list .ltext { display: flex; align-items: center; gap: 9px; min-width: 0; }
.list .ltext .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { color: var(--muted); font-size: 12px; }
.list .del { color: var(--muted); background: none; box-shadow: none; padding: 2px 8px; font-size: 16px; }
.list .del:hover { color: var(--red); }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; background: var(--muted); }
.dot.on { background: var(--green); box-shadow: 0 0 10px var(--green); }
.dot.off { background: #44485f; }

/* ---------------- Detail ---------------- */
.detail { min-height: 60vh; }
.empty-detail { display: grid; place-items: center; height: 60vh; gap: 16px; color: var(--muted); text-align: center; }
.empty-detail img { width: 110px; height: 110px; border-radius: 50%; object-fit: cover; opacity: .8;
  box-shadow: 0 0 30px var(--red-glow), 0 0 40px var(--blue-glow); }

.dhead { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.dhead h1 { margin: 0; font-size: 24px; }
.dhead .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.red { color: #fff; background: rgba(255,45,85,0.18); border-color: var(--red); }
.badge.blue { color: #fff; background: rgba(47,123,255,0.18); border-color: var(--blue); }
.badge.green { color: #fff; background: rgba(31,209,122,0.18); border-color: var(--green); }
.badge.amber { color: #fff; background: rgba(255,176,32,0.18); border-color: var(--amber); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 980px) { .grid2 { grid-template-columns: 1fr; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; backdrop-filter: blur(10px); }
.card h3 { margin: 0 0 12px; font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); }

#map { height: 320px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.leaflet-tile { filter: brightness(0.7) invert(0.92) hue-rotate(180deg) saturate(0.7); }
.maplegend { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; margin: 8px 2px 0; }
.maplegend .lg { display: inline-block; width: 16px; height: 4px; border-radius: 2px; vertical-align: middle; }
.maplegend .lg-blue { background: var(--blue); }
.maplegend .lg-red { background: var(--red); box-shadow: 0 0 6px var(--red-glow); }

.row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.row:last-child { border-bottom: none; }
.row .k { color: var(--muted); font-size: 13px; }
.row .v { font-weight: 600; }

textarea { width: 100%; min-height: 70px; resize: vertical; padding: 12px 14px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-size: 14px; }

.switch { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.switch .lbl { font-size: 14px; }
.switch .lbl small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.toggle { position: relative; width: 50px; height: 28px; flex: 0 0 auto; }
.toggle input { display: none; }
.toggle span { position: absolute; inset: 0; border-radius: 999px; background: #2a2e44; transition: .2s; cursor: pointer; }
.toggle span::after { content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: .2s; }
.toggle input:checked + span { background: linear-gradient(100deg, var(--red), var(--blue)); }
.toggle input:checked + span::after { transform: translateX(22px); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.actions button { flex: 1; min-width: 130px; }
button.danger { background: linear-gradient(100deg, #ff2d55, #ff5e3a); }
button.warn { background: linear-gradient(100deg, #ffb020, #ff7a18); color: #1a1300; }
button.ok { background: linear-gradient(100deg, #1fd17a, #2f7bff); }

/* ---------------- Modal ---------------- */
.modal-back { position: fixed; inset: 0; background: rgba(2,3,8,0.72); display: grid; place-items: center; z-index: 50; backdrop-filter: blur(4px); }
.modal { width: 440px; max-width: calc(100% - 32px); background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 22px; box-shadow: 0 30px 80px rgba(0,0,0,0.6); }
.modal h3 { margin: 0 0 14px; }
.modal .keybox { background: #06070f; border: 1px dashed var(--blue); border-radius: 10px; padding: 12px;
  font-family: ui-monospace, "Cascadia Code", monospace; font-size: 13px; word-break: break-all; color: var(--blue); }
.modal .hint { color: var(--muted); font-size: 13px; margin: 10px 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions button { flex: 1; }
.copyrow { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.copyrow button { flex: 0 0 auto; }

/* ---------------- Phone / mobile ---------------- */
@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .brand { gap: 8px; font-size: 14px; letter-spacing: 1px; }
  .brand img { width: 30px; height: 30px; }
  button.ghost { padding: 7px 11px; }

  .layout { padding: 12px; gap: 12px; }
  .panel, .card { padding: 12px; border-radius: 12px; }

  /* bigger, comfortable tap targets in the lists */
  .list li { padding: 13px 12px; }
  .list .del { padding: 4px 12px; font-size: 20px; }

  .dhead { flex-direction: column; align-items: flex-start; gap: 8px; }
  .dhead h1 { font-size: 20px; }
  .badges { gap: 6px; }

  #map { height: 260px; }

  /* stack action buttons full-width so they're easy to tap */
  .actions { flex-direction: column; gap: 8px; }
  .actions button { width: 100%; min-width: 0; }
  .copyrow button { flex: 1 1 100%; }

  .toggle { width: 56px; height: 32px; }
  .toggle span::after { width: 26px; height: 26px; }
  .toggle input:checked + span::after { transform: translateX(24px); }

  .modal { padding: 18px; border-radius: 14px; }
  .login-card { padding: 26px 20px; }
}

/* avoid accidental horizontal scrolling on small screens */
@media (max-width: 860px) {
  html, body { overflow-x: hidden; }
}
