:root {
  --content-width: 1200px;
  --content-padding: 1.25rem;
  --phact-purple: #6f2cff;
  --phact-purple-soft: #efe7ff;
  --phact-ink: #171a3a;
  --phact-sky: #f6f2ff;
  --phact-steel: #62628d;
  --phact-surface: #ffffff;
  --phact-surface-soft: #fbf9ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 0.875rem;
  font-family: "Manrope", sans-serif;
  color: var(--phact-ink);
  background:
    radial-gradient(circle at 15% 15%, rgba(111, 44, 255, 0.28), transparent 45%),
    radial-gradient(circle at 80% 20%, rgba(178, 130, 255, 0.2), transparent 42%),
    linear-gradient(140deg, var(--phact-sky), #f2ecff 58%, #fcfbff);
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.bg-pattern {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(15, 28, 46, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 28, 46, 0.03) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 90%);
  pointer-events: none;
}

.topbar {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 1.25rem var(--content-padding) 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  gap: 0.9rem;
  align-items: center;
}

.brand-logo {
  height: 40px;
  width: auto;
  filter: saturate(1.1);
}

.brand-subtitle {
  color: var(--phact-steel);
  font-weight: 700;
  letter-spacing: 0.03em;
}

.login-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.65rem 1.2rem;
  border: 1px solid color-mix(in srgb, var(--phact-purple) 30%, white);
  color: var(--phact-ink);
  background: linear-gradient(135deg, #ffffff, var(--phact-purple-soft));
  box-shadow: 0 10px 24px rgba(55, 18, 130, 0.18);
  transition: transform 180ms ease, box-shadow 180ms ease;
  font: inherit;
  cursor: pointer;
}

.auth-controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.auth-controls form {
  margin: 0;
}

.login-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 28px rgba(55, 18, 130, 0.24);
}

.login-button.disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.layout {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0.5rem var(--content-padding) 2rem;
  min-height: 0;
  display: flex;
  align-items: center;
  align-items: stretch;
  gap: 1rem;
}

.history-panel {
  flex: 0 0 220px;
  padding: 1rem;
  border: 1px solid rgba(111, 44, 255, 0.13);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 14px 30px rgba(67, 38, 125, 0.1);
  transition: flex-basis 180ms ease, padding 180ms ease;
}

.history-panel.collapsed {
  flex-basis: 44px;
  padding: 1rem 0.3rem;
}

.history-panel.collapsed .history-list,
.history-panel.collapsed h2,
.history-panel.collapsed .history-search-label,
.history-panel.collapsed .history-search {
  display: none;
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.history-heading h2 {
  margin: 0;
  font-family: "Sora", sans-serif;
  font-size: 0.9rem;
}

.history-search-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.history-search {
  width: 100%;
  margin-top: 0.85rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid rgba(111, 44, 255, 0.18);
  border-radius: 10px;
  color: var(--phact-ink);
  background: var(--phact-surface);
  font: inherit;
  font-size: 0.85rem;
}

.history-search:focus {
  border-color: var(--phact-purple);
  outline: 2px solid rgba(111, 44, 255, 0.16);
  outline-offset: 1px;
}

.history-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  padding: 0;
  border-radius: 50%;
  color: var(--phact-purple);
  background: transparent;
  cursor: pointer;
}

.history-toggle:hover,
.history-toggle:focus-visible {
  background: var(--phact-purple-soft);
  outline: none;
}

.history-toggle-icon {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.history-toggle-icon-show {
  display: none;
}

.history-panel.collapsed .history-toggle-icon-hide {
  display: none;
}

.history-panel.collapsed .history-toggle-icon-show {
  display: block;
}

.history-list {
  display: grid;
  gap: 0.4rem;
  margin-top: 1rem;
}

.history-entry {
  display: flex;
  align-items: center;
  min-width: 0;
  border-radius: 10px;
}

.history-item {
  overflow: hidden;
  flex: 1;
  overflow: hidden;
  padding: 0.7rem;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--phact-ink);
  background: transparent;
  cursor: pointer;
  font: inherit;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-entry:hover,
.history-entry:has(.history-item.active) {
  border-color: rgba(111, 44, 255, 0.2);
  background: var(--phact-purple-soft);
}

.history-delete {
  display: inline-flex;
  flex: 0 0 2rem;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  margin-right: 0.25rem;
  border: 0;
  border-radius: 7px;
  color: var(--phact-steel);
  background: transparent;
  cursor: pointer;
  opacity: 0;
  transition: opacity 160ms ease, color 160ms ease, background 160ms ease;
}

.history-entry:hover .history-delete,
.history-delete:focus-visible {
  opacity: 1;
}

.history-delete:hover,
.history-delete:focus-visible {
  color: #bd2636;
  background: rgba(189, 38, 54, 0.1);
  outline: none;
}

.history-delete svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.chat-card {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 24px;
  border: 1px solid rgba(111, 44, 255, 0.13);
  background: color-mix(in srgb, var(--phact-surface) 88%, transparent);
  box-shadow: 0 20px 44px rgba(67, 38, 125, 0.14);
  backdrop-filter: blur(4px);
}

.chat-intro {
  padding: 1rem 1rem 0.5rem;
  animation: revealUp 520ms ease both;
}

.eyebrow {
  margin: 0 0 0.85rem;
  color: var(--phact-purple);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  font-weight: 800;
}

.chat-intro h1 {
  margin: 0;
  font-family: "Sora", sans-serif;
  font-size: clamp(1.2rem, 2.2vw, 1.75rem);
  line-height: 1.1;
}

.chat-intro p {
  margin: 1rem 0 0;
  color: var(--phact-steel);
  line-height: 1.65;
}

.chat-card {
  padding: 0.85rem;
  min-height: 72vh;
  animation: revealUp 680ms ease both;
}

.chat-frame {
  display: block;
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: calc(72vh - 1.7rem);
  border: 0;
  border-radius: 16px;
  background: var(--phact-surface-soft);
}

.chat-login-prompt {
  display: flex;
  flex: 1;
  min-height: calc(72vh - 1.7rem);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  animation: revealUp 680ms ease both;
}

.chat-login-graphic {
  display: grid;
  width: 5rem;
  height: 5rem;
  place-items: center;
  margin-bottom: 1.25rem;
  border: 1px solid rgba(111, 44, 255, 0.16);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 16px 32px rgba(67, 38, 125, 0.16);
}

.chat-login-graphic img {
  width: 3.6rem;
  height: auto;
}

.chat-login-eyebrow {
  margin: 0 0 0.65rem;
  color: var(--phact-purple);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.chat-login-prompt h1 {
  max-width: 28rem;
  margin: 0;
  font-family: "Sora", sans-serif;
  font-size: clamp(1.2rem, 2.2vw, 1.75rem);
  line-height: 1.15;
}

.chat-login-description {
  max-width: 31rem;
  margin: 1rem 0 1.5rem;
  color: var(--phact-steel);
  line-height: 1.65;
}

.install-prompt {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: min(28rem, calc(100vw - 2rem));
  padding: 0.8rem 0.9rem 0.8rem 1rem;
  border: 1px solid rgba(111, 44, 255, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 14px 30px rgba(67, 38, 125, 0.2);
}

.install-prompt[hidden] {
  display: none;
}

.install-prompt p {
  margin: 0.2rem 0 0;
  color: var(--phact-steel);
  font-size: 0.8rem;
}

.install-button,
.install-dismiss {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.install-button {
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  color: #fff;
  background: var(--phact-purple);
  white-space: nowrap;
}

.install-dismiss {
  flex: 0 0 2rem;
  width: 2rem;
  height: 2rem;
  align-self: flex-start;
  padding: 0;
  color: var(--phact-steel);
  background: transparent;
  font-size: 1.2rem;
  line-height: 1;
  display: grid;
  place-items: center;
}

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

@media (max-width: 940px) {
  .chat-card {
    min-height: 62dvh;
  }

  .chat-frame {
    min-height: calc(62dvh - 1.7rem);
  }

  .chat-login-prompt {
    min-height: calc(62dvh - 1.7rem);
  }
}

@media (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
    gap: 0.75rem;
    padding-top: 1rem;
  }

  .brand {
    gap: 0.6rem;
  }

  .brand-logo {
    height: 32px;
  }

  .brand-subtitle {
    font-size: 0.8rem;
  }

  .login-button {
    padding: 0.55rem 0.8rem;
    font-size: 0.85rem;
  }

  .layout {
    align-items: flex-start;
    flex-direction: column;
    padding: 0.75rem 0.75rem 1rem;
  }

  .history-panel,
  .history-panel.collapsed {
    flex-basis: auto;
    width: 100%;
    padding: 0.8rem;
  }

  .chat-card {
    min-height: 58dvh;
    border-radius: 18px;
    padding: 0.6rem;
  }

  .chat-intro {
    padding: 0.75rem 0.65rem 0.4rem;
  }

  .chat-intro p {
    margin-top: 0.7rem;
    font-size: 0.8rem;
  }

  .chat-frame {
    min-height: calc(58dvh - 1.2rem);
    border-radius: 12px;
  }

  .chat-login-prompt {
    min-height: calc(58dvh - 1.2rem);
    padding: 1.5rem 1rem;
  }

  .chat-login-graphic {
    width: 4.5rem;
    height: 4.5rem;
    margin-bottom: 1.25rem;
  }

  .chat-login-graphic img {
    width: 3.2rem;
  }

  .chat-login-description {
    font-size: 0.8rem;
  }

  .install-prompt {
    right: 0.75rem;
    bottom: 0.75rem;
    left: 0.75rem;
    gap: 0.65rem;
  }

  .install-prompt p {
    font-size: 0.75rem;
  }
}
