@keyframes sw-open {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
@keyframes sw-close {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
}
@keyframes sw-msg {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes sw-dot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.3;
  }
  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}
@keyframes sw-glow {
  0%,
  100% {
    box-shadow:
      0 0 10px rgba(0, 180, 230, 0.15),
      0 0 3px rgba(0, 180, 230, 0.08);
  }
  50% {
    box-shadow:
      0 0 18px rgba(0, 180, 230, 0.3),
      0 0 6px rgba(0, 180, 230, 0.15);
  }
}
@keyframes sw-line {
  0% {
    transform: scaleX(0);
    opacity: 0;
  }
  100% {
    transform: scaleX(1);
    opacity: 1;
  }
}

#sw-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(0, 180, 230, 0.25);
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: #00b4e6;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.33, 1, 0.68, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: sw-glow 4s ease-in-out infinite;
  padding: 0;
}
#sw-btn:hover {
  border-color: rgba(0, 180, 230, 0.5);
  box-shadow: 0 0 28px rgba(0, 180, 230, 0.35);
  transform: scale(1.08);
}
#sw-btn:active {
  transform: scale(0.95);
}
#sw-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: all 0.3s ease;
}
#sw-btn.open {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

#sw-panel {
  position: fixed;
  top: 24px;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  width: 400px;
  height: calc(100dvh - 48px);
  border-radius: 16px;
  background: rgba(30, 30, 35, 0.92);
  backdrop-filter: blur(40px) saturate(1.2);
  -webkit-backdrop-filter: blur(40px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow:
    0 40px 100px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(0, 0, 0, 0.3),
    0 0 60px rgba(0, 180, 230, 0.04);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
  -webkit-font-smoothing: antialiased;
}
#sw-panel.open {
  display: flex;
  animation: sw-open 0.3s cubic-bezier(0.33, 1, 0.68, 1) forwards;
}
#sw-panel.closing {
  animation: sw-close 0.2s ease-in forwards;
}

#sw-hdr {
  position: sticky;
  top: 0;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(40, 40, 48, 0.7);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  z-index: 2;
  border-radius: 16px 16px 0 0;
}
#sw-hdr::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 18px;
  right: 18px;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(0, 180, 230, 0.15) 20%,
    rgba(0, 180, 230, 0.15) 80%,
    transparent
  );
  animation: sw-line 0.6s 0.2s ease-out both;
}
#sw-hdr-l {
  display: flex;
  align-items: center;
  gap: 10px;
}
#sw-hdr-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #00b4e6;
  box-shadow:
    0 0 10px rgba(0, 180, 230, 0.6),
    0 0 3px rgba(0, 180, 230, 0.3);
}
#sw-hdr-t {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
#sw-hdr-r {
  display: flex;
  align-items: center;
  gap: 6px;
}
#sw-hdr-r button {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  transition: all 0.2s;
}
#sw-hdr-r button:hover {
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
}
#sw-hdr-r button svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#sw-scroll {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.06) transparent;
}
#sw-scroll::-webkit-scrollbar {
  width: 3px;
}
#sw-scroll::-webkit-scrollbar-track {
  background: transparent;
}
#sw-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}
#sw-msgs {
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100%;
}
#sw-msgs:empty::before {
  content: 'ask anything about appgrammar';
  display: block;
  text-align: center;
  color: rgba(255, 255, 255, 0.12);
  font-size: 12px;
  margin-top: 40%;
  letter-spacing: 0.04em;
}

.sw-m {
  max-width: 90%;
  padding: 11px 15px;
  font-size: 13px;
  line-height: 1.7;
  word-wrap: break-word;
  animation: sw-msg 0.3s ease-out forwards;
  opacity: 0;
}
.sw-m a {
  color: #00b4e6;
  text-decoration: none;
  border-bottom: 1px solid rgba(0, 180, 230, 0.25);
  transition: all 0.2s;
}
.sw-m a:hover {
  border-color: #00b4e6;
  text-shadow: 0 0 8px rgba(0, 180, 230, 0.3);
}
.sw-m code {
  background: rgba(0, 180, 230, 0.08);
  color: rgba(0, 180, 230, 0.8);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}
.sw-m strong {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 600;
}

.sw-m.v {
  align-self: flex-end;
  background: rgba(0, 180, 230, 0.08);
  color: rgba(255, 255, 255, 0.85);
  border-radius: 12px 12px 2px 12px;
  border: 1px solid rgba(0, 180, 230, 0.12);
}
.sw-m.a {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.03);
  color: rgba(255, 255, 255, 0.65);
  border-radius: 12px 12px 12px 2px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.sw-dots {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 14px 16px;
}
.sw-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #00b4e6;
  opacity: 0.3;
  animation: sw-dot 1.4s ease-in-out infinite;
}
.sw-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.sw-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

#sw-input {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.1);
}
#sw-input input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.95);
  outline: none;
  font-family: inherit;
  letter-spacing: 0.01em;
}
#sw-input input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}
#sw-send {
  background: transparent;
  border: none;
  color: rgba(0, 180, 230, 0.4);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s;
}
#sw-send:hover:not(:disabled) {
  color: #00b4e6;
  background: rgba(0, 180, 230, 0.08);
}
#sw-send:active:not(:disabled) {
  transform: scale(0.9);
}
#sw-send:disabled {
  opacity: 0.15;
  cursor: not-allowed;
}
#sw-send svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#sw-history {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  background: rgba(30, 30, 35, 0.95);
  backdrop-filter: blur(40px) saturate(1.2);
  -webkit-backdrop-filter: blur(40px) saturate(1.2);
  display: none;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
}
#sw-history.open {
  display: flex;
}
#sw-history-hdr {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
#sw-history-hdr span {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
#sw-history-close {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  transition: all 0.2s;
}
#sw-history-close:hover {
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
}
#sw-history-close svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
}
#sw-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.06) transparent;
}
#sw-history-list:empty::before {
  content: 'no conversations yet';
  display: block;
  text-align: center;
  color: rgba(255, 255, 255, 0.12);
  font-size: 12px;
  margin-top: 40%;
  letter-spacing: 0.04em;
}
.sw-hrow {
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  margin-bottom: 4px;
}
.sw-hrow:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.06);
}
.sw-hrow-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.sw-hrow-date {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.3);
  letter-spacing: 0.04em;
}
.sw-hrow-count {
  font-size: 10px;
  color: rgba(0, 180, 230, 0.4);
  letter-spacing: 0.04em;
}
.sw-hrow-preview {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sw-hrow.active {
  border-color: rgba(0, 180, 230, 0.2);
  background: rgba(0, 180, 230, 0.05);
}

@media (max-width: 500px) {
  #sw-panel {
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    height: 100dvh;
    height: calc(var(--sw-vh, 100vh));
    border-radius: 0;
    border: none;
  }
  #sw-hdr {
    border-radius: 0;
  }
  #sw-history {
    border-radius: 0;
  }
  #sw-btn {
    bottom: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
  }
}
