:root {
  --bg: #0b1118;
  --bg-elev: #121a24;
  --bg-soft: #172231;
  --line: rgba(148, 163, 184, 0.16);
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #2dd4bf;
  --accent-deep: #0f766e;
  --online: #34d399;
  --unstable: #fbbf24;
  --offline: #94a3b8;
  --danger: #fb7185;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --font: "Outfit", sans-serif;
  --display: "Syne", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }

/* ——— Login ——— */
.login-view {
  min-height: 100vh;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 32px 20px;
}

.login-atmosphere {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 55% at 18% 20%, rgba(45, 212, 191, 0.18), transparent 55%),
    radial-gradient(ellipse 55% 45% at 88% 78%, rgba(56, 189, 248, 0.12), transparent 50%),
    linear-gradient(160deg, #071018 0%, #0d1621 45%, #101c2a 100%);
}
.login-atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 45%, black, transparent);
  animation: gridDrift 28s linear infinite;
}

@keyframes gridDrift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-56px, -56px, 0); }
}

.login-stage {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  animation: riseIn 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand {
  margin: 0 0 28px;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.4rem, 6vw, 3.2rem);
  letter-spacing: -0.04em;
  line-height: 0.95;
  background: linear-gradient(120deg, #f8fafc 10%, #2dd4bf 70%, #38bdf8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.login-title {
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-sub {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
  max-width: 34ch;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form label {
  display: grid;
  gap: 7px;
}

.login-form label span {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(18, 26, 36, 0.86);
  color: var(--text);
  border-radius: 12px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-form input:focus {
  border-color: rgba(45, 212, 191, 0.55);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.15);
}

.login-form button[type="submit"] {
  margin-top: 6px;
  border: 0;
  border-radius: 12px;
  padding: 14px 18px;
  font-weight: 600;
  color: #042f2e;
  background: linear-gradient(135deg, #5eead4, #2dd4bf 55%, #14b8a6);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.login-form button[type="submit"]:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.login-form button[type="submit"]:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
}

.login-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(251, 113, 133, 0.12);
  color: #fecdd3;
  border: 1px solid rgba(251, 113, 133, 0.28);
  font-size: 0.9rem;
}

/* ——— App shell ——— */
.app-view {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 68px 1fr;
  background:
    radial-gradient(ellipse 50% 40% at 100% 0%, rgba(45, 212, 191, 0.08), transparent 50%),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 17, 24, 0.85);
  backdrop-filter: blur(12px);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.brand-divider {
  width: 1px;
  height: 18px;
  background: var(--line);
}

.brand-sub {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 400;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-chip {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
}

.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  transition: background 0.15s, border-color 0.15s;
}
.ghost-btn:hover {
  background: var(--bg-soft);
  border-color: rgba(148, 163, 184, 0.28);
}
.ghost-btn.compact { padding: 6px 10px; font-size: 0.8rem; }

.shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 0;
  height: calc(100vh - 68px);
}

.rail {
  border-right: 1px solid var(--line);
  padding: 18px 16px;
  overflow: auto;
  background: rgba(18, 26, 36, 0.55);
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 10px;
  text-align: center;
}
.stat b {
  display: block;
  font-family: var(--display);
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  margin-bottom: 2px;
}
.stat span {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.rail-head h2 {
  margin: 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.device-list { display: grid; gap: 8px; }

.device {
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: inherit;
  border-radius: 14px;
  padding: 13px 14px;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.device:hover {
  border-color: rgba(45, 212, 191, 0.35);
  transform: translateY(-1px);
}
.device.active {
  border-color: rgba(45, 212, 191, 0.55);
  background: linear-gradient(160deg, rgba(45, 212, 191, 0.1), var(--bg-elev));
  box-shadow: inset 0 0 0 1px rgba(45, 212, 191, 0.12);
}

.device-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.device-top strong {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.device-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--muted);
}
.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--offline);
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.15);
}
.status-pill.online .dot {
  background: var(--online);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2);
  animation: pulseDot 2s ease-in-out infinite;
}
.status-pill.unstable .dot {
  background: var(--unstable);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.18);
}
.status-pill.offline .dot,
.status-pill.never-connected .dot {
  background: var(--offline);
}
.status-pill.removed .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(251, 113, 133, 0.2);
}

.type-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(148, 163, 184, 0.08);
}
.type-chip.laptop {
  color: #99f6e4;
  border-color: rgba(45, 212, 191, 0.35);
  background: rgba(45, 212, 191, 0.1);
}
.type-chip.pc {
  color: #bfdbfe;
  border-color: rgba(96, 165, 250, 0.35);
  background: rgba(96, 165, 250, 0.1);
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.85; }
}

.workspace {
  display: grid;
  grid-template-rows: minmax(280px, 58%) 1fr;
  min-width: 0;
  min-height: 0;
}

.map-pane {
  height: 100%;
  min-height: 280px;
  z-index: 1;
  background: #e8eef4;
}

.location-actions {
  margin: 0 0 12px;
}

.maps-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  border: 1px solid rgba(45, 212, 191, 0.35);
  background: rgba(45, 212, 191, 0.12);
  color: #99f6e4;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}
.maps-btn:hover {
  background: rgba(45, 212, 191, 0.2);
  border-color: rgba(45, 212, 191, 0.55);
}

.leaflet-container { background: #e8eef4; font-family: var(--font); }
.leaflet-popup-content-wrapper {
  background: #ffffff;
  color: #0f172a;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: #ffffff; }
.leaflet-control-attribution { background: rgba(255, 255, 255, 0.85) !important; color: #64748b !important; }

.detail-pane {
  overflow: auto;
  padding: 20px 24px 28px;
  border-top: 1px solid var(--line);
  background: rgba(12, 18, 26, 0.92);
}

.empty-state {
  max-width: 42ch;
  padding: 24px 0;
}
.empty-state h2 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-size: 1.35rem;
}
.empty-state p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.detail-head h2 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}
.detail-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.danger-btn {
  border: 1px solid rgba(251, 113, 133, 0.35);
  background: rgba(251, 113, 133, 0.08);
  color: #fecdd3;
  border-radius: 10px;
  padding: 9px 14px;
}
.danger-btn:hover { background: rgba(251, 113, 133, 0.16); }

.section-title {
  margin: 22px 0 10px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.field {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 13px;
}
.field b {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 5px;
}
.field span {
  font-size: 0.92rem;
  word-break: break-word;
}

.event-list {
  display: grid;
  gap: 8px;
}
.event-item {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  font-size: 0.88rem;
}
.event-item time {
  color: var(--muted);
  font-size: 0.78rem;
}
.event-type {
  display: inline-block;
  margin-right: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(45, 212, 191, 0.12);
  color: #99f6e4;
}
.event-type.system-restart,
.event-type.agent-restart {
  background: rgba(251, 191, 36, 0.12);
  color: #fde68a;
}
.event-type.removed {
  background: rgba(251, 113, 133, 0.14);
  color: #fecdd3;
}

.error-banner {
  padding: 14px;
  border-radius: 12px;
  background: rgba(251, 113, 133, 0.1);
  border: 1px solid rgba(251, 113, 133, 0.28);
  color: #fecdd3;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    height: auto;
  }
  .rail { max-height: 340px; border-right: 0; border-bottom: 1px solid var(--line); }
  .workspace { min-height: 720px; }
  .event-item { grid-template-columns: 1fr; gap: 4px; }
}
