.account-main {
  width: min(900px, 100%);
}

.account-page,
.legal-page {
  display: grid;
  gap: 1rem;
}

.account-kicker {
  margin: 0 0 0.35rem;
  color: #a9caff;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  line-height: 1.2;
  text-transform: uppercase;
}

.account-panel,
.account-privacy-note,
.legal-section {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(8, 14, 34, 0.78);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.2);
}

.account-panel {
  min-height: 22rem;
  padding: clamp(1rem, 2.8vw, 1.65rem);
}

.account-panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.account-panel-heading h2,
.account-privacy-note h2,
.legal-section h2 {
  margin-top: 0;
}

.account-status,
.account-summary p,
.account-delete-note,
.account-privacy-note p,
.legal-section p,
.legal-section li {
  color: #dbe7ff;
}

.account-status {
  margin: 0;
}

.account-error {
  padding: 0.85rem 1rem;
  border: 1px solid #d06c77;
  border-radius: 10px;
  color: #ffe8eb;
  background: rgba(112, 26, 40, 0.32);
}

.account-sign-in {
  display: grid;
  place-items: center;
  min-height: 18rem;
}

.account-signed-in {
  display: grid;
  gap: 1rem;
}

.account-summary {
  padding: 1rem;
  border: 1px solid rgba(122, 168, 255, 0.28);
  border-radius: 14px;
  background: rgba(20, 34, 70, 0.54);
}

.account-summary-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.account-plan {
  margin: 0.2rem 0 0.65rem;
  color: #fff;
  font-size: clamp(1.5rem, 1.15rem + 1vw, 2rem);
  font-weight: 800;
}

.account-history {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid rgba(122, 168, 255, 0.28);
  border-radius: 14px;
  background: rgba(10, 21, 50, 0.56);
}

.account-history > p,
.account-history-item p,
.account-history-empty {
  margin: 0;
  color: #dbe7ff;
}

.account-history-heading,
.account-history-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.account-history-heading h3,
.account-history-library h4,
.account-history-item h5 {
  margin: 0;
}

.account-history-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 44px;
  cursor: pointer;
}

.account-history-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.account-history-switch span {
  position: relative;
  flex: 0 0 auto;
  width: 2.75rem;
  height: 1.55rem;
  border: 1px solid #7790bc;
  border-radius: 999px;
  background: #263453;
  transition: background-color 160ms ease, border-color 160ms ease;
}

.account-history-switch span::after {
  position: absolute;
  top: 0.18rem;
  left: 0.18rem;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  background: #fff;
  content: "";
  transition: transform 160ms ease;
}

.account-history-switch input:checked + span {
  border-color: #6ed49a;
  background: #237346;
}

.account-history-switch input:checked + span::after {
  transform: translateX(1.18rem);
}

.account-history-switch input:focus-visible + span {
  outline: 3px solid rgba(122, 168, 255, 0.65);
  outline-offset: 3px;
}

.account-history-switch input:disabled + span,
.account-history-switch input:disabled ~ strong {
  cursor: wait;
  opacity: 0.6;
}

.account-history-status {
  font-weight: 700;
}

.account-history-library,
.account-history-library > section,
.account-history-list,
.account-history-item {
  display: grid;
}

.account-history-library {
  gap: 1rem;
}

.account-history-library > section {
  gap: 0.65rem;
}

.account-history-list {
  gap: 0.55rem;
}

.account-history-item {
  gap: 0.2rem;
  padding: 0.8rem 0;
  border-top: 1px solid rgba(122, 168, 255, 0.2);
}

.account-history-item:first-child {
  border-top: 0;
}

.account-history-item p,
.account-history-empty {
  font-size: 0.9rem;
}

.account-history-detail {
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
  border: 1px solid rgba(122, 168, 255, 0.3);
  border-radius: 12px;
  background: rgba(4, 10, 28, 0.62);
}

.account-history-detail[hidden] {
  display: none;
}

.account-history-detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.account-history-detail-heading h4,
.account-history-detail-heading p {
  margin: 0;
}

.account-history-detail-messages {
  display: grid;
  gap: 0.75rem;
}

.account-history-detail-message {
  width: min(92%, 54rem);
  padding: 0.8rem 0.9rem;
  border: 1px solid rgba(122, 168, 255, 0.25);
  border-radius: 12px;
  background: rgba(16, 27, 54, 0.7);
}

.account-history-detail-user {
  justify-self: end;
  border-color: rgba(255, 206, 72, 0.38);
}

.account-history-detail-assistant {
  justify-self: start;
  border-left: 3px solid rgba(122, 168, 255, 0.75);
}

.account-history-detail-message strong {
  color: #ffdc73;
}

.account-history-detail-message p {
  margin: 0.35rem 0 0;
  color: #f4f7ff;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.account-history-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.account-history-item-action {
  min-height: 36px;
  padding: 0.35rem 0.65rem;
  border: 1px solid rgba(122, 168, 255, 0.38);
  border-radius: 8px;
  color: #e8f0ff;
  font: inherit;
  font-size: 0.86rem;
  background: rgba(20, 34, 70, 0.6);
  cursor: pointer;
}

.account-history-item-action:hover,
.account-history-item-action:focus-visible {
  border-color: #9fc0ff;
  background: rgba(38, 61, 112, 0.72);
}

.account-history-item-delete {
  border-color: rgba(208, 108, 119, 0.7);
  color: #ffe8eb;
}

.account-history-item-action:disabled {
  cursor: wait;
  opacity: 0.6;
}

.account-history-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.account-history-actions button {
  font: inherit;
  cursor: pointer;
}

.account-danger-button {
  border-color: #d06c77;
  color: #ffe8eb;
}

.account-danger-button:hover,
.account-danger-button:focus-visible {
  background: rgba(112, 26, 40, 0.46);
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.account-actions button {
  font: inherit;
  cursor: pointer;
}

.account-actions button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.account-delete-note {
  margin: 0;
  font-size: 0.94rem;
}

.account-privacy-note {
  padding: 1rem 1.15rem;
}

.account-privacy-note p {
  margin-bottom: 0;
}

.legal-header {
  margin-bottom: 0;
}

.legal-section {
  padding: clamp(1rem, 2.2vw, 1.4rem);
}

.legal-section :last-child {
  margin-bottom: 0;
}

.legal-section li + li {
  margin-top: 0.7rem;
}

.account-panel [hidden],
.account-page [hidden] {
  display: none !important;
}

@media (max-width: 720px) {
  .account-panel-heading,
  .account-history-heading,
  .account-history-detail-heading,
  .account-history-actions,
  .account-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .account-history-switch {
    align-self: flex-start;
  }

  .account-history-detail-message {
    width: 100%;
  }

  .account-user-button {
    align-self: flex-start;
  }

  .account-actions .action-link {
    justify-content: center;
    width: 100%;
  }
}
